marceloelectrocyber commited on
Commit
1c5961d
·
verified ·
1 Parent(s): 1b1c502

Añadiendo app.py con código del chatbot

Browse files
Files changed (1) hide show
  1. app.py +18 -0
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()