zelk12 commited on
Commit
5365097
·
verified ·
1 Parent(s): 8064cc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -2
app.py CHANGED
@@ -106,9 +106,12 @@ def stream_gemini_response(user_message: str, messages: list) -> Iterator[list]:
106
  thinking_complete = True
107
 
108
  for chunk in response:
 
109
  parts = chunk.candidates[0].content.parts
110
  current_chunk = parts[0].text
111
 
 
 
112
  if len(parts) == 2 and not thinking_complete:
113
  # Complete thought and start response
114
  thought_buffer += current_chunk
@@ -202,7 +205,15 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", n
202
  scale=4
203
  )
204
 
205
- clear_button = gr.Button("Clear Chat", scale=1)
 
 
 
 
 
 
 
 
206
 
207
  # Add example prompts - removed file upload examples. Kept text focused examples.
208
  example_prompts = [
@@ -220,7 +231,28 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", n
220
  examples_per_page=5 # Adjust as needed
221
  )
222
 
223
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  # Set up event handlers
225
  msg_store = gr.State("") # Store for preserving user message
226
 
@@ -240,6 +272,22 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", n
240
  outputs=chatbot
241
  )
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  clear_button.click(
244
  lambda: ([], "", ""),
245
  outputs=[chatbot, input_box, msg_store],
 
106
  thinking_complete = True
107
 
108
  for chunk in response:
109
+ print("chunk start")
110
  parts = chunk.candidates[0].content.parts
111
  current_chunk = parts[0].text
112
 
113
+ print(f"\n=========\nparts len: {len(parts)}\n\nparts: {parts}\n\ncurrent chunk: {current_chunk}\n=========\n")
114
+
115
  if len(parts) == 2 and not thinking_complete:
116
  # Complete thought and start response
117
  thought_buffer += current_chunk
 
205
  scale=4
206
  )
207
 
208
+ with gr.Column(scale=1):
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("test", scale=1)
214
+ test1_button = gr.Button("test1", scale=1)
215
+ test2_button = gr.Button("test2", scale=1)
216
+ test3_button = gr.Button("test3", scale=1)
217
 
218
  # Add example prompts - removed file upload examples. Kept text focused examples.
219
  example_prompts = [
 
231
  examples_per_page=5 # Adjust as needed
232
  )
233
 
234
+ # Created by gemini-2.5-pro-exp-03-25
235
+ #def process_message(msg):
236
+ # """Обрабатывает сообщение пользователя: сохраняет, отображает и генерирует ответ."""
237
+ # msg_store_val, _, _ = lambda msg: (msg, msg, "")(msg) # Store message and clear input (inline lambda)
238
+ # input_box_val, chatbot_val = user_message(msg_store_val, chatbot) # Add user message to chat
239
+ # chatbot_val_final = stream_gemini_response(msg_store_val, chatbot_val) # Generate and stream response
240
+ # return msg_store_val, input_box_val, chatbot_val_final
241
+ #
242
+ #input_box.submit(
243
+ # process_message,
244
+ # inputs=[input_box],
245
+ # outputs=[msg_store, input_box, chatbot], # Исправлены outputs, чтобы включать chatbot
246
+ # queue=False
247
+ #)
248
+
249
+ #submit_button.click(
250
+ # process_message,
251
+ # inputs=[input_box],
252
+ # outputs=[msg_store, input_box, chatbot], # Исправлены outputs, чтобы включать chatbot
253
+ # queue=False
254
+ #)
255
+
256
  # Set up event handlers
257
  msg_store = gr.State("") # Store for preserving user message
258
 
 
272
  outputs=chatbot
273
  )
274
 
275
+ submit_button.click(
276
+ lambda msg: (msg, msg, ""), # Store message and clear input
277
+ inputs=[input_box],
278
+ outputs=[msg_store, input_box, input_box],
279
+ queue=False
280
+ ).then(
281
+ user_message, # Add user message to chat
282
+ inputs=[msg_store, chatbot],
283
+ outputs=[input_box, chatbot],
284
+ queue=False
285
+ ).then(
286
+ stream_gemini_response, # Generate and stream response
287
+ inputs=[msg_store, chatbot],
288
+ outputs=chatbot
289
+ )
290
+
291
  clear_button.click(
292
  lambda: ([], "", ""),
293
  outputs=[chatbot, input_box, msg_store],