Jobfinder / app.py
sivan26's picture
Update app.py
56c941a verified
import gradio as gr
import pandas as pd
import numpy as np
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
import json
import random
from typing import List, Dict
class JobRecommendationSystem:
def __init__(self):
# Load a lightweight sentence transformer model for CPU
self.model = SentenceTransformer('all-MiniLM-L6-v2')
# Generate comprehensive job database
self.jobs_data = self._generate_job_database()
# Pre-compute job embeddings for efficiency
print("Computing job embeddings... This may take a moment.")
self.job_descriptions = [f"{job['title']} {job['description']} {' '.join(job['requirements'])}"
for job in self.jobs_data]
self.job_embeddings = self.model.encode(self.job_descriptions, show_progress_bar=True)
print(f"Loaded {len(self.jobs_data)} jobs successfully!")
def _generate_job_database(self) -> List[Dict]:
"""Generate a comprehensive database of 1000 jobs across various industries"""
# Job templates by category
job_templates = {
"Technology": [
{"title": "Software Engineer", "desc": "Design and develop software applications",
"skills": ["Python", "Java", "JavaScript", "Git", "Agile", "Problem Solving"]},
{"title": "Data Scientist", "desc": "Analyze complex data to extract business insights",
"skills": ["Python", "R", "Machine Learning", "SQL", "Statistics", "Pandas"]},
{"title": "DevOps Engineer", "desc": "Manage infrastructure and deployment pipelines",
"skills": ["AWS", "Docker", "Kubernetes", "Linux", "Python", "Terraform"]},
{"title": "Frontend Developer", "desc": "Create user interfaces and web experiences",
"skills": ["JavaScript", "React", "CSS", "HTML", "TypeScript", "Responsive Design"]},
{"title": "Backend Developer", "desc": "Build server-side applications and APIs",
"skills": ["Python", "Node.js", "Django", "PostgreSQL", "REST APIs", "MongoDB"]},
{"title": "Mobile Developer", "desc": "Develop applications for mobile platforms",
"skills": ["React Native", "Swift", "Kotlin", "Flutter", "iOS", "Android"]},
{"title": "QA Engineer", "desc": "Test software and ensure quality standards",
"skills": ["Selenium", "Test Automation", "Python", "Manual Testing", "JIRA"]},
{"title": "UI/UX Designer", "desc": "Design user interfaces and experiences",
"skills": ["Figma", "Adobe XD", "User Research", "Prototyping", "Design Systems"]},
{"title": "Machine Learning Engineer", "desc": "Deploy and maintain ML models in production",
"skills": ["Python", "TensorFlow", "PyTorch", "MLOps", "Docker", "Scikit-learn"]},
{"title": "Cybersecurity Analyst", "desc": "Monitor and protect against security threats",
"skills": ["Network Security", "Python", "SIEM", "Incident Response", "Penetration Testing"]},
{"title": "Database Administrator", "desc": "Manage and optimize database systems",
"skills": ["SQL", "MySQL", "PostgreSQL", "Database Design", "Performance Tuning"]},
{"title": "Cloud Architect", "desc": "Design scalable cloud infrastructure solutions",
"skills": ["AWS", "Azure", "GCP", "Cloud Architecture", "Microservices", "Serverless"]},
{"title": "Product Manager", "desc": "Define product strategy and roadmap",
"skills": ["Product Strategy", "Analytics", "Agile", "User Stories", "Market Research"]},
{"title": "Systems Administrator", "desc": "Maintain IT infrastructure and systems",
"skills": ["Linux", "Windows Server", "Network Administration", "Virtualization", "Shell Scripting"]},
{"title": "Full Stack Developer", "desc": "Work on both frontend and backend development",
"skills": ["JavaScript", "Python", "React", "Node.js", "SQL", "Git"]}
],
"Healthcare": [
{"title": "Registered Nurse", "desc": "Provide patient care and medical support",
"skills": ["Patient Care", "Medical Knowledge", "CPR", "Communication", "Compassion"]},
{"title": "Medical Doctor", "desc": "Diagnose and treat medical conditions",
"skills": ["Medical Diagnosis", "Patient Care", "Clinical Skills", "Medical Ethics", "Communication"]},
{"title": "Physical Therapist", "desc": "Help patients recover from injuries",
"skills": ["Rehabilitation", "Exercise Therapy", "Patient Assessment", "Anatomy", "Communication"]},
{"title": "Medical Technologist", "desc": "Perform laboratory tests and analysis",
"skills": ["Laboratory Skills", "Medical Testing", "Quality Control", "Attention to Detail", "Safety Protocols"]},
{"title": "Pharmacist", "desc": "Dispense medications and provide drug information",
"skills": ["Pharmaceutical Knowledge", "Patient Counseling", "Drug Interactions", "Attention to Detail", "Regulatory Compliance"]},
{"title": "Medical Assistant", "desc": "Support healthcare providers with patient care",
"skills": ["Medical Procedures", "Patient Communication", "Medical Records", "Scheduling", "Basic Clinical Skills"]},
{"title": "Healthcare Administrator", "desc": "Manage healthcare facility operations",
"skills": ["Healthcare Management", "Budget Management", "Regulatory Compliance", "Leadership", "Strategic Planning"]},
{"title": "Radiologic Technologist", "desc": "Perform diagnostic imaging procedures",
"skills": ["Radiology", "Medical Imaging", "Patient Safety", "Equipment Operation", "Anatomy Knowledge"]}
],
"Finance": [
{"title": "Financial Analyst", "desc": "Analyze financial data and market trends",
"skills": ["Financial Modeling", "Excel", "Data Analysis", "Financial Reporting", "Market Research"]},
{"title": "Investment Banker", "desc": "Provide financial advisory services",
"skills": ["Financial Analysis", "Valuation", "Excel", "Presentation Skills", "Client Relations"]},
{"title": "Accountant", "desc": "Manage financial records and tax preparation",
"skills": ["Accounting", "QuickBooks", "Tax Preparation", "Financial Reporting", "Attention to Detail"]},
{"title": "Risk Analyst", "desc": "Assess and manage financial risks",
"skills": ["Risk Assessment", "Statistical Analysis", "Financial Modeling", "Regulatory Knowledge", "Problem Solving"]},
{"title": "Portfolio Manager", "desc": "Manage investment portfolios",
"skills": ["Investment Strategy", "Portfolio Analysis", "Market Research", "Risk Management", "Client Communication"]},
{"title": "Credit Analyst", "desc": "Evaluate creditworthiness of borrowers",
"skills": ["Credit Analysis", "Financial Modeling", "Risk Assessment", "Banking Regulations", "Excel"]},
{"title": "Insurance Underwriter", "desc": "Evaluate insurance applications and risks",
"skills": ["Risk Assessment", "Insurance Knowledge", "Data Analysis", "Decision Making", "Attention to Detail"]},
{"title": "Tax Consultant", "desc": "Provide tax planning and preparation services",
"skills": ["Tax Law", "Tax Preparation", "Client Consultation", "Attention to Detail", "Regulatory Compliance"]}
],
"Marketing": [
{"title": "Digital Marketing Manager", "desc": "Develop and execute digital marketing strategies",
"skills": ["Digital Marketing", "SEO", "Social Media", "Google Analytics", "Content Strategy"]},
{"title": "Content Marketing Specialist", "desc": "Create engaging content for marketing campaigns",
"skills": ["Content Creation", "SEO", "Social Media", "Writing", "Brand Management"]},
{"title": "Social Media Manager", "desc": "Manage social media presence and engagement",
"skills": ["Social Media", "Content Creation", "Community Management", "Analytics", "Brand Voice"]},
{"title": "SEO Specialist", "desc": "Optimize websites for search engine visibility",
"skills": ["SEO", "Google Analytics", "Content Optimization", "Keyword Research", "Technical SEO"]},
{"title": "Marketing Analyst", "desc": "Analyze marketing data and campaign performance",
"skills": ["Data Analysis", "Google Analytics", "Marketing Metrics", "Excel", "Reporting"]},
{"title": "Brand Manager", "desc": "Develop and maintain brand identity and strategy",
"skills": ["Brand Strategy", "Marketing", "Creative Direction", "Market Research", "Communication"]},
{"title": "Email Marketing Specialist", "desc": "Create and manage email marketing campaigns",
"skills": ["Email Marketing", "Automation", "A/B Testing", "Analytics", "Copywriting"]},
{"title": "PPC Specialist", "desc": "Manage pay-per-click advertising campaigns",
"skills": ["Google Ads", "PPC", "Campaign Management", "Analytics", "Budget Management"]}
],
"Education": [
{"title": "Elementary School Teacher", "desc": "Teach fundamental subjects to young students",
"skills": ["Teaching", "Classroom Management", "Curriculum Development", "Student Assessment", "Communication"]},
{"title": "High School Teacher", "desc": "Educate teenagers in specialized subjects",
"skills": ["Subject Expertise", "Teaching", "Classroom Management", "Lesson Planning", "Student Mentoring"]},
{"title": "Special Education Teacher", "desc": "Work with students with special needs",
"skills": ["Special Education", "IEP Development", "Adaptive Teaching", "Patience", "Communication"]},
{"title": "School Counselor", "desc": "Provide academic and personal guidance to students",
"skills": ["Counseling", "Student Support", "Academic Planning", "Crisis Intervention", "Communication"]},
{"title": "Principal", "desc": "Lead and manage school operations",
"skills": ["Educational Leadership", "Staff Management", "Budget Management", "Policy Development", "Communication"]},
{"title": "Librarian", "desc": "Manage library resources and assist patrons",
"skills": ["Information Management", "Research Skills", "Library Systems", "Customer Service", "Organization"]},
{"title": "Educational Technology Specialist", "desc": "Integrate technology into educational environments",
"skills": ["Educational Technology", "Training", "Technical Support", "Curriculum Integration", "Problem Solving"]},
{"title": "Instructional Designer", "desc": "Design educational programs and materials",
"skills": ["Instructional Design", "Curriculum Development", "Learning Theory", "Educational Technology", "Project Management"]}
],
"Sales": [
{"title": "Sales Representative", "desc": "Sell products and services to customers",
"skills": ["Sales", "Customer Relations", "Communication", "Negotiation", "Product Knowledge"]},
{"title": "Account Manager", "desc": "Manage relationships with key clients",
"skills": ["Account Management", "Client Relations", "Sales", "Communication", "Problem Solving"]},
{"title": "Sales Manager", "desc": "Lead sales teams and develop strategies",
"skills": ["Sales Management", "Team Leadership", "Strategic Planning", "Performance Management", "Communication"]},
{"title": "Business Development Manager", "desc": "Identify and develop new business opportunities",
"skills": ["Business Development", "Sales", "Market Research", "Relationship Building", "Strategic Thinking"]},
{"title": "Inside Sales Representative", "desc": "Conduct sales activities remotely",
"skills": ["Phone Sales", "CRM", "Lead Generation", "Communication", "Product Knowledge"]},
{"title": "Real Estate Agent", "desc": "Help clients buy and sell properties",
"skills": ["Real Estate", "Customer Service", "Negotiation", "Market Knowledge", "Communication"]},
{"title": "Retail Sales Associate", "desc": "Assist customers in retail environments",
"skills": ["Customer Service", "Sales", "Product Knowledge", "Cash Handling", "Communication"]},
{"title": "Territory Sales Manager", "desc": "Manage sales activities in specific geographic areas",
"skills": ["Territory Management", "Sales", "Travel", "Customer Relations", "Strategic Planning"]}
],
"Operations": [
{"title": "Operations Manager", "desc": "Oversee daily business operations",
"skills": ["Operations Management", "Process Improvement", "Team Leadership", "Budget Management", "Problem Solving"]},
{"title": "Supply Chain Manager", "desc": "Manage supply chain and logistics operations",
"skills": ["Supply Chain", "Logistics", "Vendor Management", "Process Optimization", "Analytics"]},
{"title": "Project Manager", "desc": "Lead and coordinate project execution",
"skills": ["Project Management", "PMP", "Agile", "Risk Management", "Communication"]},
{"title": "Quality Assurance Manager", "desc": "Ensure product and service quality standards",
"skills": ["Quality Management", "Process Improvement", "ISO Standards", "Auditing", "Problem Solving"]},
{"title": "Logistics Coordinator", "desc": "Coordinate transportation and distribution",
"skills": ["Logistics", "Transportation", "Inventory Management", "Coordination", "Problem Solving"]},
{"title": "Business Analyst", "desc": "Analyze business processes and requirements",
"skills": ["Business Analysis", "Requirements Gathering", "Process Mapping", "Data Analysis", "Communication"]},
{"title": "Warehouse Manager", "desc": "Manage warehouse operations and staff",
"skills": ["Warehouse Management", "Inventory Control", "Team Leadership", "Safety Management", "Logistics"]},
{"title": "Production Manager", "desc": "Oversee manufacturing and production processes",
"skills": ["Production Management", "Manufacturing", "Process Optimization", "Quality Control", "Team Leadership"]}
],
"Creative": [
{"title": "Graphic Designer", "desc": "Create visual designs for various media",
"skills": ["Adobe Creative Suite", "Graphic Design", "Typography", "Brand Design", "Creativity"]},
{"title": "Web Designer", "desc": "Design websites and digital interfaces",
"skills": ["Web Design", "HTML", "CSS", "Adobe Creative Suite", "User Experience"]},
{"title": "Video Editor", "desc": "Edit and produce video content",
"skills": ["Video Editing", "Adobe Premiere", "Final Cut Pro", "Motion Graphics", "Storytelling"]},
{"title": "Content Writer", "desc": "Create written content for various platforms",
"skills": ["Writing", "Content Creation", "SEO", "Research", "Editing"]},
{"title": "Art Director", "desc": "Lead creative vision for projects",
"skills": ["Creative Direction", "Team Leadership", "Brand Strategy", "Visual Design", "Project Management"]},
{"title": "Photographer", "desc": "Capture and edit professional photographs",
"skills": ["Photography", "Photo Editing", "Adobe Lightroom", "Photoshop", "Composition"]},
{"title": "Animator", "desc": "Create animated content and motion graphics",
"skills": ["Animation", "After Effects", "3D Animation", "Motion Graphics", "Storytelling"]},
{"title": "Copywriter", "desc": "Write compelling marketing and advertising copy",
"skills": ["Copywriting", "Marketing", "Brand Voice", "Persuasive Writing", "Creative Thinking"]}
]
}
# Experience levels and salary ranges
experience_levels = ["Entry-level", "Mid-level", "Senior", "Lead/Principal"]
salary_ranges = {
"Entry-level": ["$35k-$50k", "$40k-$55k", "$45k-$60k", "$50k-$65k"],
"Mid-level": ["$55k-$75k", "$60k-$80k", "$65k-$85k", "$70k-$90k"],
"Senior": ["$80k-$110k", "$90k-$120k", "$100k-$130k", "$110k-$140k"],
"Lead/Principal": ["$120k-$150k", "$130k-$160k", "$140k-$170k", "$150k-$180k"]
}
# Additional skills by category
additional_skills = {
"Technology": ["Problem Solving", "Debugging", "Code Review", "System Design", "API Development", "Database Design"],
"Healthcare": ["HIPAA Compliance", "Medical Ethics", "Electronic Health Records", "Patient Safety", "Clinical Documentation"],
"Finance": ["Financial Regulations", "Risk Management", "Excel Advanced", "Bloomberg Terminal", "Financial Compliance"],
"Marketing": ["Brand Strategy", "Customer Acquisition", "Marketing Automation", "CRM", "Market Analysis"],
"Education": ["Student Engagement", "Assessment", "Educational Psychology", "Classroom Technology", "Differentiated Instruction"],
"Sales": ["CRM Systems", "Lead Qualification", "Sales Forecasting", "Territory Planning", "Customer Retention"],
"Operations": ["Lean Six Sigma", "Process Documentation", "KPI Management", "Vendor Relations", "Cost Reduction"],
"Creative": ["Brand Identity", "Design Thinking", "Client Presentation", "Creative Strategy", "Visual Communication"]
}
# Generate 1000 jobs
jobs = []
job_id = 1
# Calculate jobs per category to reach 1000 total
categories = list(job_templates.keys())
jobs_per_category = 1000 // len(categories)
remaining_jobs = 1000 % len(categories)
for i, category in enumerate(categories):
templates = job_templates[category]
jobs_for_this_category = jobs_per_category + (1 if i < remaining_jobs else 0)
for j in range(jobs_for_this_category):
template = templates[j % len(templates)]
# Add variety to job titles
title_variations = [
template["title"],
f"Senior {template['title']}",
f"Junior {template['title']}",
f"Lead {template['title']}",
f"{template['title']} Specialist"
]
title = title_variations[j % len(title_variations)]
# Select experience level and corresponding salary
exp_level = random.choice(experience_levels)
salary = random.choice(salary_ranges[exp_level])
# Create skill set with some randomization
base_skills = template["skills"].copy()
extra_skills = random.sample(additional_skills[category],
random.randint(1, min(3, len(additional_skills[category]))))
all_skills = base_skills + extra_skills
# Remove duplicates and limit to reasonable number
unique_skills = list(dict.fromkeys(all_skills))[:8]
job = {
"id": job_id,
"title": title,
"description": template["desc"],
"requirements": unique_skills,
"experience_level": exp_level,
"salary_range": salary,
"category": category,
"location": random.choice(["Remote", "New York, NY", "San Francisco, CA", "Chicago, IL",
"Austin, TX", "Seattle, WA", "Boston, MA", "Los Angeles, CA",
"Denver, CO", "Atlanta, GA", "Miami, FL", "Portland, OR"])
}
jobs.append(job)
job_id += 1
return jobs
def recommend_jobs(self, user_skills, num_recommendations=10, filter_category=None, filter_experience=None):
if not user_skills.strip():
return "Please enter your skills to get job recommendations."
# Filter jobs based on criteria
filtered_jobs = self.jobs_data.copy()
filtered_indices = list(range(len(self.jobs_data)))
if filter_category and filter_category != "All Categories":
filtered_jobs = [job for i, job in enumerate(self.jobs_data) if job['category'] == filter_category]
filtered_indices = [i for i, job in enumerate(self.jobs_data) if job['category'] == filter_category]
if filter_experience and filter_experience != "All Levels":
if filter_category and filter_category != "All Categories":
filtered_jobs = [job for job in filtered_jobs if job['experience_level'] == filter_experience]
filtered_indices = [i for i, job in enumerate(self.jobs_data)
if job['category'] == filter_category and job['experience_level'] == filter_experience]
else:
filtered_jobs = [job for i, job in enumerate(self.jobs_data) if job['experience_level'] == filter_experience]
filtered_indices = [i for i, job in enumerate(self.jobs_data) if job['experience_level'] == filter_experience]
if not filtered_jobs:
return "No jobs found matching your filter criteria. Please adjust your filters."
# Encode user skills
user_embedding = self.model.encode([user_skills])
# Get embeddings for filtered jobs
filtered_embeddings = self.job_embeddings[filtered_indices]
# Calculate similarities
similarities = cosine_similarity(user_embedding, filtered_embeddings)[0]
# Get top job indices
top_indices = np.argsort(similarities)[::-1][:num_recommendations]
# Format recommendations
recommendations = []
user_skills_list = [skill.strip().lower() for skill in user_skills.split(',')]
for i, idx in enumerate(top_indices):
job = filtered_jobs[idx]
similarity_score = similarities[idx]
# Calculate skill match percentage
job_requirements = [req.lower() for req in job['requirements']]
matching_skills = []
for user_skill in user_skills_list:
for req in job['requirements']:
if user_skill in req.lower() or req.lower() in user_skill:
matching_skills.append(req)
break
match_percentage = (len(matching_skills) / len(job['requirements'])) * 100 if job['requirements'] else 0
recommendation = f"""
**{i+1}. {job['title']}** ({job['category']})
- **Match Score**: {similarity_score:.3f} ({match_percentage:.1f}% skill match)
- **Experience Level**: {job['experience_level']}
- **Location**: {job['location']}
- **Salary Range**: {job['salary_range']}
- **Description**: {job['description']}
- **Required Skills**: {', '.join(job['requirements'])}
- **Your Matching Skills**: {', '.join(matching_skills) if matching_skills else 'General relevance based on context'}
---
"""
recommendations.append(recommendation)
return '\n'.join(recommendations)
def get_categories(self):
categories = list(set(job['category'] for job in self.jobs_data))
return ["All Categories"] + sorted(categories)
def get_experience_levels(self):
levels = list(set(job['experience_level'] for job in self.jobs_data))
return ["All Levels"] + sorted(levels)
# Initialize the recommendation system
print("Initializing Job Recommendation System...")
job_system = JobRecommendationSystem()
def get_job_recommendations(skills, num_jobs, category, experience):
return job_system.recommend_jobs(skills, num_jobs, category, experience)
def get_stats():
total_jobs = len(job_system.jobs_data)
categories = {}
experience_levels = {}
for job in job_system.jobs_data:
categories[job['category']] = categories.get(job['category'], 0) + 1
experience_levels[job['experience_level']] = experience_levels.get(job['experience_level'], 0) + 1
stats = f"## Database Statistics\n"
stats += f"**Total Jobs**: {total_jobs}\n\n"
stats += f"**Jobs by Category**:\n"
for cat, count in sorted(categories.items()):
stats += f"- {cat}: {count} jobs\n"
stats += f"\n**Jobs by Experience Level**:\n"
for level, count in sorted(experience_levels.items()):
stats += f"- {level}: {count} jobs\n"
return stats
# Create Gradio interface
with gr.Blocks(title="Job Recommendation System - 1000+ Jobs", theme=gr.themes.Soft()) as app:
gr.Markdown("# 🚀 AI-Powered Job Recommendation System")
gr.Markdown("**1000+ Jobs Across 8 Industries** | Enter your skills and get personalized job recommendations!")
with gr.Row():
with gr.Column(scale=2):
skills_input = gr.Textbox(
label="Your Skills",
placeholder="e.g., Python, JavaScript, Project Management, Communication, Sales",
lines=3,
info="Enter your skills separated by commas"
)
with gr.Row():
category_filter = gr.Dropdown(
choices=job_system.get_categories(),
value="All Categories",
label="Filter by Category"
)
experience_filter = gr.Dropdown(
choices=job_system.get_experience_levels(),
value="All Levels",
label="Filter by Experience Level"
)
num_jobs = gr.Slider(
minimum=1,
maximum=20,
value=10,
step=1,
label="Number of Job Recommendations"
)
submit_btn = gr.Button("Get Job Recommendations", variant="primary")
with gr.Accordion("Database Statistics", open=False):
stats_display = gr.Markdown(get_stats())
gr.Markdown("### Example Skills to Try:")
gr.Markdown("- `Python, Data Analysis, Machine Learning`")
gr.Markdown("- `JavaScript, React, Frontend Development`")
gr.Markdown("- `Sales, Customer Relations, Communication`")
gr.Markdown("- `Project Management, Leadership, Agile`")
gr.Markdown("- `Nursing, Patient Care, Medical Knowledge`")
gr.Markdown("- `Teaching, Classroom Management, Curriculum`")
with gr.Column(scale=3):
output = gr.Markdown(
label="Job Recommendations",
value="Enter your skills and click 'Get Job Recommendations' to see personalized job matches from our database of 1000+ jobs!"
)
submit_btn.click(
fn=get_job_recommendations,
inputs=[skills_input, num_jobs, category_filter, experience_filter],
outputs=output
)
# Auto-submit on Enter key
skills_input.submit(
fn=get_job_recommendations,
inputs=[skills_input, num_jobs, category_filter, experience_filter],
outputs=output
)
# Launch the app
if __name__ == "__main__":
app.launch(
server_name="0.0.0.0",
server_port=7860,
share=True,
debug=False
)