exam_kiosk_v1 / pages /3_Take_Exam.py
louiecerv's picture
progress in the quiz interface
00c87b7
raw
history blame
1.92 kB
import streamlit as st
import json
from quiz_gui_helper import _QuizGUI
if "current_question" not in st.session_state:
st.session_state.current_question = 0
if "quiz_started" not in st.session_state:
st.session_state.quiz_started = False
if "quiz_loaded" not in st.session_state:
st.session_state.quiz_loaded = False
def main():
if not st.session_state.quiz_loaded:
st.error("Please load an exam first!")
else:
if st.session_state.quiz_started:
st.write("You are currently taking the exam.")
else:
#read the metadata and quiz_data from the session state
metadata = st.session_state.metadata
quiz_data = st.session_state.quiz_data
quiz_app = _QuizGUI(quiz_data)
quiz_app.load_quiz(metadata)
st.write("Start taking the exam.")
if st.button("Start Exam"):
st.session_state.page_access["Take Exam"] = True
st.session_state.page_access["View Results"] = False
st.session_state.current_question = 0
st.session_state.user_answers = []
st.session_state.completed = False
st.session_state.score = 0
_QuizGUI(quiz_data).start_quiz()
st.session_state.quiz_started = True
if st.button("Finish Exam"):
st.session_state.quiz_completed = True
st.session_state.page_access["View Results"] = True
st.session_state.page_access["Take Exam"] = False
st.success("Exam completed successfully!")
elif st.button("End Exam Early"):
st.session_state.page_access["View Results"] = True
st.session_state.page_access["Take Exam"] = False
st.warning("Exam ended early.")
if __name__ == "__main__":
main()