KalooAI commited on
Commit
d83d6c5
·
verified ·
1 Parent(s): 01fd5b6

Update app.py

Browse files

Added: max_retries=3, # <--- Add this line
timeout=30 # <--- Add this line
answer = response.get("answer", "")
return str(answer) if answer else "The model could not find an answer in that document."

show_error=True

Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -21,7 +21,9 @@ def get_llm():
21
  task="text-generation",
22
  max_new_tokens=512,
23
  temperature=0.1,
24
- huggingfacehub_api_token=os.getenv("HF_TOKEN")
 
 
25
  )
26
 
27
  # 2. DOCUMENT PROCESSING
@@ -49,6 +51,8 @@ def process_pdf(file_path):
49
  def retriever_qa(file, query):
50
  if file is None:
51
  return "Please upload a PDF first."
 
 
52
 
53
  llm = get_llm()
54
  retriever_obj = process_pdf(file)
@@ -69,7 +73,8 @@ def retriever_qa(file, query):
69
 
70
  # Invoke and return result
71
  response = rag_chain.invoke({"input": query})
72
- return response["answer"] # Note: 'answer' instead of 'result'
 
73
 
74
  # 4. GRADIO INTERFACE
75
  rag_application = gr.Interface(
@@ -83,4 +88,4 @@ rag_application = gr.Interface(
83
  title='Granite PDF Chatbot'
84
  )
85
 
86
- rag_application.launch()
 
21
  task="text-generation",
22
  max_new_tokens=512,
23
  temperature=0.1,
24
+ huggingfacehub_api_token=os.getenv("HF_TOKEN");
25
+ max_retries=3,
26
+ timeout=30
27
  )
28
 
29
  # 2. DOCUMENT PROCESSING
 
51
  def retriever_qa(file, query):
52
  if file is None:
53
  return "Please upload a PDF first."
54
+ if not query:
55
+ return "Error: Please enter a question."
56
 
57
  llm = get_llm()
58
  retriever_obj = process_pdf(file)
 
73
 
74
  # Invoke and return result
75
  response = rag_chain.invoke({"input": query})
76
+ answer = response.get("answer", "")
77
+ return str(answer) if answer else "The model could not find an answer in that document."
78
 
79
  # 4. GRADIO INTERFACE
80
  rag_application = gr.Interface(
 
88
  title='Granite PDF Chatbot'
89
  )
90
 
91
+ rag_application.launch(show_error=True)