Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
@spaces.GPU
|
| 5 |
-
def greet(
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
demo = gr.Interface(
|
| 9 |
fn=greet,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
+
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct")
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct", device_map="auto")
|
| 7 |
+
|
| 8 |
|
| 9 |
@spaces.GPU
|
| 10 |
+
def greet(content, intensity):
|
| 11 |
+
messages = [
|
| 12 |
+
{"role": "user", "content": content},
|
| 13 |
+
]
|
| 14 |
+
inputs = tokenizer.apply_chat_template(
|
| 15 |
+
messages,
|
| 16 |
+
add_generation_prompt=True,
|
| 17 |
+
tokenize=True,
|
| 18 |
+
return_dict=True,
|
| 19 |
+
return_tensors="pt",
|
| 20 |
+
).to(model.device)
|
| 21 |
+
|
| 22 |
+
outputs = model.generate(**inputs, max_new_tokens=40)
|
| 23 |
+
|
| 24 |
+
return tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])
|
| 25 |
|
| 26 |
demo = gr.Interface(
|
| 27 |
fn=greet,
|