Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -571,22 +571,23 @@ def handle_query(user_question, chatbot, audio=None):
|
|
| 571 |
print(user_question)
|
| 572 |
# Start the processing in a new thread
|
| 573 |
future = executor.submit(answer_question_test, user_question, chatbot)
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
try:
|
| 582 |
user_question1, response_text1 = future.result() # Get the result of the completed future
|
| 583 |
chatbot.append((user_question1, response_text1))
|
| 584 |
return gr.update(value=chatbot)
|
| 585 |
-
|
| 586 |
except Exception as e:
|
| 587 |
-
return f"Error occurred: {e}"
|
| 588 |
-
else:
|
| 589 |
-
return "Processing your request. You can stop it if needed."
|
| 590 |
|
| 591 |
|
| 592 |
def stop_processing(chatbot):
|
|
|
|
| 571 |
print(user_question)
|
| 572 |
# Start the processing in a new thread
|
| 573 |
future = executor.submit(answer_question_test, user_question, chatbot)
|
| 574 |
+
|
| 575 |
+
# Periodically check if future is done
|
| 576 |
+
while not future.done():
|
| 577 |
+
if stop_event.is_set():
|
| 578 |
+
future.cancel()
|
| 579 |
+
return [("Processing was cancelled.", "bot")]
|
| 580 |
+
time.sleep(1) # Wait for 1 second before checking again
|
| 581 |
+
|
| 582 |
+
if future.cancelled():
|
| 583 |
+
return [("Processing was cancelled.", "")]
|
| 584 |
+
else:
|
| 585 |
try:
|
| 586 |
user_question1, response_text1 = future.result() # Get the result of the completed future
|
| 587 |
chatbot.append((user_question1, response_text1))
|
| 588 |
return gr.update(value=chatbot)
|
|
|
|
| 589 |
except Exception as e:
|
| 590 |
+
return [(f"Error occurred: {e}", "bot")]
|
|
|
|
|
|
|
| 591 |
|
| 592 |
|
| 593 |
def stop_processing(chatbot):
|