Shreyas094 commited on
Commit
a5d1e67
·
verified ·
1 Parent(s): bde2fb4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -21
app.py CHANGED
@@ -246,28 +246,28 @@ with gr.Blocks() as demo:
246
  clear_btn = gr.Button("Clear")
247
 
248
  def protected_generate_response(message, history, use_web_search, model, temperature, num_calls, is_generating, stop_clicked):
249
- if is_generating:
250
- return message, history, is_generating, stop_clicked
251
- is_generating = True
252
- stop_clicked = False
253
-
254
- try:
255
- if use_web_search:
256
- main_content, sources = get_response_with_search(message, model, num_calls=num_calls, temperature=temperature)
257
- formatted_response = f"{main_content}\n\nSources:\n{sources}"
258
- else:
259
- response = get_response_from_pdf(message, model, num_calls=num_calls, temperature=temperature)
260
- formatted_response = response
261
 
262
- if not stop_clicked:
263
- # Only append the final, combined response to the history
264
- history.append((message, formatted_response))
265
- except Exception as e:
266
- print(f"Error generating response: {str(e)}")
267
- history.append((message, "I'm sorry, but I encountered an error while generating the response. Please try again."))
268
-
269
- is_generating = False
270
- return "", history, is_generating, stop_clicked
 
 
 
 
 
 
 
 
271
 
272
  submit_btn.click(
273
  protected_generate_response,
 
246
  clear_btn = gr.Button("Clear")
247
 
248
  def protected_generate_response(message, history, use_web_search, model, temperature, num_calls, is_generating, stop_clicked):
249
+ if is_generating:
250
+ return message, history, is_generating, stop_clicked
251
+ is_generating = True
252
+ stop_clicked = False
 
 
 
 
 
 
 
 
253
 
254
+ try:
255
+ if use_web_search:
256
+ main_content, sources = get_response_with_search(message, model, num_calls=num_calls, temperature=temperature)
257
+ formatted_response = f"{main_content}\n\nSources:\n{sources}"
258
+ else:
259
+ response = get_response_from_pdf(message, model, num_calls=num_calls, temperature=temperature)
260
+ formatted_response = response
261
+
262
+ if not stop_clicked:
263
+ # Only append the final, combined response to the history
264
+ history.append((message, formatted_response))
265
+ except Exception as e:
266
+ print(f"Error generating response: {str(e)}")
267
+ history.append((message, "I'm sorry, but I encountered an error while generating the response. Please try again."))
268
+
269
+ is_generating = False
270
+ return "", history, is_generating, stop_clicked
271
 
272
  submit_btn.click(
273
  protected_generate_response,