Sina Media Lab commited on
Commit
cab1b57
Β·
1 Parent(s): 2ac817c
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -62,9 +62,9 @@ def generate_pdf_report():
62
  pdf.multi_cell(0, 10, f"Q: {question}")
63
  for option in options:
64
  if option == correct:
65
- pdf.multi_cell(0, 10, f"Correct: {option}")
66
  elif option == selected:
67
- pdf.multi_cell(0, 10, f"Your Choice: {option}")
68
  else:
69
  pdf.multi_cell(0, 10, f" {option}")
70
  pdf.multi_cell(0, 10, f"Explanation: {explanation}")
@@ -110,11 +110,11 @@ module_name = st.sidebar.radio("Choose a module:", list(module_names.keys()), in
110
 
111
  if module_name != st.session_state.current_module:
112
  st.session_state.current_module = module_name
113
- st.session_state.questions = []
114
  st.session_state.current_index = 0
115
 
116
- # Generate the first question for the new module
117
- st.session_state.questions.append(generate_new_question(module_name))
 
118
 
119
  # Load the current module for title and description
120
  current_module = load_module(st.session_state.current_module)
@@ -131,7 +131,7 @@ with col1:
131
  with col2:
132
  st.button("➑️ Next", on_click=lambda: navigate_question("next"))
133
  with col3:
134
- if st.session_state.current_index > 0:
135
  pdf = generate_pdf_report()
136
  st.download_button(
137
  label="Download PDF Report πŸ“„",
@@ -144,11 +144,13 @@ with col3:
144
  st.write(f"**Question {st.session_state.current_index + 1}:** {current_question['question']}")
145
 
146
  if current_question['answered']:
147
- st.radio("Choose an answer:", current_question['options'], index=current_question['options'].index(current_question['selected']), disabled=True)
148
- if current_question['selected'] == current_question['correct']:
149
- st.success(f"Correct! Your answer: {current_question['selected']}")
150
- else:
151
- st.error(f"Incorrect. Your answer: {current_question['selected']}")
 
 
152
  st.markdown(
153
  f"""
154
  <div style='border: 2px solid #ccc; padding: 15px;'>
@@ -159,15 +161,14 @@ if current_question['answered']:
159
  )
160
  else:
161
  selected_answer = st.radio("Choose an answer:", current_question['options'], key=st.session_state.current_index)
162
- submit_clicked = st.button("Submit")
163
-
164
- if submit_clicked and selected_answer:
165
- current_question['selected'] = selected_answer
166
- current_question['answered'] = True
167
- st.session_state.module_question_count[module_name] += 1
168
 
169
- if selected_answer == current_question['correct']:
170
- st.session_state.correct_count += 1
171
- st.session_state.module_correct_count[module_name] += 1
172
 
173
- # No manual rerun; Streamlit will refresh automatically after state changes
 
62
  pdf.multi_cell(0, 10, f"Q: {question}")
63
  for option in options:
64
  if option == correct:
65
+ pdf.multi_cell(0, 10, f"βœ” Correct: {option}")
66
  elif option == selected:
67
+ pdf.multi_cell(0, 10, f"✘ Your Choice: {option}")
68
  else:
69
  pdf.multi_cell(0, 10, f" {option}")
70
  pdf.multi_cell(0, 10, f"Explanation: {explanation}")
 
110
 
111
  if module_name != st.session_state.current_module:
112
  st.session_state.current_module = module_name
 
113
  st.session_state.current_index = 0
114
 
115
+ # Generate the first question for the new module if it's a new module
116
+ if len(st.session_state.questions) == 0 or st.session_state.questions[-1]['module'] != module_name:
117
+ st.session_state.questions.append(generate_new_question(module_name))
118
 
119
  # Load the current module for title and description
120
  current_module = load_module(st.session_state.current_module)
 
131
  with col2:
132
  st.button("➑️ Next", on_click=lambda: navigate_question("next"))
133
  with col3:
134
+ if len(st.session_state.questions) > 0:
135
  pdf = generate_pdf_report()
136
  st.download_button(
137
  label="Download PDF Report πŸ“„",
 
144
  st.write(f"**Question {st.session_state.current_index + 1}:** {current_question['question']}")
145
 
146
  if current_question['answered']:
147
+ for option in current_question['options']:
148
+ if option == current_question['correct']:
149
+ st.success(f"βœ” {option}")
150
+ elif option == current_question['selected']:
151
+ st.error(f"✘ {option}")
152
+ else:
153
+ st.write(option)
154
  st.markdown(
155
  f"""
156
  <div style='border: 2px solid #ccc; padding: 15px;'>
 
161
  )
162
  else:
163
  selected_answer = st.radio("Choose an answer:", current_question['options'], key=st.session_state.current_index)
164
+ if st.button("Submit"):
165
+ if selected_answer:
166
+ current_question['selected'] = selected_answer
167
+ current_question['answered'] = True
168
+ st.session_state.module_question_count[module_name] += 1
 
169
 
170
+ if selected_answer == current_question['correct']:
171
+ st.session_state.correct_count += 1
172
+ st.session_state.module_correct_count[module_name] += 1
173
 
174
+ # Streamlit will automatically update the UI after state changes