Sina Media Lab
commited on
Commit
Β·
3a8abb6
1
Parent(s):
34e799a
Updates
Browse files
app.py
CHANGED
@@ -32,49 +32,34 @@ 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, 10, txt="Quiz Report", ln=True, align="C")
|
38 |
pdf.ln(10)
|
39 |
|
40 |
-
for
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
)
|
58 |
-
pdf.multi_cell(0, 10, f"
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
elif option == selected:
|
64 |
-
pdf.set_text_color(255, 0, 0) # Red for incorrect
|
65 |
-
pdf.multi_cell(0, 10, f"{option}")
|
66 |
-
else:
|
67 |
-
pdf.set_text_color(0, 0, 0) # Default color for others
|
68 |
-
pdf.multi_cell(0, 10, f" {option}")
|
69 |
-
pdf.set_text_color(0, 0, 0) # Reset color
|
70 |
-
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
71 |
-
pdf.ln(5)
|
72 |
-
pdf.multi_cell(0, 10, "Step-by-Step Solution:")
|
73 |
-
for step in step_by_step_solution:
|
74 |
-
pdf.multi_cell(0, 10, step)
|
75 |
-
pdf.ln(10)
|
76 |
-
|
77 |
-
pdf.ln(10) # Add space after each module
|
78 |
|
79 |
return pdf.output(dest='S').encode('latin1', 'replace')
|
80 |
|
@@ -158,7 +143,8 @@ with col3:
|
|
158 |
mime="application/pdf"
|
159 |
)
|
160 |
|
161 |
-
|
|
|
162 |
|
163 |
# Create the form for the question
|
164 |
with st.form(key=f'question_form_{st.session_state.current_index}'):
|
@@ -188,11 +174,11 @@ if submit_button:
|
|
188 |
# Show correct/incorrect feedback and explanation
|
189 |
for option in current_question['options']:
|
190 |
if option == current_question['correct_answer']:
|
191 |
-
st.markdown(f"<span style='color:green;'>{option} β
</span>", unsafe_allow_html=True)
|
192 |
elif option == current_question['selected']:
|
193 |
-
st.markdown(f"<span style='color:red;'>{option} β</span>", unsafe_allow_html=True)
|
194 |
else:
|
195 |
-
st.markdown(f"{option}")
|
196 |
|
197 |
st.write(f"**Explanation:** {current_question['explanation']}")
|
198 |
st.write("**Step-by-Step Solution:**")
|
|
|
32 |
def generate_pdf_report():
|
33 |
pdf = FPDF()
|
34 |
pdf.add_page()
|
35 |
+
pdf.set_font("Arial", size=10)
|
36 |
|
37 |
pdf.cell(200, 10, txt="Quiz Report", ln=True, align="C")
|
38 |
pdf.ln(10)
|
39 |
|
40 |
+
for i, entry in enumerate(st.session_state.questions):
|
41 |
+
# Zebra background
|
42 |
+
if i % 2 == 0:
|
43 |
+
pdf.set_fill_color(230, 230, 230) # Light gray
|
44 |
+
else:
|
45 |
+
pdf.set_fill_color(255, 255, 255) # White
|
46 |
+
|
47 |
+
pdf.multi_cell(0, 10, 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, 10, 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, 10, 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, 10, f" {option}", border=1, fill=True)
|
59 |
+
|
60 |
+
pdf.set_text_color(0, 0, 0) # Reset color
|
61 |
+
pdf.multi_cell(0, 10, f"Explanation: {entry['explanation']}", border=1, fill=True)
|
62 |
+
pdf.ln(10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
return pdf.output(dest='S').encode('latin1', 'replace')
|
65 |
|
|
|
143 |
mime="application/pdf"
|
144 |
)
|
145 |
|
146 |
+
# Display the current question
|
147 |
+
st.markdown(f"**Q{st.session_state.current_index + 1}: {current_question['question']}**")
|
148 |
|
149 |
# Create the form for the question
|
150 |
with st.form(key=f'question_form_{st.session_state.current_index}'):
|
|
|
174 |
# Show correct/incorrect feedback and explanation
|
175 |
for option in current_question['options']:
|
176 |
if option == current_question['correct_answer']:
|
177 |
+
st.markdown(f"<div style='background-color:#D3D3D3; padding: 10px;'><span style='color:green;'>{option} β
</span></div>", unsafe_allow_html=True)
|
178 |
elif option == current_question['selected']:
|
179 |
+
st.markdown(f"<div style='background-color:#D3D3D3; padding: 10px;'><span style='color:red;'>{option} β</span></div>", unsafe_allow_html=True)
|
180 |
else:
|
181 |
+
st.markdown(f"<div style='background-color:#D3D3D3; padding: 10px;'>{option}</div>", unsafe_allow_html=True)
|
182 |
|
183 |
st.write(f"**Explanation:** {current_question['explanation']}")
|
184 |
st.write("**Step-by-Step Solution:**")
|