Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_name = "mistralai/Mistral-7B-Instruct-v0.1" # Can switch to Llama later
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
model_name,
|
| 10 |
+
torch_dtype=torch.bfloat16,
|
| 11 |
+
device_map="auto"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
def chat(prompt):
|
| 15 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 16 |
+
output = model.generate(**inputs, max_new_tokens=500)
|
| 17 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 18 |
+
return response
|
| 19 |
+
|
| 20 |
+
demo = gr.Interface(fn=chat, inputs="text", outputs="text")
|
| 21 |
+
|
| 22 |
+
demo.launch()
|