Sina Media Lab
commited on
Commit
Β·
7b17e7d
1
Parent(s):
a1b650a
Updates
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ module_names = {
|
|
| 14 |
"Subtraction": "subtraction_bases",
|
| 15 |
}
|
| 16 |
|
| 17 |
-
# Initialize session state
|
| 18 |
if 'correct_count' not in st.session_state:
|
| 19 |
st.session_state.correct_count = 0
|
| 20 |
if 'question_count' not in st.session_state:
|
|
@@ -49,15 +49,15 @@ def generate_pdf_report():
|
|
| 49 |
pdf.multi_cell(0, 10, f"Q{idx+1}: {question}")
|
| 50 |
for option in options:
|
| 51 |
if option == correct:
|
| 52 |
-
pdf.multi_cell(0, 10, f"
|
| 53 |
elif option == selected:
|
| 54 |
-
pdf.multi_cell(0, 10, f"
|
| 55 |
else:
|
| 56 |
pdf.multi_cell(0, 10, f" {option}")
|
| 57 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
| 58 |
pdf.ln(10)
|
| 59 |
|
| 60 |
-
return pdf.output(dest='S').encode('
|
| 61 |
|
| 62 |
# Streamlit interface
|
| 63 |
st.sidebar.title("Quiz Modules")
|
|
@@ -84,12 +84,14 @@ if module_name:
|
|
| 84 |
correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
|
| 85 |
st.write(f"**Correct Answers:** {st.session_state.correct_count}/{st.session_state.question_count} ({correct_percentage:.2f}%)")
|
| 86 |
|
|
|
|
| 87 |
st.write(f"**Question {st.session_state.question_count + 1}:** {st.session_state.current_question}")
|
| 88 |
-
st.session_state.selected_answer = st.radio("Choose an answer:", st.session_state.options
|
|
|
|
| 89 |
|
| 90 |
-
col1, col2
|
| 91 |
-
|
| 92 |
-
|
| 93 |
if st.button("β¬
οΈ Prev"):
|
| 94 |
# Logic for previous question (if applicable)
|
| 95 |
pass
|
|
@@ -115,14 +117,13 @@ if module_name:
|
|
| 115 |
st.experimental_set_query_params(dummy_param=True)
|
| 116 |
|
| 117 |
if st.session_state.submitted and st.session_state.question_count > 0:
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
)
|
| 126 |
|
| 127 |
except ModuleNotFoundError:
|
| 128 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|
|
|
|
| 14 |
"Subtraction": "subtraction_bases",
|
| 15 |
}
|
| 16 |
|
| 17 |
+
# Initialize session state variables
|
| 18 |
if 'correct_count' not in st.session_state:
|
| 19 |
st.session_state.correct_count = 0
|
| 20 |
if 'question_count' not in st.session_state:
|
|
|
|
| 49 |
pdf.multi_cell(0, 10, f"Q{idx+1}: {question}")
|
| 50 |
for option in options:
|
| 51 |
if option == correct:
|
| 52 |
+
pdf.multi_cell(0, 10, f"{option} (Correct)")
|
| 53 |
elif option == selected:
|
| 54 |
+
pdf.multi_cell(0, 10, f"{option} (Your Choice)")
|
| 55 |
else:
|
| 56 |
pdf.multi_cell(0, 10, f" {option}")
|
| 57 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
| 58 |
pdf.ln(10)
|
| 59 |
|
| 60 |
+
return pdf.output(dest='S').encode('utf-8')
|
| 61 |
|
| 62 |
# Streamlit interface
|
| 63 |
st.sidebar.title("Quiz Modules")
|
|
|
|
| 84 |
correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
|
| 85 |
st.write(f"**Correct Answers:** {st.session_state.correct_count}/{st.session_state.question_count} ({correct_percentage:.2f}%)")
|
| 86 |
|
| 87 |
+
st.write(f"<div style='border: 2px solid #ccc; padding: 15px; background-color: #f9f9f9;'>", unsafe_allow_html=True)
|
| 88 |
st.write(f"**Question {st.session_state.question_count + 1}:** {st.session_state.current_question}")
|
| 89 |
+
st.session_state.selected_answer = st.radio("Choose an answer:", st.session_state.options)
|
| 90 |
+
st.write("</div>", unsafe_allow_html=True)
|
| 91 |
|
| 92 |
+
col1, col2 = st.columns([1, 4])
|
| 93 |
+
with col1:
|
| 94 |
+
if st.session_state.question_count > 0:
|
| 95 |
if st.button("β¬
οΈ Prev"):
|
| 96 |
# Logic for previous question (if applicable)
|
| 97 |
pass
|
|
|
|
| 117 |
st.experimental_set_query_params(dummy_param=True)
|
| 118 |
|
| 119 |
if st.session_state.submitted and st.session_state.question_count > 0:
|
| 120 |
+
pdf = generate_pdf_report()
|
| 121 |
+
st.download_button(
|
| 122 |
+
label="Download PDF Report π",
|
| 123 |
+
data=pdf,
|
| 124 |
+
file_name="quiz_report.pdf",
|
| 125 |
+
mime="application/pdf"
|
| 126 |
+
)
|
|
|
|
| 127 |
|
| 128 |
except ModuleNotFoundError:
|
| 129 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|