chatbot / app.py
ophillia's picture
Create app.py
08af1d7 verified
Raw History Blame Contribute Delete
5.25 kB
import gradio as gr
import random
# --- Smart mapping of common keywords to career categories
keyword_to_category = {
"coding": "technology", "programming": "technology", "computers": "technology",
"software": "technology", "math": "technology", "ai": "technology",
"biology": "science", "chemistry": "science", "physics": "science",
"environment": "science", "lab": "science",
"health": "health", "nurse": "health", "medical": "health", "nutrition": "health",
"art": "art", "drawing": "art", "music": "art", "design": "art", "fashion": "art",
"business": "business", "management": "business", "finance": "business",
"entrepreneur": "business", "marketing": "business",
"teach": "education", "school": "education", "history": "education",
"law": "law", "legal": "law", "justice": "law",
"plumber": "skilled", "electrician": "skilled", "welding": "skilled", "tools": "skilled",
}
career_map = {
"technology": ["Software Developer", "Cybersecurity Analyst", "UI/UX Designer", "Cloud Engineer"],
"science": ["Biologist", "Environmental Scientist", "Physicist", "Bioinformatician"],
"health": ["Nurse", "Public Health Educator", "Medical Lab Scientist", "Nutritionist"],
"art": ["Graphic Designer", "Music Producer", "Art Director", "Fashion Stylist"],
"business": ["Business Analyst", "Project Manager", "E-commerce Specialist", "HR Manager"],
"education": ["Teacher", "Career Counselor", "Educational Technologist", "Historian"],
"law": ["Lawyer", "Legal Advisor", "Compliance Officer"],
"skilled": ["Electrician", "Plumber", "Welder", "Carpenter"]
}
fallback_careers = [
"AI Prompt Engineer", "Data Analyst", "Entrepreneur", "Content Creator", "Digital Marketer",
"Social Media Manager", "Mobile App Developer", "Game Designer", "Robotics Technician",
"3D Animator", "Financial Planner", "Clinical Data Manager", "Health Tech Support",
"E-learning Designer", "Ethical Hacker", "SEO Specialist", "Tech Sales Consultant",
"Virtual Reality Developer", "Sustainability Analyst", "Product Designer", "Freelance Writer",
"Voiceover Artist", "Customer Success Manager", "Technical Recruiter"
]
def suggest_careers(name, interests, skills, subject):
if not name.strip() or not interests.strip() or not skills.strip() or not subject.strip():
return "⚠️ Please fill in all fields before submitting."
combined_input = f"{interests} {skills} {subject}".lower()
matched_categories = set()
# Match keywords to categories
for keyword, category in keyword_to_category.items():
if keyword in combined_input:
matched_categories.add(category)
suggested = set()
for category in matched_categories:
suggested.update(career_map.get(category, []))
if not suggested:
suggested.update(random.sample(fallback_careers, k=6))
suggestions = "\n".join(f"πŸŽ“ {career}" for career in sorted(suggested))
return f"""
Hi <span style='color:#2E86AB; font-weight:bold;'>{name}</span>, based on your input:<br>
βœ… <b>Interests</b>: <span style='color:#117A65'>{interests}</span><br>
βœ… <b>Skills</b>: <span style='#AF601A'>{skills}</span><br>
βœ… <b>Favorite Subject</b>: <span style='color:#6C3483'>{subject}</span><br><br>
Here are some career suggestions for you:<br><br>
{suggestions}
"""
# --- Gradio UI
with gr.Blocks(title="🎯 Career Path Finder") as demo:
gr.HTML("""
<style>
body {
background-color: #E6F2FF;
}
.gr-box {
background-color: #ffffff !important;
border-radius: 12px;
padding: 20px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
input[type="text"], textarea {
background-color: #F0FAFF !important;
color: #003366 !important;
border: 1px solid #b3d9ff !important;
font-weight: 500;
border-radius: 8px !important;
}
textarea:disabled {
background-color: #f9f9f9 !important;
color: #333333 !important;
}
</style>
""")
gr.Markdown("## 🎯 Career Path Finder")
gr.Markdown("Fill out the form below to get personalized career suggestions!")
with gr.Group():
with gr.Row():
name = gr.Textbox(label="Your Name", placeholder="e.g., Ophillia")
subject = gr.Textbox(label="Favorite Subject", placeholder="e.g., Mathematics, Life Sciences")
with gr.Group():
with gr.Row():
interests = gr.Textbox(label="Your Interests", placeholder="e.g., problem solving, creativity")
skills = gr.Textbox(label="Your Skills", placeholder="e.g., coding, teamwork, communication")
output = gr.HTML(label="πŸŽ“ Career Suggestions") # Use HTML output for formatting
with gr.Row():
submit_btn = gr.Button(" Submit", variant="primary")
clear_btn = gr.Button(" Clear", variant="stop")
def clear_all():
return "", "", "", "", ""
submit_btn.click(fn=suggest_careers, inputs=[name, interests, skills, subject], outputs=output)
clear_btn.click(fn=clear_all, inputs=[], outputs=[name, interests, skills, subject, output])
demo.launch()