Update app.py
Browse files232 unmodified lines23323423523623723823924024116 unmodified lines25825926026126226326463 unmodified lines328329330331332333334335336337338339157 unmodified lines49749849950050150250350432 unmodified lines537538539540541542543232 unmodified linesfull_response += chunkexcept 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 farreturn full_response if full_response else "The input was too long to process. Please try a shorter query."breakreturn 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):escaped_term = urllib.parse.quote_plus(term)start = 0all_results = []63 unmodified linesreturn all_resultsdef estimate_tokens(text):# Rough estimate: 1 token ~= 4 charactersreturn len(text) // 4import redef estimate_tokens(text):# Rough estimate: 1 token ~= 4 charactersreturn len(text) // 4157 unmodified linesif 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."def extract_answer(full_response, instructions=None):answer_patterns = [32 unmodified linesreturn full_response.strip()# Gradio interfacewith gr.Blocks() as demo:gr.Markdown("# Enhanced PDF Document Chat and Web Search")232 unmodified lines23323423523623723816 unmodified lines25525625725825926026163 unmodified lines325326327328329330157 unmodified lines48848949049149249349432 unmodified lines527528529530531532232 unmodified linesfull_response += chunkexcept Exception as e:print(f"Error in generate_chunked_response: {e}")breakreturn 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=5, lang="en", timeout=5, safe="active", ssl_verify=None):escaped_term = urllib.parse.quote_plus(term)start = 0all_results = []63 unmodified linesreturn all_resultsdef estimate_tokens(text):# Rough estimate: 1 token ~= 4 charactersreturn len(text) // 4157 unmodified linesif 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."."def extract_answer(full_response, instructions=None):answer_patterns = [32 unmodified linesreturn full_response.strip()# Gradio interfacewith gr.Blocks() as demo:gr.Markdown("# Enhanced PDF Document Chat and Web Search")
app.py+2-13