akhaliq HF Staff commited on
Commit
218ff72
·
verified ·
1 Parent(s): 9a03601

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -35,14 +35,19 @@ with gr.Blocks(title="K2-Think Chat") as demo:
35
  submit_btn = gr.Button("Submit", variant="primary")
36
  stop_btn = gr.Button("Stop", variant="stop")
37
 
38
- msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
 
39
  bot, chatbot, chatbot
40
  ).then(lambda: gr.update(value=""), None, msg)
41
- submit_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
 
42
  bot, chatbot, chatbot
43
  ).then(lambda: gr.update(value=""), None, msg)
 
44
  clear_btn.click(lambda: None, None, chatbot, queue=False)
45
- stop_btn.click(None, None, None, cancels=[bot])
 
 
46
 
47
  if __name__ == "__main__":
48
  demo.launch()
 
35
  submit_btn = gr.Button("Submit", variant="primary")
36
  stop_btn = gr.Button("Stop", variant="stop")
37
 
38
+ # Store the event handler to cancel it later
39
+ bot_event = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
40
  bot, chatbot, chatbot
41
  ).then(lambda: gr.update(value=""), None, msg)
42
+
43
+ submit_event = submit_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
44
  bot, chatbot, chatbot
45
  ).then(lambda: gr.update(value=""), None, msg)
46
+
47
  clear_btn.click(lambda: None, None, chatbot, queue=False)
48
+
49
+ # Cancel the events instead of trying to cancel the function directly
50
+ stop_btn.click(None, None, None, cancels=[bot_event, submit_event])
51
 
52
  if __name__ == "__main__":
53
  demo.launch()