Sina Media Lab
commited on
Commit
·
929abf5
1
Parent(s):
b003425
Updates
Browse files
app.py
CHANGED
@@ -59,6 +59,18 @@ def generate_pdf_report():
|
|
59 |
|
60 |
return pdf.output(dest='S').encode('latin-1', 'replace')
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
# Streamlit interface
|
63 |
st.sidebar.title("Quiz Modules")
|
64 |
module_name = st.sidebar.radio("Choose a module:", list(module_names.keys()), index=0)
|
@@ -71,6 +83,7 @@ if module_name:
|
|
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:
|
@@ -78,7 +91,7 @@ if module_name:
|
|
78 |
generate_question = module.generate_question
|
79 |
title = getattr(module, 'title', f"{module_name} Module")
|
80 |
description = getattr(module, 'description', "Description is not available")
|
81 |
-
|
82 |
# Show module title and description
|
83 |
st.title(title)
|
84 |
st.write(description)
|
@@ -94,11 +107,13 @@ if module_name:
|
|
94 |
st.session_state.selected_answer = question_data[2]
|
95 |
st.session_state.correct_answer = question_data[3]
|
96 |
st.session_state.explanation = question_data[4]
|
|
|
97 |
|
98 |
if st.session_state.current_question is None or st.session_state.submitted:
|
99 |
st.session_state.current_question, st.session_state.options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
|
100 |
st.session_state.submitted = False
|
101 |
st.session_state.selected_answer = None
|
|
|
102 |
|
103 |
if st.session_state.question_count > 0:
|
104 |
correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
|
@@ -124,6 +139,10 @@ if module_name:
|
|
124 |
else:
|
125 |
st.error("✘ Incorrect.")
|
126 |
|
|
|
|
|
|
|
|
|
127 |
# Explanation with proper width
|
128 |
st.markdown(
|
129 |
f"""
|
@@ -138,6 +157,7 @@ if module_name:
|
|
138 |
if st.session_state.submitted:
|
139 |
if st.button("➡️ Next"):
|
140 |
st.session_state.current_question = None
|
|
|
141 |
|
142 |
# Display the "Download PDF Report" button after at least one question has been answered
|
143 |
if st.session_state.question_count > 0:
|
@@ -148,6 +168,11 @@ if module_name:
|
|
148 |
file_name="quiz_report.pdf",
|
149 |
mime="application/pdf"
|
150 |
)
|
|
|
151 |
|
152 |
-
except ModuleNotFoundError:
|
153 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
return pdf.output(dest='S').encode('latin-1', 'replace')
|
61 |
|
62 |
+
# Debugging information
|
63 |
+
st.write("### Debugging Information")
|
64 |
+
st.write(f"Current Module: {st.session_state.current_module}")
|
65 |
+
st.write(f"Question Count: {st.session_state.question_count}")
|
66 |
+
st.write(f"Correct Count: {st.session_state.correct_count}")
|
67 |
+
st.write(f"Submitted: {st.session_state.submitted}")
|
68 |
+
st.write(f"Current Question: {st.session_state.current_question}")
|
69 |
+
st.write(f"Options: {st.session_state.options}")
|
70 |
+
st.write(f"Selected Answer: {st.session_state.selected_answer}")
|
71 |
+
st.write(f"Correct Answer: {st.session_state.correct_answer}")
|
72 |
+
st.write(f"Explanation: {st.session_state.explanation}")
|
73 |
+
|
74 |
# Streamlit interface
|
75 |
st.sidebar.title("Quiz Modules")
|
76 |
module_name = st.sidebar.radio("Choose a module:", list(module_names.keys()), index=0)
|
|
|
83 |
st.session_state.question_queue = []
|
84 |
st.session_state.current_question = None
|
85 |
st.session_state.submitted = False
|
86 |
+
st.write("Module changed. Resetting session state.")
|
87 |
|
88 |
module_file = module_names[module_name]
|
89 |
try:
|
|
|
91 |
generate_question = module.generate_question
|
92 |
title = getattr(module, 'title', f"{module_name} Module")
|
93 |
description = getattr(module, 'description', "Description is not available")
|
94 |
+
|
95 |
# Show module title and description
|
96 |
st.title(title)
|
97 |
st.write(description)
|
|
|
107 |
st.session_state.selected_answer = question_data[2]
|
108 |
st.session_state.correct_answer = question_data[3]
|
109 |
st.session_state.explanation = question_data[4]
|
110 |
+
st.write("Navigated to previous question.")
|
111 |
|
112 |
if st.session_state.current_question is None or st.session_state.submitted:
|
113 |
st.session_state.current_question, st.session_state.options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
|
114 |
st.session_state.submitted = False
|
115 |
st.session_state.selected_answer = None
|
116 |
+
st.write("Generated new question.")
|
117 |
|
118 |
if st.session_state.question_count > 0:
|
119 |
correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
|
|
|
139 |
else:
|
140 |
st.error("✘ Incorrect.")
|
141 |
|
142 |
+
st.write("Answer submitted.")
|
143 |
+
st.write(f"Selected Answer: {st.session_state.selected_answer}")
|
144 |
+
st.write(f"Correct Answer: {st.session_state.correct_answer}")
|
145 |
+
|
146 |
# Explanation with proper width
|
147 |
st.markdown(
|
148 |
f"""
|
|
|
157 |
if st.session_state.submitted:
|
158 |
if st.button("➡️ Next"):
|
159 |
st.session_state.current_question = None
|
160 |
+
st.write("Navigated to next question.")
|
161 |
|
162 |
# Display the "Download PDF Report" button after at least one question has been answered
|
163 |
if st.session_state.question_count > 0:
|
|
|
168 |
file_name="quiz_report.pdf",
|
169 |
mime="application/pdf"
|
170 |
)
|
171 |
+
st.write("PDF report generated.")
|
172 |
|
173 |
+
except ModuleNotFoundError as e:
|
174 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|
175 |
+
st.write(f"Error: {e}")
|
176 |
+
except Exception as e:
|
177 |
+
st.error(f"An unexpected error occurred: {str(e)}")
|
178 |
+
st.write(f"Error: {str(e)}")
|