Shreyas094 commited on
Commit
f5a3050
·
verified ·
1 Parent(s): 3cef93f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -399,14 +399,7 @@ def summarize_web_results(query: str, search_results: List[Dict[str, str]], conv
399
  return f"An error occurred during summarization: {str(e)}"
400
 
401
  # Modify the existing respond function to handle both PDF and web search
402
- def respond(message, history, model, temperature, num_calls, use_web_search, selected_docs):
403
- if not message:
404
- return history + [(None, "No query provided. Please try again.")]
405
-
406
- # Remove any path-like prefixes from the message
407
- message = message.split('/')[-1] if '/' in message else message
408
-
409
-
410
  logging.info(f"User Query: {message}")
411
  logging.info(f"Model Used: {model}")
412
  logging.info(f"Selected Documents: {selected_docs}")
@@ -478,11 +471,14 @@ def respond(message, history, model, temperature, num_calls, use_web_search, sel
478
  else:
479
  response = f"An error occurred with the {model} model: {str(e)}. Please try again or select a different model."
480
 
 
 
 
481
  # Update the conversation history
482
- history.append((message, response))
483
 
484
  # Yield the updated history
485
- yield history
486
 
487
  logging.basicConfig(level=logging.DEBUG)
488
 
@@ -665,14 +661,25 @@ def transcribe_and_respond(audio_file, history, model, temperature, num_calls, u
665
  logging.info(f"Query extracted from transcription: {query}")
666
 
667
  # Use the transcription as the query
668
- response = next(respond(query, history, model, temperature, num_calls, use_web_search, document_selector))
669
-
670
- logging.info(f"Response: {response}")
671
 
672
- # Update the history with the new query and response
673
- new_history = history + [(query, response)]
674
-
675
- return new_history
 
 
 
 
 
 
 
 
 
 
 
 
 
676
 
677
  def vote(data: gr.LikeData):
678
  if data.liked:
 
399
  return f"An error occurred during summarization: {str(e)}"
400
 
401
  # Modify the existing respond function to handle both PDF and web search
402
+ def respond(message, history, model, temperature, num_calls, use_web_search, selected_docs):
 
 
 
 
 
 
 
403
  logging.info(f"User Query: {message}")
404
  logging.info(f"Model Used: {model}")
405
  logging.info(f"Selected Documents: {selected_docs}")
 
471
  else:
472
  response = f"An error occurred with the {model} model: {str(e)}. Please try again or select a different model."
473
 
474
+ # Ensure response is a string
475
+ response = str(response)
476
+
477
  # Update the conversation history
478
+ new_history = history + [(message, response)]
479
 
480
  # Yield the updated history
481
+ yield new_history
482
 
483
  logging.basicConfig(level=logging.DEBUG)
484
 
 
661
  logging.info(f"Query extracted from transcription: {query}")
662
 
663
  # Use the transcription as the query
664
+ response_generator = respond(query, history, model, temperature, num_calls, use_web_search, document_selector)
 
 
665
 
666
+ # Get the first (and presumably only) response from the generator
667
+ try:
668
+ new_history = next(response_generator)
669
+ logging.info(f"New history after response: {new_history}")
670
+
671
+ # Ensure the last message pair in the history is correctly formatted
672
+ if new_history and isinstance(new_history[-1], tuple) and len(new_history[-1]) == 2:
673
+ query, response = new_history[-1]
674
+ new_history[-1] = (query, str(response)) # Ensure response is a string
675
+ else:
676
+ logging.warning(f"Unexpected format in new_history: {new_history}")
677
+ new_history = history + [(query, "Error: Unexpected response format")]
678
+
679
+ return new_history
680
+ except StopIteration:
681
+ logging.warning("No response generated")
682
+ return history + [(query, "Error: No response generated")]
683
 
684
  def vote(data: gr.LikeData):
685
  if data.liked: