Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
310 lines (238 loc) ยท 9.71 KB
/
Copy pathapp.py
File metadata and controls
310 lines (238 loc) ยท 9.71 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import streamlit as st
import pandas as pd
import joblib
import os
from groq_helper import generate_questions
from pdf_generator import create_pdf
# --- Paths for models and data ---
DATA_FILE = "cleaned_interview_dataset.csv"
MODEL_ROUND_FILE = "model_round.pkl"
MODEL_DIFFICULTY_FILE = "model_difficulty.pkl"
MODEL_ROUNDTYPE_FILE = "model_roundtype.pkl"
LE_COMPANY_FILE = "le_company.pkl"
LE_ROLE_FILE = "le_role.pkl"
LE_EXP_FILE = "le_exp.pkl"
LE_ROUNDTYPE_FILE = "le_roundtype.pkl"
LE_DIFFICULTY_FILE = "le_difficulty.pkl"
# Check if files exist
if not os.path.exists(DATA_FILE):
st.error(f"Error: Data file '{DATA_FILE}' not found. Please ensure it's in the same directory as the app.")
st.stop()
for f in [MODEL_ROUND_FILE, MODEL_DIFFICULTY_FILE, MODEL_ROUNDTYPE_FILE, LE_COMPANY_FILE, LE_ROLE_FILE, LE_EXP_FILE, LE_ROUNDTYPE_FILE, LE_DIFFICULTY_FILE]:
if not os.path.exists(f):
st.error(f"Error: Model/Encoder file '{f}' not found. Please ensure all .pkl files are in the same directory as the app.")
st.stop()
# ==========================
# LOAD DATA, MODELS AND ENCODERS
# ==========================
@st.cache_data
def load_data(file_path):
return pd.read_csv(file_path)
df = load_data(DATA_FILE)
@st.cache_resource
def load_model_and_encoders():
model_round = joblib.load(MODEL_ROUND_FILE)
model_difficulty = joblib.load(MODEL_DIFFICULTY_FILE)
model_roundtype = joblib.load(MODEL_ROUNDTYPE_FILE)
le_company = joblib.load(LE_COMPANY_FILE)
le_role = joblib.load(LE_ROLE_FILE)
le_exp = joblib.load(LE_EXP_FILE)
le_roundtype = joblib.load(LE_ROUNDTYPE_FILE)
le_difficulty = joblib.load(LE_DIFFICULTY_FILE)
return model_round, model_difficulty, model_roundtype, le_company, le_role, le_exp, le_roundtype, le_difficulty
model_round, model_difficulty, model_roundtype, le_company, le_role, le_exp, le_roundtype, le_difficulty = load_model_and_encoders()
unique_company_names = sorted(df['Company_name'].dropna().unique())
# ==========================
# PREDICTION FUNCTIONS
# ==========================
def predict_total_rounds(company_type, role, experience):
sample = pd.DataFrame({
"Company_type": [company_type],
"Job_role": [role],
"Experience_level": [experience]
})
sample["Company_type"] = le_company.transform(sample["Company_type"])
sample["Job_role"] = le_role.transform(sample["Job_role"])
sample["Experience_level"] = le_exp.transform(sample["Experience_level"])
prediction = model_round.predict(sample)
return int(prediction[0])
def predict_difficulty(company_type, role, experience):
sample = pd.DataFrame({
"Company_type": [company_type],
"Job_role": [role],
"Experience_level": [experience]
})
sample["Company_type"] = le_company.transform(sample["Company_type"])
sample["Job_role"] = le_role.transform(sample["Job_role"])
sample["Experience_level"] = le_exp.transform(sample["Experience_level"])
prediction = model_difficulty.predict(sample)
return le_difficulty.inverse_transform(prediction)[0]
def predict_round_type(company_type, role, experience, round_no):
sample = pd.DataFrame({
"Company_type": [company_type],
"Job_role": [role],
"Experience_level": [experience],
"Round_no": [round_no]
})
sample["Company_type"] = le_company.transform(sample["Company_type"])
sample["Job_role"] = le_role.transform(sample["Job_role"])
sample["Experience_level"] = le_exp.transform(sample["Experience_level"])
prediction = model_roundtype.predict(sample)
return le_roundtype.inverse_transform(prediction)[0]
def predict_round_flow(company_type, role, experience, total_rounds):
round_flow = []
for r in range(1, total_rounds + 1):
round_name = predict_round_type(company_type, role, experience, r)
round_flow.append(round_name)
return round_flow
def recommend_topics(company, role, top_n=10):
if company and role:
result = df[(df["Company_name"] == company) & (df["Job_role"] == role)]
if not result.empty:
topics = result["Topics"].value_counts()
return (topics / topics.sum() * 100).round(2).head(top_n)
if company:
result = df[df["Company_name"] == company]
if not result.empty:
topics = result["Topics"].value_counts()
return (topics / topics.sum() * 100).round(2).head(top_n)
if role:
result = df[df["Job_role"] == role]
if not result.empty:
topics = result["Topics"].value_counts()
return (topics / topics.sum() * 100).round(2).head(top_n)
topics = df["Topics"].value_counts()
return (topics / topics.sum() * 100).round(2).head(top_n)
def predict_interview(company_name, company_type, role, experience):
total_rounds = predict_total_rounds(company_type, role, experience)
difficulty = predict_difficulty(company_type, role, experience)
round_flow = predict_round_flow(company_type, role, experience, total_rounds)
topics = recommend_topics(company_name, role)
return {
"Total Rounds": total_rounds,
"Difficulty": difficulty,
"Round Flow": round_flow,
"Topics": topics
}
# ==========================
# STREAMLIT UI
# ==========================
st.set_page_config(layout="wide", page_title="AI-ATS Interview Predictor", initial_sidebar_state="auto")
col_left, col_center, col_right = st.columns([1, 2, 1])
with col_center:
st.title("AI-ATS Interview Predictor")
st.markdown("Unlock your interview potential with AI-ATS! This tool predicts interview rounds, difficulty, flow, and relevant topics based on company type, role, and experience. \n\n**How it works:** Simply input your desired company, job role, and experience level below, then click 'Predict Interview' to get instant insights.")
st.header("Input Your Details")
company_name = st.selectbox(
"๐ข Company Name",
options=[''] + unique_company_names,
index=0,
help="Select a company from the list or type to filter."
)
if company_name == '':
st.warning("Please select a Company Name.")
company_type = st.selectbox(
"๐ผ Company Type",
list(le_company.classes_)
)
job_role = st.selectbox(
"๐งโ๐ป Job Role",
list(le_role.classes_)
)
experience = st.selectbox(
"๐ Experience Level",
list(le_exp.classes_)
)
# FIX: Actually defining the prediction button inside the center column layout
predict_btn = st.button("๐ฎ Predict Interview", type="primary")
# ==========================
# OUTPUT (Kept outside columns for wider results display, or indent it into `with col_center:` if preferred)
# ==========================
if predict_btn:
if not company_name:
st.error("โ Please select a Company Name from the dropdown.")
st.stop()
with st.spinner("๐ฎ Predicting your interview insights..."):
result = predict_interview(
company_name,
company_type,
job_role,
experience
)
# Save prediction in session_state
st.session_state.result = result
# -------------------------------
# Show prediction if available
# -------------------------------
if "result" in st.session_state:
result = st.session_state.result
st.markdown("## โจ Prediction Results")
with st.container(border=True):
st.markdown("### ๐ Key Insights")
col1, col2 = st.columns(2)
with col1:
st.metric(
"Total Rounds Expected",
result["Total Rounds"]
)
with col2:
st.metric(
"Overall Difficulty",
result["Difficulty"]
)
st.markdown("### ๐ Predicted Round Flow")
with st.container(border=True):
for i, round_name in enumerate(result["Round Flow"], start=1):
st.markdown(f"**Round {i}:** `{round_name}`")
st.markdown("### ๐ Key Topics to Prepare")
with st.container(border=True):
topics = result["Topics"]
if topics is not None and not topics.empty:
for topic, percent in topics.items():
st.markdown(f"**{topic}** - `{percent}%`")
st.progress(min(int(float(percent)), 100)) # Cast to float safely before int conversion
# ---------------------------
# AI Questions
# ---------------------------
st.markdown("---")
st.markdown("## ๐ค AI Interview Coach")
if "ai_questions" not in st.session_state:
st.session_state["ai_questions"] = ""
if st.button("๐ Generate Expected Questions"):
prompt = f"""
You are an interview expert.
Company: {company_name}
Role: {job_role}
Difficulty: {result['Difficulty']}
Round Flow: {result['Round Flow']}
Topics: {list(result['Topics'].keys())}
Generate exactly 5 interview questions
for each round.
"""
with st.spinner("Generating Questions..."):
questions = generate_questions(prompt)
st.session_state["ai_questions"] = questions
pdf_file = create_pdf(
company_name,
job_role,
experience,
result,
questions
)
st.session_state["pdf_file"] = pdf_file
if "pdf_file" in st.session_state:
with open(
st.session_state["pdf_file"],
"rb"
) as file:
st.download_button(
label="๐ Download Interview Report PDF",
data=file,
file_name="Interview_Report.pdf",
mime="application/pdf"
)
if "ai_questions" in st.session_state and st.session_state["ai_questions"]:
st.markdown("## ๐ฏ Expected Interview Questions")
st.markdown(
st.session_state["ai_questions"]
)