Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -796,14 +796,21 @@ if __name__ == "__main__":
|
|
| 796 |
]
|
| 797 |
)
|
| 798 |
|
| 799 |
-
# New chat button
|
| 800 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 801 |
|
| 802 |
-
# Clear functionality
|
| 803 |
-
|
| 804 |
-
fn=clear,
|
| 805 |
-
outputs=[current_langgraph_state, current_uuid_state]
|
| 806 |
-
)
|
| 807 |
|
| 808 |
# Main chat interface - with compatibility checks
|
| 809 |
chat_interface_kwargs = {
|
|
@@ -862,6 +869,25 @@ if __name__ == "__main__":
|
|
| 862 |
*followup_question_buttons,
|
| 863 |
]
|
| 864 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 865 |
|
| 866 |
# Follow-up button functionality
|
| 867 |
def click_followup_button(btn):
|
|
|
|
| 796 |
]
|
| 797 |
)
|
| 798 |
|
| 799 |
+
# New chat button and clear button
|
| 800 |
+
with gr.Row():
|
| 801 |
+
new_chat_button = gr.Button("➕ New Chat", elem_id="new-chat-button", scale=1)
|
| 802 |
+
# Check if variant parameter is supported for buttons
|
| 803 |
+
try:
|
| 804 |
+
clear_button_kwargs = {"scale": 1}
|
| 805 |
+
if 'variant' in gr.Button.__init__.__code__.co_varnames:
|
| 806 |
+
clear_button_kwargs["variant"] = "secondary"
|
| 807 |
+
clear_chat_button = gr.Button("🗑️ Clear Chat", **clear_button_kwargs)
|
| 808 |
+
except Exception as e:
|
| 809 |
+
logger.warning(f"Error creating clear button with variant: {e}")
|
| 810 |
+
clear_chat_button = gr.Button("🗑️ Clear Chat", scale=1)
|
| 811 |
|
| 812 |
+
# Clear functionality - implement manually since chatbot.clear() is not available in older Gradio versions
|
| 813 |
+
# We'll handle clearing through the clear chat button instead
|
|
|
|
|
|
|
|
|
|
| 814 |
|
| 815 |
# Main chat interface - with compatibility checks
|
| 816 |
chat_interface_kwargs = {
|
|
|
|
| 869 |
*followup_question_buttons,
|
| 870 |
]
|
| 871 |
)
|
| 872 |
+
|
| 873 |
+
# Clear chat button functionality
|
| 874 |
+
def clear_current_chat():
|
| 875 |
+
"""Clear the current chat and reset state"""
|
| 876 |
+
new_state, new_uuid = clear()
|
| 877 |
+
# Clear followup buttons
|
| 878 |
+
cleared_buttons = [gr.Button(visible=False) for _ in range(FOLLOWUP_QUESTION_NUMBER)]
|
| 879 |
+
return [], new_state, new_uuid, *cleared_buttons
|
| 880 |
+
|
| 881 |
+
clear_chat_button.click(
|
| 882 |
+
fn=clear_current_chat,
|
| 883 |
+
inputs=[],
|
| 884 |
+
outputs=[
|
| 885 |
+
chatbot,
|
| 886 |
+
current_langgraph_state,
|
| 887 |
+
current_uuid_state,
|
| 888 |
+
*followup_question_buttons
|
| 889 |
+
]
|
| 890 |
+
)
|
| 891 |
|
| 892 |
# Follow-up button functionality
|
| 893 |
def click_followup_button(btn):
|