FractalAIR commited on
Commit
d326db3
·
verified ·
1 Parent(s): 06f021e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -33
app.py CHANGED
@@ -119,18 +119,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
119
  current_convo_id = gr.State(generate_conversation_id())
120
  history_state = gr.State([])
121
 
122
- def send_message(user_message, max_tokens, temperature, top_p, convo_id, history):
123
- if convo_id not in conversations:
124
- #title = user_message.strip().split("\n")[0][:40]
125
- title = " ".join(user_message.strip().split()[:5])
126
- conversations[convo_id] = {"title": title, "messages": history}
127
- if conversations[convo_id]["title"].startswith("New Conversation"):
128
- #conversations[convo_id]["title"] = user_message.strip().split("\n")[0][:40]
129
- conversations[convo_id]["title"] = " ".join(user_message.strip().split()[:5])
130
- for updated_history, new_history in generate_response(user_message, max_tokens, temperature, top_p, history):
131
- conversations[convo_id]["messages"] = new_history
132
- yield updated_history, new_history, gr.update(choices=update_conversation_list(), value=conversations[convo_id]["title"])
133
-
134
  with gr.Row():
135
  with gr.Column(scale=1):
136
  # INTRO TEXT MOVED HERE
@@ -161,30 +149,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
161
 
162
  with gr.Column(scale=4):
163
  #chatbot = gr.Chatbot(label="Chat", type="messages")
164
- chatbot = gr.Chatbot(label="Chat", type="messages", height=500)
165
  with gr.Row():
166
- user_input = gr.Textbox(label="User Input", placeholder="Type your question here...", lines=4, scale=8)
167
  with gr.Column():
168
  submit_button = gr.Button("Send", variant="primary", scale=1)
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:**")
189
  with gr.Row():
190
  example1_button = gr.Button("JEE Main 2025\nCombinatorics")
@@ -206,6 +176,17 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
206
  return cid, convo["messages"], convo["messages"]
207
  return current_convo_id.value, history_state.value, history_state.value
208
 
 
 
 
 
 
 
 
 
 
 
 
209
 
210
  submit_button.click(
211
  fn=send_message,
@@ -244,4 +225,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
244
 
245
  if __name__ == "__main__":
246
  # first positional argument = concurrency_count
247
- demo.queue(6).launch(share=True, ssr_mode=False)
 
119
  current_convo_id = gr.State(generate_conversation_id())
120
  history_state = gr.State([])
121
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  with gr.Row():
123
  with gr.Column(scale=1):
124
  # INTRO TEXT MOVED HERE
 
149
 
150
  with gr.Column(scale=4):
151
  #chatbot = gr.Chatbot(label="Chat", type="messages")
152
+ chatbot = gr.Chatbot(label="Chat", type="messages", height=520)
153
  with gr.Row():
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")
 
176
  return cid, convo["messages"], convo["messages"]
177
  return current_convo_id.value, history_state.value, history_state.value
178
 
179
+ def send_message(user_message, max_tokens, temperature, top_p, convo_id, history):
180
+ if convo_id not in conversations:
181
+ #title = user_message.strip().split("\n")[0][:40]
182
+ title = " ".join(user_message.strip().split()[:5])
183
+ conversations[convo_id] = {"title": title, "messages": history}
184
+ if conversations[convo_id]["title"].startswith("New Conversation"):
185
+ #conversations[convo_id]["title"] = user_message.strip().split("\n")[0][:40]
186
+ conversations[convo_id]["title"] = " ".join(user_message.strip().split()[:5])
187
+ for updated_history, new_history in generate_response(user_message, max_tokens, temperature, top_p, history):
188
+ conversations[convo_id]["messages"] = new_history
189
+ yield updated_history, new_history, gr.update(choices=update_conversation_list(), value=conversations[convo_id]["title"])
190
 
191
  submit_button.click(
192
  fn=send_message,
 
225
 
226
  if __name__ == "__main__":
227
  # first positional argument = concurrency_count
228
+ demo.queue(8).launch(share=True, ssr_mode=False)