Shreyas094 commited on
Commit
40aa611
1 Parent(s): 34461d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -13
app.py CHANGED
@@ -233,9 +233,6 @@ def generate_chunked_response(model, prompt, max_tokens=1000, max_chunks=5):
233
  full_response += chunk
234
  except Exception as e:
235
  print(f"Error in generate_chunked_response: {e}")
236
- if "Input validation error" in str(e):
237
- # If we hit the token limit, return what we have so far
238
- return full_response if full_response else "The input was too long to process. Please try a shorter query."
239
  break
240
  return full_response.strip()
241
 
@@ -258,7 +255,7 @@ _useragent_list = [
258
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36",
259
  ]
260
 
261
- def google_search(term, num_results=3, lang="en", timeout=5, safe="active", ssl_verify=None):
262
  escaped_term = urllib.parse.quote_plus(term)
263
  start = 0
264
  all_results = []
@@ -328,12 +325,6 @@ def google_search(term, num_results=3, lang="en", timeout=5, safe="active", ssl_
328
 
329
  return all_results
330
 
331
- def estimate_tokens(text):
332
- # Rough estimate: 1 token ~= 4 characters
333
- return len(text) // 4
334
-
335
- import re
336
-
337
  def estimate_tokens(text):
338
  # Rough estimate: 1 token ~= 4 characters
339
  return len(text) // 4
@@ -497,8 +488,7 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search, c
497
  if attempt == max_attempts - 1:
498
  return f"I apologize, but an unexpected error occurred. Please try again with a different question."
499
 
500
- return "An unexpected error occurred. Please try again later."
501
-
502
 
503
  def extract_answer(full_response, instructions=None):
504
  answer_patterns = [
@@ -537,7 +527,6 @@ def extract_answer(full_response, instructions=None):
537
 
538
  return full_response.strip()
539
 
540
-
541
  # Gradio interface
542
  with gr.Blocks() as demo:
543
  gr.Markdown("# Enhanced PDF Document Chat and Web Search")
 
233
  full_response += chunk
234
  except Exception as e:
235
  print(f"Error in generate_chunked_response: {e}")
 
 
 
236
  break
237
  return full_response.strip()
238
 
 
255
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36",
256
  ]
257
 
258
+ def google_search(term, num_results=5, lang="en", timeout=5, safe="active", ssl_verify=None):
259
  escaped_term = urllib.parse.quote_plus(term)
260
  start = 0
261
  all_results = []
 
325
 
326
  return all_results
327
 
 
 
 
 
 
 
328
  def estimate_tokens(text):
329
  # Rough estimate: 1 token ~= 4 characters
330
  return len(text) // 4
 
488
  if attempt == max_attempts - 1:
489
  return f"I apologize, but an unexpected error occurred. Please try again with a different question."
490
 
491
+ return "An unexpected error occurred. Please try again later."."
 
492
 
493
  def extract_answer(full_response, instructions=None):
494
  answer_patterns = [
 
527
 
528
  return full_response.strip()
529
 
 
530
  # Gradio interface
531
  with gr.Blocks() as demo:
532
  gr.Markdown("# Enhanced PDF Document Chat and Web Search")