-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfidence_quiz_page.py
78 lines (63 loc) · 2.73 KB
/
confidence_quiz_page.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import streamlit as st
from src.confidence_quiz import ConfidenceQuiz
from src.utils import reset_session_state, init_session_state
import google.generativeai as genai
# Configure Gemini API
if 'GEMINI_API_KEY' in st.secrets:
genai.configure(api_key=st.secrets['GEMINI_API_KEY'])
else:
st.error("Missing Gemini API key in secrets!")
# Initialize session state
init_session_state()
def app():
st.title("Confidence Assessment")
# Ensure session state variables are initialized
if "quiz_started" not in st.session_state:
st.session_state.quiz_started = False
if "quiz_complete" not in st.session_state:
st.session_state.quiz_complete = False
if "current_question" not in st.session_state:
st.session_state.current_question = 0
if "quiz_answers" not in st.session_state:
st.session_state.quiz_answers = []
quiz = ConfidenceQuiz()
if not st.session_state.quiz_started:
st.write("Take our confidence assessment to get personalized advice.")
if st.button("Start Quiz"):
st.session_state.quiz_started = True
st.rerun()
elif not st.session_state.quiz_complete:
current_q = quiz.questions[st.session_state.current_question]
st.write(f"Question {current_q['id']} of {len(quiz.questions)}")
st.write(current_q['question'])
answer = st.radio(
"Choose your answer:",
list(current_q['options'].items()),
format_func=lambda x: f"{x[0]}) {x[1]}"
)
if st.button("Next"):
st.session_state.quiz_answers.append(answer[0])
if st.session_state.current_question < len(quiz.questions) - 1:
st.session_state.current_question += 1
st.rerun()
else:
st.session_state.quiz_complete = True
st.rerun()
else:
results = quiz.calculate_score(st.session_state.quiz_answers)
st.write(f"**Score:** {results['score']} out of {results['max_score']}")
st.write(f"**Confidence Level:** {results['feedback']['level']}")
st.write(results['feedback']['summary'])
with st.expander("View Detailed Feedback"):
st.subheader("Your Strengths")
for strength in results['feedback']['strengths']:
st.write(f"- {strength}")
st.subheader("Recommended Next Steps")
for step in results['feedback']['next_steps']:
st.write(f"- {step}")
st.subheader("Interview Tips")
for tip in results['feedback']['interview_tips']:
st.write(f"- {tip}")
if st.button("Retake Quiz"):
reset_session_state()
st.rerun()