Spaces:
Running
Running
streaming fixed
Browse files
app.py
CHANGED
@@ -668,35 +668,58 @@ 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,
|
678 |
-
|
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 |
-
|
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 |
#-------------------- Gradio voodoo -------------------------
|
702 |
|
@@ -710,7 +733,7 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
710 |
# queue=True, concurrency_limit=8, api_name="chat_textbox")
|
711 |
# .then(show_feedback, [feedback_state], [feedback_row, feedback_thanks, feedback_state], api_name="show_feedback_textbox")
|
712 |
# .then(finish_chat, None, [textbox], api_name="finish_chat_textbox"))
|
713 |
-
|
714 |
(textbox
|
715 |
.submit(
|
716 |
check_filters,
|
@@ -723,10 +746,11 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
723 |
[client_ip],
|
724 |
show_progress=False
|
725 |
)
|
726 |
-
.then(
|
727 |
handle_chat_flow,
|
728 |
[warning_state, textbox, chatbot, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year, client_ip, session_id],
|
729 |
-
[chatbot, sources_textbox, feedback_state, session_id]
|
|
|
730 |
)
|
731 |
.then(
|
732 |
handle_feedback,
|
@@ -758,10 +782,11 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
758 |
get_client_ip_handler,
|
759 |
[textbox],
|
760 |
[client_ip]
|
761 |
-
).then(
|
762 |
handle_chat_flow,
|
763 |
[warning_state, textbox, chatbot, dropdown_sources, dropdown_reports, dropdown_category, dropdown_year, client_ip, session_id],
|
764 |
-
[chatbot, sources_textbox, feedback_state, session_id]
|
|
|
765 |
).then(
|
766 |
handle_feedback,
|
767 |
[feedback_state],
|
|
|
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 hard stop for warnings"""
|
703 |
# Check if any filters are selected
|
704 |
no_filters = (not reports) and (not sources) and (not subtype) and (not year)
|
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
|
711 |
None, # no feedback state
|
712 |
session_id # keep session
|
713 |
)
|
714 |
+
return # Exit the generator
|
715 |
|
716 |
# Include start_chat functionality here
|
717 |
history = chatbot + [(query, None)]
|
718 |
history = [tuple(x) for x in history]
|
719 |
|
720 |
+
# Proceed with chat and yield each update
|
721 |
async for update in chat(query, history, sources, reports, subtype, year, client_ip, session_id):
|
722 |
+
yield update
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
723 |
|
724 |
#-------------------- Gradio voodoo -------------------------
|
725 |
|
|
|
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,
|
|
|
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 # Changed from streaming=True
|
754 |
)
|
755 |
.then(
|
756 |
handle_feedback,
|
|
|
782 |
get_client_ip_handler,
|
783 |
[textbox],
|
784 |
[client_ip]
|
785 |
+
).then(
|
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 # Changed from streaming=True
|
790 |
).then(
|
791 |
handle_feedback,
|
792 |
[feedback_state],
|