Spaces:
Sleeping
Sleeping
File size: 1,236 Bytes
516de6c 7a6f06b 516de6c 7a6f06b 516de6c 7a6f06b 516de6c 7a6f06b 516de6c |
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 |
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 = 5
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 speech recognition systems 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 answer == question["answer"]:
st.success("Correct!")
else:
st.error("Incorrect!")
st.info("Click on the button below to complete the tutorial!")
if st.button("Complete"):
complete_level(LEVEL)
render_page(step_page, LEVEL)
|