Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
def model(params):
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
app = gr.Interface(fn=model, inputs="textbox", outputs="textbox")
|
7 |
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
import torch
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
model_id = "meta-llama/Llama-3.2-3B-Instruct"
|
7 |
+
pipe = pipeline(
|
8 |
+
"text-generation",
|
9 |
+
model=model_id,
|
10 |
+
torch_dtype=torch.bfloat16,
|
11 |
+
device_map="auto",
|
12 |
+
)
|
13 |
+
messages = [
|
14 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
15 |
+
{"role": "user", "content": "Who are you?"},
|
16 |
+
]
|
17 |
+
|
18 |
+
|
19 |
def model(params):
|
20 |
+
outputs = pipe(
|
21 |
+
messages,
|
22 |
+
max_new_tokens=256,
|
23 |
+
)
|
24 |
+
output = outputs[0]["generated_text"][-1]
|
25 |
+
print(output)
|
26 |
+
return output
|
27 |
|
28 |
app = gr.Interface(fn=model, inputs="textbox", outputs="textbox")
|
29 |
app.launch()
|