FractalAIR commited on
Commit
684e9eb
·
verified ·
1 Parent(s): 519bd98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -154,7 +154,29 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
154
  user_input = gr.Textbox(label="User Input", placeholder="Type your question here...", lines=3, scale=8)
155
  with gr.Column():
156
  submit_button = gr.Button("Send", variant="primary", scale=1)
 
157
  clear_button = gr.Button("Clear", scale=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  gr.Markdown("**Try these examples:**")
159
  with gr.Row():
160
  example1_button = gr.Button("JEE Main 2025\nCombinatorics")
@@ -225,4 +247,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
225
 
226
  if __name__ == "__main__":
227
  # first positional argument = concurrency_count
228
- demo.queue(8).launch(share=True, ssr_mode=False)
 
154
  user_input = gr.Textbox(label="User Input", placeholder="Type your question here...", lines=3, scale=8)
155
  with gr.Column():
156
  submit_button = gr.Button("Send", variant="primary", scale=1)
157
+ stop_button = gr.Button("⏹ Stop", variant="secondary", scale=1)
158
  clear_button = gr.Button("Clear", scale=1)
159
+
160
+ # 1️⃣ keep the event object in a variable
161
+ submit_event = submit_button.click(
162
+ fn = send_message,
163
+ inputs = [user_input, max_tokens_slider, temperature_slider,
164
+ top_p_slider, current_convo_id, history_state],
165
+ outputs= [chatbot, history_state, conversation_selector]
166
+ ).then(
167
+ fn = lambda: gr.update(value=""), # clear the textbox
168
+ inputs = None,
169
+ outputs= user_input
170
+ )
171
+
172
+ # 2️⃣ the stop button only needs to cancel that event
173
+ stop_button.click(
174
+ fn = None, # nothing has to run
175
+ inputs = None,
176
+ outputs = None,
177
+ cancels = [submit_event] # <-- this does the interrupt
178
+ )
179
+
180
  gr.Markdown("**Try these examples:**")
181
  with gr.Row():
182
  example1_button = gr.Button("JEE Main 2025\nCombinatorics")
 
247
 
248
  if __name__ == "__main__":
249
  # first positional argument = concurrency_count
250
+ demo.queue(6).launch(share=True, ssr_mode=False)