Spaces:
Build error
Build error
| import gradio as gr | |
| from sentence_transformers import SentenceTransformer, util | |
| # Load embedding model (small + free CPU friendly) | |
| model = SentenceTransformer("all-MiniLM-L6-v2") | |
| # Example dataset of jobs & required skills | |
| jobs = [ | |
| {"title": "Data Scientist", "skills": "python, machine learning, data analysis, statistics"}, | |
| {"title": "Web Developer", "skills": "html, css, javascript, react"}, | |
| {"title": "Graphic Designer", "skills": "photoshop, illustrator, creativity, ui design"}, | |
| {"title": "Digital Marketer", "skills": "seo, social media, content creation, advertising"}, | |
| {"title": "Project Manager", "skills": "planning, communication, leadership, risk management"}, | |
| {"title": "Cybersecurity Analyst", "skills": "network security, risk assessment, ethical hacking"}, | |
| {"title": "Data Engineer", "skills": "sql, big data, etl, data pipelines"}, | |
| ] | |
| # Precompute job embeddings | |
| job_embeddings = model.encode([job["skills"] for job in jobs], convert_to_tensor=True) | |
| def recommend_jobs(user_skills): | |
| # Encode user input | |
| user_embedding = model.encode(user_skills, convert_to_tensor=True) | |
| # Compute cosine similarity | |
| scores = util.cos_sim(user_embedding, job_embeddings)[0] | |
| # Sort top 3 | |
| top_results = scores.topk(3) | |
| recommendations = [] | |
| for idx in top_results.indices: | |
| job = jobs[int(idx)] | |
| recommendations.append(f"{job['title']} — Skills: {job['skills']}") | |
| return "\n".join(recommendations) | |
| # Gradio UI | |
| iface = gr.Interface( | |
| fn=recommend_jobs, | |
| inputs=gr.Textbox(lines=3, placeholder="Enter your skills (comma separated)..."), | |
| outputs="text", | |
| title="AI Job Recommender", | |
| description="Type in your skills and get 3 job suggestions that match your profile." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |