juanelot commited on
Commit
fc3cf6d
verified
1 Parent(s): 6297154

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # Cargar el modelo y el tokenizador
5
+ model_name = "microsoft/DialoGPT-medium" # Puedes cambiar esto por otro modelo de chatbot
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ def chatbot(input, history=[]):
10
+ # Agregar el input del usuario al historial
11
+ history.append(input)
12
+
13
+ # Tokenizar la conversaci贸n
14
+ input_ids = tokenizer.encode(" ".join(history), return_tensors="pt")
15
+
16
+ # Generar una respuesta
17
+ output = model.generate(input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
18
+
19
+ # Decodificar la respuesta
20
+ response = tokenizer.decode(output[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
21
+
22
+ # Agregar la respuesta al historial
23
+ history.append(response)
24
+
25
+ return history, history
26
+
27
+ # Crear la interfaz de Gradio
28
+ iface = gr.Interface(
29
+ fn=chatbot,
30
+ inputs=["text", "state"],
31
+ outputs=["chatbot", "state"],
32
+ title="Tu Compa帽ero AI",
33
+ description="Un chatbot de IA dise帽ado para simular conversaciones personales.",
34
+ )
35
+
36
+ iface.launch()