Sina Media Lab commited on
Commit Β·
9d5f38a
1
Parent(s): 0743bdc
Updates
Browse files
app.py
CHANGED
|
@@ -33,6 +33,11 @@ if 'module_question_count' not in st.session_state:
|
|
| 33 |
st.session_state.module_question_count = {name: 0 for name in module_names}
|
| 34 |
if 'selected_answer' not in st.session_state:
|
| 35 |
st.session_state.selected_answer = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def generate_pdf_report():
|
| 38 |
pdf = FPDF()
|
|
@@ -43,6 +48,7 @@ def generate_pdf_report():
|
|
| 43 |
pdf.ln(10)
|
| 44 |
|
| 45 |
for module in module_names.keys():
|
|
|
|
| 46 |
pdf.cell(200, 10, txt=f"Module: {module}", ln=True, align="L")
|
| 47 |
pdf.ln(5)
|
| 48 |
correct_count = st.session_state.module_correct_count[module]
|
|
@@ -62,11 +68,15 @@ def generate_pdf_report():
|
|
| 62 |
pdf.multi_cell(0, 10, f"Q: {question}")
|
| 63 |
for option in options:
|
| 64 |
if option == correct:
|
| 65 |
-
pdf.
|
|
|
|
| 66 |
elif option == selected:
|
| 67 |
-
pdf.
|
|
|
|
| 68 |
else:
|
|
|
|
| 69 |
pdf.multi_cell(0, 10, f" {option}")
|
|
|
|
| 70 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
| 71 |
pdf.ln(10)
|
| 72 |
|
|
@@ -113,8 +123,7 @@ if module_name != st.session_state.current_module:
|
|
| 113 |
st.session_state.current_index = 0
|
| 114 |
|
| 115 |
# Generate the first question for the new module if it's a new module
|
| 116 |
-
|
| 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)
|
|
@@ -133,9 +142,10 @@ with col2:
|
|
| 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 π",
|
| 138 |
-
data=
|
| 139 |
file_name="quiz_report.pdf",
|
| 140 |
mime="application/pdf"
|
| 141 |
)
|
|
@@ -159,17 +169,8 @@ if st.button("Submit"):
|
|
| 159 |
if current_question['answered']:
|
| 160 |
for option in current_question['options']:
|
| 161 |
if option == current_question['correct']:
|
| 162 |
-
st.markdown(f"<div style='background-color:#d4edda;padding:10px;border-radius:5px;'>
|
| 163 |
elif option == current_question['selected']:
|
| 164 |
-
st.markdown(f"<div style='background-color:#f8d7da;padding:10px;border-radius:5px;'>
|
| 165 |
else:
|
| 166 |
-
st.
|
| 167 |
-
|
| 168 |
-
st.markdown(
|
| 169 |
-
f"""
|
| 170 |
-
<div style='border: 2px solid #ccc; padding: 15px;'>
|
| 171 |
-
<strong>Explanation:</strong> {current_question['explanation']}
|
| 172 |
-
</div>
|
| 173 |
-
""",
|
| 174 |
-
unsafe_allow_html=True
|
| 175 |
-
)
|
|
|
|
| 33 |
st.session_state.module_question_count = {name: 0 for name in module_names}
|
| 34 |
if 'selected_answer' not in st.session_state:
|
| 35 |
st.session_state.selected_answer = None
|
| 36 |
+
if 'pdf_data' not in st.session_state:
|
| 37 |
+
st.session_state.pdf_data = None
|
| 38 |
+
|
| 39 |
+
def reset_pdf_cache():
|
| 40 |
+
st.session_state.pdf_data = None
|
| 41 |
|
| 42 |
def generate_pdf_report():
|
| 43 |
pdf = FPDF()
|
|
|
|
| 48 |
pdf.ln(10)
|
| 49 |
|
| 50 |
for module in module_names.keys():
|
| 51 |
+
pdf.set_text_color(0, 0, 0)
|
| 52 |
pdf.cell(200, 10, txt=f"Module: {module}", ln=True, align="L")
|
| 53 |
pdf.ln(5)
|
| 54 |
correct_count = st.session_state.module_correct_count[module]
|
|
|
|
| 68 |
pdf.multi_cell(0, 10, f"Q: {question}")
|
| 69 |
for option in options:
|
| 70 |
if option == correct:
|
| 71 |
+
pdf.set_text_color(0, 128, 0) # Green for correct
|
| 72 |
+
pdf.multi_cell(0, 10, f"{option}")
|
| 73 |
elif option == selected:
|
| 74 |
+
pdf.set_text_color(255, 0, 0) # Red for incorrect
|
| 75 |
+
pdf.multi_cell(0, 10, f"{option}")
|
| 76 |
else:
|
| 77 |
+
pdf.set_text_color(0, 0, 0) # Default color for others
|
| 78 |
pdf.multi_cell(0, 10, f" {option}")
|
| 79 |
+
pdf.set_text_color(0, 0, 0) # Reset color
|
| 80 |
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
| 81 |
pdf.ln(10)
|
| 82 |
|
|
|
|
| 123 |
st.session_state.current_index = 0
|
| 124 |
|
| 125 |
# Generate the first question for the new module if it's a new module
|
| 126 |
+
st.session_state.questions.append(generate_new_question(module_name))
|
|
|
|
| 127 |
|
| 128 |
# Load the current module for title and description
|
| 129 |
current_module = load_module(st.session_state.current_module)
|
|
|
|
| 142 |
with col3:
|
| 143 |
if len(st.session_state.questions) > 0:
|
| 144 |
pdf = generate_pdf_report()
|
| 145 |
+
st.session_state.pdf_data = pdf # Reset PDF cache
|
| 146 |
st.download_button(
|
| 147 |
label="Download PDF Report π",
|
| 148 |
+
data=st.session_state.pdf_data,
|
| 149 |
file_name="quiz_report.pdf",
|
| 150 |
mime="application/pdf"
|
| 151 |
)
|
|
|
|
| 169 |
if current_question['answered']:
|
| 170 |
for option in current_question['options']:
|
| 171 |
if option == current_question['correct']:
|
| 172 |
+
st.markdown(f"<div style='background-color:#d4edda;padding:10px;border-radius:5px;'>{option}</div>", unsafe_allow_html=True)
|
| 173 |
elif option == current_question['selected']:
|
| 174 |
+
st.markdown(f"<div style='background-color:#f8d7da;padding:10px;border-radius:5px;'>{option}</div>", unsafe_allow_html=True)
|
| 175 |
else:
|
| 176 |
+
st.markdown(f"<div style='padding:10px;border-radius:5px;'>{option}</div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|