Spaces:
Sleeping
Sleeping
File size: 1,411 Bytes
92e31e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import streamlit as st
from utils.levels import complete_level, render_page, initialize_level
from utils.login import initialize_login
import random
import json
LEVEL = 3
initialize_login()
initialize_level()
if "questions" not in st.session_state:
with open("assets/quiz.json") as f:
questions = json.load(f)
for i in range(len(questions)):
random.shuffle(questions[i]["options"])
random.shuffle(questions)
st.session_state["questions"] = questions
def step_page():
st.header("Quiz")
st.markdown(
"""Now that you've learned about how Face Recognition work, let's test your knowledge with a quiz!"""
)
for i in range(len(st.session_state["questions"])):
st.subheader(f"Question {i + 1}")
question = st.session_state["questions"][i]
st.markdown(question["question"])
answer = st.radio("Select an answer:", question["options"], key=f"radio{i}")
if st.session_state.get("EVALUATE", False):
if answer == question["answer"]:
st.success("Correct!")
else:
st.error("Incorrect! Try Again")
if st.button("Evaluate"):
st.session_state["EVALUATE"] = True
st.experimental_rerun()
st.info("Click on the button below to complete the tutorial!")
if st.button("Complete"):
complete_level(LEVEL)
render_page(step_page, LEVEL)
|