Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
model_id,
|
| 10 |
+
torch_dtype=torch.float32
|
| 11 |
+
).to("cpu")
|
| 12 |
+
|
| 13 |
+
def chat(prompt):
|
| 14 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 15 |
+
outputs = model.generate(**inputs, max_new_tokens=100, do_sample=True)
|
| 16 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 17 |
+
return response
|
| 18 |
+
|
| 19 |
+
gr.Interface(fn=chat, inputs="text", outputs="text", title="Stella AI").launch()
|