Sina Media Lab
commited on
Commit
Β·
9124e0f
1
Parent(s):
795b9ba
Updates
Browse files
app.py
CHANGED
@@ -25,6 +25,8 @@ if 'question_queue' not in st.session_state:
|
|
25 |
st.session_state.question_queue = []
|
26 |
if 'submitted' not in st.session_state:
|
27 |
st.session_state.submitted = False
|
|
|
|
|
28 |
|
29 |
def generate_pdf_report():
|
30 |
pdf = FPDF()
|
@@ -59,9 +61,6 @@ if module_name:
|
|
59 |
# Show module title and description
|
60 |
st.title(title)
|
61 |
st.write(description)
|
62 |
-
|
63 |
-
# Add spacing to ensure question visibility on Hugging Face
|
64 |
-
st.markdown("<br><br>", unsafe_allow_html=True)
|
65 |
|
66 |
if st.session_state.submitted:
|
67 |
st.session_state.submitted = False
|
@@ -79,32 +78,44 @@ if module_name:
|
|
79 |
else:
|
80 |
st.error("β Incorrect.")
|
81 |
st.write(f"**Explanation:** {st.session_state.explanation}")
|
82 |
-
|
83 |
if st.session_state.question_count > 0:
|
84 |
correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
|
85 |
st.write(f"**Correct Answers:** {st.session_state.correct_count}/{st.session_state.question_count} ({correct_percentage:.2f}%)")
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
if st.session_state.question_count > 0:
|
97 |
with col2:
|
98 |
-
if st.button("
|
|
|
99 |
st.experimental_rerun()
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
with col3:
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
109 |
except ModuleNotFoundError:
|
110 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|
|
|
25 |
st.session_state.question_queue = []
|
26 |
if 'submitted' not in st.session_state:
|
27 |
st.session_state.submitted = False
|
28 |
+
if 'selected_answer' not in st.session_state:
|
29 |
+
st.session_state.selected_answer = None
|
30 |
|
31 |
def generate_pdf_report():
|
32 |
pdf = FPDF()
|
|
|
61 |
# Show module title and description
|
62 |
st.title(title)
|
63 |
st.write(description)
|
|
|
|
|
|
|
64 |
|
65 |
if st.session_state.submitted:
|
66 |
st.session_state.submitted = False
|
|
|
78 |
else:
|
79 |
st.error("β Incorrect.")
|
80 |
st.write(f"**Explanation:** {st.session_state.explanation}")
|
81 |
+
|
82 |
if st.session_state.question_count > 0:
|
83 |
correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
|
84 |
st.write(f"**Correct Answers:** {st.session_state.correct_count}/{st.session_state.question_count} ({correct_percentage:.2f}%)")
|
85 |
|
86 |
+
if not st.session_state.submitted:
|
87 |
+
st.session_state.current_question, options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
|
88 |
+
st.write(f"**Question {st.session_state.question_count + 1}:** {st.session_state.current_question}")
|
89 |
+
st.session_state.selected_answer = st.radio("Choose an answer:", options)
|
90 |
|
91 |
+
col1, col2 = st.columns([1, 5])
|
92 |
+
with col1:
|
93 |
+
if st.button("β¬
οΈ Prev"):
|
94 |
+
# Logic for previous question (if applicable)
|
95 |
+
pass
|
|
|
96 |
with col2:
|
97 |
+
if st.button("Submit"):
|
98 |
+
st.session_state.submitted = True
|
99 |
st.experimental_rerun()
|
100 |
|
101 |
+
if st.session_state.submitted:
|
102 |
+
col1, col2, col3 = st.columns([1, 1, 3])
|
103 |
+
with col1:
|
104 |
+
if st.button("β¬
οΈ Prev"):
|
105 |
+
# Logic for previous question (if applicable)
|
106 |
+
pass
|
107 |
+
with col2:
|
108 |
+
if st.button("β‘οΈ Next"):
|
109 |
+
st.experimental_rerun()
|
110 |
with col3:
|
111 |
+
if st.session_state.question_count > 0:
|
112 |
+
pdf = generate_pdf_report()
|
113 |
+
st.download_button(
|
114 |
+
label="Download PDF Report π",
|
115 |
+
data=pdf,
|
116 |
+
file_name="quiz_report.pdf",
|
117 |
+
mime="application/pdf"
|
118 |
+
)
|
119 |
+
|
120 |
except ModuleNotFoundError:
|
121 |
st.error(f"The module '{module_name}' was not found. Please select another module.")
|