Sina Media Lab
commited on
Commit
·
22745fe
1
Parent(s):
a862f0d
Updates
Browse files
app.py
CHANGED
@@ -36,19 +36,6 @@ if 'explanation' not in st.session_state:
|
|
36 |
if 'selected_answer' not in st.session_state:
|
37 |
st.session_state.selected_answer = None
|
38 |
|
39 |
-
# Handle Next and Previous question navigation
|
40 |
-
def navigate_question(direction):
|
41 |
-
if direction == "next":
|
42 |
-
st.session_state.question_count += 1
|
43 |
-
elif direction == "prev" and st.session_state.question_count > 1:
|
44 |
-
st.session_state.question_count -= 1
|
45 |
-
st.session_state.submitted = False
|
46 |
-
st.session_state.current_question = st.session_state.question_queue[st.session_state.question_count - 1][0]
|
47 |
-
st.session_state.options = st.session_state.question_queue[st.session_state.question_count - 1][1]
|
48 |
-
st.session_state.selected_answer = st.session_state.question_queue[st.session_state.question_count - 1][2]
|
49 |
-
st.session_state.correct_answer = st.session_state.question_queue[st.session_state.question_count - 1][3]
|
50 |
-
st.session_state.explanation = st.session_state.question_queue[st.session_state.question_count - 1][4]
|
51 |
-
|
52 |
def generate_pdf_report():
|
53 |
pdf = FPDF()
|
54 |
pdf.add_page()
|
@@ -62,9 +49,9 @@ def generate_pdf_report():
|
|
62 |
pdf.multi_cell(0, 10, f"Q{idx+1}: {question}")
|
63 |
for option in options:
|
64 |
if option == correct:
|
65 |
-
pdf.multi_cell(0, 10, f"{option} (Correct)")
|
66 |
elif option == selected:
|
67 |
-
pdf.multi_cell(0, 10, f"{option} (Your Choice)")
|
68 |
else:
|
69 |
pdf.multi_cell(0, 10, f" {option}")
|
70 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
@@ -77,6 +64,14 @@ st.sidebar.title("Quiz Modules")
|
|
77 |
module_name = st.sidebar.radio("Choose a module:", list(module_names.keys()), index=0)
|
78 |
|
79 |
if module_name:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
module_file = module_names[module_name]
|
81 |
try:
|
82 |
module = importlib.import_module(f'modules.{module_file}')
|
@@ -91,13 +86,20 @@ if module_name:
|
|
91 |
# Navigation and PDF Download buttons
|
92 |
col_nav_1, col_nav_2, col_pdf = st.columns([1, 1, 2])
|
93 |
with col_nav_1:
|
94 |
-
if st.session_state.question_count >
|
95 |
if st.button("⬅️ Prev"):
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
with col_nav_2:
|
98 |
if st.session_state.submitted:
|
99 |
if st.button("➡️ Next"):
|
100 |
-
|
101 |
with col_pdf:
|
102 |
if st.session_state.question_count > 0:
|
103 |
pdf = generate_pdf_report()
|
@@ -122,7 +124,7 @@ if module_name:
|
|
122 |
<div style='border: 2px solid #ccc; padding: 15px; background-color: #f9f9f9;'>
|
123 |
<strong>Question {st.session_state.question_count + 1}:</strong> {st.session_state.current_question}
|
124 |
<br>
|
125 |
-
{st.radio("Choose an answer:", st.session_state.options)}
|
126 |
</div>
|
127 |
""",
|
128 |
unsafe_allow_html=True
|
@@ -130,6 +132,7 @@ if module_name:
|
|
130 |
|
131 |
if st.button("Submit"):
|
132 |
st.session_state.submitted = True
|
|
|
133 |
st.session_state.question_queue.append((
|
134 |
st.session_state.current_question,
|
135 |
st.session_state.options,
|
@@ -153,7 +156,6 @@ if module_name:
|
|
153 |
""",
|
154 |
unsafe_allow_html=True
|
155 |
)
|
156 |
-
st.session_state.current_question = None
|
157 |
|
158 |
except ModuleNotFoundError:
|
159 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|
|
|
36 |
if 'selected_answer' not in st.session_state:
|
37 |
st.session_state.selected_answer = None
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
def generate_pdf_report():
|
40 |
pdf = FPDF()
|
41 |
pdf.add_page()
|
|
|
49 |
pdf.multi_cell(0, 10, f"Q{idx+1}: {question}")
|
50 |
for option in options:
|
51 |
if option == correct:
|
52 |
+
pdf.multi_cell(0, 10, f"✅ {option} (Correct)")
|
53 |
elif option == selected:
|
54 |
+
pdf.multi_cell(0, 10, f"❌ {option} (Your Choice)")
|
55 |
else:
|
56 |
pdf.multi_cell(0, 10, f" {option}")
|
57 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
|
|
64 |
module_name = st.sidebar.radio("Choose a module:", list(module_names.keys()), index=0)
|
65 |
|
66 |
if module_name:
|
67 |
+
if st.session_state.current_module != module_name:
|
68 |
+
st.session_state.current_module = module_name
|
69 |
+
st.session_state.question_count = 0
|
70 |
+
st.session_state.correct_count = 0
|
71 |
+
st.session_state.question_queue = []
|
72 |
+
st.session_state.current_question = None
|
73 |
+
st.session_state.submitted = False
|
74 |
+
|
75 |
module_file = module_names[module_name]
|
76 |
try:
|
77 |
module = importlib.import_module(f'modules.{module_file}')
|
|
|
86 |
# Navigation and PDF Download buttons
|
87 |
col_nav_1, col_nav_2, col_pdf = st.columns([1, 1, 2])
|
88 |
with col_nav_1:
|
89 |
+
if st.session_state.question_count > 1:
|
90 |
if st.button("⬅️ Prev"):
|
91 |
+
st.session_state.question_count -= 1
|
92 |
+
st.session_state.submitted = False
|
93 |
+
question_data = st.session_state.question_queue[st.session_state.question_count - 1]
|
94 |
+
st.session_state.current_question = question_data[0]
|
95 |
+
st.session_state.options = question_data[1]
|
96 |
+
st.session_state.selected_answer = question_data[2]
|
97 |
+
st.session_state.correct_answer = question_data[3]
|
98 |
+
st.session_state.explanation = question_data[4]
|
99 |
with col_nav_2:
|
100 |
if st.session_state.submitted:
|
101 |
if st.button("➡️ Next"):
|
102 |
+
st.session_state.current_question = None
|
103 |
with col_pdf:
|
104 |
if st.session_state.question_count > 0:
|
105 |
pdf = generate_pdf_report()
|
|
|
124 |
<div style='border: 2px solid #ccc; padding: 15px; background-color: #f9f9f9;'>
|
125 |
<strong>Question {st.session_state.question_count + 1}:</strong> {st.session_state.current_question}
|
126 |
<br>
|
127 |
+
{st.radio("Choose an answer:", st.session_state.options, key=st.session_state.question_count)}
|
128 |
</div>
|
129 |
""",
|
130 |
unsafe_allow_html=True
|
|
|
132 |
|
133 |
if st.button("Submit"):
|
134 |
st.session_state.submitted = True
|
135 |
+
st.session_state.question_count += 1
|
136 |
st.session_state.question_queue.append((
|
137 |
st.session_state.current_question,
|
138 |
st.session_state.options,
|
|
|
156 |
""",
|
157 |
unsafe_allow_html=True
|
158 |
)
|
|
|
159 |
|
160 |
except ModuleNotFoundError:
|
161 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|