Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -329,25 +329,31 @@ class Gradio_Events:
|
|
| 329 |
return gr.update(value=e._data["payload"][0]["value"]["description"])
|
| 330 |
|
| 331 |
@staticmethod
|
| 332 |
-
def new_chat(state_value):
|
| 333 |
if not state_value["conversation_id"]:
|
| 334 |
return gr.skip()
|
| 335 |
state_value["conversation_id"] = ""
|
|
|
|
| 336 |
return gr.update(active_key=state_value["conversation_id"]), gr.update(
|
| 337 |
value=None), gr.update(value=DEFAULT_SETTINGS), gr.update(
|
| 338 |
-
value=state_value)
|
| 339 |
|
| 340 |
@staticmethod
|
| 341 |
-
def select_conversation(state_value,
|
|
|
|
| 342 |
active_key = e._data["payload"][0]
|
| 343 |
if state_value["conversation_id"] == active_key or (
|
| 344 |
active_key not in state_value["conversation_contexts"]):
|
| 345 |
return gr.skip()
|
| 346 |
state_value["conversation_id"] = active_key
|
|
|
|
|
|
|
| 347 |
return gr.update(active_key=active_key), gr.update(
|
| 348 |
value=state_value["conversation_contexts"][active_key]["history"]
|
| 349 |
), gr.update(value=state_value["conversation_contexts"][active_key]
|
| 350 |
-
["settings"]), gr.update(
|
|
|
|
|
|
|
| 351 |
|
| 352 |
@staticmethod
|
| 353 |
def click_conversation_menu(state_value, e: gr.EventData):
|
|
@@ -379,14 +385,6 @@ class Gradio_Events:
|
|
| 379 |
"open"] = not settings_header_state_value["open"]
|
| 380 |
return gr.update(value=settings_header_state_value)
|
| 381 |
|
| 382 |
-
@staticmethod
|
| 383 |
-
def apply_thinking_btn_state(thinking_btn_state_value, state_value):
|
| 384 |
-
if not state_value["conversation_id"]:
|
| 385 |
-
return gr.skip()
|
| 386 |
-
state_value["conversation_contexts"][state_value["conversation_id"]][
|
| 387 |
-
"enable_thinking"] = thinking_btn_state_value["enable_thinking"]
|
| 388 |
-
return gr.update(value=state_value)
|
| 389 |
-
|
| 390 |
@staticmethod
|
| 391 |
def clear_conversation_history(state_value):
|
| 392 |
if not state_value["conversation_id"]:
|
|
@@ -579,14 +577,18 @@ with gr.Blocks(css=css, js=js, fill_width=True) as demo:
|
|
| 579 |
outputs=[conversations, state])
|
| 580 |
|
| 581 |
# Conversations Handler
|
| 582 |
-
add_conversation_btn.click(
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 590 |
conversations.menu_click(fn=Gradio_Events.click_conversation_menu,
|
| 591 |
inputs=[state],
|
| 592 |
outputs=[conversations, chatbot, state])
|
|
@@ -626,9 +628,6 @@ with gr.Blocks(css=css, js=js, fill_width=True) as demo:
|
|
| 626 |
cancels=[submit_event, regenerating_event],
|
| 627 |
queue=False)
|
| 628 |
# Input Actions Handler
|
| 629 |
-
thinking_btn_state.change(fn=Gradio_Events.apply_thinking_btn_state,
|
| 630 |
-
inputs=[thinking_btn_state, state],
|
| 631 |
-
outputs=[state])
|
| 632 |
setting_btn.click(fn=Gradio_Events.toggle_settings_header,
|
| 633 |
inputs=[settings_header_state],
|
| 634 |
outputs=[settings_header_state])
|
|
|
|
| 329 |
return gr.update(value=e._data["payload"][0]["value"]["description"])
|
| 330 |
|
| 331 |
@staticmethod
|
| 332 |
+
def new_chat(thinking_btn_state, state_value):
|
| 333 |
if not state_value["conversation_id"]:
|
| 334 |
return gr.skip()
|
| 335 |
state_value["conversation_id"] = ""
|
| 336 |
+
thinking_btn_state["enable_thinking"] = True
|
| 337 |
return gr.update(active_key=state_value["conversation_id"]), gr.update(
|
| 338 |
value=None), gr.update(value=DEFAULT_SETTINGS), gr.update(
|
| 339 |
+
value=thinking_btn_state), gr.update(value=state_value)
|
| 340 |
|
| 341 |
@staticmethod
|
| 342 |
+
def select_conversation(thinking_btn_state_value, state_value,
|
| 343 |
+
e: gr.EventData):
|
| 344 |
active_key = e._data["payload"][0]
|
| 345 |
if state_value["conversation_id"] == active_key or (
|
| 346 |
active_key not in state_value["conversation_contexts"]):
|
| 347 |
return gr.skip()
|
| 348 |
state_value["conversation_id"] = active_key
|
| 349 |
+
thinking_btn_state_value["enable_thinking"] = state_value[
|
| 350 |
+
"conversation_contexts"][active_key]["enable_thinking"]
|
| 351 |
return gr.update(active_key=active_key), gr.update(
|
| 352 |
value=state_value["conversation_contexts"][active_key]["history"]
|
| 353 |
), gr.update(value=state_value["conversation_contexts"][active_key]
|
| 354 |
+
["settings"]), gr.update(
|
| 355 |
+
value=thinking_btn_state_value), gr.update(
|
| 356 |
+
value=state_value)
|
| 357 |
|
| 358 |
@staticmethod
|
| 359 |
def click_conversation_menu(state_value, e: gr.EventData):
|
|
|
|
| 385 |
"open"] = not settings_header_state_value["open"]
|
| 386 |
return gr.update(value=settings_header_state_value)
|
| 387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
@staticmethod
|
| 389 |
def clear_conversation_history(state_value):
|
| 390 |
if not state_value["conversation_id"]:
|
|
|
|
| 577 |
outputs=[conversations, state])
|
| 578 |
|
| 579 |
# Conversations Handler
|
| 580 |
+
add_conversation_btn.click(fn=Gradio_Events.new_chat,
|
| 581 |
+
inputs=[thinking_btn_state, state],
|
| 582 |
+
outputs=[
|
| 583 |
+
conversations, chatbot, settings_form,
|
| 584 |
+
thinking_btn_state, state
|
| 585 |
+
])
|
| 586 |
+
conversations.active_change(fn=Gradio_Events.select_conversation,
|
| 587 |
+
inputs=[thinking_btn_state, state],
|
| 588 |
+
outputs=[
|
| 589 |
+
conversations, chatbot, settings_form,
|
| 590 |
+
thinking_btn_state, state
|
| 591 |
+
])
|
| 592 |
conversations.menu_click(fn=Gradio_Events.click_conversation_menu,
|
| 593 |
inputs=[state],
|
| 594 |
outputs=[conversations, chatbot, state])
|
|
|
|
| 628 |
cancels=[submit_event, regenerating_event],
|
| 629 |
queue=False)
|
| 630 |
# Input Actions Handler
|
|
|
|
|
|
|
|
|
|
| 631 |
setting_btn.click(fn=Gradio_Events.toggle_settings_header,
|
| 632 |
inputs=[settings_header_state],
|
| 633 |
outputs=[settings_header_state])
|