Sina Media Lab
commited on
Commit
Β·
a862f0d
1
Parent(s):
7b6a611
Updates
Browse files
app.py
CHANGED
@@ -88,6 +88,26 @@ if module_name:
|
|
88 |
st.title(title)
|
89 |
st.write(description)
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
if st.session_state.current_question is None or st.session_state.submitted:
|
92 |
st.session_state.current_question, st.session_state.options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
|
93 |
st.session_state.submitted = False
|
@@ -101,49 +121,39 @@ if module_name:
|
|
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 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
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.")
|
|
|
88 |
st.title(title)
|
89 |
st.write(description)
|
90 |
|
91 |
+
# Navigation and PDF Download buttons
|
92 |
+
col_nav_1, col_nav_2, col_pdf = st.columns([1, 1, 2])
|
93 |
+
with col_nav_1:
|
94 |
+
if st.session_state.question_count > 0:
|
95 |
+
if st.button("β¬
οΈ Prev"):
|
96 |
+
navigate_question("prev")
|
97 |
+
with col_nav_2:
|
98 |
+
if st.session_state.submitted:
|
99 |
+
if st.button("β‘οΈ Next"):
|
100 |
+
navigate_question("next")
|
101 |
+
with col_pdf:
|
102 |
+
if st.session_state.question_count > 0:
|
103 |
+
pdf = generate_pdf_report()
|
104 |
+
st.download_button(
|
105 |
+
label="Download PDF Report π",
|
106 |
+
data=pdf,
|
107 |
+
file_name="quiz_report.pdf",
|
108 |
+
mime="application/pdf"
|
109 |
+
)
|
110 |
+
|
111 |
if st.session_state.current_question is None or st.session_state.submitted:
|
112 |
st.session_state.current_question, st.session_state.options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
|
113 |
st.session_state.submitted = False
|
|
|
121 |
f"""
|
122 |
<div style='border: 2px solid #ccc; padding: 15px; background-color: #f9f9f9;'>
|
123 |
<strong>Question {st.session_state.question_count + 1}:</strong> {st.session_state.current_question}
|
124 |
+
<br>
|
125 |
+
{st.radio("Choose an answer:", st.session_state.options)}
|
126 |
</div>
|
127 |
""",
|
128 |
unsafe_allow_html=True
|
129 |
)
|
130 |
|
131 |
+
if st.button("Submit"):
|
132 |
+
st.session_state.submitted = True
|
133 |
+
st.session_state.question_queue.append((
|
134 |
+
st.session_state.current_question,
|
135 |
+
st.session_state.options,
|
136 |
+
st.session_state.selected_answer,
|
137 |
+
st.session_state.correct_answer,
|
138 |
+
st.session_state.explanation
|
139 |
+
))
|
140 |
+
|
141 |
+
if st.session_state.selected_answer == st.session_state.correct_answer:
|
142 |
+
st.session_state.correct_count += 1
|
143 |
+
st.success("β
Correct!")
|
144 |
+
else:
|
145 |
+
st.error("β Incorrect.")
|
146 |
+
|
147 |
+
# Explanation with proper width
|
148 |
+
st.markdown(
|
149 |
+
f"""
|
150 |
+
<div style='border: 2px solid #ccc; padding: 15px; background-color: #f0f0f0;'>
|
151 |
+
<strong>Explanation:</strong> {st.session_state.explanation}
|
152 |
+
</div>
|
153 |
+
""",
|
154 |
+
unsafe_allow_html=True
|
155 |
+
)
|
156 |
+
st.session_state.current_question = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
except ModuleNotFoundError:
|
159 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|