Sina Media Lab
commited on
Commit
·
a2a9522
1
Parent(s):
a29d38b
Updates
Browse files
app.py
CHANGED
@@ -23,8 +23,8 @@ if 'pdf_data' not in st.session_state:
|
|
23 |
st.session_state.pdf_data = None
|
24 |
if 'selected_answer' not in st.session_state:
|
25 |
st.session_state.selected_answer = None
|
26 |
-
if '
|
27 |
-
st.session_state.
|
28 |
|
29 |
def reset_pdf_cache():
|
30 |
st.session_state.pdf_data = None
|
@@ -107,14 +107,10 @@ 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.
|
111 |
-
elif direction == "next":
|
112 |
-
|
113 |
-
|
114 |
-
else:
|
115 |
-
st.session_state.questions.append(generate_new_question(st.session_state.current_module, modules[st.session_state.current_module]))
|
116 |
-
st.session_state.current_index = len(st.session_state.questions) - 1
|
117 |
-
st.session_state.button_disabled = False # Enable the button for new questions
|
118 |
|
119 |
# Load all modules dynamically
|
120 |
modules = load_modules()
|
@@ -136,7 +132,7 @@ if selected_module != st.session_state.current_module:
|
|
136 |
st.session_state.module_question_count[selected_module] = 0
|
137 |
st.session_state.module_correct_count[selected_module] = 0
|
138 |
st.session_state.selected_answer = None
|
139 |
-
st.session_state.
|
140 |
|
141 |
# Load the current module's question
|
142 |
current_question = st.session_state.questions[st.session_state.current_index]
|
@@ -151,7 +147,7 @@ with col1:
|
|
151 |
if st.button("⬅️ Prev", disabled=st.session_state.current_index == 0):
|
152 |
navigate_question("prev")
|
153 |
with col2:
|
154 |
-
if st.button("➡️ Next"):
|
155 |
navigate_question("next")
|
156 |
with col3:
|
157 |
if len(st.session_state.questions) > 0:
|
@@ -172,14 +168,13 @@ with st.form(key=f'question_form_{st.session_state.current_index}'):
|
|
172 |
"Choose an answer:",
|
173 |
options=current_question['options'],
|
174 |
key=f"question_{st.session_state.current_index}_options",
|
175 |
-
index=
|
176 |
-
disabled=current_question['answered'] # Disable if the question has been answered
|
177 |
)
|
178 |
|
179 |
-
submit_button = st.form_submit_button(label=
|
180 |
|
181 |
# Handle button state and answer submission
|
182 |
-
if submit_button:
|
183 |
if selected_answer is not None:
|
184 |
# Process the answer
|
185 |
current_question['selected'] = selected_answer
|
@@ -191,7 +186,7 @@ if submit_button:
|
|
191 |
st.session_state.module_correct_count[selected_module] += 1
|
192 |
|
193 |
# Show correct/incorrect feedback and explanation
|
194 |
-
st.session_state.
|
195 |
|
196 |
# Show correct/incorrect feedback after submission
|
197 |
if current_question.get('answered', False):
|
@@ -207,4 +202,14 @@ if current_question.get('answered', False):
|
|
207 |
st.write(f"**Explanation:** {current_question['explanation']}")
|
208 |
st.write("**Step-by-Step Solution:**")
|
209 |
for step in current_question['step_by_step_solution']:
|
210 |
-
st.write(step)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
st.session_state.pdf_data = None
|
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
|
|
|
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]
|
|
|
147 |
if st.button("⬅️ Prev", disabled=st.session_state.current_index == 0):
|
148 |
navigate_question("prev")
|
149 |
with col2:
|
150 |
+
if st.button("➡️ Next", disabled=st.session_state.current_index >= len(st.session_state.questions) - 1):
|
151 |
navigate_question("next")
|
152 |
with col3:
|
153 |
if len(st.session_state.questions) > 0:
|
|
|
168 |
"Choose an answer:",
|
169 |
options=current_question['options'],
|
170 |
key=f"question_{st.session_state.current_index}_options",
|
171 |
+
index=None # Ensure no option is pre-selected
|
|
|
172 |
)
|
173 |
|
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
|
|
|
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):
|
|
|
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"
|