Sina Media Lab
commited on
Commit
·
d3582b2
1
Parent(s):
2e0828b
Updates
Browse files
app.py
CHANGED
@@ -25,8 +25,6 @@ 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 |
-
if 'button_clicked' not in st.session_state:
|
29 |
-
st.session_state.button_clicked = False
|
30 |
|
31 |
def reset_pdf_cache():
|
32 |
st.session_state.pdf_data = None
|
@@ -72,7 +70,7 @@ def generate_pdf_report():
|
|
72 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
73 |
pdf.ln(5)
|
74 |
pdf.multi_cell(0, 10, "Step-by-Step Solution:")
|
75 |
-
for step in step_by_step_solution:
|
76 |
pdf.multi_cell(0, 10, step)
|
77 |
pdf.ln(10)
|
78 |
|
@@ -135,7 +133,6 @@ if selected_module != st.session_state.current_module:
|
|
135 |
st.session_state.module_correct_count[selected_module] = 0
|
136 |
st.session_state.selected_answer = None
|
137 |
st.session_state.answered = False
|
138 |
-
st.session_state.button_clicked = False
|
139 |
|
140 |
# Load the current module's question
|
141 |
current_question = st.session_state.questions[st.session_state.current_index]
|
@@ -165,13 +162,16 @@ with col3:
|
|
165 |
|
166 |
st.write(current_question["question"])
|
167 |
|
|
|
|
|
|
|
168 |
# Create the form for the question
|
169 |
with st.form(key=f'question_form_{st.session_state.current_index}'):
|
170 |
selected_answer = st.radio(
|
171 |
"Choose an answer:",
|
172 |
options=current_question['options'],
|
173 |
index=current_question['options'].index(current_question['selected']) if current_question['answered'] else None,
|
174 |
-
disabled=
|
175 |
key=f"question_{st.session_state.current_index}_options"
|
176 |
)
|
177 |
|
@@ -193,20 +193,6 @@ if submit_button:
|
|
193 |
# Set answered to true to disable options
|
194 |
st.session_state.questions[st.session_state.current_index]['answered'] = True
|
195 |
st.session_state.selected_answer = selected_answer
|
196 |
-
st.session_state.button_clicked = True
|
197 |
-
|
198 |
-
else:
|
199 |
-
# If already answered, move to the next question
|
200 |
-
new_question = generate_new_question(selected_module, modules[selected_module])
|
201 |
-
st.session_state.questions.append(new_question)
|
202 |
-
st.session_state.current_index = len(st.session_state.questions) - 1
|
203 |
-
st.session_state.answered = False
|
204 |
-
st.session_state.button_clicked = False
|
205 |
-
|
206 |
-
# Re-render the form if the button was clicked to disable the options
|
207 |
-
if st.session_state.button_clicked:
|
208 |
-
st.session_state.button_clicked = False
|
209 |
-
st.experimental_rerun()
|
210 |
|
211 |
# Show correct/incorrect feedback after submission
|
212 |
if current_question.get('answered', False):
|
@@ -223,3 +209,7 @@ if current_question.get('answered', False):
|
|
223 |
st.write("**Step-by-Step Solution:**")
|
224 |
for step in current_question['step_by_step_solution']:
|
225 |
st.write(step)
|
|
|
|
|
|
|
|
|
|
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
|
|
|
70 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
71 |
pdf.ln(5)
|
72 |
pdf.multi_cell(0, 10, "Step-by-Step Solution:")
|
73 |
+
for step in step_by_step_solution:
|
74 |
pdf.multi_cell(0, 10, step)
|
75 |
pdf.ln(10)
|
76 |
|
|
|
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]
|
|
|
162 |
|
163 |
st.write(current_question["question"])
|
164 |
|
165 |
+
# Disable the radio buttons if the question is already answered
|
166 |
+
disabled_options = current_question['answered']
|
167 |
+
|
168 |
# Create the form for the question
|
169 |
with st.form(key=f'question_form_{st.session_state.current_index}'):
|
170 |
selected_answer = st.radio(
|
171 |
"Choose an answer:",
|
172 |
options=current_question['options'],
|
173 |
index=current_question['options'].index(current_question['selected']) if current_question['answered'] else None,
|
174 |
+
disabled=disabled_options, # Disable if the question has been answered
|
175 |
key=f"question_{st.session_state.current_index}_options"
|
176 |
)
|
177 |
|
|
|
193 |
# Set answered to true to disable options
|
194 |
st.session_state.questions[st.session_state.current_index]['answered'] = True
|
195 |
st.session_state.selected_answer = selected_answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
|
197 |
# Show correct/incorrect feedback after submission
|
198 |
if current_question.get('answered', False):
|
|
|
209 |
st.write("**Step-by-Step Solution:**")
|
210 |
for step in current_question['step_by_step_solution']:
|
211 |
st.write(step)
|
212 |
+
|
213 |
+
# If submit button was pressed and question was answered, update the UI to disable options
|
214 |
+
if current_question.get('answered', False) and not disabled_options:
|
215 |
+
st.experimental_rerun()
|