longobardomartin commited on
Commit
11e2a72
1 Parent(s): 2bccea9

maqueta interfaz

Browse files
Files changed (1) hide show
  1. app.py +27 -3
app.py CHANGED
@@ -1,7 +1,31 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ # Funci贸n del bot que procesa el mensaje del usuario
4
+ def chatbot(message, history=[]):
5
+ # Agregar el mensaje del usuario al historial
6
+ history.append(("Usuario:", message))
7
+ # Generar una respuesta simple del bot
8
+ response = f"Bot: Entendido, has dicho '{message}'"
9
+ history.append((response,))
10
+ # Formatear el historial como un bloque de texto
11
+ chat_history = "\n".join([f"{msg[0]} {msg[1]}" if len(msg) > 1 else msg[0] for msg in history])
12
+ return chat_history, history
13
 
14
+ # Interfaz de Gradio
15
+ with gr.Blocks() as demo:
16
+ gr.Markdown("## Chatbot sencillo con Gradio")
17
+
18
+ # Caja para mostrar el historial de mensajes
19
+ chatbox = gr.Textbox(lines=10, label="Historial de mensajes", interactive=False)
20
+
21
+ # Caja para escribir mensajes
22
+ input_box = gr.Textbox(lines=1, placeholder="Escribe tu mensaje aqu铆", label="Mensaje")
23
+
24
+ # Almacenamiento interno para el historial de chat
25
+ state = gr.State([])
26
+
27
+ # L贸gica al presionar Enter en la caja de texto
28
+ input_box.submit(chatbot, inputs=[input_box, state], outputs=[chatbox, state])
29
+
30
+ # Ejecutar la aplicaci贸n
31
  demo.launch()