Sina Media Lab
commited on
Commit
·
af783a4
1
Parent(s):
a2a9522
Updates
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ if 'pdf_data' not in st.session_state:
|
|
24 |
if 'selected_answer' not in st.session_state:
|
25 |
st.session_state.selected_answer = None
|
26 |
if 'button_label' not in st.session_state:
|
27 |
-
st.session_state.button_label = "Submit"
|
28 |
|
29 |
def reset_pdf_cache():
|
30 |
st.session_state.pdf_data = None
|
@@ -95,11 +95,9 @@ def load_modules():
|
|
95 |
|
96 |
def generate_new_question(module_name, module):
|
97 |
question_data = module['generate_question']()
|
98 |
-
# Ensure 'answered' is initialized to False and add the 'module' and 'selected' keys
|
99 |
question_data['answered'] = False
|
100 |
-
question_data['module'] = module_name
|
101 |
-
question_data['selected'] = None
|
102 |
-
# Ensure there are exactly 4 options
|
103 |
if len(question_data['options']) != 4:
|
104 |
st.warning(f"Question in module '{module_name}' does not have 4 options. Found {len(question_data['options'])}.")
|
105 |
return question_data
|
@@ -107,10 +105,8 @@ def generate_new_question(module_name, module):
|
|
107 |
def navigate_question(direction):
|
108 |
if direction == "prev" and st.session_state.current_index > 0:
|
109 |
st.session_state.current_index -= 1
|
110 |
-
st.session_state.button_label = "Next Question"
|
111 |
elif direction == "next" and st.session_state.current_index < len(st.session_state.questions) - 1:
|
112 |
st.session_state.current_index += 1
|
113 |
-
st.session_state.button_label = "Next Question"
|
114 |
|
115 |
# Load all modules dynamically
|
116 |
modules = load_modules()
|
@@ -132,7 +128,7 @@ if selected_module != st.session_state.current_module:
|
|
132 |
st.session_state.module_question_count[selected_module] = 0
|
133 |
st.session_state.module_correct_count[selected_module] = 0
|
134 |
st.session_state.selected_answer = None
|
135 |
-
st.session_state.button_label = "Submit"
|
136 |
|
137 |
# Load the current module's question
|
138 |
current_question = st.session_state.questions[st.session_state.current_index]
|
@@ -174,7 +170,7 @@ with st.form(key=f'question_form_{st.session_state.current_index}'):
|
|
174 |
submit_button = st.form_submit_button(label=st.session_state.button_label)
|
175 |
|
176 |
# Handle button state and answer submission
|
177 |
-
if submit_button and st.session_state.button_label == "Submit":
|
178 |
if selected_answer is not None:
|
179 |
# Process the answer
|
180 |
current_question['selected'] = selected_answer
|
@@ -185,8 +181,10 @@ if submit_button and st.session_state.button_label == "Submit":
|
|
185 |
st.session_state.correct_count += 1
|
186 |
st.session_state.module_correct_count[selected_module] += 1
|
187 |
|
188 |
-
# Show correct/incorrect feedback and explanation
|
189 |
st.session_state.button_label = "Next Question"
|
|
|
|
|
|
|
190 |
|
191 |
# Show correct/incorrect feedback after submission
|
192 |
if current_question.get('answered', False):
|
@@ -198,18 +196,19 @@ if current_question.get('answered', False):
|
|
198 |
else:
|
199 |
st.markdown(f"{option}")
|
200 |
|
201 |
-
# Show explanation and step-by-step solution
|
202 |
st.write(f"**Explanation:** {current_question['explanation']}")
|
203 |
st.write("**Step-by-Step Solution:**")
|
204 |
for step in current_question['step_by_step_solution']:
|
205 |
st.write(step)
|
206 |
-
|
207 |
-
|
|
|
208 |
st.session_state.button_label = "Next Question"
|
|
|
|
|
209 |
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
st.session_state.
|
214 |
-
st.
|
215 |
-
st.session_state.button_label = "Submit"
|
|
|
24 |
if 'selected_answer' not in st.session_state:
|
25 |
st.session_state.selected_answer = None
|
26 |
if 'button_label' not in st.session_state:
|
27 |
+
st.session_state.button_label = "Submit/New"
|
28 |
|
29 |
def reset_pdf_cache():
|
30 |
st.session_state.pdf_data = None
|
|
|
95 |
|
96 |
def generate_new_question(module_name, module):
|
97 |
question_data = module['generate_question']()
|
|
|
98 |
question_data['answered'] = False
|
99 |
+
question_data['module'] = module_name
|
100 |
+
question_data['selected'] = None
|
|
|
101 |
if len(question_data['options']) != 4:
|
102 |
st.warning(f"Question in module '{module_name}' does not have 4 options. Found {len(question_data['options'])}.")
|
103 |
return question_data
|
|
|
105 |
def navigate_question(direction):
|
106 |
if direction == "prev" and st.session_state.current_index > 0:
|
107 |
st.session_state.current_index -= 1
|
|
|
108 |
elif direction == "next" and st.session_state.current_index < len(st.session_state.questions) - 1:
|
109 |
st.session_state.current_index += 1
|
|
|
110 |
|
111 |
# Load all modules dynamically
|
112 |
modules = load_modules()
|
|
|
128 |
st.session_state.module_question_count[selected_module] = 0
|
129 |
st.session_state.module_correct_count[selected_module] = 0
|
130 |
st.session_state.selected_answer = None
|
131 |
+
st.session_state.button_label = "Submit/New"
|
132 |
|
133 |
# Load the current module's question
|
134 |
current_question = st.session_state.questions[st.session_state.current_index]
|
|
|
170 |
submit_button = st.form_submit_button(label=st.session_state.button_label)
|
171 |
|
172 |
# Handle button state and answer submission
|
173 |
+
if submit_button and st.session_state.button_label == "Submit/New":
|
174 |
if selected_answer is not None:
|
175 |
# Process the answer
|
176 |
current_question['selected'] = selected_answer
|
|
|
181 |
st.session_state.correct_count += 1
|
182 |
st.session_state.module_correct_count[selected_module] += 1
|
183 |
|
|
|
184 |
st.session_state.button_label = "Next Question"
|
185 |
+
else:
|
186 |
+
st.warning("Please select an option before submitting.", icon="⚠️")
|
187 |
+
st.experimental_rerun()
|
188 |
|
189 |
# Show correct/incorrect feedback after submission
|
190 |
if current_question.get('answered', False):
|
|
|
196 |
else:
|
197 |
st.markdown(f"{option}")
|
198 |
|
|
|
199 |
st.write(f"**Explanation:** {current_question['explanation']}")
|
200 |
st.write("**Step-by-Step Solution:**")
|
201 |
for step in current_question['step_by_step_solution']:
|
202 |
st.write(step)
|
203 |
+
|
204 |
+
# Disable options and button when navigating through previous questions
|
205 |
+
if st.session_state.current_index < len(st.session_state.questions) - 1:
|
206 |
st.session_state.button_label = "Next Question"
|
207 |
+
else:
|
208 |
+
st.session_state.button_label = "Submit/New"
|
209 |
|
210 |
+
if st.session_state.current_index > 0:
|
211 |
+
st.session_state.button_label = "Next Question"
|
212 |
+
st.session_state.selected_answer = None
|
213 |
+
st.form_submit_button(label=st.session_state.button_label, disabled=True)
|
214 |
+
st.radio("Choose an answer:", options=current_question['options'], index=None, disabled=True)
|
|