Sina Media Lab
commited on
Commit
·
67f54db
1
Parent(s):
c63a46d
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,9 +95,11 @@ def load_modules():
|
|
| 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,8 +107,10 @@ def generate_new_question(module_name, module):
|
|
| 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,7 +132,7 @@ if selected_module != st.session_state.current_module:
|
|
| 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
|
| 132 |
|
| 133 |
# Load the current module's question
|
| 134 |
current_question = st.session_state.questions[st.session_state.current_index]
|
|
@@ -170,7 +174,7 @@ with st.form(key=f'question_form_{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
|
| 174 |
if selected_answer is not None:
|
| 175 |
# Process the answer
|
| 176 |
current_question['selected'] = selected_answer
|
|
@@ -181,10 +185,8 @@ if submit_button and st.session_state.button_label == "Submit/New":
|
|
| 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.stop()
|
| 188 |
|
| 189 |
# Show correct/incorrect feedback after submission
|
| 190 |
if current_question.get('answered', False):
|
|
@@ -196,19 +198,18 @@ 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 |
-
#
|
| 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 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
st.
|
| 214 |
-
st.
|
|
|
|
|
|
| 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 |
|
| 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 # Add the module name to the question data
|
| 101 |
+
question_data['selected'] = None # Initialize 'selected' to 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 |
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 |
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 |
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 |
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 |
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 |
+
# Change the button label immediately after showing the solution
|
|
|
|
| 208 |
st.session_state.button_label = "Next Question"
|
|
|
|
|
|
|
| 209 |
|
| 210 |
+
# This part handles switching to the next question on button click
|
| 211 |
+
if submit_button and st.session_state.button_label == "Next Question":
|
| 212 |
+
new_question = generate_new_question(selected_module, modules[selected_module])
|
| 213 |
+
st.session_state.questions.append(new_question)
|
| 214 |
+
st.session_state.current_index = len(st.session_state.questions) - 1
|
| 215 |
+
st.session_state.button_label = "Submit"
|