Sina Media Lab
commited on
Commit
Β·
bf6b2ac
1
Parent(s):
a743789
Updates
Browse files
app.py
CHANGED
@@ -23,12 +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 |
-
if 'new_enabled' not in st.session_state:
|
29 |
-
st.session_state.new_enabled = False
|
30 |
-
if 'action' not in st.session_state:
|
31 |
-
st.session_state.action = None
|
32 |
|
33 |
def reset_pdf_cache():
|
34 |
st.session_state.pdf_data = None
|
@@ -102,9 +98,8 @@ def generate_new_question(module_name, module):
|
|
102 |
question_data['answered'] = False
|
103 |
question_data['module'] = module_name
|
104 |
question_data['selected'] = None
|
105 |
-
st.session_state.
|
106 |
-
st.session_state.
|
107 |
-
st.session_state.action = None # Reset action
|
108 |
return question_data
|
109 |
|
110 |
def navigate_question(direction):
|
@@ -137,6 +132,7 @@ if selected_module != st.session_state.current_module:
|
|
137 |
st.session_state.module_question_count[selected_module] = 0
|
138 |
st.session_state.module_correct_count[selected_module] = 0
|
139 |
st.session_state.selected_answer = None
|
|
|
140 |
|
141 |
# Load the current module's question
|
142 |
current_question = st.session_state.questions[st.session_state.current_index]
|
@@ -166,7 +162,7 @@ with col3:
|
|
166 |
|
167 |
st.write(current_question["question"])
|
168 |
|
169 |
-
#
|
170 |
selected_answer = st.radio(
|
171 |
"Choose an answer:",
|
172 |
options=current_question['options'],
|
@@ -174,52 +170,64 @@ selected_answer = st.radio(
|
|
174 |
index=None # Ensure no option is pre-selected
|
175 |
)
|
176 |
|
177 |
-
#
|
178 |
if selected_answer:
|
179 |
-
st.session_state.
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
(
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 'state' not in st.session_state:
|
27 |
+
st.session_state.state = "NewQuestion" # Initial state is NewQuestion
|
|
|
|
|
|
|
|
|
28 |
|
29 |
def reset_pdf_cache():
|
30 |
st.session_state.pdf_data = None
|
|
|
98 |
question_data['answered'] = False
|
99 |
question_data['module'] = module_name
|
100 |
question_data['selected'] = None
|
101 |
+
st.session_state.selected_answer = None
|
102 |
+
st.session_state.state = "NewQuestion" # Set state to NewQuestion
|
|
|
103 |
return question_data
|
104 |
|
105 |
def navigate_question(direction):
|
|
|
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.state = "NewQuestion"
|
136 |
|
137 |
# Load the current module's question
|
138 |
current_question = st.session_state.questions[st.session_state.current_index]
|
|
|
162 |
|
163 |
st.write(current_question["question"])
|
164 |
|
165 |
+
# Display the question options
|
166 |
selected_answer = st.radio(
|
167 |
"Choose an answer:",
|
168 |
options=current_question['options'],
|
|
|
170 |
index=None # Ensure no option is pre-selected
|
171 |
)
|
172 |
|
173 |
+
# Transition to State 2 if an option is selected
|
174 |
if selected_answer:
|
175 |
+
st.session_state.selected_answer = selected_answer
|
176 |
+
st.session_state.state = "OptionSelected"
|
177 |
+
|
178 |
+
# Display Submit/New actions based on state
|
179 |
+
if st.session_state.state == "NewQuestion":
|
180 |
+
action = st.radio(
|
181 |
+
"Choose an action:",
|
182 |
+
("Submit", "New"),
|
183 |
+
index=None, # Do not pre-select any action
|
184 |
+
key="action_radio_new",
|
185 |
+
horizontal=True
|
186 |
+
)
|
187 |
+
|
188 |
+
# Handle Submit/New actions
|
189 |
+
if action == "Submit":
|
190 |
+
st.warning("Please select an option before submitting.", icon="β οΈ")
|
191 |
+
st.session_state.action = None # Reset action
|
192 |
+
elif action == "New":
|
193 |
+
navigate_question("new")
|
194 |
+
|
195 |
+
elif st.session_state.state == "OptionSelected":
|
196 |
+
action = st.radio(
|
197 |
+
"Choose an action:",
|
198 |
+
("Submit", "New"),
|
199 |
+
index=None, # Do not pre-select any action
|
200 |
+
key="action_radio_submit",
|
201 |
+
horizontal=True
|
202 |
+
)
|
203 |
+
|
204 |
+
# Handle Submit/New actions
|
205 |
+
if action == "Submit":
|
206 |
+
# Process the answer
|
207 |
+
current_question['selected'] = st.session_state.selected_answer
|
208 |
+
current_question['answered'] = True
|
209 |
+
st.session_state.module_question_count[selected_module] += 1
|
210 |
+
|
211 |
+
if st.session_state.selected_answer == current_question['correct_answer']:
|
212 |
+
st.session_state.correct_count += 1
|
213 |
+
st.session_state.module_correct_count[selected_module] += 1
|
214 |
+
|
215 |
+
# Display correct/incorrect feedback
|
216 |
+
for option in current_question['options']:
|
217 |
+
if option == current_question['correct_answer']:
|
218 |
+
st.markdown(f"<span style='color:green;'>{option} β
</span>", unsafe_allow_html=True)
|
219 |
+
elif option == current_question['selected']:
|
220 |
+
st.markdown(f"<span style='color:red;'>{option} β</span>", unsafe_allow_html=True)
|
221 |
+
else:
|
222 |
+
st.markdown(f"{option}")
|
223 |
+
|
224 |
+
st.write(f"**Explanation:** {current_question['explanation']}")
|
225 |
+
st.write("**Step-by-Step Solution:**")
|
226 |
+
for step in current_question['step_by_step_solution']:
|
227 |
+
st.write(step)
|
228 |
+
|
229 |
+
st.session_state.state = "NewQuestion" # Transition back to NewQuestion after submission
|
230 |
+
|
231 |
+
elif action == "New":
|
232 |
+
navigate_question("new")
|
233 |
+
st.session_state.state = "NewQuestion" # Transition to NewQuestion
|