Shreyas094 commited on
Commit
5fa63cc
·
verified ·
1 Parent(s): 75e9d4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -258,7 +258,6 @@ with gr.Blocks() as demo:
258
 
259
  is_generating = True
260
 
261
- # Handle both boolean and Gradio State object
262
  if isinstance(stop_clicked, gr.State):
263
  stop_clicked.value = False
264
  else:
@@ -277,24 +276,20 @@ with gr.Blocks() as demo:
277
 
278
  print(f"Generated response: {formatted_response[:100]}...")
279
 
280
- if not (isinstance(stop_clicked, gr.State) and stop_clicked.value) and not stop_clicked:
281
- print("Appending to history")
282
- history.append((message, formatted_response))
283
- else:
284
- print("Stop clicked, not appending to history")
285
  except Exception as e:
286
  print(f"Error generating response: {str(e)}")
287
- history.append((message, "I'm sorry, but I encountered an error while generating the response. Please try again."))
288
 
289
  is_generating = False
290
- print(f"Returning history with {len(history)} items")
291
- return "", history, is_generating, stop_clicked
292
-
293
  def on_submit(message, history, use_web_search, model, temperature, num_calls, is_generating, stop_clicked):
294
  print(f"Submit button clicked with message: {message}")
295
- _, new_history, new_is_generating, new_stop_clicked = protected_generate_response(
296
  message, history, use_web_search, model, temperature, num_calls, is_generating, stop_clicked
297
  )
 
298
  print(f"New history has {len(new_history)} items")
299
  return "", new_history, new_is_generating, new_stop_clicked
300
 
 
258
 
259
  is_generating = True
260
 
 
261
  if isinstance(stop_clicked, gr.State):
262
  stop_clicked.value = False
263
  else:
 
276
 
277
  print(f"Generated response: {formatted_response[:100]}...")
278
 
 
 
 
 
 
279
  except Exception as e:
280
  print(f"Error generating response: {str(e)}")
281
+ formatted_response = "I'm sorry, but I encountered an error while generating the response. Please try again."
282
 
283
  is_generating = False
284
+ print(f"Returning final response")
285
+ return formatted_response, is_generating, stop_clicked
286
+
287
  def on_submit(message, history, use_web_search, model, temperature, num_calls, is_generating, stop_clicked):
288
  print(f"Submit button clicked with message: {message}")
289
+ response, new_is_generating, new_stop_clicked = protected_generate_response(
290
  message, history, use_web_search, model, temperature, num_calls, is_generating, stop_clicked
291
  )
292
+ new_history = history + [(message, response)]
293
  print(f"New history has {len(new_history)} items")
294
  return "", new_history, new_is_generating, new_stop_clicked
295