DataCracker commited on
Commit
4755734
1 Parent(s): c9b557a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from fpdf import FPDF
3
+ import tempfile
4
+
5
+ if 'qa_pairs' not in st.session_state:
6
+ st.session_state.qa_pairs = []
7
+
8
+ def generate_pdf(qa_pairs):
9
+ pdf = FPDF()
10
+ pdf.add_page()
11
+ pdf.set_font("Arial", size=12)
12
+
13
+ for qa in qa_pairs:
14
+ pdf.multi_cell(0, 10, f"Q: {qa['question']}")
15
+ pdf.multi_cell(0, 10, f"A: {qa['answer']}")
16
+ pdf.ln()
17
+
18
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
19
+ pdf.output(temp_file.name)
20
+ return temp_file.name
21
+
22
+ st.title("Q&A Input Tool")
23
+ question = st.text_input("Enter a question:")
24
+ answer = st.text_area("Enter the answer:")
25
+
26
+ if st.button("Add Question & Answer"):
27
+ if question and answer:
28
+ st.session_state.qa_pairs.append({"question": question, "answer": answer})
29
+ st.success("Q&A added successfully!")
30
+ else:
31
+ st.error("Please enter both a question and an answer.")
32
+
33
+ if st.session_state.qa_pairs:
34
+ pdf_file_path = generate_pdf(st.session_state.qa_pairs)
35
+ with open(pdf_file_path, "rb") as pdf_file:
36
+ st.download_button(
37
+ label="Download PDF",
38
+ data=pdf_file,
39
+ file_name="QandA.pdf",
40
+ mime="application/pdf"
41
+ )
42
+
43
+ st.header("Current Q&A Pairs")
44
+ for qa in st.session_state.qa_pairs:
45
+ st.write(f"Q: {qa['question']}")
46
+ st.write(f"A: {qa['answer']}")
47
+ st.write("---")