Sina Media Lab commited on
Commit
3a8abb6
Β·
1 Parent(s): 34e799a
Files changed (1) hide show
  1. app.py +29 -43
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=12)
36
 
37
  pdf.cell(200, 10, txt="Quiz Report", ln=True, align="C")
38
  pdf.ln(10)
39
 
40
- for module, data in st.session_state.module_question_count.items():
41
- correct_count = st.session_state.module_correct_count.get(module, 0)
42
- total_count = data
43
- pdf.cell(200, 10, txt=f"Module: {module}", ln=True, align="L")
44
- pdf.ln(5)
45
- pdf.cell(200, 10, txt=f"Correct Answers: {correct_count}/{total_count}", ln=True, align="L")
46
- pdf.ln(5)
47
-
48
- for entry in st.session_state.questions:
49
- if entry['module'] == module:
50
- question, options, selected, correct, explanation, step_by_step_solution = (
51
- entry['question'],
52
- entry['options'],
53
- entry['selected'] if entry['selected'] is not None else "Not Answered",
54
- entry['correct_answer'],
55
- entry['explanation'],
56
- entry['step_by_step_solution']
57
- )
58
- pdf.multi_cell(0, 10, f"Q: {question}")
59
- for option in options:
60
- if option == correct:
61
- pdf.set_text_color(0, 128, 0) # Green for correct
62
- pdf.multi_cell(0, 10, f"{option}")
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
- st.write(current_question["question"])
 
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:**")