OnlyTheTruth03 commited on
Commit
d943582
·
1 Parent(s): 87fa998

pdf download button code

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +15 -3
src/streamlit_app.py CHANGED
@@ -48,8 +48,7 @@ question = st.text_input(
48
  # ---------------- ANSWER ----------------
49
  if question:
50
  with st.spinner("Searching document..."):
51
- query_embedding = embedder.encode([question]).astype("float32")
52
- contexts = retrieve(query_embedding)
53
 
54
  context_text = "\n\n".join(c["text"] for c in contexts)
55
 
@@ -72,7 +71,20 @@ Answer clearly and concisely.
72
  {"role": "system", "content": "You are a helpful assistant."},
73
  {"role": "user", "content": prompt},
74
  ],
 
75
  )
76
 
 
 
 
77
  st.subheader("Answer")
78
- st.write(response.choices[0].message.content)
 
 
 
 
 
 
 
 
 
 
48
  # ---------------- ANSWER ----------------
49
  if question:
50
  with st.spinner("Searching document..."):
51
+ contexts = retrieve(question)
 
52
 
53
  context_text = "\n\n".join(c["text"] for c in contexts)
54
 
 
71
  {"role": "system", "content": "You are a helpful assistant."},
72
  {"role": "user", "content": prompt},
73
  ],
74
+ max_tokens=800
75
  )
76
 
77
+ answer = response.choices[0].message.content
78
+ st.session_state["last_answer"] = answer
79
+
80
  st.subheader("Answer")
81
+ st.write(answer)
82
+
83
+ pdf_buffer = answer_to_pdf(question, answer)
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
+ )