Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# HR Interview Questions
|
| 4 |
+
questions = [
|
| 5 |
+
"Tell me about yourself.",
|
| 6 |
+
"Why do you want to join our company?",
|
| 7 |
+
"What are your strengths?",
|
| 8 |
+
"What is your biggest weakness?",
|
| 9 |
+
"Where do you see yourself in 5 years?",
|
| 10 |
+
"Describe a challenging situation you faced and how you overcame it.",
|
| 11 |
+
"How do you handle pressure or stress?",
|
| 12 |
+
"Tell me about a time you worked in a team.",
|
| 13 |
+
"Why should we hire you?",
|
| 14 |
+
"Do you have any questions for us?"
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
# Soft Skills Keywords
|
| 18 |
+
soft_skills = {
|
| 19 |
+
"Communication": ["communicate", "communication", "presented", "explained"],
|
| 20 |
+
"Leadership": ["lead", "led", "managed", "organized", "supervised"],
|
| 21 |
+
"Teamwork": ["team", "collaborated", "together", "group", "cooperate"],
|
| 22 |
+
"Problem-Solving": ["solve", "fixed", "handled", "resolved", "dealt"],
|
| 23 |
+
"Adaptability": ["adapt", "change", "adjust", "flexible"],
|
| 24 |
+
"Time Management": ["deadline", "time", "schedule", "prioritize"],
|
| 25 |
+
"Critical Thinking": ["analyze", "think", "evaluated", "decision"]
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# Chat History State
|
| 29 |
+
chat_history = []
|
| 30 |
+
|
| 31 |
+
# Core Chatbot Logic
|
| 32 |
+
def interview_bot(user_input, history):
|
| 33 |
+
if len(history) < len(questions):
|
| 34 |
+
current_question = questions[len(history)]
|
| 35 |
+
history.append((current_question, user_input))
|
| 36 |
+
detected_skills = []
|
| 37 |
+
for skill, keywords in soft_skills.items():
|
| 38 |
+
if any(keyword in user_input.lower() for keyword in keywords):
|
| 39 |
+
detected_skills.append(skill)
|
| 40 |
+
if detected_skills:
|
| 41 |
+
feedback = f"✅ You highlighted soft skills: {', '.join(detected_skills)}"
|
| 42 |
+
else:
|
| 43 |
+
feedback = "ℹ️ Try mentioning soft skills like teamwork, leadership, or problem-solving."
|
| 44 |
+
return history, f"{feedback}\n\n➡️ Next Question: {questions[len(history)]}" if len(history) < len(questions) else "🎯 You've completed the interview practice!"
|
| 45 |
+
else:
|
| 46 |
+
return history, "🎯 You've completed the interview practice!"
|
| 47 |
+
|
| 48 |
+
# Gradio Interface
|
| 49 |
+
with gr.Blocks() as demo:
|
| 50 |
+
gr.Markdown("# 🤖 HR Interview Practice Chatbot")
|
| 51 |
+
chatbot = gr.Chatbot()
|
| 52 |
+
msg = gr.Textbox(label="Your Answer")
|
| 53 |
+
state = gr.State([])
|
| 54 |
+
btn = gr.Button("Submit")
|
| 55 |
+
|
| 56 |
+
def respond(user_message, chat_state):
|
| 57 |
+
response_state, bot_reply = interview_bot(user_message, chat_state)
|
| 58 |
+
chat_display = []
|
| 59 |
+
for q, a in response_state:
|
| 60 |
+
chat_display.append((f"💬 {q}", f"📝 {a}"))
|
| 61 |
+
chat_display.append(("🤖 Feedback", bot_reply))
|
| 62 |
+
return chat_display, response_state
|
| 63 |
+
|
| 64 |
+
btn.click(respond, [msg, state], [chatbot, state])
|
| 65 |
+
|
| 66 |
+
gr.Markdown("👉 Practice your answers an
|