Update app.py
Browse files
app.py
CHANGED
@@ -209,34 +209,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", n
|
|
209 |
submit_button = gr.Button("Submit", scale=1)
|
210 |
clear_button = gr.Button("Clear Chat", scale=1)
|
211 |
|
212 |
-
with gr.Row(equal_height=True):
|
213 |
-
test_button = gr.Button("undo", scale=1)
|
214 |
-
test1_button = gr.Button("redo", scale=1)
|
215 |
-
test2_button = gr.Button("regenerate", scale=1)
|
216 |
-
with gr.Row(equal_height=True):
|
217 |
-
test_button = gr.Button("undo", scale=1)
|
218 |
-
test1_button = gr.Button("redo", scale=1)
|
219 |
-
test2_button = gr.Button("regenerate", scale=1)
|
220 |
-
with gr.Row(equal_height=True):
|
221 |
-
test_button = gr.Button("undo", scale=1)
|
222 |
-
test1_button = gr.Button("redo", scale=1)
|
223 |
-
test2_button = gr.Button("regenerate", scale=1)
|
224 |
-
with gr.Row(equal_height=True):
|
225 |
-
test_button = gr.Button("undo", scale=1)
|
226 |
-
test1_button = gr.Button("redo", scale=1)
|
227 |
-
test2_button = gr.Button("regenerate", scale=1)
|
228 |
-
with gr.Row(equal_height=True):
|
229 |
-
test_button = gr.Button("undo", scale=1)
|
230 |
-
test1_button = gr.Button("redo", scale=1)
|
231 |
-
test2_button = gr.Button("regenerate", scale=1)
|
232 |
-
with gr.Row(equal_height=True):
|
233 |
-
test_button = gr.Button("undo", scale=1)
|
234 |
-
test1_button = gr.Button("redo", scale=1)
|
235 |
-
test2_button = gr.Button("regenerate", scale=1)
|
236 |
-
with gr.Row(equal_height=True):
|
237 |
-
test_button = gr.Button("undo", scale=1)
|
238 |
-
test1_button = gr.Button("redo", scale=1)
|
239 |
-
test2_button = gr.Button("regenerate", scale=1)
|
240 |
with gr.Row(equal_height=True):
|
241 |
test_button = gr.Button("undo", scale=1)
|
242 |
test1_button = gr.Button("redo", scale=1)
|
@@ -259,61 +231,63 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", n
|
|
259 |
)
|
260 |
|
261 |
# Created by gemini-2.5-pro-exp-03-25
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
# process_message,
|
271 |
-
# inputs=[input_box],
|
272 |
-
# outputs=[msg_store, input_box, chatbot], # Исправлены outputs, чтобы включать chatbot
|
273 |
-
# queue=False
|
274 |
-
#)
|
275 |
-
|
276 |
-
#submit_button.click(
|
277 |
-
# process_message,
|
278 |
-
# inputs=[input_box],
|
279 |
-
# outputs=[msg_store, input_box, chatbot], # Исправлены outputs, чтобы включать chatbot
|
280 |
-
# queue=False
|
281 |
-
#)
|
282 |
|
283 |
# Set up event handlers
|
284 |
msg_store = gr.State("") # Store for preserving user message
|
285 |
|
286 |
input_box.submit(
|
287 |
-
|
288 |
inputs=[input_box],
|
289 |
-
outputs=[msg_store, input_box,
|
290 |
-
queue=False
|
291 |
-
).then(
|
292 |
-
user_message, # Add user message to chat
|
293 |
-
inputs=[msg_store, chatbot],
|
294 |
-
outputs=[input_box, chatbot],
|
295 |
queue=False
|
296 |
-
).then(
|
297 |
-
stream_gemini_response, # Generate and stream response
|
298 |
-
inputs=[msg_store, chatbot],
|
299 |
-
outputs=chatbot
|
300 |
)
|
301 |
|
302 |
submit_button.click(
|
303 |
-
|
304 |
inputs=[input_box],
|
305 |
-
outputs=[msg_store, input_box,
|
306 |
queue=False
|
307 |
-
).then(
|
308 |
-
user_message, # Add user message to chat
|
309 |
-
inputs=[msg_store, chatbot],
|
310 |
-
outputs=[input_box, chatbot],
|
311 |
-
queue=False
|
312 |
-
).then(
|
313 |
-
stream_gemini_response, # Generate and stream response
|
314 |
-
inputs=[msg_store, chatbot],
|
315 |
-
outputs=chatbot
|
316 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
|
318 |
clear_button.click(
|
319 |
lambda: ([], "", ""),
|
|
|
209 |
submit_button = gr.Button("Submit", scale=1)
|
210 |
clear_button = gr.Button("Clear Chat", scale=1)
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
with gr.Row(equal_height=True):
|
213 |
test_button = gr.Button("undo", scale=1)
|
214 |
test1_button = gr.Button("redo", scale=1)
|
|
|
231 |
)
|
232 |
|
233 |
# Created by gemini-2.5-pro-exp-03-25
|
234 |
+
def process_message(msg):
|
235 |
+
"""Обрабатывает сообщение пользователя: сохраняет, отображает и генерирует ответ."""
|
236 |
+
msg_store_val, _, _ = lambda msg: (msg, msg, "")(msg) # Store message and clear input (inline lambda)
|
237 |
+
input_box_val, chatbot_val = user_message(msg_store_val, chatbot) # Add user message to chat
|
238 |
+
chatbot_val_final = stream_gemini_response(msg_store_val, chatbot_val) # Generate and stream response
|
239 |
+
return msg_store_val, input_box_val, chatbot_val_final
|
240 |
+
|
241 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
# Set up event handlers
|
244 |
msg_store = gr.State("") # Store for preserving user message
|
245 |
|
246 |
input_box.submit(
|
247 |
+
process_message,
|
248 |
inputs=[input_box],
|
249 |
+
outputs=[msg_store, input_box, chatbot], # Исправлены outputs, чтобы включать chatbot
|
|
|
|
|
|
|
|
|
|
|
250 |
queue=False
|
|
|
|
|
|
|
|
|
251 |
)
|
252 |
|
253 |
submit_button.click(
|
254 |
+
process_message,
|
255 |
inputs=[input_box],
|
256 |
+
outputs=[msg_store, input_box, chatbot], # Исправлены outputs, чтобы включать chatbot
|
257 |
queue=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
)
|
259 |
+
|
260 |
+
#input_box.submit(
|
261 |
+
# lambda msg: (msg, msg, ""), # Store message and clear input
|
262 |
+
# inputs=[input_box],
|
263 |
+
# outputs=[msg_store, input_box, input_box],
|
264 |
+
# queue=False
|
265 |
+
#).then(
|
266 |
+
# user_message, # Add user message to chat
|
267 |
+
# inputs=[msg_store, chatbot],
|
268 |
+
# outputs=[input_box, chatbot],
|
269 |
+
# queue=False
|
270 |
+
#).then(
|
271 |
+
# stream_gemini_response, # Generate and stream response
|
272 |
+
# inputs=[msg_store, chatbot],
|
273 |
+
# outputs=chatbot
|
274 |
+
#)
|
275 |
+
|
276 |
+
#submit_button.click(
|
277 |
+
# lambda msg: (msg, msg, ""), # Store message and clear input
|
278 |
+
# inputs=[input_box],
|
279 |
+
# outputs=[msg_store, input_box, input_box],
|
280 |
+
# queue=False
|
281 |
+
#).then(
|
282 |
+
# user_message, # Add user message to chat
|
283 |
+
# inputs=[msg_store, chatbot],
|
284 |
+
# outputs=[input_box, chatbot],
|
285 |
+
# queue=False
|
286 |
+
#).then(
|
287 |
+
# stream_gemini_response, # Generate and stream response
|
288 |
+
# inputs=[msg_store, chatbot],
|
289 |
+
# outputs=chatbot
|
290 |
+
#)
|
291 |
|
292 |
clear_button.click(
|
293 |
lambda: ([], "", ""),
|