Nightmare143's picture
Update app.py
82c089d verified
import gradio as gr
# HR Interview Questions
questions = [
"Tell me about yourself.",
"Why do you want to join our company?",
"What are your strengths?",
"What is your biggest weakness?",
"Where do you see yourself in 5 years?",
"Describe a challenging situation you faced and how you overcame it.",
"How do you handle pressure or stress?",
"Tell me about a time you worked in a team.",
"Why should we hire you?",
"Do you have any questions for us?"
]
# Soft Skills Keywords
soft_skills = {
"Communication": ["communicate", "communication", "presented", "explained"],
"Leadership": ["lead", "led", "managed", "organized", "supervised"],
"Teamwork": ["team", "collaborated", "together", "group", "cooperate"],
"Problem-Solving": ["solve", "fixed", "handled", "resolved", "dealt"],
"Adaptability": ["adapt", "change", "adjust", "flexible"],
"Time Management": ["deadline", "time", "schedule", "prioritize"],
"Critical Thinking": ["analyze", "think", "evaluated", "decision"]
}
# Core Chatbot Logic
def interview_bot(user_input, history):
if len(history) < len(questions):
current_question = questions[len(history)]
history.append((current_question, user_input))
detected_skills = []
for skill, keywords in soft_skills.items():
if any(keyword in user_input.lower() for keyword in keywords):
detected_skills.append(skill)
if detected_skills:
feedback = f"βœ… You highlighted soft skills: {', '.join(detected_skills)}"
else:
feedback = "ℹ️ Try mentioning soft skills like teamwork, leadership, or problem-solving."
if len(history) < len(questions):
next_question = f"\n\n➑️ Next Question: {questions[len(history)]}"
else:
next_question = "\n\n🎯 You've completed the interview practice!"
return history, feedback + next_question
else:
return history, "🎯 You've completed the interview practice!"
# Gradio Interface demo
with gr.Blocks() as demo:
gr.Markdown("# πŸ€– HR Interview Practice Chatbot")
chatbot = gr.Chatbot()
msg = gr.Textbox(label="Your Answer", placeholder="Type your answer here...")
state = gr.State([])
btn = gr.Button("Submit")
def respond(user_message, chat_state):
response_state, bot_reply = interview_bot(user_message, chat_state)
chat_display = []
for q, a in response_state:
chat_display.append((f"πŸ’¬ {q}", f"πŸ“ {a}"))
chat_display.append(("πŸ€– Feedback", bot_reply))
return chat_display, response_state
btn.click(respond, [msg, state], [chatbot, state])
gr.Markdown("πŸ‘‰ Practice your answers and get soft skill feedback! Made with ❀️ using Gradio.")
demo.launch()