Update app.py
Browse files
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 |
-
#
|
| 173 |
-
|
| 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 |
-
#
|
| 185 |
stop_button.click(
|
| 186 |
-
fn = None,
|
| 187 |
inputs = None,
|
| 188 |
outputs = None,
|
| 189 |
-
cancels = [
|
| 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:**")
|