LordCoffee commited on
Commit
38fb619
verified
1 Parent(s): 890afaa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, Conversation
3
+
4
+ # Modelo de Hugging Face para conversaci贸n
5
+ model_name = "microsoft/DialoGPT-large"
6
+ conversation_model = pipeline("conversational", model=model_name)
7
+
8
+ # Historial de la conversaci贸n, se mantendr谩 dentro del contexto de la aplicaci贸n
9
+ conversation = Conversation()
10
+
11
+ # Funci贸n para procesar la entrada del usuario y generar la respuesta
12
+ def chatbot_response(user_input):
13
+ # Agregar la respuesta del usuario al historial de la conversaci贸n
14
+ conversation.add_user_input(user_input)
15
+
16
+ # Generar la respuesta del bot
17
+ bot_response = conversation_model(user_input, conversation=conversation)["generated_text"]
18
+
19
+ # Agregar la respuesta del bot al historial de la conversaci贸n
20
+ conversation.add_system_output(bot_response)
21
+
22
+ # Retornar la respuesta del bot para mostrarla en la interfaz
23
+ return bot_response
24
+
25
+ # Ejecuci贸n de la aplicaci贸n
26
+ if __name__ == "__main__":
27
+ # Interfaz de Gradio para la aplicaci贸n web
28
+ iface = gr.Interface(
29
+ fn=chatbot_response,
30
+ inputs=gr.Textbox(lines=2, placeholder="Escribe tu mensaje aqu铆..."),
31
+ outputs=gr.Textbox(lines=2, placeholder="Respuesta del bot..."),
32
+ title="Entrevista de Programaci贸n - ChatBot",
33
+ theme="compact",
34
+ live=True
35
+ )
36
+
37
+ # Lanzar la interfaz de Gradio
38
+ iface.launch()