Sina Media Lab
commited on
Commit
·
a810341
1
Parent(s):
26df557
Updates
Browse files
app.py
CHANGED
@@ -21,10 +21,10 @@ if 'module_question_count' not in st.session_state:
|
|
21 |
st.session_state.module_question_count = {}
|
22 |
if 'pdf_data' not in st.session_state:
|
23 |
st.session_state.pdf_data = None
|
24 |
-
if 'next_disabled' not in st.session_state:
|
25 |
-
st.session_state.next_disabled = True
|
26 |
if 'selected_answer' not in st.session_state:
|
27 |
st.session_state.selected_answer = None
|
|
|
|
|
28 |
|
29 |
def reset_pdf_cache():
|
30 |
st.session_state.pdf_data = None
|
@@ -107,12 +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 |
-
|
111 |
-
|
112 |
-
st.session_state.
|
113 |
-
st.session_state.
|
114 |
-
st.session_state.next_disabled = True
|
115 |
-
st.session_state.selected_answer = None
|
116 |
|
117 |
# Load all modules dynamically
|
118 |
modules = load_modules()
|
@@ -133,8 +131,8 @@ if selected_module != st.session_state.current_module:
|
|
133 |
st.session_state.questions = [generate_new_question(selected_module, modules[selected_module])]
|
134 |
st.session_state.module_question_count[selected_module] = 0
|
135 |
st.session_state.module_correct_count[selected_module] = 0
|
136 |
-
st.session_state.next_disabled = True
|
137 |
st.session_state.selected_answer = None
|
|
|
138 |
|
139 |
# Load the current module's question
|
140 |
current_question = st.session_state.questions[st.session_state.current_index]
|
@@ -149,7 +147,7 @@ with col1:
|
|
149 |
if st.button("⬅️ Prev", disabled=st.session_state.current_index == 0):
|
150 |
navigate_question("prev")
|
151 |
with col2:
|
152 |
-
if st.button("➡️ Next", disabled=st.session_state.
|
153 |
navigate_question("next")
|
154 |
with col3:
|
155 |
if len(st.session_state.questions) > 0:
|
@@ -169,24 +167,35 @@ with st.form(key=f'question_form_{st.session_state.current_index}'):
|
|
169 |
selected_answer = st.radio(
|
170 |
"Choose an answer:",
|
171 |
options=current_question['options'],
|
172 |
-
|
173 |
-
|
174 |
)
|
175 |
-
|
|
|
176 |
|
177 |
# Handle button state and answer submission
|
178 |
if submit_button:
|
179 |
-
if
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
# Show correct/incorrect feedback after submission
|
192 |
if current_question.get('answered', False):
|
@@ -198,8 +207,15 @@ 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.
|
|
|
|
|
|
|
|
|
|
|
204 |
for step in current_question['step_by_step_solution']:
|
205 |
-
st.
|
|
|
|
|
|
21 |
st.session_state.module_question_count = {}
|
22 |
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 'answered' not in st.session_state:
|
27 |
+
st.session_state.answered = False
|
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.answered = True
|
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.answered = True
|
|
|
|
|
114 |
|
115 |
# Load all modules dynamically
|
116 |
modules = load_modules()
|
|
|
131 |
st.session_state.questions = [generate_new_question(selected_module, modules[selected_module])]
|
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.answered = False
|
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:
|
|
|
167 |
selected_answer = st.radio(
|
168 |
"Choose an answer:",
|
169 |
options=current_question['options'],
|
170 |
+
index=current_question['options'].index(current_question['selected']) if current_question['answered'] else None,
|
171 |
+
key=f"question_{st.session_state.current_index}_options"
|
172 |
)
|
173 |
+
|
174 |
+
submit_button = st.form_submit_button(label="Submit/Next")
|
175 |
|
176 |
# Handle button state and answer submission
|
177 |
if submit_button:
|
178 |
+
if not current_question['answered']:
|
179 |
+
if selected_answer is not None:
|
180 |
+
# Process the answer
|
181 |
+
current_question['selected'] = selected_answer
|
182 |
+
current_question['answered'] = True
|
183 |
+
st.session_state.module_question_count[selected_module] += 1
|
184 |
+
|
185 |
+
if selected_answer == current_question['correct_answer']:
|
186 |
+
st.session_state.correct_count += 1
|
187 |
+
st.session_state.module_correct_count[selected_module] += 1
|
188 |
+
|
189 |
+
# Set answered to true to disable options
|
190 |
+
st.session_state.questions[st.session_state.current_index]['answered'] = True
|
191 |
+
st.session_state.selected_answer = selected_answer
|
192 |
+
|
193 |
+
else:
|
194 |
+
# If already answered, move to the next question
|
195 |
+
new_question = generate_new_question(selected_module, modules[selected_module])
|
196 |
+
st.session_state.questions.append(new_question)
|
197 |
+
st.session_state.current_index = len(st.session_state.questions) - 1
|
198 |
+
st.session_state.answered = False
|
199 |
|
200 |
# Show correct/incorrect feedback after submission
|
201 |
if current_question.get('answered', False):
|
|
|
207 |
else:
|
208 |
st.markdown(f"{option}")
|
209 |
|
210 |
+
# Show explanation and step-by-step solution with improved visuals
|
211 |
st.write(f"**Explanation:** {current_question['explanation']}")
|
212 |
+
st.markdown("""
|
213 |
+
<div style='border: 2px solid #4CAF50; padding: 10px; margin-top: 20px; background-color: #f9f9f9;'>
|
214 |
+
<h4 style='color: #4CAF50;'>Step-by-Step Solution:</h4>
|
215 |
+
<ol>
|
216 |
+
""", unsafe_allow_html=True)
|
217 |
+
|
218 |
for step in current_question['step_by_step_solution']:
|
219 |
+
st.markdown(f"<li style='margin-bottom: 10px;'>{step}</li>", unsafe_allow_html=True)
|
220 |
+
|
221 |
+
st.markdown("</ol></div>", unsafe_allow_html=True)
|