Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ def initialize_model():
|
|
| 13 |
for key in API_KEYS:
|
| 14 |
try:
|
| 15 |
genai.configure(api_key=key)
|
| 16 |
-
model = genai.GenerativeModel("gemini-
|
| 17 |
test = model.generate_content("Hello!")
|
| 18 |
if "Hello" in test.text:
|
| 19 |
print(f"[INFO] Using Gemini API key ending with: ...{key[-4:]}")
|
|
@@ -24,331 +24,43 @@ def initialize_model():
|
|
| 24 |
|
| 25 |
initialize_model()
|
| 26 |
|
| 27 |
-
# ========== Load Whisper ==========
|
| 28 |
-
|
| 29 |
|
| 30 |
-
# ========== Questions ==========
|
| 31 |
all_questions = {
|
| 32 |
"general": [
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
"Where do you see yourself in 5 years?",
|
| 40 |
-
"Describe a challenge or conflict you faced and how you dealt with it.",
|
| 41 |
-
"What motivates you to do your best?",
|
| 42 |
-
"How do you handle feedback and criticism?",
|
| 43 |
-
"Tell me about a time you took initiative.",
|
| 44 |
-
"How do you stay organized during busy schedules?",
|
| 45 |
-
"What do you do when you face a task you don’t know how to solve?",
|
| 46 |
-
"Tell me about a mistake you made and what you learned from it.",
|
| 47 |
-
"Have you ever led a project or team? What was your experience?",
|
| 48 |
-
"How do you manage deadlines when working on multiple tasks?",
|
| 49 |
-
"Why should we hire you?",
|
| 50 |
-
"Tell me about a time you failed. How did you respond?",
|
| 51 |
-
"How do you approach learning something new?",
|
| 52 |
-
"What do you know about our company?",
|
| 53 |
-
"How do you balance quality and speed in your work?",
|
| 54 |
-
"Describe a time when you had to make a difficult decision.",
|
| 55 |
-
"How do you communicate in a remote or hybrid work environment?",
|
| 56 |
-
"What kind of work culture are you most comfortable in?",
|
| 57 |
-
"Do you prefer working independently or in a team? Why?"
|
| 58 |
-
],
|
| 59 |
-
"web development": [
|
| 60 |
-
"What is the difference between HTML and XHTML?",
|
| 61 |
-
"Explain how RESTful APIs work.",
|
| 62 |
-
"What are the advantages of using React over plain JavaScript?",
|
| 63 |
-
"How does the virtual DOM improve performance?",
|
| 64 |
-
"What are HTTP methods? Explain each.",
|
| 65 |
-
"What is the difference between sessionStorage and localStorage?",
|
| 66 |
-
"What is CORS and how do you handle it?",
|
| 67 |
-
"Explain the box model in CSS.",
|
| 68 |
-
"What is responsive design?",
|
| 69 |
-
"What is the difference between SQL and NoSQL databases?",
|
| 70 |
-
"What are web sockets and when are they used?",
|
| 71 |
-
"What is a service worker in PWA?",
|
| 72 |
-
"What is lazy loading and why is it useful?",
|
| 73 |
-
"Difference between GET and POST requests?",
|
| 74 |
-
"How does server-side rendering differ from client-side rendering?",
|
| 75 |
-
"What is Next.js and how is it different from React?",
|
| 76 |
-
"What is a CDN and how does it help?",
|
| 77 |
-
"What is HTTPS and why is it important?",
|
| 78 |
-
"Explain the concept of middleware in Express.js.",
|
| 79 |
-
"What is an ORM and why use it?",
|
| 80 |
-
"Explain MVC architecture.",
|
| 81 |
-
"What is the difference between PUT and PATCH requests?",
|
| 82 |
-
"What is GraphQL and how does it compare to REST?",
|
| 83 |
-
"How do cookies and sessions work?",
|
| 84 |
-
"What is JWT and how is it used in authentication?"
|
| 85 |
-
],
|
| 86 |
-
"devops": [
|
| 87 |
-
"What is CI/CD and why is it important?",
|
| 88 |
-
"Explain the concept of Infrastructure as Code.",
|
| 89 |
-
"What is Docker and how is it different from a virtual machine?",
|
| 90 |
-
"What are containers and how do they help in deployment?",
|
| 91 |
-
"What is Kubernetes used for?",
|
| 92 |
-
"How do you monitor applications in production?",
|
| 93 |
-
"What is the role of Jenkins in DevOps?",
|
| 94 |
-
"What are some popular logging tools?",
|
| 95 |
-
"Explain blue-green deployment.",
|
| 96 |
-
"What is Ansible used for?",
|
| 97 |
-
"What is Terraform and how is it used?",
|
| 98 |
-
"What is a build pipeline?",
|
| 99 |
-
"What is Helm in Kubernetes?",
|
| 100 |
-
"What is a rolling update in deployments?",
|
| 101 |
-
"Explain canary deployments.",
|
| 102 |
-
"What is load balancing and how does it work?",
|
| 103 |
-
"What is the difference between horizontal and vertical scaling?",
|
| 104 |
-
"What are artifacts in a CI/CD pipeline?",
|
| 105 |
-
"What is the use of Prometheus and Grafana?",
|
| 106 |
-
"What is a reverse proxy?",
|
| 107 |
-
"How do you ensure zero-downtime deployments?",
|
| 108 |
-
"Explain the role of GitOps.",
|
| 109 |
-
"What are secrets management tools?",
|
| 110 |
-
"What is the purpose of using NGINX in DevOps?",
|
| 111 |
-
"What is a container registry?"
|
| 112 |
-
],
|
| 113 |
-
"cybersecurity": [
|
| 114 |
-
"What is the difference between symmetric and asymmetric encryption?",
|
| 115 |
-
"What is SQL injection and how do you prevent it?",
|
| 116 |
-
"What are some common types of malware?",
|
| 117 |
-
"What is the CIA triad?",
|
| 118 |
-
"What is multi-factor authentication?",
|
| 119 |
-
"What are firewalls and how do they work?",
|
| 120 |
-
"Explain HTTPS and how it secures data.",
|
| 121 |
-
"What is penetration testing?",
|
| 122 |
-
"How do you secure an API?",
|
| 123 |
-
"What are some best practices for password security?",
|
| 124 |
-
"What is phishing and how can it be prevented?",
|
| 125 |
-
"What is social engineering?",
|
| 126 |
-
"What is a DDoS attack?",
|
| 127 |
-
"What are intrusion detection systems?",
|
| 128 |
-
"What is a VPN and how does it work?",
|
| 129 |
-
"What is data encryption at rest vs in transit?",
|
| 130 |
-
"What is a zero-day vulnerability?",
|
| 131 |
-
"Explain role-based access control (RBAC).",
|
| 132 |
-
"What is a digital certificate?",
|
| 133 |
-
"How does a public key infrastructure (PKI) work?",
|
| 134 |
-
"What is a man-in-the-middle attack?",
|
| 135 |
-
"What are honeypots in cybersecurity?",
|
| 136 |
-
"Explain sandboxing in malware analysis.",
|
| 137 |
-
"What are security patches?",
|
| 138 |
-
"What is OWASP Top 10?"
|
| 139 |
-
],
|
| 140 |
-
"ai": [
|
| 141 |
-
"What is the difference between AI, ML, and Deep Learning?",
|
| 142 |
-
"Explain a neural network and how it learns.",
|
| 143 |
-
"What is gradient descent?",
|
| 144 |
-
"What is the role of activation functions in neural networks?",
|
| 145 |
-
"Explain supervised vs. unsupervised learning.",
|
| 146 |
-
"What is backpropagation?",
|
| 147 |
-
"What is overfitting and how do you avoid it?",
|
| 148 |
-
"What is transfer learning?",
|
| 149 |
-
"What are some common use-cases of AI?",
|
| 150 |
-
"How do you evaluate a classification model?",
|
| 151 |
-
"What is reinforcement learning?",
|
| 152 |
-
"What is an autoencoder?",
|
| 153 |
-
"Explain convolutional neural networks (CNNs).",
|
| 154 |
-
"What are recurrent neural networks (RNNs)?",
|
| 155 |
-
"What is a transformer model?",
|
| 156 |
-
"What is attention mechanism in NLP?",
|
| 157 |
-
"What is the Turing test?",
|
| 158 |
-
"What are generative adversarial networks (GANs)?",
|
| 159 |
-
"What is the bias-variance tradeoff?",
|
| 160 |
-
"What is explainable AI (XAI)?",
|
| 161 |
-
"How do you train a deep learning model?",
|
| 162 |
-
"What is early stopping in training?",
|
| 163 |
-
"What are hyperparameters?",
|
| 164 |
-
"What is a confusion matrix?",
|
| 165 |
-
"What is the role of regularization in deep learning?"
|
| 166 |
],
|
| 167 |
"ml": [
|
| 168 |
-
"What is
|
| 169 |
"What is the difference between classification and regression?",
|
| 170 |
-
"How does
|
| 171 |
-
"What
|
| 172 |
-
"
|
| 173 |
-
"
|
| 174 |
-
"
|
| 175 |
-
|
| 176 |
-
"What is the role of a cost function?",
|
| 177 |
-
"How do you handle missing data in ML datasets?",
|
| 178 |
-
"What is the k-nearest neighbors (KNN) algorithm?",
|
| 179 |
-
"What is support vector machine (SVM)?",
|
| 180 |
-
"What is Naive Bayes algorithm?",
|
| 181 |
-
"What is logistic regression?",
|
| 182 |
-
"What is feature scaling and why is it needed?",
|
| 183 |
-
"What is principal component analysis (PCA)?",
|
| 184 |
-
"What is model drift?",
|
| 185 |
-
"How do you tune hyperparameters?",
|
| 186 |
-
"What is grid search and random search?",
|
| 187 |
-
"What are ensemble models?",
|
| 188 |
-
"What is a confusion matrix and what do its values represent?",
|
| 189 |
-
"How do you balance an imbalanced dataset?",
|
| 190 |
-
"What is precision-recall tradeoff?",
|
| 191 |
-
"What is ROC-AUC score?",
|
| 192 |
-
"What is the purpose of stratified sampling?"
|
| 193 |
-
],
|
| 194 |
-
"mobile development": [
|
| 195 |
-
"What is the difference between native and hybrid apps?",
|
| 196 |
-
"Explain the lifecycle of an Android activity.",
|
| 197 |
-
"What is Flutter and why use it?",
|
| 198 |
-
"How do you handle data persistence in mobile apps?",
|
| 199 |
-
"What is MVVM architecture?",
|
| 200 |
-
"Explain push notifications and how they work.",
|
| 201 |
-
"What are the limitations of mobile development?",
|
| 202 |
-
"How do you optimize performance in mobile apps?",
|
| 203 |
-
"What is the role of App Store Optimization (ASO)?",
|
| 204 |
-
"Explain the concept of responsive design in mobile.",
|
| 205 |
-
"What is the difference between Android and iOS development?",
|
| 206 |
-
"What is React Native and how does it work?",
|
| 207 |
-
"How do you handle offline mode in apps?",
|
| 208 |
-
"What is a RecyclerView?",
|
| 209 |
-
"Explain intents in Android.",
|
| 210 |
-
"What is dependency injection in Android?",
|
| 211 |
-
"What are permissions in mobile apps?",
|
| 212 |
-
"How do you debug a mobile app?",
|
| 213 |
-
"What is Jetpack Compose?",
|
| 214 |
-
"How is state management handled in Flutter?",
|
| 215 |
-
"What is a storyboard in iOS?",
|
| 216 |
-
"What are background services?",
|
| 217 |
-
"How do you handle API calls in mobile apps?",
|
| 218 |
-
"What is the difference between LiveData and Flow?",
|
| 219 |
-
"How do you publish an app to Google Play Store?"
|
| 220 |
-
],
|
| 221 |
-
"uiux": [
|
| 222 |
-
"What is the difference between UI and UX?",
|
| 223 |
-
"What are some principles of good UX design?",
|
| 224 |
-
"What is a user journey?",
|
| 225 |
-
"How do you conduct user testing?",
|
| 226 |
-
"What tools do you use for UI/UX design?",
|
| 227 |
-
"What is wireframing?",
|
| 228 |
-
"How do you design for accessibility?",
|
| 229 |
-
"What is the role of prototyping?",
|
| 230 |
-
"Explain the concept of design thinking.",
|
| 231 |
-
"How do you collect and incorporate user feedback?",
|
| 232 |
-
"What is the importance of consistency in UI design?",
|
| 233 |
-
"What is heuristic evaluation?",
|
| 234 |
-
"What is the role of typography in UI?",
|
| 235 |
-
"What are color theory principles?",
|
| 236 |
-
"How does UX impact business goals?",
|
| 237 |
-
"What is A/B testing in UI/UX?",
|
| 238 |
-
"What is microcopy and why is it important?",
|
| 239 |
-
"Explain responsive vs adaptive design.",
|
| 240 |
-
"What is a user persona?",
|
| 241 |
-
"What is interaction design?",
|
| 242 |
-
"What is a high-fidelity vs low-fidelity prototype?",
|
| 243 |
-
"How do you measure UX success?",
|
| 244 |
-
"What is card sorting?",
|
| 245 |
-
"What are accessibility standards (WCAG)?",
|
| 246 |
-
"What is the role of animation in UI?"
|
| 247 |
-
],
|
| 248 |
-
"data analytics": [
|
| 249 |
-
"What is the difference between descriptive and inferential statistics?",
|
| 250 |
-
"What are some common data cleaning techniques?",
|
| 251 |
-
"Explain how to deal with missing data.",
|
| 252 |
-
"What is the role of data visualization?",
|
| 253 |
-
"What is a pivot table?",
|
| 254 |
-
"What are outliers and how do you handle them?",
|
| 255 |
-
"Explain correlation vs causation.",
|
| 256 |
-
"What are some commonly used data analytics tools?",
|
| 257 |
-
"How do you handle large datasets efficiently?",
|
| 258 |
-
"What is ETL and how does it work?",
|
| 259 |
-
"What is a histogram and when is it used?",
|
| 260 |
-
"What is data wrangling?",
|
| 261 |
-
"What is the difference between mean, median, and mode?",
|
| 262 |
-
"What is standard deviation and variance?",
|
| 263 |
-
"What is a box plot?",
|
| 264 |
-
"What is a time series analysis?",
|
| 265 |
-
"What is the difference between R and Python for analytics?",
|
| 266 |
-
"What is the use of SQL in data analytics?",
|
| 267 |
-
"How do dashboards help in analytics?",
|
| 268 |
-
"What is cohort analysis?",
|
| 269 |
-
"What is hypothesis testing?",
|
| 270 |
-
"What are confidence intervals?",
|
| 271 |
-
"How do you avoid bias in analytics?",
|
| 272 |
-
"What is the purpose of a heatmap?",
|
| 273 |
-
"What is a funnel analysis?"
|
| 274 |
-
],
|
| 275 |
-
"data scientist": [
|
| 276 |
-
"What is the difference between supervised and unsupervised learning?",
|
| 277 |
-
"Explain bias-variance tradeoff in machine learning.",
|
| 278 |
-
"How do you handle imbalanced datasets?",
|
| 279 |
-
"What are precision, recall, and F1-score? Why are they important?",
|
| 280 |
-
"Describe a machine learning project you've worked on.",
|
| 281 |
-
"What is feature engineering? Give examples.",
|
| 282 |
-
"How do you select important variables in a dataset?",
|
| 283 |
-
"Explain overfitting and how to prevent it.",
|
| 284 |
-
"What’s the difference between bagging and boosting?",
|
| 285 |
-
"Describe the steps in a typical machine learning pipeline.",
|
| 286 |
-
"What tools do you use as a data scientist?",
|
| 287 |
-
"What is dimensionality reduction?",
|
| 288 |
-
"How do you evaluate regression models?",
|
| 289 |
-
"What is the difference between ROC and PR curves?",
|
| 290 |
-
"What is model interpretability?",
|
| 291 |
-
"How do you deploy a machine learning model?",
|
| 292 |
-
"What is a recommendation system?",
|
| 293 |
-
"How do you deal with outliers?",
|
| 294 |
-
"What is SMOTE?",
|
| 295 |
-
"What is A/B testing in data science?",
|
| 296 |
-
"How do you build a data pipeline?",
|
| 297 |
-
"What are data lakes and data warehouses?",
|
| 298 |
-
"What is a baseline model?",
|
| 299 |
-
"How do you perform EDA (Exploratory Data Analysis)?",
|
| 300 |
-
"What is clustering and what are its applications?"
|
| 301 |
-
],
|
| 302 |
-
"prompt engineering": [
|
| 303 |
-
"What is prompt engineering and why is it important?",
|
| 304 |
-
"How do temperature and top_p affect model output in LLMs?",
|
| 305 |
-
"How do you write a good system prompt for a chatbot?",
|
| 306 |
-
"What are the risks of prompt injection attacks?",
|
| 307 |
-
"What is chain-of-thought prompting?",
|
| 308 |
-
"How does few-shot prompting improve performance?",
|
| 309 |
-
"What are embeddings, and how are they used in retrieval-augmented generation?",
|
| 310 |
-
"What are the limitations of prompt-based techniques?",
|
| 311 |
-
"Explain the role of role-based prompts in function calling.",
|
| 312 |
-
"How would you structure a prompt to summarize a large document accurately?",
|
| 313 |
-
"What is zero-shot learning in prompt design?",
|
| 314 |
-
"What is in-context learning?",
|
| 315 |
-
"What is semantic search and how is it used with LLMs?",
|
| 316 |
-
"How do you evaluate the output of an LLM?",
|
| 317 |
-
"What is hallucination in LLMs?",
|
| 318 |
-
"What are guardrails in LLM applications?",
|
| 319 |
-
"What is prompt chaining?",
|
| 320 |
-
"How do you personalize prompts for users?",
|
| 321 |
-
"What are system vs user prompts?",
|
| 322 |
-
"What is instruction tuning?",
|
| 323 |
-
"How do you manage memory in prompt-based agents?",
|
| 324 |
-
"What is RAG (retrieval-augmented generation)?",
|
| 325 |
-
"What is the difference between deterministic and probabilistic LLM output?",
|
| 326 |
-
"How do prompts interact with tools in agent systems?",
|
| 327 |
-
"How do you test prompt robustness?"
|
| 328 |
]
|
| 329 |
}
|
| 330 |
|
| 331 |
# ========== Session State ==========
|
| 332 |
session = {
|
| 333 |
-
"questions": [],
|
| 334 |
-
"
|
| 335 |
-
"scores": [],
|
| 336 |
-
"feedbacks": [],
|
| 337 |
-
"transcripts": []
|
| 338 |
}
|
| 339 |
|
| 340 |
-
# ==========
|
| 341 |
-
def
|
| 342 |
-
|
| 343 |
-
return "No audio provided"
|
| 344 |
-
result = whisper_model.transcribe(audio)
|
| 345 |
return result["text"]
|
| 346 |
|
| 347 |
-
#
|
| 348 |
-
def transcribe_and_show(audio):
|
| 349 |
-
return handle_audio(audio)
|
| 350 |
-
|
| 351 |
-
# ========== Evaluate Answer ==========
|
| 352 |
def get_score(question, answer):
|
| 353 |
prompt = f"""
|
| 354 |
You are an interview expert. A user was asked:
|
|
@@ -361,85 +73,65 @@ Format:
|
|
| 361 |
1. **Rating:** <score>/10
|
| 362 |
2. **Feedback:** <text>
|
| 363 |
"""
|
| 364 |
-
|
| 365 |
-
score =
|
| 366 |
-
feedback = "
|
| 367 |
-
for line in
|
| 368 |
if "**Rating:**" in line:
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
pass
|
| 373 |
-
elif "**Feedback:**" in line:
|
| 374 |
-
feedback = line.split("**Feedback:**")[1].strip()
|
| 375 |
return score, feedback
|
| 376 |
|
| 377 |
-
# ==========
|
| 378 |
-
def
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
|
|
|
| 386 |
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
session["
|
|
|
|
|
|
|
| 390 |
|
|
|
|
|
|
|
| 391 |
score, feedback = get_score(question, transcript)
|
|
|
|
|
|
|
| 392 |
session["scores"].append(score)
|
| 393 |
-
session["feedbacks"].append(f"Q{
|
| 394 |
session["current_index"] += 1
|
| 395 |
|
| 396 |
if session["current_index"] < len(session["questions"]):
|
| 397 |
next_q = session["questions"][session["current_index"]]
|
| 398 |
-
return (
|
| 399 |
-
f"🗣️ Answer: {transcript}\n\n🔢 Score: {score}/10\n💬 Feedback: {feedback}\n\n➡️ Next: {next_q}",
|
| 400 |
-
"",
|
| 401 |
-
gr.update(visible=True),
|
| 402 |
-
)
|
| 403 |
else:
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
return (
|
| 407 |
-
f"✅ Interview Complete!\n\n📊 Avg Score: {avg_score:.2f}/10\n\n📝 Summary:\n{summary}",
|
| 408 |
-
"",
|
| 409 |
-
gr.update(visible=False),
|
| 410 |
-
)
|
| 411 |
-
|
| 412 |
-
# ========== Start New Session ==========
|
| 413 |
-
def start_session(field):
|
| 414 |
-
general_qs = random.sample(all_questions["general"], 10)
|
| 415 |
-
domain_qs = random.sample(all_questions[field], 10)
|
| 416 |
-
session["questions"] = general_qs + domain_qs
|
| 417 |
-
random.shuffle(session["questions"])
|
| 418 |
-
session["current_index"] = 0
|
| 419 |
-
session["scores"] = []
|
| 420 |
-
session["feedbacks"] = []
|
| 421 |
-
session["transcripts"] = []
|
| 422 |
-
return session["questions"][0], gr.update(visible=True)
|
| 423 |
|
| 424 |
# ========== Gradio UI ==========
|
| 425 |
with gr.Blocks() as demo:
|
| 426 |
-
gr.Markdown("#
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
)
|
| 433 |
-
start_btn = gr.Button("Start Interview")
|
| 434 |
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
output = gr.Textbox(label="Feedback", lines=10)
|
| 440 |
|
| 441 |
-
start_btn.click(start_session, inputs=field, outputs=[
|
| 442 |
-
|
| 443 |
-
submit_btn.click(run_session, inputs=audio_input, outputs=[output, transcript_display, submit_btn])
|
| 444 |
|
|
|
|
| 445 |
demo.launch()
|
|
|
|
| 13 |
for key in API_KEYS:
|
| 14 |
try:
|
| 15 |
genai.configure(api_key=key)
|
| 16 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 17 |
test = model.generate_content("Hello!")
|
| 18 |
if "Hello" in test.text:
|
| 19 |
print(f"[INFO] Using Gemini API key ending with: ...{key[-4:]}")
|
|
|
|
| 24 |
|
| 25 |
initialize_model()
|
| 26 |
|
| 27 |
+
# ========== Load Whisper Model ==========
|
| 28 |
+
asr_model = whisper.load_model("base")
|
| 29 |
|
| 30 |
+
# ========== All Questions (Shortened Example) ==========
|
| 31 |
all_questions = {
|
| 32 |
"general": [
|
| 33 |
+
"Tell me about yourself.", "What are your strengths and weaknesses?",
|
| 34 |
+
"Describe a time you worked in a team.", "Where do you see yourself in 5 years?",
|
| 35 |
+
"Why should we hire you?", "How do you manage stress and deadlines?",
|
| 36 |
+
"Tell me about a challenge you overcame.", "What motivates you to perform?",
|
| 37 |
+
"How do you handle feedback?", "What is your biggest achievement?",
|
| 38 |
+
# Add up to 25
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
],
|
| 40 |
"ml": [
|
| 41 |
+
"What is overfitting?", "Explain supervised vs unsupervised learning.",
|
| 42 |
"What is the difference between classification and regression?",
|
| 43 |
+
"How does cross-validation help in model evaluation?",
|
| 44 |
+
"What is the purpose of regularization?",
|
| 45 |
+
"Explain decision trees.", "What is PCA?",
|
| 46 |
+
"What are ensemble methods?", "What is model drift?",
|
| 47 |
+
"How do you evaluate a regression model?",
|
| 48 |
+
# Add up to 25
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
]
|
| 50 |
}
|
| 51 |
|
| 52 |
# ========== Session State ==========
|
| 53 |
session = {
|
| 54 |
+
"questions": [], "current_index": 0,
|
| 55 |
+
"scores": [], "feedbacks": [], "transcripts": []
|
|
|
|
|
|
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
+
# ========== Transcribe Audio ==========
|
| 59 |
+
def transcribe_audio(audio):
|
| 60 |
+
result = asr_model.transcribe(audio)
|
|
|
|
|
|
|
| 61 |
return result["text"]
|
| 62 |
|
| 63 |
+
# ========== Get Score From Gemini ==========
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
def get_score(question, answer):
|
| 65 |
prompt = f"""
|
| 66 |
You are an interview expert. A user was asked:
|
|
|
|
| 73 |
1. **Rating:** <score>/10
|
| 74 |
2. **Feedback:** <text>
|
| 75 |
"""
|
| 76 |
+
res = model.generate_content(prompt).text
|
| 77 |
+
score = 0
|
| 78 |
+
feedback = "No feedback"
|
| 79 |
+
for line in res.splitlines():
|
| 80 |
if "**Rating:**" in line:
|
| 81 |
+
score = int(line.split("**Rating:**")[-1].split("/")[0].strip())
|
| 82 |
+
if "**Feedback:**" in line:
|
| 83 |
+
feedback = line.split("**Feedback:**")[-1].strip()
|
|
|
|
|
|
|
|
|
|
| 84 |
return score, feedback
|
| 85 |
|
| 86 |
+
# ========== Start Interview ==========
|
| 87 |
+
def start_session(field):
|
| 88 |
+
general_qs = random.sample(all_questions["general"], 10)
|
| 89 |
+
domain_qs = random.sample(all_questions[field], 10)
|
| 90 |
+
session["questions"] = random.sample(general_qs + domain_qs, 20)
|
| 91 |
+
session["current_index"] = 0
|
| 92 |
+
session["scores"] = []
|
| 93 |
+
session["feedbacks"] = []
|
| 94 |
+
session["transcripts"] = []
|
| 95 |
+
return session["questions"][0], gr.update(visible=True), ""
|
| 96 |
|
| 97 |
+
# ========== Process Answer ==========
|
| 98 |
+
def process(audio):
|
| 99 |
+
idx = session["current_index"]
|
| 100 |
+
if idx >= len(session["questions"]):
|
| 101 |
+
return "Interview complete!", "", gr.update(visible=False)
|
| 102 |
|
| 103 |
+
question = session["questions"][idx]
|
| 104 |
+
transcript = transcribe_audio(audio)
|
| 105 |
score, feedback = get_score(question, transcript)
|
| 106 |
+
|
| 107 |
+
session["transcripts"].append(transcript)
|
| 108 |
session["scores"].append(score)
|
| 109 |
+
session["feedbacks"].append(f"Q{idx+1}: {feedback}")
|
| 110 |
session["current_index"] += 1
|
| 111 |
|
| 112 |
if session["current_index"] < len(session["questions"]):
|
| 113 |
next_q = session["questions"][session["current_index"]]
|
| 114 |
+
return f"🗣 {transcript}\n\n🔢 Score: {score}/10\n💬 {feedback}", next_q, gr.update(visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
else:
|
| 116 |
+
avg = sum(session["scores"]) / len(session["scores"])
|
| 117 |
+
return f"✅ Interview Done!\n\nAvg Score: {avg:.2f}/10", "", gr.update(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
# ========== Gradio UI ==========
|
| 120 |
with gr.Blocks() as demo:
|
| 121 |
+
gr.Markdown("# 🎤 AI Mock Interview (Voice-Based)")
|
| 122 |
+
|
| 123 |
+
with gr.Tab("Start Interview"):
|
| 124 |
+
field = gr.Dropdown(choices=list(all_questions.keys()), label="Choose your field", value="ml")
|
| 125 |
+
start_btn = gr.Button("Start")
|
| 126 |
+
question_box = gr.Textbox(label="Current Question", interactive=False)
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
with gr.Tab("Interview"):
|
| 129 |
+
audio_in = gr.Audio(source="microphone", type="filepath", label="Speak your answer")
|
| 130 |
+
submit_btn = gr.Button("Submit Answer", visible=False)
|
| 131 |
+
result_box = gr.Textbox(label="Evaluation", lines=6)
|
|
|
|
| 132 |
|
| 133 |
+
start_btn.click(start_session, inputs=field, outputs=[question_box, submit_btn, result_box])
|
| 134 |
+
submit_btn.click(process, inputs=audio_in, outputs=[result_box, question_box, submit_btn])
|
|
|
|
| 135 |
|
| 136 |
+
# ========== Launch ==========
|
| 137 |
demo.launch()
|