Sina Media Lab
commited on
Commit
Β·
7b6a611
1
Parent(s):
7b17e7d
Updates
Browse files
app.py
CHANGED
|
@@ -36,6 +36,19 @@ if 'explanation' not in st.session_state:
|
|
| 36 |
if 'selected_answer' not in st.session_state:
|
| 37 |
st.session_state.selected_answer = None
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def generate_pdf_report():
|
| 40 |
pdf = FPDF()
|
| 41 |
pdf.add_page()
|
|
@@ -84,21 +97,25 @@ 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.
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|
| 93 |
with col1:
|
| 94 |
if st.session_state.question_count > 0:
|
| 95 |
if st.button("β¬
οΈ Prev"):
|
| 96 |
-
|
| 97 |
-
pass
|
| 98 |
with col2:
|
| 99 |
if st.button("Submit"):
|
| 100 |
st.session_state.submitted = True
|
| 101 |
-
st.session_state.question_count += 1
|
| 102 |
st.session_state.question_queue.append((
|
| 103 |
st.session_state.current_question,
|
| 104 |
st.session_state.options,
|
|
@@ -114,16 +131,19 @@ if module_name:
|
|
| 114 |
st.error("β Incorrect.")
|
| 115 |
st.write(f"**Explanation:** {st.session_state.explanation}")
|
| 116 |
st.session_state.current_question = None
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
except ModuleNotFoundError:
|
| 129 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|
|
|
|
| 36 |
if 'selected_answer' not in st.session_state:
|
| 37 |
st.session_state.selected_answer = None
|
| 38 |
|
| 39 |
+
# Handle Next and Previous question navigation
|
| 40 |
+
def navigate_question(direction):
|
| 41 |
+
if direction == "next":
|
| 42 |
+
st.session_state.question_count += 1
|
| 43 |
+
elif direction == "prev" and st.session_state.question_count > 1:
|
| 44 |
+
st.session_state.question_count -= 1
|
| 45 |
+
st.session_state.submitted = False
|
| 46 |
+
st.session_state.current_question = st.session_state.question_queue[st.session_state.question_count - 1][0]
|
| 47 |
+
st.session_state.options = st.session_state.question_queue[st.session_state.question_count - 1][1]
|
| 48 |
+
st.session_state.selected_answer = st.session_state.question_queue[st.session_state.question_count - 1][2]
|
| 49 |
+
st.session_state.correct_answer = st.session_state.question_queue[st.session_state.question_count - 1][3]
|
| 50 |
+
st.session_state.explanation = st.session_state.question_queue[st.session_state.question_count - 1][4]
|
| 51 |
+
|
| 52 |
def generate_pdf_report():
|
| 53 |
pdf = FPDF()
|
| 54 |
pdf.add_page()
|
|
|
|
| 97 |
correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
|
| 98 |
st.write(f"**Correct Answers:** {st.session_state.correct_count}/{st.session_state.question_count} ({correct_percentage:.2f}%)")
|
| 99 |
|
| 100 |
+
st.markdown(
|
| 101 |
+
f"""
|
| 102 |
+
<div style='border: 2px solid #ccc; padding: 15px; background-color: #f9f9f9;'>
|
| 103 |
+
<strong>Question {st.session_state.question_count + 1}:</strong> {st.session_state.current_question}
|
| 104 |
+
</div>
|
| 105 |
+
""",
|
| 106 |
+
unsafe_allow_html=True
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
st.session_state.selected_answer = st.radio("Choose an answer:", st.session_state.options)
|
|
|
|
| 110 |
|
| 111 |
+
col1, col2, col3 = st.columns([1, 1, 3])
|
| 112 |
with col1:
|
| 113 |
if st.session_state.question_count > 0:
|
| 114 |
if st.button("β¬
οΈ Prev"):
|
| 115 |
+
navigate_question("prev")
|
|
|
|
| 116 |
with col2:
|
| 117 |
if st.button("Submit"):
|
| 118 |
st.session_state.submitted = True
|
|
|
|
| 119 |
st.session_state.question_queue.append((
|
| 120 |
st.session_state.current_question,
|
| 121 |
st.session_state.options,
|
|
|
|
| 131 |
st.error("β Incorrect.")
|
| 132 |
st.write(f"**Explanation:** {st.session_state.explanation}")
|
| 133 |
st.session_state.current_question = None
|
| 134 |
+
|
| 135 |
+
if st.session_state.submitted:
|
| 136 |
+
with col3:
|
| 137 |
+
if st.button("β‘οΈ Next"):
|
| 138 |
+
navigate_question("next")
|
| 139 |
+
if st.session_state.question_count > 0:
|
| 140 |
+
pdf = generate_pdf_report()
|
| 141 |
+
st.download_button(
|
| 142 |
+
label="Download PDF Report π",
|
| 143 |
+
data=pdf,
|
| 144 |
+
file_name="quiz_report.pdf",
|
| 145 |
+
mime="application/pdf"
|
| 146 |
+
)
|
| 147 |
|
| 148 |
except ModuleNotFoundError:
|
| 149 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|