shahed125238 commited on
Commit
26d3a32
·
verified ·
1 Parent(s): a4c9a15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -19,9 +19,18 @@ def get_pdf_text(pdf_docs):
19
 
20
  def get_gemini_response(question, context):
21
  """Sends question and context to Gemini for an answer"""
22
- prompt = f"Context:\n{context}\n\nQuestion:\n{question}\n\nAnswer:"
23
- response = genai.generate_text(prompt=prompt)
24
- return response.generations[0].text
 
 
 
 
 
 
 
 
 
25
 
26
  def main():
27
  st.set_page_config(page_title="Chat with PDF")
 
19
 
20
  def get_gemini_response(question, context):
21
  """Sends question and context to Gemini for an answer"""
22
+ try:
23
+ prompt = f"Context:\n{context}\n\nQuestion:\n{question}\n\nAnswer:"
24
+ st.write(f"Sending prompt to Gemini:\n{prompt}") # Debugging: Check prompt
25
+ response = genai.generate_text(prompt=prompt)
26
+ st.write(f"API Response:\n{response}") # Debugging: Check raw response
27
+ if response and response.generations:
28
+ return response.generations[0].text
29
+ else:
30
+ return "No valid response from the API."
31
+ except Exception as e:
32
+ st.error(f"Error generating response: {e}")
33
+ return "Error while generating response."
34
 
35
  def main():
36
  st.set_page_config(page_title="Chat with PDF")