Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Load the Mistral
|
| 6 |
-
model_name = "mistralai/Mistral-7B-v0.1"
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 14 |
-
model_name,
|
| 15 |
-
device_map="auto",
|
| 16 |
-
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
| 17 |
-
token=True
|
| 18 |
-
).to(device)
|
| 19 |
|
| 20 |
# Define chatbot function
|
| 21 |
def chat_with_mistral(user_input):
|
| 22 |
try:
|
| 23 |
-
inputs = tokenizer(user_input, return_tensors="pt").to(
|
| 24 |
outputs = model.generate(
|
| 25 |
**inputs,
|
| 26 |
max_new_tokens=100,
|
|
@@ -45,4 +40,3 @@ chatbot = gr.Interface(
|
|
| 45 |
|
| 46 |
# Launch app
|
| 47 |
chatbot.launch()
|
| 48 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Load a smaller version of the Mistral model (4-bit quantized)
|
| 6 |
+
model_name = "mistralai/Mistral-7B-Instruct-v0.1"
|
| 7 |
+
quantization_config = BitsAndBytesConfig(
|
| 8 |
+
load_in_4bit=True,
|
| 9 |
+
bnb_4bit_compute_dtype=torch.float16
|
| 10 |
+
)
|
| 11 |
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, token=True)
|
| 13 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=quantization_config, token=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Define chatbot function
|
| 16 |
def chat_with_mistral(user_input):
|
| 17 |
try:
|
| 18 |
+
inputs = tokenizer(user_input, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
| 19 |
outputs = model.generate(
|
| 20 |
**inputs,
|
| 21 |
max_new_tokens=100,
|
|
|
|
| 40 |
|
| 41 |
# Launch app
|
| 42 |
chatbot.launch()
|
|
|