Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,46 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
# st.session_state["openai_model"] = "gpt-4o"
|
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 |
# # Setup stage for collecting user details
|
47 |
# if not st.session_state.setup_complete:
|
@@ -101,141 +100,6 @@
|
|
101 |
# if st.button("Start Interview", on_click=complete_setup):
|
102 |
# st.write("Setup complete. Starting interview...")
|
103 |
|
104 |
-
# # Interview phase
|
105 |
-
# if st.session_state.setup_complete and not st.session_state.chat_complete:
|
106 |
-
|
107 |
-
# st.info(
|
108 |
-
# """
|
109 |
-
# Start by introducing yourself
|
110 |
-
# """,
|
111 |
-
# icon="π",
|
112 |
-
# )
|
113 |
-
|
114 |
-
# # Initialize OpenAI client
|
115 |
-
# client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"])
|
116 |
-
|
117 |
-
# # Initializing the system prompt for the chatbot
|
118 |
-
# if not st.session_state.messages:
|
119 |
-
# st.session_state.messages = [{
|
120 |
-
# "role": "system",
|
121 |
-
# "content": (f"You are an HR that interviews {st.session_state['name']}. You should interview him for the "
|
122 |
-
# f"{st.session_state['position']} position in the company {st.session_state['company']}")
|
123 |
-
# }]
|
124 |
-
|
125 |
-
# # Display chat messages
|
126 |
-
# for message in st.session_state.messages:
|
127 |
-
# if message["role"] != "system":
|
128 |
-
# with st.chat_message(message["role"]):
|
129 |
-
# st.markdown(message["content"])
|
130 |
-
|
131 |
-
# # Handle user input and OpenAI response
|
132 |
-
# # Put a max_chars limit
|
133 |
-
# if st.session_state.user_message_count < 5:
|
134 |
-
# if prompt := st.chat_input("Your response", max_chars=1000):
|
135 |
-
# st.session_state.messages.append({"role": "user", "content": prompt})
|
136 |
-
# with st.chat_message("user"):
|
137 |
-
# st.markdown(prompt)
|
138 |
-
|
139 |
-
# if st.session_state.user_message_count < 4:
|
140 |
-
# with st.chat_message("assistant"):
|
141 |
-
# stream = client.chat.completions.create(
|
142 |
-
# model=st.session_state["openai_model"],
|
143 |
-
# messages=[{"role": m["role"], "content": m["content"]} for m in st.session_state.messages],
|
144 |
-
# stream=True,
|
145 |
-
# )
|
146 |
-
# response = st.write_stream(stream)
|
147 |
-
# st.session_state.messages.append({"role": "assistant", "content": response})
|
148 |
-
|
149 |
-
# # Increment the user message count
|
150 |
-
# st.session_state.user_message_count += 1
|
151 |
-
|
152 |
-
# # Check if the user message count reaches 5
|
153 |
-
# if st.session_state.user_message_count >= 5:
|
154 |
-
# st.session_state.chat_complete = True
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
import streamlit as st
|
159 |
-
from openai import OpenAI
|
160 |
-
|
161 |
-
# Setting up the Streamlit page configuration
|
162 |
-
st.set_page_config(page_title="StreamlitChatMessageHistory", page_icon="π¬")
|
163 |
-
st.title("Chatbot")
|
164 |
-
|
165 |
-
# Initialize session state variables
|
166 |
-
if "setup_complete" not in st.session_state:
|
167 |
-
st.session_state.setup_complete = False
|
168 |
-
if "user_message_count" not in st.session_state:
|
169 |
-
st.session_state.user_message_count = 0
|
170 |
-
if "feedback_shown" not in st.session_state:
|
171 |
-
st.session_state.feedback_shown = False
|
172 |
-
if "chat_complete" not in st.session_state:
|
173 |
-
st.session_state.chat_complete = False
|
174 |
-
if "messages" not in st.session_state:
|
175 |
-
st.session_state.messages = []
|
176 |
-
|
177 |
-
# Helper functions to update session state
|
178 |
-
def complete_setup():
|
179 |
-
st.session_state.setup_complete = True
|
180 |
-
|
181 |
-
# Setup stage for collecting user details
|
182 |
-
if not st.session_state.setup_complete:
|
183 |
-
st.subheader('Personal Information')
|
184 |
-
|
185 |
-
# Initialize session state for personal information
|
186 |
-
if "name" not in st.session_state:
|
187 |
-
st.session_state["name"] = ""
|
188 |
-
if "experience" not in st.session_state:
|
189 |
-
st.session_state["experience"] = ""
|
190 |
-
if "skills" not in st.session_state:
|
191 |
-
st.session_state["skills"] = ""
|
192 |
-
|
193 |
-
|
194 |
-
# Get personal information input
|
195 |
-
st.session_state["name"] = st.text_input(label="Name", value=st.session_state["name"], placeholder="Enter your name", max_chars=40)
|
196 |
-
st.session_state["experience"] = st.text_area(label="Experience", value=st.session_state["experience"], placeholder="Describe your experience", max_chars=200)
|
197 |
-
st.session_state["skills"] = st.text_area(label="Skills", value=st.session_state["skills"], placeholder="List your skills", max_chars=200)
|
198 |
-
|
199 |
-
|
200 |
-
# Company and Position Section
|
201 |
-
st.subheader('Company and Position')
|
202 |
-
|
203 |
-
# Initialize session state for company and position information and setting default values
|
204 |
-
if "level" not in st.session_state:
|
205 |
-
st.session_state["level"] = "Junior"
|
206 |
-
if "position" not in st.session_state:
|
207 |
-
st.session_state["position"] = "Data Scientist"
|
208 |
-
if "company" not in st.session_state:
|
209 |
-
st.session_state["company"] = "Amazon"
|
210 |
-
|
211 |
-
col1, col2 = st.columns(2)
|
212 |
-
with col1:
|
213 |
-
st.session_state["level"] = st.radio(
|
214 |
-
"Choose level",
|
215 |
-
key="visibility",
|
216 |
-
options=["Junior", "Mid-level", "Senior"],
|
217 |
-
index=["Junior", "Mid-level", "Senior"].index(st.session_state["level"])
|
218 |
-
)
|
219 |
-
|
220 |
-
with col2:
|
221 |
-
st.session_state["position"] = st.selectbox(
|
222 |
-
"Choose a position",
|
223 |
-
("Data Scientist", "Data Engineer", "ML Engineer", "BI Analyst", "Financial Analyst"),
|
224 |
-
index=("Data Scientist", "Data Engineer", "ML Engineer", "BI Analyst", "Financial Analyst").index(st.session_state["position"])
|
225 |
-
)
|
226 |
-
|
227 |
-
st.session_state["company"] = st.selectbox(
|
228 |
-
"Select a Company",
|
229 |
-
("Amazon", "Meta", "Udemy", "365 Company", "Nestle", "LinkedIn", "Spotify"),
|
230 |
-
index=("Amazon", "Meta", "Udemy", "365 Company", "Nestle", "LinkedIn", "Spotify").index(st.session_state["company"])
|
231 |
-
)
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
# Button to complete setup
|
236 |
-
if st.button("Start Interview", on_click=complete_setup):
|
237 |
-
st.write("Setup complete. Starting interview...")
|
238 |
-
|
239 |
# Interview phase
|
240 |
if st.session_state.setup_complete and not st.session_state.chat_complete:
|
241 |
|
@@ -257,10 +121,8 @@ if st.session_state.setup_complete and not st.session_state.chat_complete:
|
|
257 |
if not st.session_state.messages:
|
258 |
st.session_state.messages = [{
|
259 |
"role": "system",
|
260 |
-
"content": (f"You are an HR
|
261 |
-
f"
|
262 |
-
f"You should interview him for the position {st.session_state['level']} {st.session_state['position']} "
|
263 |
-
f"at the company {st.session_state['company']}")
|
264 |
}]
|
265 |
|
266 |
# Display chat messages
|
@@ -281,10 +143,7 @@ if st.session_state.setup_complete and not st.session_state.chat_complete:
|
|
281 |
with st.chat_message("assistant"):
|
282 |
stream = client.chat.completions.create(
|
283 |
model=st.session_state["openai_model"],
|
284 |
-
messages=[
|
285 |
-
{"role": m["role"], "content": m["content"]}
|
286 |
-
for m in st.session_state.messages
|
287 |
-
],
|
288 |
stream=True,
|
289 |
)
|
290 |
response = st.write_stream(stream)
|
@@ -295,4 +154,152 @@ if st.session_state.setup_complete and not st.session_state.chat_complete:
|
|
295 |
|
296 |
# Check if the user message count reaches 5
|
297 |
if st.session_state.user_message_count >= 5:
|
298 |
-
st.session_state.chat_complete = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from openai import OpenAI
|
3 |
|
4 |
+
# Setting up the Streamlit page configuration
|
5 |
+
st.set_page_config(page_title="StreamlitChatMessageHistory", page_icon="π¬")
|
6 |
+
st.title("Chatbot")
|
7 |
|
8 |
+
# Initialize session state variables
|
9 |
+
st.session_state.setup_complete = False
|
10 |
+
st.session_state.user_message_count = 0
|
11 |
+
st.session_state.chat_complete = False
|
12 |
+
st.session_state.messages = []
|
|
|
13 |
|
14 |
|
15 |
+
# Helper functions to update session state
|
16 |
+
def complete_setup():
|
17 |
+
st.session_state.setup_complete = True
|
18 |
|
19 |
+
# Setup stage for collecting user details
|
20 |
+
if not st.session_state.setup_complete:
|
21 |
+
st.subheader('Personal Information')
|
22 |
|
23 |
+
# Get personal information input
|
24 |
+
st.session_state["name"] = st.text_input(label="Name", value="", placeholder="Enter your name", max_chars=40)
|
25 |
|
26 |
+
# Company and Position Section
|
27 |
+
st.subheader('Company and Position')
|
28 |
|
29 |
+
st.session_state["position"] = st.selectbox(
|
30 |
+
"Choose a position",
|
31 |
+
("Data Scientist", "Data Engineer", "ML Engineer", "BI Analyst", "Financial Analyst"),
|
32 |
+
index=("Data Scientist", "Data Engineer", "ML Engineer", "BI Analyst", "Financial Analyst").index("Data Scientist")
|
33 |
+
)
|
34 |
|
35 |
+
st.session_state["company"] = st.selectbox(
|
36 |
+
"Select a Company",
|
37 |
+
("Amazon", "Meta", "Udemy", "365 Company", "Nestle", "LinkedIn", "Spotify"),
|
38 |
+
index=("Amazon", "Meta", "Udemy", "365 Company", "Nestle", "LinkedIn", "Spotify").index("Amazon")
|
39 |
+
)
|
40 |
|
41 |
+
# Button to complete setup
|
42 |
+
if st.button("Start Interview", on_click=complete_setup):
|
43 |
+
st.write("Setup complete. Starting interview...")
|
44 |
|
45 |
# # Setup stage for collecting user details
|
46 |
# if not st.session_state.setup_complete:
|
|
|
100 |
# if st.button("Start Interview", on_click=complete_setup):
|
101 |
# st.write("Setup complete. Starting interview...")
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
# Interview phase
|
104 |
if st.session_state.setup_complete and not st.session_state.chat_complete:
|
105 |
|
|
|
121 |
if not st.session_state.messages:
|
122 |
st.session_state.messages = [{
|
123 |
"role": "system",
|
124 |
+
"content": (f"You are an HR that interviews {st.session_state['name']}. You should interview him for the "
|
125 |
+
f"{st.session_state['position']} position in the company {st.session_state['company']}")
|
|
|
|
|
126 |
}]
|
127 |
|
128 |
# Display chat messages
|
|
|
143 |
with st.chat_message("assistant"):
|
144 |
stream = client.chat.completions.create(
|
145 |
model=st.session_state["openai_model"],
|
146 |
+
messages=[{"role": m["role"], "content": m["content"]} for m in st.session_state.messages],
|
|
|
|
|
|
|
147 |
stream=True,
|
148 |
)
|
149 |
response = st.write_stream(stream)
|
|
|
154 |
|
155 |
# Check if the user message count reaches 5
|
156 |
if st.session_state.user_message_count >= 5:
|
157 |
+
st.session_state.chat_complete = True
|
158 |
+
|
159 |
+
|
160 |
+
|
161 |
+
|
162 |
+
|
163 |
+
|
164 |
+
|
165 |
+
# import streamlit as st
|
166 |
+
# from openai import OpenAI
|
167 |
+
|
168 |
+
# # Setting up the Streamlit page configuration
|
169 |
+
# st.set_page_config(page_title="StreamlitChatMessageHistory", page_icon="π¬")
|
170 |
+
# st.title("Chatbot")
|
171 |
+
|
172 |
+
# # Initialize session state variables
|
173 |
+
# if "setup_complete" not in st.session_state:
|
174 |
+
# st.session_state.setup_complete = False
|
175 |
+
# if "user_message_count" not in st.session_state:
|
176 |
+
# st.session_state.user_message_count = 0
|
177 |
+
# if "feedback_shown" not in st.session_state:
|
178 |
+
# st.session_state.feedback_shown = False
|
179 |
+
# if "chat_complete" not in st.session_state:
|
180 |
+
# st.session_state.chat_complete = False
|
181 |
+
# if "messages" not in st.session_state:
|
182 |
+
# st.session_state.messages = []
|
183 |
+
|
184 |
+
# # Helper functions to update session state
|
185 |
+
# def complete_setup():
|
186 |
+
# st.session_state.setup_complete = True
|
187 |
+
|
188 |
+
# # Setup stage for collecting user details
|
189 |
+
# if not st.session_state.setup_complete:
|
190 |
+
# st.subheader('Personal Information')
|
191 |
+
|
192 |
+
# # Initialize session state for personal information
|
193 |
+
# if "name" not in st.session_state:
|
194 |
+
# st.session_state["name"] = ""
|
195 |
+
# if "experience" not in st.session_state:
|
196 |
+
# st.session_state["experience"] = ""
|
197 |
+
# if "skills" not in st.session_state:
|
198 |
+
# st.session_state["skills"] = ""
|
199 |
+
|
200 |
+
|
201 |
+
# # Get personal information input
|
202 |
+
# st.session_state["name"] = st.text_input(label="Name", value=st.session_state["name"], placeholder="Enter your name", max_chars=40)
|
203 |
+
# st.session_state["experience"] = st.text_area(label="Experience", value=st.session_state["experience"], placeholder="Describe your experience", max_chars=200)
|
204 |
+
# st.session_state["skills"] = st.text_area(label="Skills", value=st.session_state["skills"], placeholder="List your skills", max_chars=200)
|
205 |
+
|
206 |
+
|
207 |
+
# # Company and Position Section
|
208 |
+
# st.subheader('Company and Position')
|
209 |
+
|
210 |
+
# # Initialize session state for company and position information and setting default values
|
211 |
+
# if "level" not in st.session_state:
|
212 |
+
# st.session_state["level"] = "Junior"
|
213 |
+
# if "position" not in st.session_state:
|
214 |
+
# st.session_state["position"] = "Data Scientist"
|
215 |
+
# if "company" not in st.session_state:
|
216 |
+
# st.session_state["company"] = "Amazon"
|
217 |
+
|
218 |
+
# col1, col2 = st.columns(2)
|
219 |
+
# with col1:
|
220 |
+
# st.session_state["level"] = st.radio(
|
221 |
+
# "Choose level",
|
222 |
+
# key="visibility",
|
223 |
+
# options=["Junior", "Mid-level", "Senior"],
|
224 |
+
# index=["Junior", "Mid-level", "Senior"].index(st.session_state["level"])
|
225 |
+
# )
|
226 |
+
|
227 |
+
# with col2:
|
228 |
+
# st.session_state["position"] = st.selectbox(
|
229 |
+
# "Choose a position",
|
230 |
+
# ("Data Scientist", "Data Engineer", "ML Engineer", "BI Analyst", "Financial Analyst"),
|
231 |
+
# index=("Data Scientist", "Data Engineer", "ML Engineer", "BI Analyst", "Financial Analyst").index(st.session_state["position"])
|
232 |
+
# )
|
233 |
+
|
234 |
+
# st.session_state["company"] = st.selectbox(
|
235 |
+
# "Select a Company",
|
236 |
+
# ("Amazon", "Meta", "Udemy", "365 Company", "Nestle", "LinkedIn", "Spotify"),
|
237 |
+
# index=("Amazon", "Meta", "Udemy", "365 Company", "Nestle", "LinkedIn", "Spotify").index(st.session_state["company"])
|
238 |
+
# )
|
239 |
+
|
240 |
+
|
241 |
+
|
242 |
+
# # Button to complete setup
|
243 |
+
# if st.button("Start Interview", on_click=complete_setup):
|
244 |
+
# st.write("Setup complete. Starting interview...")
|
245 |
+
|
246 |
+
# # Interview phase
|
247 |
+
# if st.session_state.setup_complete and not st.session_state.chat_complete:
|
248 |
+
|
249 |
+
# st.info(
|
250 |
+
# """
|
251 |
+
# Start by introducing yourself
|
252 |
+
# """,
|
253 |
+
# icon="π",
|
254 |
+
# )
|
255 |
+
|
256 |
+
# # Initialize OpenAI client
|
257 |
+
# client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"])
|
258 |
+
|
259 |
+
# # Setting OpenAI model if not already initialized
|
260 |
+
# if "openai_model" not in st.session_state:
|
261 |
+
# st.session_state["openai_model"] = "gpt-4o"
|
262 |
+
|
263 |
+
# # Initializing the system prompt for the chatbot
|
264 |
+
# if not st.session_state.messages:
|
265 |
+
# st.session_state.messages = [{
|
266 |
+
# "role": "system",
|
267 |
+
# "content": (f"You are an HR executive that interviews an interviewee called {st.session_state['name']} "
|
268 |
+
# f"with experience {st.session_state['experience']} and skills {st.session_state['skills']}. "
|
269 |
+
# f"You should interview him for the position {st.session_state['level']} {st.session_state['position']} "
|
270 |
+
# f"at the company {st.session_state['company']}")
|
271 |
+
# }]
|
272 |
+
|
273 |
+
# # Display chat messages
|
274 |
+
# for message in st.session_state.messages:
|
275 |
+
# if message["role"] != "system":
|
276 |
+
# with st.chat_message(message["role"]):
|
277 |
+
# st.markdown(message["content"])
|
278 |
+
|
279 |
+
# # Handle user input and OpenAI response
|
280 |
+
# # Put a max_chars limit
|
281 |
+
# if st.session_state.user_message_count < 5:
|
282 |
+
# if prompt := st.chat_input("Your response", max_chars=1000):
|
283 |
+
# st.session_state.messages.append({"role": "user", "content": prompt})
|
284 |
+
# with st.chat_message("user"):
|
285 |
+
# st.markdown(prompt)
|
286 |
+
|
287 |
+
# if st.session_state.user_message_count < 4:
|
288 |
+
# with st.chat_message("assistant"):
|
289 |
+
# stream = client.chat.completions.create(
|
290 |
+
# model=st.session_state["openai_model"],
|
291 |
+
# messages=[
|
292 |
+
# {"role": m["role"], "content": m["content"]}
|
293 |
+
# for m in st.session_state.messages
|
294 |
+
# ],
|
295 |
+
# stream=True,
|
296 |
+
# )
|
297 |
+
# response = st.write_stream(stream)
|
298 |
+
# st.session_state.messages.append({"role": "assistant", "content": response})
|
299 |
+
|
300 |
+
# # Increment the user message count
|
301 |
+
# st.session_state.user_message_count += 1
|
302 |
+
|
303 |
+
# # Check if the user message count reaches 5
|
304 |
+
# if st.session_state.user_message_count >= 5:
|
305 |
+
# st.session_state.chat_complete = True
|