Sina Media Lab
commited on
Commit
·
8e6cd67
1
Parent(s):
764cfc6
Updates
Browse files
app.py
CHANGED
|
@@ -61,7 +61,7 @@ def generate_pdf_report():
|
|
| 61 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
| 62 |
pdf.ln(10)
|
| 63 |
|
| 64 |
-
return pdf.output(dest='S').encode('
|
| 65 |
|
| 66 |
# Logging for debugging
|
| 67 |
logging.info(f"Current Module: {st.session_state.current_module}")
|
|
@@ -99,18 +99,35 @@ if module_name:
|
|
| 99 |
st.title(title)
|
| 100 |
st.write(description)
|
| 101 |
|
| 102 |
-
#
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
st.
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
st.
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
if st.session_state.current_question is None or st.session_state.submitted:
|
| 116 |
st.session_state.current_question, st.session_state.options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
|
|
@@ -156,23 +173,6 @@ if module_name:
|
|
| 156 |
unsafe_allow_html=True
|
| 157 |
)
|
| 158 |
|
| 159 |
-
# Show the "Next" button after the question has been answered
|
| 160 |
-
if st.session_state.submitted:
|
| 161 |
-
if st.button("➡️ Next"):
|
| 162 |
-
st.session_state.current_question = None
|
| 163 |
-
logging.info("Navigated to next question.")
|
| 164 |
-
|
| 165 |
-
# Display the "Download PDF Report" button after at least one question has been answered
|
| 166 |
-
if st.session_state.question_count > 0:
|
| 167 |
-
pdf = generate_pdf_report()
|
| 168 |
-
st.download_button(
|
| 169 |
-
label="Download PDF Report 📄",
|
| 170 |
-
data=pdf,
|
| 171 |
-
file_name="quiz_report.pdf",
|
| 172 |
-
mime="application/pdf"
|
| 173 |
-
)
|
| 174 |
-
logging.info("PDF report generated.")
|
| 175 |
-
|
| 176 |
except ModuleNotFoundError as e:
|
| 177 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|
| 178 |
logging.error(f"Error: {e}")
|
|
|
|
| 61 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
| 62 |
pdf.ln(10)
|
| 63 |
|
| 64 |
+
return pdf.output(dest='S').encode('latin1', 'replace')
|
| 65 |
|
| 66 |
# Logging for debugging
|
| 67 |
logging.info(f"Current Module: {st.session_state.current_module}")
|
|
|
|
| 99 |
st.title(title)
|
| 100 |
st.write(description)
|
| 101 |
|
| 102 |
+
# Display the "Next" and "Download PDF Report" buttons above the question
|
| 103 |
+
col1, col2, col3 = st.columns([1, 1, 2])
|
| 104 |
+
with col1:
|
| 105 |
+
if st.session_state.submitted:
|
| 106 |
+
if st.button("➡️ Next"):
|
| 107 |
+
st.session_state.current_question = None
|
| 108 |
+
logging.info("Navigated to next question.")
|
| 109 |
+
with col2:
|
| 110 |
+
if st.session_state.question_count > 1:
|
| 111 |
+
if st.button("⬅️ Prev"):
|
| 112 |
+
st.session_state.question_count -= 1
|
| 113 |
+
st.session_state.submitted = False
|
| 114 |
+
question_data = st.session_state.question_queue[st.session_state.question_count - 1]
|
| 115 |
+
st.session_state.current_question = question_data[0]
|
| 116 |
+
st.session_state.options = question_data[1]
|
| 117 |
+
st.session_state.selected_answer = question_data[2]
|
| 118 |
+
st.session_state.correct_answer = question_data[3]
|
| 119 |
+
st.session_state.explanation = question_data[4]
|
| 120 |
+
logging.info("Navigated to previous question.")
|
| 121 |
+
with col3:
|
| 122 |
+
if st.session_state.question_count > 0:
|
| 123 |
+
pdf = generate_pdf_report()
|
| 124 |
+
st.download_button(
|
| 125 |
+
label="Download PDF Report 📄",
|
| 126 |
+
data=pdf,
|
| 127 |
+
file_name="quiz_report.pdf",
|
| 128 |
+
mime="application/pdf"
|
| 129 |
+
)
|
| 130 |
+
logging.info("PDF report generated.")
|
| 131 |
|
| 132 |
if st.session_state.current_question is None or st.session_state.submitted:
|
| 133 |
st.session_state.current_question, st.session_state.options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
|
|
|
|
| 173 |
unsafe_allow_html=True
|
| 174 |
)
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
except ModuleNotFoundError as e:
|
| 177 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|
| 178 |
logging.error(f"Error: {e}")
|