Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -629,21 +629,26 @@ def create_demo():
|
|
629 |
"content": "I apologize, but I'm experiencing technical difficulties. For emergencies, please call 999."
|
630 |
}]
|
631 |
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
|
|
|
|
|
|
|
|
|
|
647 |
# Create enhanced Gradio interface
|
648 |
with gr.Blocks(theme=gr.themes.Soft(
|
649 |
primary_hue="blue",
|
@@ -706,6 +711,33 @@ def create_demo():
|
|
706 |
}
|
707 |
</style>
|
708 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
709 |
|
710 |
# Emergency Banner
|
711 |
gr.HTML("""
|
@@ -820,17 +852,7 @@ def create_demo():
|
|
820 |
- Prescription renewals
|
821 |
""")
|
822 |
|
823 |
-
|
824 |
-
msg.submit(chat, [msg, chatbot], [chatbot]).then(
|
825 |
-
lambda: gr.update(value=""), None, [msg]
|
826 |
-
)
|
827 |
-
|
828 |
-
submit.click(chat, [msg, chatbot], [chatbot]).then(
|
829 |
-
lambda: gr.update(value=""), None, [msg]
|
830 |
-
)
|
831 |
-
|
832 |
-
# Add queue for handling multiple users
|
833 |
-
demo.queue(concurrency_count=1, max_size=10)
|
834 |
|
835 |
return demo
|
836 |
|
|
|
629 |
"content": "I apologize, but I'm experiencing technical difficulties. For emergencies, please call 999."
|
630 |
}]
|
631 |
|
632 |
+
def process_feedback(positive: bool, comment: str, history: list):
|
633 |
+
try:
|
634 |
+
if not history or len(history) < 2:
|
635 |
+
return gr.update(value="")
|
636 |
+
|
637 |
+
last_user_msg = history[-2]["content"] if isinstance(history[-2], dict) else history[-2][0]
|
638 |
+
last_bot_msg = history[-1]["content"] if isinstance(history[-1], dict) else history[-1][1]
|
639 |
+
|
640 |
+
bot.handle_feedback(
|
641 |
+
message=last_user_msg,
|
642 |
+
response=last_bot_msg,
|
643 |
+
feedback=1 if positive else -1
|
644 |
+
)
|
645 |
+
|
646 |
+
return gr.update(value="")
|
647 |
+
except Exception as e:
|
648 |
+
logger.error(f"Error processing feedback: {e}")
|
649 |
+
return gr.update(value="")
|
650 |
+
|
651 |
+
|
652 |
# Create enhanced Gradio interface
|
653 |
with gr.Blocks(theme=gr.themes.Soft(
|
654 |
primary_hue="blue",
|
|
|
711 |
}
|
712 |
</style>
|
713 |
""")
|
714 |
+
# Event Handlers - Moved inside the gr.Blocks context
|
715 |
+
msg.submit(chat, [msg, chatbot], [chatbot]).then(
|
716 |
+
lambda: gr.update(value=""), None, [msg]
|
717 |
+
)
|
718 |
+
|
719 |
+
submit.click(chat, [msg, chatbot], [chatbot]).then(
|
720 |
+
lambda: gr.update(value=""), None, [msg]
|
721 |
+
)
|
722 |
+
|
723 |
+
# Feedback handlers
|
724 |
+
feedback_positive.click(
|
725 |
+
lambda h: process_feedback(True, feedback_text.value, h),
|
726 |
+
inputs=[chatbot],
|
727 |
+
outputs=[feedback_text]
|
728 |
+
)
|
729 |
+
|
730 |
+
feedback_negative.click(
|
731 |
+
lambda h: process_feedback(False, feedback_text.value, h),
|
732 |
+
inputs=[chatbot],
|
733 |
+
outputs=[feedback_text]
|
734 |
+
)
|
735 |
+
|
736 |
+
# Clear chat
|
737 |
+
clear.click(lambda: None, None, chatbot)
|
738 |
+
|
739 |
+
# Add queue for handling multiple users
|
740 |
+
demo.queue(concurrency_count=1, max_size=10)
|
741 |
|
742 |
# Emergency Banner
|
743 |
gr.HTML("""
|
|
|
852 |
- Prescription renewals
|
853 |
""")
|
854 |
|
855 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
856 |
|
857 |
return demo
|
858 |
|