Sina Media Lab
commited on
Commit
·
c5fe3bc
1
Parent(s):
07ba05d
Updates
Browse files
app.py
CHANGED
@@ -136,33 +136,51 @@ st.write(current_question["question"])
|
|
136 |
|
137 |
# Option highlighting logic
|
138 |
def get_option_style(option):
|
139 |
-
if current_question.get('answered', False):
|
140 |
if option == current_question['correct_answer']:
|
141 |
return "background-color:#d4edda;padding:10px;border-radius:5px;" # Green background for correct
|
142 |
elif option == current_question['selected']:
|
143 |
return "background-color:#f8d7da;padding:10px;border-radius:5px;" # Red background for incorrect
|
144 |
return "background-color:#f0f0f0;padding:10px;border-radius:5px;" # Gray background by default
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
if
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
# Option highlighting logic
|
138 |
def get_option_style(option):
|
139 |
+
if current_question.get('answered', False):
|
140 |
if option == current_question['correct_answer']:
|
141 |
return "background-color:#d4edda;padding:10px;border-radius:5px;" # Green background for correct
|
142 |
elif option == current_question['selected']:
|
143 |
return "background-color:#f8d7da;padding:10px;border-radius:5px;" # Red background for incorrect
|
144 |
return "background-color:#f0f0f0;padding:10px;border-radius:5px;" # Gray background by default
|
145 |
|
146 |
+
# Display each option with custom styles
|
147 |
+
selected_answer = None
|
148 |
+
for i, option in enumerate(current_question['options']):
|
149 |
+
option_html = f"<div style='{get_option_style(option)}'>{option}</div>"
|
150 |
+
if st.button(option_html, key=f"option_{i}"):
|
151 |
+
selected_answer = option
|
152 |
+
|
153 |
+
if selected_answer:
|
154 |
+
current_question['selected'] = selected_answer
|
155 |
+
current_question['answered'] = True
|
156 |
+
st.session_state.module_question_count[module_name] += 1
|
157 |
+
|
158 |
+
if selected_answer == current_question['correct_answer']:
|
159 |
+
st.session_state.correct_count += 1
|
160 |
+
st.session_state.module_correct_count[module_name] += 1
|
161 |
+
|
162 |
+
# Refresh the display after submission to show the correct/incorrect styles
|
163 |
+
st.experimental_rerun()
|
164 |
+
|
165 |
+
# Navigation buttons
|
166 |
+
col1, col2, col3 = st.columns([1, 1, 2])
|
167 |
+
with col1:
|
168 |
+
if st.button("⬅️ Prev", disabled=st.session_state.current_index == 0):
|
169 |
+
navigate_question("prev")
|
170 |
+
st.experimental_rerun()
|
171 |
+
|
172 |
+
with col2:
|
173 |
+
if st.button("➡️ Next"):
|
174 |
+
navigate_question("next")
|
175 |
+
st.experimental_rerun()
|
176 |
+
|
177 |
+
with col3:
|
178 |
+
if len(st.session_state.questions) > 0:
|
179 |
+
pdf = generate_pdf_report()
|
180 |
+
st.session_state.pdf_data = pdf # Reset PDF cache
|
181 |
+
st.download_button(
|
182 |
+
label="Download PDF Report 📄",
|
183 |
+
data=st.session_state.pdf_data,
|
184 |
+
file_name="quiz_report.pdf",
|
185 |
+
mime="application/pdf"
|
186 |
+
)
|