Sina Media Lab
commited on
Commit
Β·
cab1b57
1
Parent(s):
2ac817c
Updates
Browse files
app.py
CHANGED
@@ -62,9 +62,9 @@ def generate_pdf_report():
|
|
62 |
pdf.multi_cell(0, 10, f"Q: {question}")
|
63 |
for option in options:
|
64 |
if option == correct:
|
65 |
-
pdf.multi_cell(0, 10, f"Correct: {option}")
|
66 |
elif option == selected:
|
67 |
-
pdf.multi_cell(0, 10, f"Your Choice: {option}")
|
68 |
else:
|
69 |
pdf.multi_cell(0, 10, f" {option}")
|
70 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
@@ -110,11 +110,11 @@ module_name = st.sidebar.radio("Choose a module:", list(module_names.keys()), in
|
|
110 |
|
111 |
if module_name != st.session_state.current_module:
|
112 |
st.session_state.current_module = module_name
|
113 |
-
st.session_state.questions = []
|
114 |
st.session_state.current_index = 0
|
115 |
|
116 |
-
# Generate the first question for the new module
|
117 |
-
st.session_state.questions.
|
|
|
118 |
|
119 |
# Load the current module for title and description
|
120 |
current_module = load_module(st.session_state.current_module)
|
@@ -131,7 +131,7 @@ with col1:
|
|
131 |
with col2:
|
132 |
st.button("β‘οΈ Next", on_click=lambda: navigate_question("next"))
|
133 |
with col3:
|
134 |
-
if st.session_state.
|
135 |
pdf = generate_pdf_report()
|
136 |
st.download_button(
|
137 |
label="Download PDF Report π",
|
@@ -144,11 +144,13 @@ with col3:
|
|
144 |
st.write(f"**Question {st.session_state.current_index + 1}:** {current_question['question']}")
|
145 |
|
146 |
if current_question['answered']:
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
|
|
152 |
st.markdown(
|
153 |
f"""
|
154 |
<div style='border: 2px solid #ccc; padding: 15px;'>
|
@@ -159,15 +161,14 @@ if current_question['answered']:
|
|
159 |
)
|
160 |
else:
|
161 |
selected_answer = st.radio("Choose an answer:", current_question['options'], key=st.session_state.current_index)
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
st.session_state.module_question_count[module_name] += 1
|
168 |
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
|
173 |
-
|
|
|
62 |
pdf.multi_cell(0, 10, f"Q: {question}")
|
63 |
for option in options:
|
64 |
if option == correct:
|
65 |
+
pdf.multi_cell(0, 10, f"β Correct: {option}")
|
66 |
elif option == selected:
|
67 |
+
pdf.multi_cell(0, 10, f"β Your Choice: {option}")
|
68 |
else:
|
69 |
pdf.multi_cell(0, 10, f" {option}")
|
70 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
|
|
110 |
|
111 |
if module_name != st.session_state.current_module:
|
112 |
st.session_state.current_module = module_name
|
|
|
113 |
st.session_state.current_index = 0
|
114 |
|
115 |
+
# Generate the first question for the new module if it's a new module
|
116 |
+
if len(st.session_state.questions) == 0 or st.session_state.questions[-1]['module'] != module_name:
|
117 |
+
st.session_state.questions.append(generate_new_question(module_name))
|
118 |
|
119 |
# Load the current module for title and description
|
120 |
current_module = load_module(st.session_state.current_module)
|
|
|
131 |
with col2:
|
132 |
st.button("β‘οΈ Next", on_click=lambda: navigate_question("next"))
|
133 |
with col3:
|
134 |
+
if len(st.session_state.questions) > 0:
|
135 |
pdf = generate_pdf_report()
|
136 |
st.download_button(
|
137 |
label="Download PDF Report π",
|
|
|
144 |
st.write(f"**Question {st.session_state.current_index + 1}:** {current_question['question']}")
|
145 |
|
146 |
if current_question['answered']:
|
147 |
+
for option in current_question['options']:
|
148 |
+
if option == current_question['correct']:
|
149 |
+
st.success(f"β {option}")
|
150 |
+
elif option == current_question['selected']:
|
151 |
+
st.error(f"β {option}")
|
152 |
+
else:
|
153 |
+
st.write(option)
|
154 |
st.markdown(
|
155 |
f"""
|
156 |
<div style='border: 2px solid #ccc; padding: 15px;'>
|
|
|
161 |
)
|
162 |
else:
|
163 |
selected_answer = st.radio("Choose an answer:", current_question['options'], key=st.session_state.current_index)
|
164 |
+
if st.button("Submit"):
|
165 |
+
if selected_answer:
|
166 |
+
current_question['selected'] = selected_answer
|
167 |
+
current_question['answered'] = True
|
168 |
+
st.session_state.module_question_count[module_name] += 1
|
|
|
169 |
|
170 |
+
if selected_answer == current_question['correct']:
|
171 |
+
st.session_state.correct_count += 1
|
172 |
+
st.session_state.module_correct_count[module_name] += 1
|
173 |
|
174 |
+
# Streamlit will automatically update the UI after state changes
|