Jeremy Live commited on
Commit
713a6e6
1 Parent(s): 4eccef6
Files changed (1) hide show
  1. app.py +51 -42
app.py CHANGED
@@ -382,10 +382,11 @@ def create_ui():
382
  El asistente est谩 listo para responder tus preguntas sobre la base de datos.
383
  """)
384
 
385
- # Interfaz de chat - versi贸n simplificada para compatibilidad
386
  chatbot = gr.Chatbot(
387
  label="Chat",
388
- height=500
 
389
  )
390
 
391
  # 脕rea de entrada
@@ -437,48 +438,56 @@ def create_ui():
437
 
438
  return demo, chatbot, question_input, submit_button, streaming_output_display
439
 
440
- # Create the UI components
441
- demo, chatbot, question_input, submit_button, streaming_output_display = create_ui()
442
-
443
- def user_message(user_input: str, chat_history: List) -> Tuple[str, List]:
444
- """Add user message to chat history and clear input."""
445
- if not user_input.strip():
446
- return "", chat_history
447
- logger.info(f"User message: {user_input}")
448
- return "", chat_history + [[user_input, None]]
449
-
450
- def bot_response(chat_history: List) -> Tuple[List, Dict]:
451
- """Get bot response and update chat history."""
452
- if not chat_history or not chat_history[-1][0]:
453
- return chat_history, gr.update(visible=False)
454
 
455
- question = chat_history[-1][0]
456
- logger.info(f"Processing question: {question}")
457
- return stream_agent_response(question, chat_history[:-1])
458
-
459
- # Event handlers
460
- submit_click = submit_button.click(
461
- fn=user_message,
462
- inputs=[question_input, chatbot],
463
- outputs=[question_input, chatbot],
464
- queue=True
465
- ).then(
466
- fn=bot_response,
467
- inputs=[chatbot],
468
- outputs=[chatbot, streaming_output_display],
469
- api_name="ask"
470
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
 
472
- question_input.submit(
473
- fn=user_message,
474
- inputs=[question_input, chatbot],
475
- outputs=[question_input, chatbot],
476
- queue=True
477
- ).then(
478
- fn=bot_response,
479
- inputs=[chatbot],
480
- outputs=[chatbot, streaming_output_display]
481
- )
482
 
483
  # Configuraci贸n para Hugging Face Spaces
484
  def get_app():
 
382
  El asistente est谩 listo para responder tus preguntas sobre la base de datos.
383
  """)
384
 
385
+ # Interfaz de chat - usando el nuevo formato de mensajes
386
  chatbot = gr.Chatbot(
387
  label="Chat",
388
+ height=500,
389
+ type="messages" # Usando el nuevo formato de mensajes
390
  )
391
 
392
  # 脕rea de entrada
 
438
 
439
  return demo, chatbot, question_input, submit_button, streaming_output_display
440
 
441
+ def create_application():
442
+ """Create and configure the Gradio application."""
443
+ # Create the UI components
444
+ demo, chatbot, question_input, submit_button, streaming_output_display = create_ui()
 
 
 
 
 
 
 
 
 
 
445
 
446
+ def user_message(user_input: str, chat_history: List) -> Tuple[str, List]:
447
+ """Add user message to chat history and clear input."""
448
+ if not user_input.strip():
449
+ return "", chat_history
450
+ logger.info(f"User message: {user_input}")
451
+ return "", chat_history + [[user_input, None]]
452
+
453
+ def bot_response(chat_history: List) -> Tuple[List, Dict]:
454
+ """Get bot response and update chat history."""
455
+ if not chat_history or not chat_history[-1][0]:
456
+ return chat_history, gr.update(visible=False)
457
+
458
+ question = chat_history[-1][0]
459
+ logger.info(f"Processing question: {question}")
460
+ return stream_agent_response(question, chat_history[:-1])
461
+
462
+ # Event handlers
463
+ with demo:
464
+ submit_click = submit_button.click(
465
+ fn=user_message,
466
+ inputs=[question_input, chatbot],
467
+ outputs=[question_input, chatbot],
468
+ queue=True
469
+ ).then(
470
+ fn=bot_response,
471
+ inputs=[chatbot],
472
+ outputs=[chatbot, streaming_output_display],
473
+ api_name="ask"
474
+ )
475
+
476
+ question_input.submit(
477
+ fn=user_message,
478
+ inputs=[question_input, chatbot],
479
+ outputs=[question_input, chatbot],
480
+ queue=True
481
+ ).then(
482
+ fn=bot_response,
483
+ inputs=[chatbot],
484
+ outputs=[chatbot, streaming_output_display]
485
+ )
486
+
487
+ return demo
488
 
489
+ # Create the application
490
+ demo = create_application()
 
 
 
 
 
 
 
 
491
 
492
  # Configuraci贸n para Hugging Face Spaces
493
  def get_app():