Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,7 +83,8 @@ def generate_question(context, answer, num_beams=5):
|
|
| 83 |
# Function to export questions to CSV
|
| 84 |
def export_to_csv(data):
|
| 85 |
df = pd.DataFrame(data, columns=["Context", "Answer", "Question"])
|
| 86 |
-
df.to_csv('questions.csv', index=False)
|
|
|
|
| 87 |
|
| 88 |
# Function to export questions to PDF
|
| 89 |
def export_to_pdf(data):
|
|
@@ -97,7 +98,8 @@ def export_to_pdf(data):
|
|
| 97 |
pdf.multi_cell(0, 10, f"Question: {question}")
|
| 98 |
pdf.ln(10)
|
| 99 |
|
| 100 |
-
pdf.output("questions.pdf")
|
|
|
|
| 101 |
|
| 102 |
# Streamlit interface
|
| 103 |
st.title(":blue[Question Generator from Text]")
|
|
@@ -108,8 +110,8 @@ num_beams = st.slider("Select number of beams for question generation", min_valu
|
|
| 108 |
context_window_size = st.slider("Select context window size (number of sentences before and after)", min_value=1, max_value=5, value=1)
|
| 109 |
num_questions = st.slider("Select number of questions to generate", min_value=1, max_value=1000, value=5)
|
| 110 |
question_complexity = st.selectbox("Select question complexity", ["Simple", "Intermediate", "Complex"])
|
| 111 |
-
downlaod_csv = st.toggle('Download CSV',value=
|
| 112 |
-
download_pdf = st.toggle('Download PDF',value=
|
| 113 |
if st.button("Generate Questions"):
|
| 114 |
if text:
|
| 115 |
keywords = extract_keywords(text)
|
|
@@ -133,12 +135,14 @@ if st.button("Generate Questions"):
|
|
| 133 |
# Export buttons
|
| 134 |
# if st.button("Export to CSV"):
|
| 135 |
if downlaod_csv:
|
| 136 |
-
export_to_csv(data)
|
| 137 |
st.success("Questions exported to questions.csv")
|
|
|
|
| 138 |
|
| 139 |
# if st.button("Export to PDF"):
|
| 140 |
if download_pdf:
|
| 141 |
-
export_to_pdf(data)
|
| 142 |
st.success("Questions exported to questions.pdf")
|
|
|
|
| 143 |
else:
|
| 144 |
st.write("Please enter some text to generate questions.")
|
|
|
|
| 83 |
# Function to export questions to CSV
|
| 84 |
def export_to_csv(data):
|
| 85 |
df = pd.DataFrame(data, columns=["Context", "Answer", "Question"])
|
| 86 |
+
csv = df.to_csv('questions.csv', index=False)
|
| 87 |
+
return csv
|
| 88 |
|
| 89 |
# Function to export questions to PDF
|
| 90 |
def export_to_pdf(data):
|
|
|
|
| 98 |
pdf.multi_cell(0, 10, f"Question: {question}")
|
| 99 |
pdf.ln(10)
|
| 100 |
|
| 101 |
+
# pdf.output("questions.pdf")
|
| 102 |
+
return pdf.output(name='questions.pdf',dest='S').encode('latin1')
|
| 103 |
|
| 104 |
# Streamlit interface
|
| 105 |
st.title(":blue[Question Generator from Text]")
|
|
|
|
| 110 |
context_window_size = st.slider("Select context window size (number of sentences before and after)", min_value=1, max_value=5, value=1)
|
| 111 |
num_questions = st.slider("Select number of questions to generate", min_value=1, max_value=1000, value=5)
|
| 112 |
question_complexity = st.selectbox("Select question complexity", ["Simple", "Intermediate", "Complex"])
|
| 113 |
+
downlaod_csv = st.toggle('Download CSV',value=True)
|
| 114 |
+
download_pdf = st.toggle('Download PDF',value=True)
|
| 115 |
if st.button("Generate Questions"):
|
| 116 |
if text:
|
| 117 |
keywords = extract_keywords(text)
|
|
|
|
| 135 |
# Export buttons
|
| 136 |
# if st.button("Export to CSV"):
|
| 137 |
if downlaod_csv:
|
| 138 |
+
csv_data = export_to_csv(data)
|
| 139 |
st.success("Questions exported to questions.csv")
|
| 140 |
+
st.download_button(label="Download CSV", data=csv_data, file_name='questions.csv', mime='text/csv')
|
| 141 |
|
| 142 |
# if st.button("Export to PDF"):
|
| 143 |
if download_pdf:
|
| 144 |
+
pdf_data = export_to_pdf(data)
|
| 145 |
st.success("Questions exported to questions.pdf")
|
| 146 |
+
st.download_button(label="Download PDF", data=pdf_data, file_name='questions.pdf', mime='application/pdf')
|
| 147 |
else:
|
| 148 |
st.write("Please enter some text to generate questions.")
|