Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,7 +44,8 @@ def ask_question_from_pdf(pdf_text, user_question, api_key):
|
|
| 44 |
# Collect the streamed response.
|
| 45 |
answer = ""
|
| 46 |
for chunk in stream:
|
| 47 |
-
|
|
|
|
| 48 |
return answer
|
| 49 |
|
| 50 |
# Streamlit app
|
|
@@ -66,9 +67,12 @@ if uploaded_file is not None:
|
|
| 66 |
|
| 67 |
if st.button("Get Answer") and user_question and api_key:
|
| 68 |
with st.spinner("Fetching the answer..."):
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
| 72 |
elif not api_key:
|
| 73 |
st.error("Please provide a valid Groq API key.")
|
| 74 |
elif not user_question:
|
|
|
|
| 44 |
# Collect the streamed response.
|
| 45 |
answer = ""
|
| 46 |
for chunk in stream:
|
| 47 |
+
if chunk.choices[0].delta.content: # Ensure content is not None
|
| 48 |
+
answer += chunk.choices[0].delta.content
|
| 49 |
return answer
|
| 50 |
|
| 51 |
# Streamlit app
|
|
|
|
| 67 |
|
| 68 |
if st.button("Get Answer") and user_question and api_key:
|
| 69 |
with st.spinner("Fetching the answer..."):
|
| 70 |
+
try:
|
| 71 |
+
answer = ask_question_from_pdf(pdf_text, user_question, api_key)
|
| 72 |
+
st.success("Answer fetched!")
|
| 73 |
+
st.write("**Answer:**", answer)
|
| 74 |
+
except Exception as e:
|
| 75 |
+
st.error(f"An error occurred: {e}")
|
| 76 |
elif not api_key:
|
| 77 |
st.error("Please provide a valid Groq API key.")
|
| 78 |
elif not user_question:
|