Nagaraj81's picture
Upload app.py
05df9c7 verified
import gradio as gr
import pandas as pd
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
import plotly.express as px
# Load embedding model
model = SentenceTransformer('all-MiniLM-L6-v2')
# Synthetic job board data (blue & white collar)
job_board = pd.DataFrame([
{"job_title": "Plumber Apprentice", "skills_required": "pipe fitting, leak repair, water systems, hand tools"},
{"job_title": "Construction Laborer", "skills_required": "heavy lifting, brick laying, site safety, concrete mixing"},
{"job_title": "Auto Mechanic", "skills_required": "engine repair, brake systems, diagnostics, tool handling"},
{"job_title": "Electrician Helper", "skills_required": "circuit wiring, voltage testing, insulation, safety"},
{"job_title": "HVAC Technician", "skills_required": "air conditioning, heating systems, refrigerant handling"},
{"job_title": "Welding Assistant", "skills_required": "metal joining, arc welding, safety gear, blueprint reading"},
{"job_title": "Forklift Operator", "skills_required": "loading, warehouse navigation, safety protocols"},
{"job_title": "Junior Data Analyst", "skills_required": "excel, data cleaning, visualization, python"},
{"job_title": "Call Center Agent", "skills_required": "customer service, communication, CRM software"},
{"job_title": "Administrative Assistant", "skills_required": "calendar management, typing, MS Office"},
{"job_title": "Bookkeeper", "skills_required": "accounts payable, ledger maintenance, QuickBooks"},
{"job_title": "HR Assistant", "skills_required": "recruiting, onboarding, data entry, compliance"},
{"job_title": "Marketing Intern", "skills_required": "social media, content creation, SEO basics"},
{"job_title": "Sales Representative", "skills_required": "negotiation, CRM, product knowledge, cold calling"},
{"job_title": "IT Support Technician", "skills_required": "network troubleshooting, help desk, Windows support"}
])
# Precompute embeddings
job_embeddings = model.encode(job_board["skills_required"].tolist())
# Optional curated learning paths
career_pathways = {
"Auto Mechanic": ["Engine Repair Basics", "Diagnostics Workshop", "Tool Handling Training"],
"Junior Data Analyst": ["Excel Mastery", "Intro to Python", "Data Visualization Bootcamp"],
"Electrician Helper": ["Basic Circuits Course", "Voltage Safety Training"],
"Sales Representative": ["CRM Tools Training", "Advanced Negotiation Skills"]
}
def generate_dynamic_path(user_input, job_skills):
user_set = set([s.strip().lower() for s in user_input.split(",") if s.strip()])
job_set = set([s.strip().lower() for s in job_skills.split(",") if s.strip()])
missing = job_set - user_set
return list(missing) if missing else ["No additional learning needed"]
def recommend(selected_job, user_skills):
if selected_job:
job_row = job_board[job_board["job_title"] == selected_job].iloc[0]
required_skills = job_row["skills_required"]
pathway = career_pathways.get(selected_job, generate_dynamic_path(user_skills, required_skills))
fig = px.bar(x=[1], y=[selected_job], orientation='h', title=f"Selected Job: {selected_job}")
summary = f"### {selected_job}\n\n**Required Skills:** {required_skills}\n\n"
summary += "**Recommended Learning Path:**\n- " + "\n- ".join(pathway)
return fig, summary
if not user_skills.strip():
return None, "Please enter your skills or select a job role."
user_vec = model.encode([user_skills])
sims = cosine_similarity(user_vec, job_embeddings)[0]
job_board["similarity"] = sims
top_matches = job_board.sort_values(by="similarity", ascending=False).head(5).copy()
top_matches["career_pathway"] = top_matches.apply(
lambda row: career_pathways.get(row["job_title"], generate_dynamic_path(user_skills, row["skills_required"])),
axis=1
)
fig = px.bar(top_matches, x="similarity", y="job_title", orientation="h",
color="similarity", color_continuous_scale="Blues",
title="Top Job Matches Based on Your Skills")
summary = "### Recommended Job Matches\n"
for _, row in top_matches.iterrows():
summary += f"**{row['job_title']}** (match: {row['similarity']:.2f})\n"
summary += f"Skills to Learn: {', '.join(row['career_pathway'])}\n\n"
return fig, summary
with gr.Blocks() as demo:
gr.Markdown("# AI-Powered Job Recommender")
gr.Markdown("Select a job or enter your skills below to receive tailored job suggestions and learning paths.")
job_list = job_board["job_title"].tolist()
job_dropdown = gr.Dropdown(choices=[""] + job_list, label="Select a Job Role (optional)")
skill_input = gr.Textbox(label="Or enter your skills (comma separated)", placeholder="e.g. engine repair, python, customer service")
submit_btn = gr.Button("Get Recommendations")
output_plot = gr.Plot()
output_text = gr.Markdown()
submit_btn.click(fn=recommend, inputs=[job_dropdown, skill_input], outputs=[output_plot, output_text])
demo.launch()