Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ load_dotenv()
|
|
| 9 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 10 |
|
| 11 |
def get_pdf_text(pdf_docs):
|
| 12 |
-
"""Extracts text from uploaded PDF files"""
|
| 13 |
text = ""
|
| 14 |
for pdf in pdf_docs:
|
| 15 |
pdf_reader = PdfReader(pdf)
|
|
@@ -18,14 +18,17 @@ def get_pdf_text(pdf_docs):
|
|
| 18 |
return text
|
| 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.
|
|
|
|
|
|
|
|
|
|
| 26 |
st.write(f"API Response:\n{response}") # Debugging: Check raw response
|
| 27 |
-
if response and response
|
| 28 |
-
return response
|
| 29 |
else:
|
| 30 |
return "No valid response from the API."
|
| 31 |
except Exception as e:
|
|
|
|
| 9 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 10 |
|
| 11 |
def get_pdf_text(pdf_docs):
|
| 12 |
+
"""Extracts text from uploaded PDF files."""
|
| 13 |
text = ""
|
| 14 |
for pdf in pdf_docs:
|
| 15 |
pdf_reader = PdfReader(pdf)
|
|
|
|
| 18 |
return text
|
| 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.ChatCompletion.create(
|
| 26 |
+
model="gemini-pro",
|
| 27 |
+
messages=[{"role": "user", "content": prompt}],
|
| 28 |
+
)
|
| 29 |
st.write(f"API Response:\n{response}") # Debugging: Check raw response
|
| 30 |
+
if response and response['choices']:
|
| 31 |
+
return response['choices'][0]['message']['content']
|
| 32 |
else:
|
| 33 |
return "No valid response from the API."
|
| 34 |
except Exception as e:
|