Sina Media Lab
commited on
Commit
Β·
63a8505
1
Parent(s):
b24def3
Updates
Browse files
app.py
CHANGED
@@ -23,6 +23,10 @@ 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 |
|
27 |
def reset_pdf_cache():
|
28 |
st.session_state.pdf_data = None
|
@@ -96,8 +100,8 @@ def generate_new_question(module_name, module):
|
|
96 |
question_data['answered'] = False
|
97 |
question_data['module'] = module_name
|
98 |
question_data['selected'] = None
|
99 |
-
|
100 |
-
|
101 |
return question_data
|
102 |
|
103 |
def navigate_question(direction):
|
@@ -159,46 +163,57 @@ with col3:
|
|
159 |
|
160 |
st.write(current_question["question"])
|
161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
# Submit/New actions as radio buttons
|
163 |
action = st.radio(
|
164 |
"Choose an action:",
|
165 |
("Submit", "New"),
|
166 |
index=0 if not current_question['answered'] else 1,
|
167 |
key="action_radio",
|
|
|
168 |
horizontal=True
|
169 |
)
|
170 |
|
171 |
-
if action == "Submit":
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
st.
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
for step in current_question['step_by_step_solution']:
|
201 |
-
st.write(step)
|
202 |
-
|
203 |
-
elif action == "New":
|
204 |
navigate_question("new")
|
|
|
|
|
|
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 'submit_enabled' not in st.session_state:
|
27 |
+
st.session_state.submit_enabled = False
|
28 |
+
if 'new_enabled' not in st.session_state:
|
29 |
+
st.session_state.new_enabled = False
|
30 |
|
31 |
def reset_pdf_cache():
|
32 |
st.session_state.pdf_data = None
|
|
|
100 |
question_data['answered'] = False
|
101 |
question_data['module'] = module_name
|
102 |
question_data['selected'] = None
|
103 |
+
st.session_state.submit_enabled = False # Disable submit initially
|
104 |
+
st.session_state.new_enabled = False # Disable new initially
|
105 |
return question_data
|
106 |
|
107 |
def navigate_question(direction):
|
|
|
163 |
|
164 |
st.write(current_question["question"])
|
165 |
|
166 |
+
# Create the form for the question
|
167 |
+
selected_answer = st.radio(
|
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 |
+
# Enable submit if an option is selected
|
175 |
+
if selected_answer:
|
176 |
+
st.session_state.submit_enabled = True
|
177 |
+
|
178 |
# Submit/New actions as radio buttons
|
179 |
action = st.radio(
|
180 |
"Choose an action:",
|
181 |
("Submit", "New"),
|
182 |
index=0 if not current_question['answered'] else 1,
|
183 |
key="action_radio",
|
184 |
+
disabled=not st.session_state.submit_enabled and not st.session_state.new_enabled,
|
185 |
horizontal=True
|
186 |
)
|
187 |
|
188 |
+
if action == "Submit" and st.session_state.submit_enabled:
|
189 |
+
# Process the answer
|
190 |
+
current_question['selected'] = selected_answer
|
191 |
+
current_question['answered'] = True
|
192 |
+
st.session_state.module_question_count[selected_module] += 1
|
193 |
+
|
194 |
+
if selected_answer == current_question['correct_answer']:
|
195 |
+
st.session_state.correct_count += 1
|
196 |
+
st.session_state.module_correct_count[selected_module] += 1
|
197 |
+
|
198 |
+
# Display correct/incorrect feedback
|
199 |
+
for option in current_question['options']:
|
200 |
+
if option == current_question['correct_answer']:
|
201 |
+
st.markdown(f"<span style='color:green;'>{option} β
</span>", unsafe_allow_html=True)
|
202 |
+
elif option == current_question['selected']:
|
203 |
+
st.markdown(f"<span style='color:red;'>{option} β</span>", unsafe_allow_html=True)
|
204 |
+
else:
|
205 |
+
st.markdown(f"{option}")
|
206 |
+
|
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)
|
211 |
+
|
212 |
+
# Disable submit and enable new
|
213 |
+
st.session_state.submit_enabled = False
|
214 |
+
st.session_state.new_enabled = True
|
215 |
+
|
216 |
+
elif action == "New" and st.session_state.new_enabled:
|
|
|
|
|
|
|
|
|
217 |
navigate_question("new")
|
218 |
+
st.session_state.submit_enabled = False
|
219 |
+
st.session_state.new_enabled = False
|