Sina Media Lab commited on
Commit
7b17e7d
Β·
1 Parent(s): a1b650a
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -14,7 +14,7 @@ module_names = {
14
  "Subtraction": "subtraction_bases",
15
  }
16
 
17
- # Initialize session state for tracking answers, progress, and questions queue
18
  if 'correct_count' not in st.session_state:
19
  st.session_state.correct_count = 0
20
  if 'question_count' not in st.session_state:
@@ -49,15 +49,15 @@ def generate_pdf_report():
49
  pdf.multi_cell(0, 10, f"Q{idx+1}: {question}")
50
  for option in options:
51
  if option == correct:
52
- pdf.multi_cell(0, 10, f"βœ… {option} (Correct)")
53
  elif option == selected:
54
- pdf.multi_cell(0, 10, f"❌ {option} (Your Choice)")
55
  else:
56
  pdf.multi_cell(0, 10, f" {option}")
57
  pdf.multi_cell(0, 10, f"Explanation: {explanation}")
58
  pdf.ln(10)
59
 
60
- return pdf.output(dest='S').encode('latin1')
61
 
62
  # Streamlit interface
63
  st.sidebar.title("Quiz Modules")
@@ -84,12 +84,14 @@ if module_name:
84
  correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
85
  st.write(f"**Correct Answers:** {st.session_state.correct_count}/{st.session_state.question_count} ({correct_percentage:.2f}%)")
86
 
 
87
  st.write(f"**Question {st.session_state.question_count + 1}:** {st.session_state.current_question}")
88
- st.session_state.selected_answer = st.radio("Choose an answer:", st.session_state.options, index=0)
 
89
 
90
- col1, col2, col3 = st.columns([1, 1, 3])
91
- if st.session_state.question_count > 0:
92
- with col1:
93
  if st.button("⬅️ Prev"):
94
  # Logic for previous question (if applicable)
95
  pass
@@ -115,14 +117,13 @@ if module_name:
115
  st.experimental_set_query_params(dummy_param=True)
116
 
117
  if st.session_state.submitted and st.session_state.question_count > 0:
118
- with col3:
119
- pdf = generate_pdf_report()
120
- st.download_button(
121
- label="Download PDF Report πŸ“„",
122
- data=pdf,
123
- file_name="quiz_report.pdf",
124
- mime="application/pdf"
125
- )
126
 
127
  except ModuleNotFoundError:
128
  st.error(f"The module '{module_name}' was not found. Please select another module.")
 
14
  "Subtraction": "subtraction_bases",
15
  }
16
 
17
+ # Initialize session state variables
18
  if 'correct_count' not in st.session_state:
19
  st.session_state.correct_count = 0
20
  if 'question_count' not in st.session_state:
 
49
  pdf.multi_cell(0, 10, f"Q{idx+1}: {question}")
50
  for option in options:
51
  if option == correct:
52
+ pdf.multi_cell(0, 10, f"{option} (Correct)")
53
  elif option == selected:
54
+ pdf.multi_cell(0, 10, f"{option} (Your Choice)")
55
  else:
56
  pdf.multi_cell(0, 10, f" {option}")
57
  pdf.multi_cell(0, 10, f"Explanation: {explanation}")
58
  pdf.ln(10)
59
 
60
+ return pdf.output(dest='S').encode('utf-8')
61
 
62
  # Streamlit interface
63
  st.sidebar.title("Quiz Modules")
 
84
  correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
85
  st.write(f"**Correct Answers:** {st.session_state.correct_count}/{st.session_state.question_count} ({correct_percentage:.2f}%)")
86
 
87
+ st.write(f"<div style='border: 2px solid #ccc; padding: 15px; background-color: #f9f9f9;'>", unsafe_allow_html=True)
88
  st.write(f"**Question {st.session_state.question_count + 1}:** {st.session_state.current_question}")
89
+ st.session_state.selected_answer = st.radio("Choose an answer:", st.session_state.options)
90
+ st.write("</div>", unsafe_allow_html=True)
91
 
92
+ col1, col2 = st.columns([1, 4])
93
+ with col1:
94
+ if st.session_state.question_count > 0:
95
  if st.button("⬅️ Prev"):
96
  # Logic for previous question (if applicable)
97
  pass
 
117
  st.experimental_set_query_params(dummy_param=True)
118
 
119
  if st.session_state.submitted and st.session_state.question_count > 0:
120
+ pdf = generate_pdf_report()
121
+ st.download_button(
122
+ label="Download PDF Report πŸ“„",
123
+ data=pdf,
124
+ file_name="quiz_report.pdf",
125
+ mime="application/pdf"
126
+ )
 
127
 
128
  except ModuleNotFoundError:
129
  st.error(f"The module '{module_name}' was not found. Please select another module.")