Spaces:
Build error
Build error
Add application file
Browse files- app.py +17 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
# Загружаем Mistral-7B
|
| 5 |
+
model_name = "mistralai/Mistral-7B-Instruct-v0.1"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
| 8 |
+
|
| 9 |
+
def chat(message):
|
| 10 |
+
inputs = tokenizer(message, return_tensors="pt").to("cpu")
|
| 11 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
| 12 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 13 |
+
return response
|
| 14 |
+
|
| 15 |
+
iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="Mistral-7B Chatbot")
|
| 16 |
+
iface.launch()
|
| 17 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
gradio
|
| 4 |
+
|