Spaces:
Running
Running
no filters warning fully working with examples
Browse files
app.py
CHANGED
@@ -572,18 +572,7 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
572 |
|
573 |
|
574 |
#-------------------- New UI elements for Feedback -------------------------
|
575 |
-
|
576 |
-
# gr.Markdown("Was this response helpful?")
|
577 |
-
# with gr.Row():
|
578 |
-
# okay_btn = gr.Button("👍 Okay", elem_classes="feedback-button")
|
579 |
-
# not_okay_btn = gr.Button("👎 Not to expectations", elem_classes="feedback-button")
|
580 |
-
#
|
581 |
-
# feedback_thanks = gr.Markdown("Thanks for the feedback!", visible=False)
|
582 |
-
# feedback_state = gr.State() # Add state to store logs data
|
583 |
-
|
584 |
-
def show_feedback(logs):
|
585 |
-
"""Show feedback buttons and store logs in state"""
|
586 |
-
return gr.update(visible=True), gr.update(visible=False), logs
|
587 |
|
588 |
def submit_feedback_okay(logs_data):
|
589 |
"""Handle 'okay' feedback submission"""
|
@@ -593,7 +582,7 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
593 |
"""Handle 'not okay' feedback submission"""
|
594 |
return submit_feedback("not_okay", logs_data)
|
595 |
|
596 |
-
def
|
597 |
"""Handle feedback display with proper output format"""
|
598 |
if logs_data is None:
|
599 |
return (
|
@@ -668,43 +657,10 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
668 |
None # no need to store query
|
669 |
)
|
670 |
|
671 |
-
# async def handle_chat_flow(warning_active, query, chatbot, sources, reports, subtype, year, client_ip, session_id):
|
672 |
-
# """Handle chat flow with hard stop for warnings"""
|
673 |
-
# # Check if any filters are selected
|
674 |
-
# no_filters = (not reports) and (not sources) and (not subtype) and (not year)
|
675 |
-
|
676 |
-
# if warning_active: # Only check warning_active, not no_filters
|
677 |
-
# # If warning is active, return unchanged components
|
678 |
-
# return (
|
679 |
-
# chatbot, # unchanged chatbot
|
680 |
-
# "", # empty sources
|
681 |
-
# None, # no feedback state
|
682 |
-
# session_id # keep session
|
683 |
-
# )
|
684 |
-
|
685 |
-
# # Include start_chat functionality here
|
686 |
-
# history = chatbot + [(query, None)]
|
687 |
-
# history = [tuple(x) for x in history]
|
688 |
-
|
689 |
-
# # Proceed with chat
|
690 |
-
# async for update in chat(query, history, sources, reports, subtype, year, client_ip, session_id):
|
691 |
-
# # The last update will be returned
|
692 |
-
# chatbot_update, sources_update, feedback_update, session_update = update
|
693 |
-
|
694 |
-
# return (
|
695 |
-
# chatbot_update,
|
696 |
-
# sources_update,
|
697 |
-
# feedback_update,
|
698 |
-
# session_update
|
699 |
-
# )
|
700 |
-
|
701 |
async def handle_chat_flow(warning_active, query, chatbot, sources, reports, subtype, year, client_ip, session_id):
|
702 |
-
"""Handle chat flow with
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
if warning_active: # Only check warning_active, not no_filters
|
707 |
-
# If warning is active, yield unchanged components instead of returning
|
708 |
yield (
|
709 |
chatbot, # unchanged chatbot
|
710 |
"", # empty sources
|
@@ -721,50 +677,80 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
721 |
async for update in chat(query, history, sources, reports, subtype, year, client_ip, session_id):
|
722 |
yield update
|
723 |
|
724 |
-
#-------------------- Gradio
|
725 |
|
726 |
-
#
|
727 |
-
# (textbox
|
728 |
-
# .submit(get_client_ip_handler, [textbox], [client_ip], api_name="get_ip_textbox")
|
729 |
-
# .then(start_chat, [textbox, chatbot], [textbox, tabs, chatbot], queue=False, api_name="start_chat_textbox")
|
730 |
-
# .then(chat,
|
731 |
-
# [textbox, chatbot, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year, client_ip, session_id],
|
732 |
-
# [chatbot, sources_textbox, feedback_state, session_id],
|
733 |
-
# queue=True, concurrency_limit=8, api_name="chat_textbox")
|
734 |
-
# .then(show_feedback, [feedback_state], [feedback_row, feedback_thanks, feedback_state], api_name="show_feedback_textbox")
|
735 |
-
# .then(finish_chat, None, [textbox], api_name="finish_chat_textbox"))
|
736 |
-
|
737 |
(textbox
|
738 |
.submit(
|
739 |
check_filters,
|
740 |
[textbox, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year],
|
741 |
-
[warning_state, warning_row, textbox, pending_query]
|
|
|
742 |
)
|
743 |
.then(
|
744 |
get_client_ip_handler,
|
745 |
[textbox],
|
746 |
[client_ip],
|
747 |
-
show_progress=False
|
|
|
748 |
)
|
749 |
.then(
|
750 |
handle_chat_flow,
|
751 |
[warning_state, textbox, chatbot, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year, client_ip, session_id],
|
752 |
[chatbot, sources_textbox, feedback_state, session_id],
|
753 |
-
queue=True
|
|
|
754 |
)
|
755 |
.then(
|
756 |
-
|
757 |
[feedback_state],
|
758 |
-
[feedback_row, feedback_thanks, feedback_state]
|
|
|
759 |
)
|
760 |
.then(
|
761 |
finish_chat,
|
762 |
None,
|
763 |
-
[textbox]
|
|
|
764 |
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
765 |
|
766 |
|
767 |
-
#
|
768 |
proceed_btn.click(
|
769 |
lambda query: (
|
770 |
False, # warning state
|
@@ -775,7 +761,7 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
775 |
pending_query,
|
776 |
[warning_state, warning_row, textbox, pending_query]
|
777 |
).then(
|
778 |
-
lambda: False,
|
779 |
None,
|
780 |
warning_state
|
781 |
).then(
|
@@ -786,9 +772,9 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
786 |
handle_chat_flow,
|
787 |
[warning_state, textbox, chatbot, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year, client_ip, session_id],
|
788 |
[chatbot, sources_textbox, feedback_state, session_id],
|
789 |
-
queue=True
|
790 |
).then(
|
791 |
-
|
792 |
[feedback_state],
|
793 |
[feedback_row, feedback_thanks, feedback_state]
|
794 |
).then(
|
@@ -808,15 +794,6 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
808 |
[warning_state, warning_row, textbox, pending_query]
|
809 |
)
|
810 |
|
811 |
-
(examples_hidden
|
812 |
-
.change(start_chat, [examples_hidden, chatbot], [textbox, tabs, chatbot], queue=False, api_name="start_chat_examples")
|
813 |
-
.then(get_client_ip_handler, [examples_hidden], [client_ip], api_name="get_ip_examples")
|
814 |
-
.then(chat,
|
815 |
-
[examples_hidden, chatbot, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year, client_ip, session_id],
|
816 |
-
[chatbot, sources_textbox, feedback_state, session_id],
|
817 |
-
concurrency_limit=8, api_name="chat_examples")
|
818 |
-
.then(show_feedback, [feedback_state], [feedback_row, feedback_thanks, feedback_state], api_name="show_feedback_examples")
|
819 |
-
.then(finish_chat, None, [textbox], api_name="finish_chat_examples"))
|
820 |
|
821 |
demo.queue()
|
822 |
|
|
|
572 |
|
573 |
|
574 |
#-------------------- New UI elements for Feedback -------------------------
|
575 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
576 |
|
577 |
def submit_feedback_okay(logs_data):
|
578 |
"""Handle 'okay' feedback submission"""
|
|
|
582 |
"""Handle 'not okay' feedback submission"""
|
583 |
return submit_feedback("not_okay", logs_data)
|
584 |
|
585 |
+
def show_feedback(logs_data):
|
586 |
"""Handle feedback display with proper output format"""
|
587 |
if logs_data is None:
|
588 |
return (
|
|
|
657 |
None # no need to store query
|
658 |
)
|
659 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
660 |
async def handle_chat_flow(warning_active, query, chatbot, sources, reports, subtype, year, client_ip, session_id):
|
661 |
+
"""Handle chat flow with warning check and chat processing"""
|
662 |
+
if warning_active or query is None:
|
663 |
+
# Either warning is active or query was stopped by filter check
|
|
|
|
|
|
|
664 |
yield (
|
665 |
chatbot, # unchanged chatbot
|
666 |
"", # empty sources
|
|
|
677 |
async for update in chat(query, history, sources, reports, subtype, year, client_ip, session_id):
|
678 |
yield update
|
679 |
|
680 |
+
#-------------------- Gradio Handlers -------------------------
|
681 |
|
682 |
+
# Hanlders: Text input from Textbox
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
683 |
(textbox
|
684 |
.submit(
|
685 |
check_filters,
|
686 |
[textbox, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year],
|
687 |
+
[warning_state, warning_row, textbox, pending_query],
|
688 |
+
api_name="submit_textbox"
|
689 |
)
|
690 |
.then(
|
691 |
get_client_ip_handler,
|
692 |
[textbox],
|
693 |
[client_ip],
|
694 |
+
show_progress=False,
|
695 |
+
api_name="get_client_ip_textbox"
|
696 |
)
|
697 |
.then(
|
698 |
handle_chat_flow,
|
699 |
[warning_state, textbox, chatbot, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year, client_ip, session_id],
|
700 |
[chatbot, sources_textbox, feedback_state, session_id],
|
701 |
+
queue=True,
|
702 |
+
api_name="handle_chat_flow_textbox"
|
703 |
)
|
704 |
.then(
|
705 |
+
show_feedback,
|
706 |
[feedback_state],
|
707 |
+
[feedback_row, feedback_thanks, feedback_state],
|
708 |
+
api_name="show_feedback_textbox"
|
709 |
)
|
710 |
.then(
|
711 |
finish_chat,
|
712 |
None,
|
713 |
+
[textbox],
|
714 |
+
api_name="finish_chat_textbox"
|
715 |
))
|
716 |
+
|
717 |
+
# Hanlders: Text input from Examples (same chain as textbox)
|
718 |
+
examples_hidden.change(
|
719 |
+
lambda x: x, # just get the example string and send it through the chain
|
720 |
+
inputs=examples_hidden,
|
721 |
+
outputs=textbox,
|
722 |
+
api_name="submit_examples"
|
723 |
+
).then(
|
724 |
+
check_filters,
|
725 |
+
[textbox, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year],
|
726 |
+
[warning_state, warning_row, textbox, pending_query],
|
727 |
+
api_name="check_filters_examples"
|
728 |
+
).then(
|
729 |
+
get_client_ip_handler,
|
730 |
+
[textbox],
|
731 |
+
[client_ip],
|
732 |
+
show_progress=False,
|
733 |
+
api_name="get_client_ip_examples"
|
734 |
+
).then(
|
735 |
+
handle_chat_flow,
|
736 |
+
[warning_state, textbox, chatbot, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year, client_ip, session_id],
|
737 |
+
[chatbot, sources_textbox, feedback_state, session_id],
|
738 |
+
queue=True,
|
739 |
+
api_name="handle_chat_flow_examples"
|
740 |
+
).then(
|
741 |
+
show_feedback,
|
742 |
+
[feedback_state],
|
743 |
+
[feedback_row, feedback_thanks, feedback_state],
|
744 |
+
api_name="show_feedback_examples"
|
745 |
+
).then(
|
746 |
+
finish_chat,
|
747 |
+
None,
|
748 |
+
[textbox],
|
749 |
+
api_name="finish_chat_examples"
|
750 |
+
)
|
751 |
|
752 |
|
753 |
+
# Handlers for the warning buttons
|
754 |
proceed_btn.click(
|
755 |
lambda query: (
|
756 |
False, # warning state
|
|
|
761 |
pending_query,
|
762 |
[warning_state, warning_row, textbox, pending_query]
|
763 |
).then(
|
764 |
+
lambda: False,
|
765 |
None,
|
766 |
warning_state
|
767 |
).then(
|
|
|
772 |
handle_chat_flow,
|
773 |
[warning_state, textbox, chatbot, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year, client_ip, session_id],
|
774 |
[chatbot, sources_textbox, feedback_state, session_id],
|
775 |
+
queue=True
|
776 |
).then(
|
777 |
+
show_feedback,
|
778 |
[feedback_state],
|
779 |
[feedback_row, feedback_thanks, feedback_state]
|
780 |
).then(
|
|
|
794 |
[warning_state, warning_row, textbox, pending_query]
|
795 |
)
|
796 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
797 |
|
798 |
demo.queue()
|
799 |
|