Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
158 lines (123 loc) · 6.64 KB
/
Copy pathapp.py
File metadata and controls
158 lines (123 loc) · 6.64 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import streamlit as st
from openai import OpenAI
from streamlit_js_eval import streamlit_js_eval
st.set_page_config(page_title="Streamlit Chat", page_icon="§")
st.title("Chatbot")
if "setup_complete" not in st.session_state:
st.session_state.setup_complete = False
if "user_message_count" not in st.session_state:
st.session_state.user_message_count = 0
if "feedback_shown" not in st.session_state:
st.session_state.feedback_shown = False
if "messages" not in st.session_state:
st.session_state.messages = []
if "chat_complete" not in st.session_state:
st.session_state.chat_complete = False
def complete_setup():
st.session_state.setup_complete = True
def show_feedback():
st.session_state.feedback_shown = True
if not st.session_state.setup_complete:
# == Personal Info ==
st.subheader('Personal Information', divider = 'rainbow')
if "name" not in st.session_state:
st.session_state["name"] = ""
if "experience" not in st.session_state:
st.session_state["experience"] = ""
if "skills" not in st.session_state:
st.session_state["skills"] = ""
st.session_state["name"] = st.text_input(label = "Name", max_chars=40, value = st.session_state["name"], placeholder="Enter your name")
st.session_state["experience"] = st.text_area(label = "Experience", value = st.session_state["experience"], height = None, max_chars=200, placeholder="Describe any experience you have")
st.session_state["skills"] = st.text_area(label = "Skills", value = st.session_state["skills"], height = None, max_chars=200, placeholder="List any skills you have")
# st.write(f"**Your Name**: {st.session_state['name']}")
# st.write(f"**Your Expereince**: {st.session_state['experience']}")
# st.write(f"**Your Skills**: {st.session_state['skills']}")
st.subheader('Company and Position', divider = 'rainbow')
if "level" not in st.session_state:
st.session_state["level"] = "Junior"
if "position" not in st.session_state:
st.session_state["position"] = "Data Scientist"
if "company" not in st.session_state:
st.session_state["company"] = "Amazon"
col1, col2 = st.columns(2)
with col1:
st.session_state["level"] = st.radio(
"Choose level",
key = "visibility",
options = ["Junior", "Mid-Level", "Senior"]
)
with col2:
st.session_state["position"] = st.selectbox(
"Choose a position",
("Data Scientist", "Data Engineer", "ML Engineer", "BI Analyst", "Financial Analyst")
)
st.session_state["company"] = st.selectbox(
"Choose a company",
("Amazon", "Meta", "Udemy", "365 Company", "LinkedIn", "Spotify")
)
# st.write(f"**Your Information**: {st.session_state['level']} {st.session_state['position']} at {st.session_state['company']}")
if st.button("Start Interview", on_click=complete_setup):
st.write("Setup complete. Starting interview...")
# == Setup bot ==
if st.session_state.setup_complete and not st.session_state.feedback_shown and not st.session_state.chat_complete:
st.info(
"""
Start by introducing yourself!
"""
)
client = OpenAI(api_key=st.secrets["OPENROUTER_API_KEY"], base_url="https://openrouter.ai/api/v1")
if "openai_model" not in st.session_state:
st.session_state["openai_model"] = "openai/gpt-oss-20b:free"
# ==== Chat ====
if not st.session_state.messages:
st.session_state.messages = [{"role":"system", "content": f"You are a NAMELESS HR executive that interviews an interviewee called {st.session_state['name']} with experience {st.session_state['experience']} and skills {st.session_state['skills']}. You should interview them for the position {st.session_state['level']} {st.session_state['position']} at the company {st.session_state['company']}. Start by greeting the interviewee then begin asking questions. You should ask a single interview question at a time phrased as if you were speaking casually with the interviewee. NO BULLET POINTS."}]
for message in st.session_state.messages:
if message["role"] != "system":
with st.chat_message(message["role"]):
st.markdown(message["content"])
if st.session_state.user_message_count < 5:
if prompt := st.chat_input("Your answer.", max_chars=1000):
st.session_state.messages.append({"role":"user", "content":prompt})
with st.chat_message("user"):
st.markdown(prompt)
if st.session_state.user_message_count < 4:
with st.chat_message("assistant"):
stream = client.chat.completions.create(
model = st.session_state["openai_model"],
messages = [
{"role": m["role"], "content": m["content"]}
for m in st.session_state.messages
],
stream = True
)
response = st.write_stream(stream)
st.session_state.messages.append({"role": "assistant", "content": response})
st.session_state.user_message_count += 1
if st.session_state.user_message_count >= 5:
st.session_state.chat_complete = True
# ==== Feedback ====
if st.session_state.chat_complete and not st.session_state.feedback_shown:
if st.button("Get Feedback", on_click=show_feedback):
st.write("Getting feedback...")
if st.session_state.feedback_shown:
st.subheader("Feedback")
conversation_history = "\n".join([f"{msg['role']}: {msg['content']}" for msg in st.session_state.messages])
feedback_client = OpenAI(api_key=st.secrets["OPENROUTER_API_KEY"], base_url="https://openrouter.ai/api/v1")
feedback_completion = feedback_client.chat.completions.create(
model = "openai/gpt-oss-20b:free",
messages=[
{"role":"system", "content":
"""
You are a helpful tool that provides feedback on an interviewee performance.
Before the Feedback give a score of 1 to 10.
Follow this format:
Overall Score: // Your score
Feedback: // Write feedback
Give only the feedback, do not ask additional questions.
"""},
{"role": "user", "content": f"This is the interview you need to evaluate. Keep in mind that you are only a tool. And you shouldn't engage in any converstation: {conversation_history}"}
]
)
st.write(feedback_completion.choices[0].message.content)
if st.button("Restart Interview", type = "primary"):
streamlit_js_eval(js_expressions = "parent.window.location.reload()")