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

Added download button for the answer

Browse files
Files changed (3) hide show
  1. requirements.txt +2 -1
  2. src/pdf_utils.py +31 -0
  3. src/streamlit_app.py +1 -0
requirements.txt CHANGED
@@ -9,4 +9,5 @@ datasets
9
  scikit-learn
10
  pypdf
11
  pdfplumber
12
- torch
 
 
9
  scikit-learn
10
  pypdf
11
  pdfplumber
12
+ torch
13
+ reportlab
src/pdf_utils.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from io import BytesIO
2
+ from reportlab.lib.pagesizes import A4
3
+ from reportlab.pdfgen import canvas
4
+ from reportlab.lib.units import inch
5
+
6
+ def answer_to_pdf(question: str, answer: str) -> BytesIO:
7
+ buffer = BytesIO()
8
+ c = canvas.Canvas(buffer, pagesize=A4)
9
+ width, height = A4
10
+
11
+ textobject = c.beginText(1 * inch, height - 1 * inch)
12
+ textobject.setFont("Helvetica", 11)
13
+
14
+ textobject.textLine("OTT Bot – Answer")
15
+ textobject.textLine("-" * 50)
16
+ textobject.textLine("")
17
+ textobject.textLine(f"Question:")
18
+ textobject.textLine(question)
19
+ textobject.textLine("")
20
+ textobject.textLine("Answer:")
21
+ textobject.textLine("")
22
+
23
+ for line in answer.split("\n"):
24
+ textobject.textLine(line)
25
+
26
+ c.drawText(textobject)
27
+ c.showPage()
28
+ c.save()
29
+
30
+ buffer.seek(0)
31
+ return buffer
src/streamlit_app.py CHANGED
@@ -6,6 +6,7 @@ from ingest import build_index
6
  from rag import retrieve
7
  from groq import Groq
8
  from config import EMBEDDING_MODEL
 
9
 
10
  # ---------------- CONFIG ----------------
11
  st.set_page_config(page_title="OTT Bot", layout="wide")
 
6
  from rag import retrieve
7
  from groq import Groq
8
  from config import EMBEDDING_MODEL
9
+ from pdf_utils import answer_to_pdf
10
 
11
  # ---------------- CONFIG ----------------
12
  st.set_page_config(page_title="OTT Bot", layout="wide")