Spaces:
Sleeping
Sleeping
Commit
Β·
9de5fcf
1
Parent(s):
d943582
Corrected code for download button
Browse files- src/streamlit_app.py +9 -10
src/streamlit_app.py
CHANGED
|
@@ -28,7 +28,6 @@ client = Groq(api_key=GROQ_API_KEY)
|
|
| 28 |
|
| 29 |
# ---------------- UI ----------------
|
| 30 |
st.title("π OTT Bot")
|
| 31 |
-
|
| 32 |
st.markdown("Upload PDFs via HF Dataset and query them using AI")
|
| 33 |
|
| 34 |
# ---------------- INGESTION ----------------
|
|
@@ -48,11 +47,12 @@ question = st.text_input(
|
|
| 48 |
# ---------------- ANSWER ----------------
|
| 49 |
if question:
|
| 50 |
with st.spinner("Searching document..."):
|
| 51 |
-
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
Answer the question based on the context below.
|
| 57 |
|
| 58 |
Context:
|
|
@@ -71,20 +71,19 @@ Answer clearly and concisely.
|
|
| 71 |
{"role": "system", "content": "You are a helpful assistant."},
|
| 72 |
{"role": "user", "content": prompt},
|
| 73 |
],
|
| 74 |
-
max_tokens=800
|
| 75 |
)
|
| 76 |
|
| 77 |
-
|
| 78 |
-
st.session_state["last_answer"] = answer
|
| 79 |
|
| 80 |
st.subheader("Answer")
|
| 81 |
-
st.write(
|
| 82 |
|
| 83 |
-
|
|
|
|
| 84 |
|
| 85 |
st.download_button(
|
| 86 |
label="π Download Answer as PDF",
|
| 87 |
data=pdf_buffer,
|
| 88 |
file_name="OTT_Bot_Answer.pdf",
|
| 89 |
mime="application/pdf"
|
| 90 |
-
)
|
|
|
|
| 28 |
|
| 29 |
# ---------------- UI ----------------
|
| 30 |
st.title("π OTT Bot")
|
|
|
|
| 31 |
st.markdown("Upload PDFs via HF Dataset and query them using AI")
|
| 32 |
|
| 33 |
# ---------------- INGESTION ----------------
|
|
|
|
| 47 |
# ---------------- ANSWER ----------------
|
| 48 |
if question:
|
| 49 |
with st.spinner("Searching document..."):
|
| 50 |
+
query_embedding = embedder.encode([question]).astype("float32")
|
| 51 |
+
contexts = retrieve(query_embedding)
|
| 52 |
|
| 53 |
+
context_text = "\n\n".join(c["text"] for c in contexts)
|
| 54 |
|
| 55 |
+
prompt = f"""
|
| 56 |
Answer the question based on the context below.
|
| 57 |
|
| 58 |
Context:
|
|
|
|
| 71 |
{"role": "system", "content": "You are a helpful assistant."},
|
| 72 |
{"role": "user", "content": prompt},
|
| 73 |
],
|
|
|
|
| 74 |
)
|
| 75 |
|
| 76 |
+
answer_text = response.choices[0].message.content
|
|
|
|
| 77 |
|
| 78 |
st.subheader("Answer")
|
| 79 |
+
st.write(answer_text)
|
| 80 |
|
| 81 |
+
# ---------------- PDF DOWNLOAD ----------------
|
| 82 |
+
pdf_buffer = answer_to_pdf(question, answer_text)
|
| 83 |
|
| 84 |
st.download_button(
|
| 85 |
label="π Download Answer as PDF",
|
| 86 |
data=pdf_buffer,
|
| 87 |
file_name="OTT_Bot_Answer.pdf",
|
| 88 |
mime="application/pdf"
|
| 89 |
+
)
|