FractalAIR commited on
Commit
8158154
·
verified ·
1 Parent(s): fb86a3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -169,24 +169,20 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
169
  stop_button = gr.Button("⏹ Stop", variant="secondary", scale=1)
170
  clear_button = gr.Button("Clear", scale=1)
171
 
172
- # 1️⃣ keep the event object in a variable
173
- submit_event = submit_button.click(
174
  fn = send_message,
175
  inputs = [user_input, max_tokens_slider, temperature_slider,
176
  top_p_slider, current_convo_id, history_state],
177
  outputs= [chatbot, history_state, conversation_selector]
178
- ).then(
179
- fn = lambda: gr.update(value=""), # clear the textbox
180
- inputs = None,
181
- outputs= user_input
182
  )
183
 
184
- # 2️⃣ the stop button only needs to cancel that event
185
  stop_button.click(
186
- fn = None, # nothing has to run
187
  inputs = None,
188
  outputs = None,
189
- cancels = [submit_event] # <-- this does the interrupt
190
  )
191
 
192
  gr.Markdown("**Try these examples:**")
 
169
  stop_button = gr.Button("⏹ Stop", variant="secondary", scale=1)
170
  clear_button = gr.Button("Clear", scale=1)
171
 
172
+ # build the streaming event and save its handle -----------------
173
+ stream_event = submit_button.click(
174
  fn = send_message,
175
  inputs = [user_input, max_tokens_slider, temperature_slider,
176
  top_p_slider, current_convo_id, history_state],
177
  outputs= [chatbot, history_state, conversation_selector]
 
 
 
 
178
  )
179
 
180
+ # stop button cancels the real streaming event ------------------
181
  stop_button.click(
182
+ fn = None,
183
  inputs = None,
184
  outputs = None,
185
+ cancels = [stream_event] # <-- correct event to cancel
186
  )
187
 
188
  gr.Markdown("**Try these examples:**")