Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -226,11 +226,15 @@ class CitingSources(BaseModel):
|
|
226 |
...,
|
227 |
description="List of sources to cite. Should be an URL of the source."
|
228 |
)
|
229 |
-
def chatbot_interface(message, history,
|
230 |
if not message.strip():
|
231 |
-
return
|
232 |
|
233 |
-
|
|
|
|
|
|
|
|
|
234 |
|
235 |
try:
|
236 |
for response in respond(message, history, model, temperature, num_calls, use_web_search):
|
@@ -254,7 +258,7 @@ def retry_last_response(history, use_web_search, model, temperature, num_calls):
|
|
254 |
|
255 |
def respond(message, history, model, temperature, num_calls, use_web_search, selected_docs):
|
256 |
if not message.strip():
|
257 |
-
return
|
258 |
|
259 |
history = history + [(message, "")]
|
260 |
|
@@ -270,13 +274,14 @@ def respond(message, history, model, temperature, num_calls, use_web_search, sel
|
|
270 |
yield history
|
271 |
except Exception as e:
|
272 |
if "cancelled" in str(e).lower():
|
273 |
-
# This is likely a cancellation, so we'll just return the current history
|
274 |
yield history
|
275 |
else:
|
276 |
logging.error(f"Unexpected error in respond: {str(e)}")
|
277 |
history[-1] = (message, f"An unexpected error occurred: {str(e)}")
|
278 |
yield history
|
279 |
|
|
|
|
|
280 |
logging.basicConfig(level=logging.DEBUG)
|
281 |
|
282 |
def get_response_from_cloudflare(prompt, context, query, num_calls=3, temperature=0.2, search_type="pdf"):
|
@@ -449,7 +454,7 @@ def continue_generation(history, model, temperature, num_calls, use_web_search,
|
|
449 |
"""
|
450 |
|
451 |
try:
|
452 |
-
for response in respond(continuation_prompt, history[:-1],
|
453 |
new_response = f"{last_ai_response}\n\n{response[-1][1]}"
|
454 |
history[-1] = (last_user_msg, new_response)
|
455 |
yield history
|
@@ -458,6 +463,8 @@ def continue_generation(history, model, temperature, num_calls, use_web_search,
|
|
458 |
history[-1] = (last_user_msg, f"{last_ai_response}\n\nError continuing generation: {str(e)}")
|
459 |
yield history
|
460 |
|
|
|
|
|
461 |
css = """
|
462 |
/* Add your custom CSS here */
|
463 |
"""
|
@@ -477,7 +484,7 @@ document_selector = gr.CheckboxGroup(label="Select documents to query")
|
|
477 |
use_web_search = gr.Checkbox(label="Use Web Search", value=False)
|
478 |
|
479 |
demo = gr.ChatInterface(
|
480 |
-
|
481 |
additional_inputs=[
|
482 |
gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[0]),
|
483 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
|
@@ -531,12 +538,9 @@ with demo:
|
|
531 |
inputs=[file_input, parser_dropdown],
|
532 |
outputs=[update_output, document_selector])
|
533 |
|
534 |
-
|
535 |
-
continue_btn = gr.Button("Continue Generation", visible=False)
|
536 |
-
|
537 |
-
# Add the click event for the Continue Generation button
|
538 |
continue_btn.click(continue_generation,
|
539 |
-
inputs=[demo.chatbot] + demo.additional_inputs,
|
540 |
outputs=[demo.chatbot])
|
541 |
|
542 |
gr.Markdown(
|
|
|
226 |
...,
|
227 |
description="List of sources to cite. Should be an URL of the source."
|
228 |
)
|
229 |
+
def chatbot_interface(message, history, model, temperature, num_calls, use_web_search, selected_docs):
|
230 |
if not message.strip():
|
231 |
+
return history
|
232 |
|
233 |
+
for response in respond(message, history, model, temperature, num_calls, use_web_search, selected_docs):
|
234 |
+
yield response
|
235 |
+
|
236 |
+
# Make the Continue Generation button visible after the response is complete
|
237 |
+
demo.update(visible=True, elem_id="continue_btn")
|
238 |
|
239 |
try:
|
240 |
for response in respond(message, history, model, temperature, num_calls, use_web_search):
|
|
|
258 |
|
259 |
def respond(message, history, model, temperature, num_calls, use_web_search, selected_docs):
|
260 |
if not message.strip():
|
261 |
+
return history
|
262 |
|
263 |
history = history + [(message, "")]
|
264 |
|
|
|
274 |
yield history
|
275 |
except Exception as e:
|
276 |
if "cancelled" in str(e).lower():
|
|
|
277 |
yield history
|
278 |
else:
|
279 |
logging.error(f"Unexpected error in respond: {str(e)}")
|
280 |
history[-1] = (message, f"An unexpected error occurred: {str(e)}")
|
281 |
yield history
|
282 |
|
283 |
+
return history # Ensure we always return the history at the end
|
284 |
+
|
285 |
logging.basicConfig(level=logging.DEBUG)
|
286 |
|
287 |
def get_response_from_cloudflare(prompt, context, query, num_calls=3, temperature=0.2, search_type="pdf"):
|
|
|
454 |
"""
|
455 |
|
456 |
try:
|
457 |
+
for response in respond(continuation_prompt, history[:-1], model, temperature, num_calls, use_web_search, selected_docs):
|
458 |
new_response = f"{last_ai_response}\n\n{response[-1][1]}"
|
459 |
history[-1] = (last_user_msg, new_response)
|
460 |
yield history
|
|
|
463 |
history[-1] = (last_user_msg, f"{last_ai_response}\n\nError continuing generation: {str(e)}")
|
464 |
yield history
|
465 |
|
466 |
+
return history
|
467 |
+
|
468 |
css = """
|
469 |
/* Add your custom CSS here */
|
470 |
"""
|
|
|
484 |
use_web_search = gr.Checkbox(label="Use Web Search", value=False)
|
485 |
|
486 |
demo = gr.ChatInterface(
|
487 |
+
chatbot_interface,
|
488 |
additional_inputs=[
|
489 |
gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[0]),
|
490 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
|
|
|
538 |
inputs=[file_input, parser_dropdown],
|
539 |
outputs=[update_output, document_selector])
|
540 |
|
541 |
+
continue_btn = gr.Button("Continue Generation", visible=False, elem_id="continue_btn")
|
|
|
|
|
|
|
542 |
continue_btn.click(continue_generation,
|
543 |
+
inputs=[demo.chatbot] + demo.additional_inputs,
|
544 |
outputs=[demo.chatbot])
|
545 |
|
546 |
gr.Markdown(
|