sivan26 commited on
Commit
6915a10
·
verified ·
1 Parent(s): a1bc38d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -0
app.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ from typing import List, Dict
3
+ import pandas as pd
4
+ import gradio as gr
5
+ from sentence_transformers import SentenceTransformer
6
+ from sklearn.metrics.pairwise import cosine_similarity
7
+
8
+ # ------------------------------
9
+ # 1. Generate synthetic job database
10
+ # ------------------------------
11
+ def generate_job_database() -> List[Dict]:
12
+ job_templates = {
13
+ "Technology": [
14
+ {"title": "Software Engineer", "desc": "Design and develop software applications",
15
+ "skills": ["Python", "Java", "JavaScript", "Git", "Agile", "Problem Solving"]},
16
+ {"title": "Data Scientist", "desc": "Analyze complex data to extract business insights",
17
+ "skills": ["Python", "R", "Machine Learning", "SQL", "Statistics", "Pandas"]},
18
+ {"title": "DevOps Engineer", "desc": "Manage infrastructure and deployment pipelines",
19
+ "skills": ["AWS", "Docker", "Kubernetes", "Linux", "Python", "Terraform"]},
20
+ {"title": "Frontend Developer", "desc": "Create user interfaces and web experiences",
21
+ "skills": ["JavaScript", "React", "CSS", "HTML", "TypeScript", "Responsive Design"]},
22
+ {"title": "Backend Developer", "desc": "Build server-side applications and APIs",
23
+ "skills": ["Python", "Node.js", "Django", "PostgreSQL", "REST APIs", "MongoDB"]},
24
+ {"title": "Mobile Developer", "desc": "Develop applications for mobile platforms",
25
+ "skills": ["React Native", "Swift", "Kotlin", "Flutter", "iOS", "Android"]},
26
+ ],
27
+ "Healthcare": [
28
+ {"title": "Registered Nurse", "desc": "Provide patient care and medical support",
29
+ "skills": ["Patient Care", "Medical Knowledge", "CPR", "Communication", "Compassion"]},
30
+ {"title": "Medical Doctor", "desc": "Diagnose and treat medical conditions",
31
+ "skills": ["Medical Diagnosis", "Patient Care", "Clinical Skills", "Medical Ethics", "Communication"]},
32
+ ],
33
+ "Finance": [
34
+ {"title": "Financial Analyst", "desc": "Analyze financial data and market trends",
35
+ "skills": ["Financial Modeling", "Excel", "Data Analysis", "Financial Reporting", "Market Research"]},
36
+ {"title": "Accountant", "desc": "Manage financial records and tax preparation",
37
+ "skills": ["Accounting", "QuickBooks", "Tax Preparation", "Financial Reporting", "Attention to Detail"]},
38
+ ],
39
+ "Marketing": [
40
+ {"title": "Digital Marketing Manager", "desc": "Develop and execute digital marketing strategies",
41
+ "skills": ["Digital Marketing", "SEO", "Social Media", "Google Analytics", "Content Strategy"]},
42
+ {"title": "Content Marketing Specialist", "desc": "Create engaging content for marketing campaigns",
43
+ "skills": ["Content Creation", "SEO", "Social Media", "Writing", "Brand Management"]},
44
+ ],
45
+ "Education": [
46
+ {"title": "Elementary School Teacher", "desc": "Teach fundamental subjects to young students",
47
+ "skills": ["Teaching", "Classroom Management", "Curriculum Development", "Student Assessment", "Communication"]},
48
+ {"title": "High School Teacher", "desc": "Educate teenagers in specialized subjects",
49
+ "skills": ["Subject Expertise", "Teaching", "Classroom Management", "Lesson Planning", "Student Mentoring"]},
50
+ ],
51
+ "Sales": [
52
+ {"title": "Sales Representative", "desc": "Sell products and services to customers",
53
+ "skills": ["Sales", "Customer Relations", "Communication", "Negotiation", "Product Knowledge"]},
54
+ {"title": "Account Manager", "desc": "Manage relationships with key clients",
55
+ "skills": ["Account Management", "Client Relations", "Sales", "Communication", "Problem Solving"]},
56
+ ],
57
+ "Operations": [
58
+ {"title": "Operations Manager", "desc": "Oversee daily business operations",
59
+ "skills": ["Operations Management", "Process Improvement", "Team Leadership", "Budget Management", "Problem Solving"]},
60
+ {"title": "Project Manager", "desc": "Lead and coordinate project execution",
61
+ "skills": ["Project Management", "PMP", "Agile", "Risk Management", "Communication"]},
62
+ ],
63
+ "Creative": [
64
+ {"title": "Graphic Designer", "desc": "Create visual designs for various media",
65
+ "skills": ["Adobe Creative Suite", "Graphic Design", "Typography", "Brand Design", "Creativity"]},
66
+ {"title": "Content Writer", "desc": "Create written content for various platforms",
67
+ "skills": ["Writing", "Content Creation", "SEO", "Research", "Editing"]},
68
+ ]
69
+ }
70
+
71
+ experience_levels = ["Entry-level", "Mid-level", "Senior", "Lead/Principal"]
72
+
73
+ jobs = []
74
+ job_id = 1
75
+ categories = list(job_templates.keys())
76
+ jobs_per_category = 1000 // len(categories)
77
+ remaining_jobs = 1000 % len(categories)
78
+
79
+ for i, category in enumerate(categories):
80
+ templates = job_templates[category]
81
+ jobs_for_this_category = jobs_per_category + (1 if i < remaining_jobs else 0)
82
+
83
+ for j in range(jobs_for_this_category):
84
+ template = templates[j % len(templates)]
85
+ title_variations = [
86
+ template["title"],
87
+ f"Senior {template['title']}",
88
+ f"Junior {template['title']}",
89
+ f"Lead {template['title']}",
90
+ f"{template['title']} Specialist"
91
+ ]
92
+ title = title_variations[j % len(title_variations)]
93
+ exp_level = random.choice(experience_levels)
94
+ job = {
95
+ "id": job_id,
96
+ "title": title,
97
+ "description": template["desc"],
98
+ "requirements": template["skills"],
99
+ "experience_level": exp_level,
100
+ "category": category,
101
+ "location": random.choice([
102
+ "Remote", "New York, NY", "San Francisco, CA", "Chicago, IL",
103
+ "Austin, TX", "Seattle, WA", "Boston, MA", "Los Angeles, CA"
104
+ ])
105
+ }
106
+ jobs.append(job)
107
+ job_id += 1
108
+ return jobs
109
+
110
+ # ------------------------------
111
+ # 2. Prepare DataFrame and Embeddings
112
+ # ------------------------------
113
+ jobs = generate_job_database()
114
+ df = pd.DataFrame(jobs)
115
+ model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
116
+ job_embeddings = model.encode(df['requirements'].apply(lambda x: " ".join(x)).tolist())
117
+
118
+ # ------------------------------
119
+ # 3. Job Recommendation Function
120
+ # ------------------------------
121
+ def recommend_jobs(user_skills, top_k=5):
122
+ user_embedding = model.encode([" ".join(user_skills)])
123
+ similarities = cosine_similarity(user_embedding, job_embeddings)[0]
124
+ top_indices = similarities.argsort()[-top_k:][::-1]
125
+ top_jobs = df.iloc[top_indices]
126
+ return top_jobs[['title', 'description', 'requirements', 'experience_level', 'category', 'location']]
127
+
128
+ # ------------------------------
129
+ # 4. Gradio Interface
130
+ # ------------------------------
131
+ def gradio_interface(skills_text):
132
+ user_skills = [skill.strip() for skill in skills_text.split(",")]
133
+ recommended = recommend_jobs(user_skills)
134
+ return recommended.to_dict(orient="records")
135
+
136
+ app = gr.Interface(
137
+ fn=gradio_interface,
138
+ inputs=gr.Textbox(lines=2, placeholder="Enter your skills separated by commas"),
139
+ outputs=gr.Dataframe(headers=["Title", "Description", "Skills", "Experience", "Category", "Location"]),
140
+ title="AI Job Finder",
141
+ description="Enter your skills and find the best matching jobs!"
142
+ )
143
+
144
+ if __name__ == "__main__":
145
+ app.launch()