Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ from langchain_core.documents import Document
|
|
| 15 |
from huggingface_hub import InferenceClient
|
| 16 |
import inspect
|
| 17 |
import logging
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
# Set up basic configuration for logging
|
|
@@ -244,7 +245,7 @@ def retry_last_response(history, use_web_search, model, temperature, num_calls):
|
|
| 244 |
|
| 245 |
return chatbot_interface(last_user_msg, history, use_web_search, model, temperature, num_calls)
|
| 246 |
|
| 247 |
-
def respond(message, history,
|
| 248 |
if not message.strip():
|
| 249 |
return "", history
|
| 250 |
|
|
@@ -255,17 +256,17 @@ def respond(message, history, use_web_search, model, temperature, num_calls, sel
|
|
| 255 |
for main_content, sources in get_response_with_search(message, model, num_calls=num_calls, temperature=temperature):
|
| 256 |
response = f"{main_content}\n\n{sources}"
|
| 257 |
history[-1] = (message, response)
|
| 258 |
-
yield history
|
| 259 |
else:
|
| 260 |
-
for partial_response in get_response_from_pdf(message, model, selected_docs, num_calls=num_calls, temperature=temperature
|
| 261 |
history[-1] = (message, partial_response)
|
| 262 |
-
yield history
|
| 263 |
-
except
|
| 264 |
-
yield history
|
| 265 |
except Exception as e:
|
| 266 |
logging.error(f"Unexpected error in respond: {str(e)}")
|
| 267 |
history[-1] = (message, f"An unexpected error occurred: {str(e)}")
|
| 268 |
-
yield history
|
| 269 |
|
| 270 |
logging.basicConfig(level=logging.DEBUG)
|
| 271 |
|
|
@@ -526,12 +527,7 @@ with demo:
|
|
| 526 |
|
| 527 |
# Add the click event for the Continue Generation button
|
| 528 |
continue_btn.click(continue_generation,
|
| 529 |
-
inputs=[demo.chatbot,
|
| 530 |
-
gr.Dropdown(choices=MODELS, label="Select Model"),
|
| 531 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
|
| 532 |
-
gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
|
| 533 |
-
use_web_search,
|
| 534 |
-
document_selector],
|
| 535 |
outputs=[demo.chatbot])
|
| 536 |
|
| 537 |
gr.Markdown(
|
|
|
|
| 15 |
from huggingface_hub import InferenceClient
|
| 16 |
import inspect
|
| 17 |
import logging
|
| 18 |
+
from gradio.exceptions import CancelledError
|
| 19 |
|
| 20 |
|
| 21 |
# Set up basic configuration for logging
|
|
|
|
| 245 |
|
| 246 |
return chatbot_interface(last_user_msg, history, use_web_search, model, temperature, num_calls)
|
| 247 |
|
| 248 |
+
def respond(message, history, model, temperature, num_calls, use_web_search, selected_docs):
|
| 249 |
if not message.strip():
|
| 250 |
return "", history
|
| 251 |
|
|
|
|
| 256 |
for main_content, sources in get_response_with_search(message, model, num_calls=num_calls, temperature=temperature):
|
| 257 |
response = f"{main_content}\n\n{sources}"
|
| 258 |
history[-1] = (message, response)
|
| 259 |
+
yield history
|
| 260 |
else:
|
| 261 |
+
for partial_response in get_response_from_pdf(message, model, selected_docs, num_calls=num_calls, temperature=temperature):
|
| 262 |
history[-1] = (message, partial_response)
|
| 263 |
+
yield history
|
| 264 |
+
except CancelledError:
|
| 265 |
+
yield history
|
| 266 |
except Exception as e:
|
| 267 |
logging.error(f"Unexpected error in respond: {str(e)}")
|
| 268 |
history[-1] = (message, f"An unexpected error occurred: {str(e)}")
|
| 269 |
+
yield history
|
| 270 |
|
| 271 |
logging.basicConfig(level=logging.DEBUG)
|
| 272 |
|
|
|
|
| 527 |
|
| 528 |
# Add the click event for the Continue Generation button
|
| 529 |
continue_btn.click(continue_generation,
|
| 530 |
+
inputs=[demo.chatbot] + demo.additional_inputs, # Use existing inputs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
outputs=[demo.chatbot])
|
| 532 |
|
| 533 |
gr.Markdown(
|