Spaces:
Running
Running
louiecerv
commited on
Commit
Β·
67386c7
1
Parent(s):
984ed78
fixed issues in the Take Quiz form
Browse files- __pycache__/quiz_gui_helper.cpython-313.pyc +0 -0
- pages/2_Load_Exam.py +5 -0
- pages/3_Take_Exam.py +7 -3
- pages/4_View_Result.py +1 -6
- quiz_gui_helper.py +35 -14
__pycache__/quiz_gui_helper.cpython-313.pyc
CHANGED
Binary files a/__pycache__/quiz_gui_helper.cpython-313.pyc and b/__pycache__/quiz_gui_helper.cpython-313.pyc differ
|
|
pages/2_Load_Exam.py
CHANGED
@@ -6,6 +6,9 @@ from quiz_gui_helper import _QuizGUI
|
|
6 |
if "page_access" not in st.session_state:
|
7 |
st.session_state.page_access = {"About": True, "Load Exam": True, "Take Exam": False, "View Results": False}
|
8 |
|
|
|
|
|
|
|
9 |
def load_quiz_from_file():
|
10 |
uploaded_file = st.file_uploader("Upload a JSON quiz file", type="json")
|
11 |
if uploaded_file is not None:
|
@@ -20,9 +23,11 @@ def load_quiz_from_file():
|
|
20 |
# Save the metadata and content to session state
|
21 |
st.session_state.metadata = metadata
|
22 |
st.session_state.quiz_data = quiz_data
|
|
|
23 |
|
24 |
# Return the extracted data
|
25 |
return metadata, quiz_data
|
|
|
26 |
except json.JSONDecodeError:
|
27 |
st.error("Invalid JSON file. Please upload a properly formatted JSON file.")
|
28 |
return None, None
|
|
|
6 |
if "page_access" not in st.session_state:
|
7 |
st.session_state.page_access = {"About": True, "Load Exam": True, "Take Exam": False, "View Results": False}
|
8 |
|
9 |
+
if "quiz_completed" not in st.session_state:
|
10 |
+
st.session_state.quiz_completed = False
|
11 |
+
|
12 |
def load_quiz_from_file():
|
13 |
uploaded_file = st.file_uploader("Upload a JSON quiz file", type="json")
|
14 |
if uploaded_file is not None:
|
|
|
23 |
# Save the metadata and content to session state
|
24 |
st.session_state.metadata = metadata
|
25 |
st.session_state.quiz_data = quiz_data
|
26 |
+
st.session_state.quiz_completed = False
|
27 |
|
28 |
# Return the extracted data
|
29 |
return metadata, quiz_data
|
30 |
+
|
31 |
except json.JSONDecodeError:
|
32 |
st.error("Invalid JSON file. Please upload a properly formatted JSON file.")
|
33 |
return None, None
|
pages/3_Take_Exam.py
CHANGED
@@ -17,10 +17,14 @@ def main():
|
|
17 |
else:
|
18 |
|
19 |
if st.session_state.quiz_started:
|
20 |
-
|
|
|
21 |
quiz_data = st.session_state.quiz_data
|
22 |
_QuizGUI(quiz_data).start_quiz()
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
else:
|
26 |
#read the metadata and quiz_data from the session state
|
@@ -42,7 +46,7 @@ def main():
|
|
42 |
|
43 |
_QuizGUI(quiz_data).start_quiz()
|
44 |
st.session_state.quiz_started = True
|
45 |
-
|
46 |
|
47 |
|
48 |
if __name__ == "__main__":
|
|
|
17 |
else:
|
18 |
|
19 |
if st.session_state.quiz_started:
|
20 |
+
|
21 |
+
# start_quiz will handle if the quiz is completed
|
22 |
quiz_data = st.session_state.quiz_data
|
23 |
_QuizGUI(quiz_data).start_quiz()
|
24 |
+
|
25 |
+
if not st.session_state.quiz_completed:
|
26 |
+
st.write("You are currently taking the active exam.")
|
27 |
+
_QuizGUI(quiz_data).confirm_end_quiz()
|
28 |
|
29 |
else:
|
30 |
#read the metadata and quiz_data from the session state
|
|
|
46 |
|
47 |
_QuizGUI(quiz_data).start_quiz()
|
48 |
st.session_state.quiz_started = True
|
49 |
+
st.rerun()
|
50 |
|
51 |
|
52 |
if __name__ == "__main__":
|
pages/4_View_Result.py
CHANGED
@@ -17,12 +17,7 @@ def main():
|
|
17 |
st.session_state.quiz_loaded = True
|
18 |
st.session_state.page_access["Take Exam"] = True
|
19 |
st.session_state.page_access["View Results"] = False
|
20 |
-
st.success("You can retake the exam.")
|
21 |
-
elif st.button("Load Another Exam"):
|
22 |
-
st.session_state.quiz_loaded = False
|
23 |
-
st.session_state.quiz_completed = False
|
24 |
-
st.session_state.page_access = {"About": True, "Load Exam": True, "Take Exam": False, "View Results": False}
|
25 |
-
st.success("Ready to load another exam.")
|
26 |
|
27 |
if __name__ == "__main__":
|
28 |
main()
|
|
|
17 |
st.session_state.quiz_loaded = True
|
18 |
st.session_state.page_access["Take Exam"] = True
|
19 |
st.session_state.page_access["View Results"] = False
|
20 |
+
st.success("You can now retake the exam. Go to the Take Exam page to start.")
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
if __name__ == "__main__":
|
23 |
main()
|
quiz_gui_helper.py
CHANGED
@@ -46,10 +46,15 @@ class _QuizGUI:
|
|
46 |
|
47 |
def start_quiz(self):
|
48 |
self.quiz_data = st.session_state.quiz_data
|
|
|
49 |
|
50 |
-
if not st.session_state.
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
|
54 |
st.selectbox(
|
55 |
"Select an option:",
|
@@ -64,17 +69,29 @@ class _QuizGUI:
|
|
64 |
st.session_state.quiz_completed = True
|
65 |
|
66 |
def view_results(self):
|
67 |
-
if st.session_state.
|
68 |
st.write("### Quiz Summary")
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
st.write("- **
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
def confirm_end_quiz(self):
|
80 |
if st.button("End Quiz"):
|
@@ -86,11 +103,15 @@ class _QuizGUI:
|
|
86 |
col1, col2 = st.columns(2)
|
87 |
with col1:
|
88 |
if st.button("OK"):
|
|
|
|
|
|
|
|
|
89 |
|
90 |
st.session_state.quiz_completed = True
|
91 |
st.session_state.page_access["View Results"] = True
|
92 |
st.session_state.page_access["Take Exam"] = False
|
93 |
-
st.success("Exam ended successfully!")
|
94 |
|
95 |
st.session_state.show_confirm = False
|
96 |
st.rerun()
|
|
|
46 |
|
47 |
def start_quiz(self):
|
48 |
self.quiz_data = st.session_state.quiz_data
|
49 |
+
metadata = st.session_state.metadata
|
50 |
|
51 |
+
if not st.session_state.quiz_completed:
|
52 |
+
if metadata.get("exam_type") == "Multiple Choice":
|
53 |
+
question_data = self.quiz_data[st.session_state.current_question]
|
54 |
+
st.write(f"**Question {st.session_state.current_question + 1}:** {question_data['question']}")
|
55 |
+
elif metadata.get("exam_type") == "True or False":
|
56 |
+
question_data = self.quiz_data[st.session_state.current_question]
|
57 |
+
st.write(f"**Statement {st.session_state.current_question + 1}:** {question_data['statement']}")
|
58 |
|
59 |
st.selectbox(
|
60 |
"Select an option:",
|
|
|
69 |
st.session_state.quiz_completed = True
|
70 |
|
71 |
def view_results(self):
|
72 |
+
if st.session_state.quiz_completed:
|
73 |
st.write("### Quiz Summary")
|
74 |
+
|
75 |
+
if st.session_state.metadata.get("exam_type") == "Multiple Choice":
|
76 |
+
for i, question_data in enumerate(self.quiz_data):
|
77 |
+
st.write(f"**Question {i + 1}:** {question_data['question']}")
|
78 |
+
st.write(f"- **Options:** {', '.join(question_data['options'])}")
|
79 |
+
st.write(f"- **Correct Answer:** {question_data['correct_answer']}")
|
80 |
+
st.write(f"- **Your Answer:** {st.session_state.user_answers[i]}")
|
81 |
+
if st.session_state.user_answers[i] == question_data["correct_answer"]:
|
82 |
+
st.write("- **Result:** β
Correct")
|
83 |
+
else:
|
84 |
+
st.write("- **Result:** β Incorrect")
|
85 |
+
|
86 |
+
elif st.session_state.metadata.get("exam_type") == "True or False":
|
87 |
+
for i, question_data in enumerate(self.quiz_data):
|
88 |
+
st.write(f"**Statement {i + 1}:** {question_data['statement']}")
|
89 |
+
st.write(f"- **Correct Answer:** {question_data['correct_answer']}")
|
90 |
+
st.write(f"- **Your Answer:** {st.session_state.user_answers[i]}")
|
91 |
+
if st.session_state.user_answers[i] == question_data["correct_answer"]:
|
92 |
+
st.write("- **Result:** β
Correct")
|
93 |
+
else:
|
94 |
+
st.write("- **Result:** β Incorrect")
|
95 |
|
96 |
def confirm_end_quiz(self):
|
97 |
if st.button("End Quiz"):
|
|
|
103 |
col1, col2 = st.columns(2)
|
104 |
with col1:
|
105 |
if st.button("OK"):
|
106 |
+
# ending the quiz and updating the session state
|
107 |
+
remaining_questions = len(self.quiz_data) - st.session_state.current_question
|
108 |
+
for item in range(remaining_questions):
|
109 |
+
st.session_state.user_answers.append("---")
|
110 |
|
111 |
st.session_state.quiz_completed = True
|
112 |
st.session_state.page_access["View Results"] = True
|
113 |
st.session_state.page_access["Take Exam"] = False
|
114 |
+
st.success("Exam ended successfully! View the results in the result page.")
|
115 |
|
116 |
st.session_state.show_confirm = False
|
117 |
st.rerun()
|