Sina Media Lab
commited on
Commit
·
c11ab58
1
Parent(s):
03bf907
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
|
@@ -99,7 +99,7 @@ def generate_new_question(module_name, module):
|
|
99 |
question_data['module'] = module_name
|
100 |
question_data['selected'] = None
|
101 |
st.session_state.selected_answer = None
|
102 |
-
st.session_state.
|
103 |
return question_data
|
104 |
|
105 |
def navigate_question(direction):
|
@@ -111,7 +111,6 @@ def navigate_question(direction):
|
|
111 |
new_question = generate_new_question(st.session_state.current_module, modules[st.session_state.current_module])
|
112 |
st.session_state.questions.append(new_question)
|
113 |
st.session_state.current_index = len(st.session_state.questions) - 1
|
114 |
-
# No need to call rerun, Streamlit will automatically update the UI
|
115 |
|
116 |
# Load all modules dynamically
|
117 |
modules = load_modules()
|
@@ -133,7 +132,6 @@ if selected_module != st.session_state.current_module:
|
|
133 |
st.session_state.module_question_count[selected_module] = 0
|
134 |
st.session_state.module_correct_count[selected_module] = 0
|
135 |
st.session_state.selected_answer = None
|
136 |
-
st.session_state.state = "NewQuestion"
|
137 |
|
138 |
# Load the current module's question
|
139 |
current_question = st.session_state.questions[st.session_state.current_index]
|
@@ -171,64 +169,46 @@ selected_answer = st.radio(
|
|
171 |
index=None # Ensure no option is pre-selected
|
172 |
)
|
173 |
|
174 |
-
#
|
175 |
-
|
176 |
-
|
177 |
-
st.
|
178 |
-
|
179 |
-
|
180 |
-
if st.
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
)
|
188 |
-
|
189 |
-
# Handle Submit/New actions
|
190 |
-
if action == "Submit":
|
191 |
-
st.warning("Please select an option before submitting.", icon="⚠️")
|
192 |
-
st.session_state.action = None # Reset action
|
193 |
-
elif action == "New":
|
194 |
-
navigate_question("new")
|
195 |
-
|
196 |
-
elif st.session_state.state == "OptionSelected":
|
197 |
-
action = st.radio(
|
198 |
-
"Choose an action:",
|
199 |
-
("Submit", "New"),
|
200 |
-
index=None, # Do not pre-select any action
|
201 |
-
key="action_radio_submit",
|
202 |
-
horizontal=True
|
203 |
-
)
|
204 |
-
|
205 |
-
# Handle Submit/New actions
|
206 |
-
if action == "Submit":
|
207 |
-
# Process the answer
|
208 |
-
current_question['selected'] = st.session_state.selected_answer
|
209 |
-
current_question['answered'] = True
|
210 |
-
st.session_state.module_question_count[selected_module] += 1
|
211 |
-
|
212 |
-
if st.session_state.selected_answer == current_question['correct_answer']:
|
213 |
-
st.session_state.correct_count += 1
|
214 |
-
st.session_state.module_correct_count[selected_module] += 1
|
215 |
-
|
216 |
-
# Display correct/incorrect feedback
|
217 |
-
for option in current_question['options']:
|
218 |
-
if option == current_question['correct_answer']:
|
219 |
-
st.markdown(f"<span style='color:green;'>{option} ✅</span>", unsafe_allow_html=True)
|
220 |
-
elif option == current_question['selected']:
|
221 |
-
st.markdown(f"<span style='color:red;'>{option} ❌</span>", unsafe_allow_html=True)
|
222 |
else:
|
223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
|
230 |
-
|
|
|
231 |
|
232 |
-
|
233 |
-
|
234 |
-
|
|
|
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 'action' not in st.session_state:
|
27 |
+
st.session_state.action = None
|
28 |
|
29 |
def reset_pdf_cache():
|
30 |
st.session_state.pdf_data = None
|
|
|
99 |
question_data['module'] = module_name
|
100 |
question_data['selected'] = None
|
101 |
st.session_state.selected_answer = None
|
102 |
+
st.session_state.action = None # Reset action
|
103 |
return question_data
|
104 |
|
105 |
def navigate_question(direction):
|
|
|
111 |
new_question = generate_new_question(st.session_state.current_module, modules[st.session_state.current_module])
|
112 |
st.session_state.questions.append(new_question)
|
113 |
st.session_state.current_index = len(st.session_state.questions) - 1
|
|
|
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 |
|
136 |
# Load the current module's question
|
137 |
current_question = st.session_state.questions[st.session_state.current_index]
|
|
|
169 |
index=None # Ensure no option is pre-selected
|
170 |
)
|
171 |
|
172 |
+
# Set the action based on the user's selection
|
173 |
+
action_col1, action_col2, go_col = st.columns([1, 1, 1])
|
174 |
+
with action_col1:
|
175 |
+
if st.button("Submit"):
|
176 |
+
st.session_state.action = "Submit"
|
177 |
+
with action_col2:
|
178 |
+
if st.button("New"):
|
179 |
+
st.session_state.action = "New"
|
180 |
+
with go_col:
|
181 |
+
if st.button("Go!"):
|
182 |
+
if st.session_state.action == "Submit":
|
183 |
+
if selected_answer is None:
|
184 |
+
st.warning("Please select an option before submitting.", icon="⚠️")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
else:
|
186 |
+
# Process the answer
|
187 |
+
current_question['selected'] = selected_answer
|
188 |
+
current_question['answered'] = True
|
189 |
+
st.session_state.module_question_count[selected_module] += 1
|
190 |
+
|
191 |
+
if selected_answer == current_question['correct_answer']:
|
192 |
+
st.session_state.correct_count += 1
|
193 |
+
st.session_state.module_correct_count[selected_module] += 1
|
194 |
+
|
195 |
+
# Display correct/incorrect feedback
|
196 |
+
for option in current_question['options']:
|
197 |
+
if option == current_question['correct_answer']:
|
198 |
+
st.markdown(f"<span style='color:green;'>{option} ✅</span>", unsafe_allow_html=True)
|
199 |
+
elif option == current_question['selected']:
|
200 |
+
st.markdown(f"<span style='color:red;'>{option} ❌</span>", unsafe_allow_html=True)
|
201 |
+
else:
|
202 |
+
st.markdown(f"{option}")
|
203 |
|
204 |
+
st.write(f"**Explanation:** {current_question['explanation']}")
|
205 |
+
st.write("**Step-by-Step Solution:**")
|
206 |
+
for step in current_question['step_by_step_solution']:
|
207 |
+
st.write(step)
|
208 |
|
209 |
+
# Reset action after submission
|
210 |
+
st.session_state.action = None
|
211 |
|
212 |
+
elif st.session_state.action == "New":
|
213 |
+
navigate_question("new")
|
214 |
+
st.session_state.action = None # Reset action after generating a new question
|