Update app.py
Browse files232 unmodified lines23323423523623723823623723816 unmodified lines25525625726125825926026163 unmodified lines325326327331332333334335336328329330157 unmodified lines48848949050050149149249349432 unmodified lines527528529540530531532232 unmodified lines full_response += chunk except Exception as e: print(f"Error in generate_chunked_response: {e}") if "Input validation error" in str(e): # If we hit the token limit, return what we have so far return full_response if full_response else "The input was too long to process. Please try a shorter query." break return full_response.strip()
16 unmodified lines "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36",]
def google_search(term, num_results=3, lang="en", timeout=5, safe="active", ssl_verify=None):def google_search(term, num_results=5, lang="en", timeout=5, safe="active", ssl_verify=None): escaped_term = urllib.parse.quote_plus(term) start = 0 all_results = []63 unmodified lines
return all_results
def estimate_tokens(text): # Rough estimate: 1 token ~= 4 characters return len(text) // 4
import re
def estimate_tokens(text): # Rough estimate: 1 token ~= 4 characters return len(text) // 4157 unmodified lines if attempt == max_attempts - 1: return f"I apologize, but an unexpected error occurred. Please try again with a different question."
return "An unexpected error occurred. Please try again later."
return "An unexpected error occurred. Please try again later."."
def extract_answer(full_response, instructions=None): answer_patterns = [32 unmodified lines return full_response.strip()
# Gradio interfacewith gr.Blocks() as demo: gr.Markdown("# Enhanced PDF Document Chat and Web Search")app.py+2-13