Sina Media Lab
commited on
Commit
Β·
b5d0d2c
1
Parent(s):
3a8abb6
Updates
Browse files
app.py
CHANGED
@@ -32,34 +32,35 @@ def reset_pdf_cache():
|
|
32 |
def generate_pdf_report():
|
33 |
pdf = FPDF()
|
34 |
pdf.add_page()
|
35 |
-
pdf.set_font("Arial", size=
|
36 |
|
37 |
-
pdf.cell(200,
|
38 |
-
pdf.ln(
|
39 |
|
40 |
for i, entry in enumerate(st.session_state.questions):
|
41 |
# Zebra background
|
42 |
if i % 2 == 0:
|
43 |
-
pdf.set_fill_color(
|
44 |
else:
|
45 |
pdf.set_fill_color(255, 255, 255) # White
|
46 |
|
47 |
-
pdf.multi_cell(0,
|
48 |
|
49 |
for option in entry['options']:
|
50 |
if option == entry['correct_answer']:
|
51 |
pdf.set_text_color(0, 128, 0) # Green for correct
|
52 |
-
pdf.multi_cell(0,
|
53 |
elif option == entry['selected']:
|
54 |
pdf.set_text_color(255, 0, 0) # Red for incorrect
|
55 |
-
pdf.multi_cell(0,
|
56 |
else:
|
57 |
pdf.set_text_color(0, 0, 0) # Default color for others
|
58 |
-
pdf.multi_cell(0,
|
59 |
|
60 |
pdf.set_text_color(0, 0, 0) # Reset color
|
61 |
-
pdf.multi_cell(0,
|
62 |
-
pdf.
|
|
|
63 |
|
64 |
return pdf.output(dest='S').encode('latin1', 'replace')
|
65 |
|
@@ -110,10 +111,10 @@ for module in modules:
|
|
110 |
|
111 |
if selected_module != st.session_state.current_module:
|
112 |
st.session_state.current_module = selected_module
|
113 |
-
st.session_state.current_index =
|
114 |
-
st.session_state.questions
|
115 |
-
st.session_state.module_question_count[selected_module] = 0
|
116 |
-
st.session_state.module_correct_count[selected_module] = 0
|
117 |
st.session_state.selected_answer = None
|
118 |
st.session_state.button_label = "Submit/New"
|
119 |
|
@@ -144,7 +145,7 @@ with col3:
|
|
144 |
)
|
145 |
|
146 |
# Display the current question
|
147 |
-
st.markdown(f"
|
148 |
|
149 |
# Create the form for the question
|
150 |
with st.form(key=f'question_form_{st.session_state.current_index}'):
|
@@ -171,19 +172,21 @@ if submit_button:
|
|
171 |
st.session_state.correct_count += 1
|
172 |
st.session_state.module_correct_count[selected_module] += 1
|
173 |
|
174 |
-
# Show correct/incorrect feedback and
|
|
|
175 |
for option in current_question['options']:
|
176 |
if option == current_question['correct_answer']:
|
177 |
-
st.markdown(f"<
|
178 |
elif option == current_question['selected']:
|
179 |
-
st.markdown(f"<
|
180 |
else:
|
181 |
-
st.markdown(f"
|
182 |
|
183 |
st.write(f"**Explanation:** {current_question['explanation']}")
|
184 |
st.write("**Step-by-Step Solution:**")
|
185 |
for step in current_question['step_by_step_solution']:
|
186 |
st.write(step)
|
|
|
187 |
|
188 |
# Generate a new question after submission
|
189 |
new_question = generate_new_question(selected_module, modules[selected_module])
|
|
|
32 |
def generate_pdf_report():
|
33 |
pdf = FPDF()
|
34 |
pdf.add_page()
|
35 |
+
pdf.set_font("Arial", size=8)
|
36 |
|
37 |
+
pdf.cell(200, 8, txt="Quiz Report", ln=True, align="C")
|
38 |
+
pdf.ln(8)
|
39 |
|
40 |
for i, entry in enumerate(st.session_state.questions):
|
41 |
# Zebra background
|
42 |
if i % 2 == 0:
|
43 |
+
pdf.set_fill_color(245, 245, 245) # Light gray
|
44 |
else:
|
45 |
pdf.set_fill_color(255, 255, 255) # White
|
46 |
|
47 |
+
pdf.multi_cell(0, 8, f"Q{i+1}: {entry['question']}", border=1, fill=True)
|
48 |
|
49 |
for option in entry['options']:
|
50 |
if option == entry['correct_answer']:
|
51 |
pdf.set_text_color(0, 128, 0) # Green for correct
|
52 |
+
pdf.multi_cell(0, 8, f"{option}", border=1, fill=True)
|
53 |
elif option == entry['selected']:
|
54 |
pdf.set_text_color(255, 0, 0) # Red for incorrect
|
55 |
+
pdf.multi_cell(0, 8, f"{option}", border=1, fill=True)
|
56 |
else:
|
57 |
pdf.set_text_color(0, 0, 0) # Default color for others
|
58 |
+
pdf.multi_cell(0, 8, f" {option}", border=1, fill=True)
|
59 |
|
60 |
pdf.set_text_color(0, 0, 0) # Reset color
|
61 |
+
pdf.multi_cell(0, 8, f"Explanation: {entry['explanation']}", border=1, fill=True)
|
62 |
+
pdf.multi_cell(0, 8, f"Step-by-Step Solution: {', '.join(entry['step_by_step_solution'])}", border=1, fill=True)
|
63 |
+
pdf.ln(8)
|
64 |
|
65 |
return pdf.output(dest='S').encode('latin1', 'replace')
|
66 |
|
|
|
111 |
|
112 |
if selected_module != st.session_state.current_module:
|
113 |
st.session_state.current_module = selected_module
|
114 |
+
st.session_state.current_index = len(st.session_state.questions) # Continue numbering from previous questions
|
115 |
+
st.session_state.questions.append(generate_new_question(selected_module, modules[selected_module]))
|
116 |
+
st.session_state.module_question_count[selected_module] = st.session_state.module_question_count.get(selected_module, 0)
|
117 |
+
st.session_state.module_correct_count[selected_module] = st.session_state.module_correct_count.get(selected_module, 0)
|
118 |
st.session_state.selected_answer = None
|
119 |
st.session_state.button_label = "Submit/New"
|
120 |
|
|
|
145 |
)
|
146 |
|
147 |
# Display the current question
|
148 |
+
st.markdown(f"<span style='font-size: 12px;'><b>Q{st.session_state.current_index + 1}: {current_question['question']}</b></span>", unsafe_allow_html=True)
|
149 |
|
150 |
# Create the form for the question
|
151 |
with st.form(key=f'question_form_{st.session_state.current_index}'):
|
|
|
172 |
st.session_state.correct_count += 1
|
173 |
st.session_state.module_correct_count[selected_module] += 1
|
174 |
|
175 |
+
# Show correct/incorrect feedback, explanation, and step-by-step solution
|
176 |
+
st.markdown("<div style='background-color:#f0f0f0; padding: 10px;'>", unsafe_allow_html=True)
|
177 |
for option in current_question['options']:
|
178 |
if option == current_question['correct_answer']:
|
179 |
+
st.markdown(f"<span style='color:green;'>{option} β
</span>", unsafe_allow_html=True)
|
180 |
elif option == current_question['selected']:
|
181 |
+
st.markdown(f"<span style='color:red;'>{option} β</span>", unsafe_allow_html=True)
|
182 |
else:
|
183 |
+
st.markdown(f"{option}", unsafe_allow_html=True)
|
184 |
|
185 |
st.write(f"**Explanation:** {current_question['explanation']}")
|
186 |
st.write("**Step-by-Step Solution:**")
|
187 |
for step in current_question['step_by_step_solution']:
|
188 |
st.write(step)
|
189 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
190 |
|
191 |
# Generate a new question after submission
|
192 |
new_question = generate_new_question(selected_module, modules[selected_module])
|