Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -656,12 +656,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
656 |
no_key_msg = "L'Agente AI non è disponibile. Assicurati che GEMINI_API_KEY sia configurata e che l'agente sia caricato."
|
657 |
current_chat_history.append([user_message, no_key_msg])
|
658 |
# Ensure all outputs are updated
|
659 |
-
|
|
|
660 |
|
661 |
if not user_message.strip():
|
662 |
# Ensure all outputs are updated even for empty message
|
663 |
-
|
664 |
-
|
|
|
665 |
status_update_msg = "Stato Agente: Elaborazione della tua richiesta..."
|
666 |
pending_history = current_chat_history + [[user_message, None]]
|
667 |
# Yield intermediate state to show user message immediately
|
@@ -720,8 +722,9 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
720 |
error_msg = "Errore: Impossibile inizializzare l'agente AI."
|
721 |
# Use pending_history which already has the user message
|
722 |
updated_history = pending_history[:-1] + [[user_message, error_msg]] # Replace None with error
|
723 |
-
|
724 |
-
|
|
|
725 |
logging.info(f"Sending to EB Agent. User: '{user_message}'. DF Keys: {list(dataframes_for_agent.keys())}")
|
726 |
ai_response_dict = await current_agent.process_query(user_query=user_message)
|
727 |
|
@@ -763,16 +766,17 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
763 |
updated_history = pending_history[:-1] + [[user_message, bot_message_for_display]]
|
764 |
|
765 |
status_update_msg = "Stato Agente: Risposta ricevuta."
|
766 |
-
|
767 |
-
|
|
|
768 |
except Exception as e:
|
769 |
logging.error(f"Error during EB Agent processing: {e}", exc_info=True)
|
770 |
error_msg_for_chat = f"# Errore dell'Agente AI:\n{type(e).__name__}: {str(e)}"
|
771 |
# Use pending_history which already has the user message
|
772 |
updated_history = pending_history[:-1] + [[user_message, error_msg_for_chat]]
|
773 |
status_update_msg = f"Stato Agente: Errore - {type(e).__name__}"
|
774 |
-
|
775 |
-
|
776 |
|
777 |
def clear_eb_agent_chat_history():
|
778 |
initial_msg = "Ciao! Sono il tuo Agente AI per l'Employer Branding. Come posso aiutarti?" if EB_AGENT_AVAILABLE else "Agente AI non disponibile."
|
|
|
656 |
no_key_msg = "L'Agente AI non è disponibile. Assicurati che GEMINI_API_KEY sia configurata e che l'agente sia caricato."
|
657 |
current_chat_history.append([user_message, no_key_msg])
|
658 |
# Ensure all outputs are updated
|
659 |
+
yield current_chat_history, current_chat_history, gr.update(value=""), gr.update(value=no_key_msg), gr.update(value="Nessuno schema disponibile.")
|
660 |
+
return
|
661 |
|
662 |
if not user_message.strip():
|
663 |
# Ensure all outputs are updated even for empty message
|
664 |
+
yield current_chat_history, current_chat_history, gr.update(value=""), gr.update(value="Stato Agente: Per favore, inserisci una domanda."), gr.update()
|
665 |
+
return
|
666 |
+
|
667 |
status_update_msg = "Stato Agente: Elaborazione della tua richiesta..."
|
668 |
pending_history = current_chat_history + [[user_message, None]]
|
669 |
# Yield intermediate state to show user message immediately
|
|
|
722 |
error_msg = "Errore: Impossibile inizializzare l'agente AI."
|
723 |
# Use pending_history which already has the user message
|
724 |
updated_history = pending_history[:-1] + [[user_message, error_msg]] # Replace None with error
|
725 |
+
yield updated_history, updated_history, gr.update(value=""), gr.update(value="Stato Agente: Errore di inizializzazione"), gr.update(value=schemas_text_for_display)
|
726 |
+
return
|
727 |
+
|
728 |
logging.info(f"Sending to EB Agent. User: '{user_message}'. DF Keys: {list(dataframes_for_agent.keys())}")
|
729 |
ai_response_dict = await current_agent.process_query(user_query=user_message)
|
730 |
|
|
|
766 |
updated_history = pending_history[:-1] + [[user_message, bot_message_for_display]]
|
767 |
|
768 |
status_update_msg = "Stato Agente: Risposta ricevuta."
|
769 |
+
yield updated_history, updated_history, gr.update(value=""), gr.update(value=status_update_msg), gr.update(value=schemas_text_for_display)
|
770 |
+
return
|
771 |
+
|
772 |
except Exception as e:
|
773 |
logging.error(f"Error during EB Agent processing: {e}", exc_info=True)
|
774 |
error_msg_for_chat = f"# Errore dell'Agente AI:\n{type(e).__name__}: {str(e)}"
|
775 |
# Use pending_history which already has the user message
|
776 |
updated_history = pending_history[:-1] + [[user_message, error_msg_for_chat]]
|
777 |
status_update_msg = f"Stato Agente: Errore - {type(e).__name__}"
|
778 |
+
yield updated_history, updated_history, gr.update(value=""), gr.update(value=status_update_msg), gr.update(value=schemas_text_for_display)
|
779 |
+
return
|
780 |
|
781 |
def clear_eb_agent_chat_history():
|
782 |
initial_msg = "Ciao! Sono il tuo Agente AI per l'Employer Branding. Come posso aiutarti?" if EB_AGENT_AVAILABLE else "Agente AI non disponibile."
|