Lzy01241010 commited on
Commit
e717b76
·
1 Parent(s): e92ff2c

fix: Stop button actually cancels run_ui generator (not the .then lambda)

Browse files

run_event was captured from .click().then(), so it pointed at the chained
0ms textbox-clear lambda. stop_btn.cancels=[run_event] was therefore
cancelling that no-op while the actual research generator kept running.
Capture .click() into run_event first, then chain .then() separately.

Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -2600,13 +2600,19 @@ with gr.Blocks(
2600
  """
2601
  )
2602
 
 
 
 
 
 
2603
  run_event = run_btn.click(
2604
  fn=run_ui,
2605
  inputs=[question, max_turns, memory_strategy, temperature],
2606
  outputs=[answer, trace],
2607
- ).then(
2608
- # Auto-clear the question textbox once the run finishes so the user
2609
- # can immediately ask a follow-up without manually pressing Clear.
 
2610
  fn=lambda: "",
2611
  inputs=[],
2612
  outputs=[question],
 
2600
  """
2601
  )
2602
 
2603
+ # IMPORTANT: keep `run_event` pointing at the .click() (the long-running
2604
+ # generator), not at the chained .then(). stop_btn.cancels=[run_event]
2605
+ # must target the generator for Stop to actually interrupt it; if we
2606
+ # capture the .then() result instead, Stop cancels the instant clear
2607
+ # lambda and the agent keeps running.
2608
  run_event = run_btn.click(
2609
  fn=run_ui,
2610
  inputs=[question, max_turns, memory_strategy, temperature],
2611
  outputs=[answer, trace],
2612
+ )
2613
+ run_event.then(
2614
+ # Auto-clear the question textbox once the run finishes (or is
2615
+ # cancelled) so the user can immediately ask a follow-up.
2616
  fn=lambda: "",
2617
  inputs=[],
2618
  outputs=[question],