Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# ✅ Load your model
|
| 6 |
+
model_name = "meta-llama/Llama-3.2-1B-Instruct"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
model_name,
|
| 10 |
+
device_map="auto",
|
| 11 |
+
torch_dtype=torch.float16
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# ✅ Define chatbot function
|
| 15 |
+
def chatbot(prompt):
|
| 16 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 17 |
+
output = model.generate(**inputs, max_length=200)
|
| 18 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
| 19 |
+
|
| 20 |
+
# ✅ Deploy on Gradio
|
| 21 |
+
gr.Interface(fn=chatbot, inputs="text", outputs="text", title="Llama Chatbot").launch()
|