-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
133 lines (108 loc) · 4.3 KB
/
app.py
File metadata and controls
133 lines (108 loc) · 4.3 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
import streamlit as st
import requests
API_BASE_URL = "https://interviewai-fastapi.onrender.com"
st.set_page_config(page_title="InterviewAI", page_icon="💬")
st.title("💬 InterviewAI")
if "session_id" not in st.session_state:
st.session_state.session_id = None
if "messages" not in st.session_state:
st.session_state.messages = []
if "interview_complete" not in st.session_state:
st.session_state.interview_complete = False
if st.session_state.session_id is None:
st.subheader("Personal Information")
name = st.text_input("Name", placeholder="Enter your name")
experience = st.text_area("Experience", placeholder="Describe your experience")
skills = st.text_area("Skills", placeholder="List your skills")
st.subheader("Company and Position")
col1, col2 = st.columns(2)
with col1:
level = st.radio("Level", ["Junior", "Mid-level", "Senior"])
with col2:
position = st.selectbox(
"Position",
["Data Scientist", "Data Engineer", "ML Engineer", "BI Analyst", "Financial Analyst"]
)
company = st.selectbox(
"Company",
["Amazon", "Meta", "Udemy", "365 Company", "Nestle", "LinkedIn", "Spotify"]
)
if st.button("Start Interview"):
try:
resp = requests.post(
f"{API_BASE_URL}/start-interview",
json={
"name": name,
"experience": experience,
"skills": skills,
"level": level,
"position": position,
"company": company
},
timeout=60
)
if resp.status_code != 200:
st.error(f"Backend error: {resp.text}")
else:
data = resp.json()
st.session_state.session_id = data["session_id"]
st.session_state.messages = [
{"role": "assistant", "content": data["message"]}
]
st.rerun()
except Exception as e:
st.error(f"Could not connect to backend: {e}")
elif not st.session_state.interview_complete:
st.info("Start by introducing yourself", icon="👋")
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.markdown(msg["content"])
if prompt := st.chat_input("Your response"):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
try:
with st.spinner("Thinking..."):
resp = requests.post(
f"{API_BASE_URL}/chat/{st.session_state.session_id}",
json={"message": prompt},
timeout=60
)
if resp.status_code != 200:
st.error(f"Backend error: {resp.text}")
else:
data = resp.json()
if data.get("message"):
st.session_state.messages.append(
{"role": "assistant", "content": data["message"]}
)
with st.chat_message("assistant"):
st.markdown(data["message"])
if data.get("interview_complete"):
st.session_state.interview_complete = True
st.rerun()
except Exception as e:
st.error(f"Could not connect to backend: {e}")
else:
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.markdown(msg["content"])
if st.button("Get Feedback"):
try:
with st.spinner("Generating feedback..."):
resp = requests.get(
f"{API_BASE_URL}/feedback/{st.session_state.session_id}",
timeout=60
)
if resp.status_code != 200:
st.error(f"Backend error: {resp.text}")
else:
data = resp.json()
st.subheader("📝 Interview Feedback")
st.write(data["feedback"])
except Exception as e:
st.error(f"Could not get feedback: {e}")
if st.button("Restart", type="primary"):
for key in list(st.session_state.keys()):
del st.session_state[key]
st.rerun()