Spaces:
Sleeping
Sleeping
Añadiendo app.py con código del chatbot
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Cargar modelo Qwen2.5
|
6 |
+
model_name = "Qwen/Qwen2.5-7B"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
9 |
+
|
10 |
+
# Función de respuesta
|
11 |
+
def chat(message):
|
12 |
+
inputs = tokenizer(message, return_tensors="pt").to("cuda")
|
13 |
+
output = model.generate(**inputs, max_new_tokens=50)
|
14 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
15 |
+
|
16 |
+
# Interfaz Gradio
|
17 |
+
iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="Chat con Qwen2.5")
|
18 |
+
iface.launch()
|