yasserrmd commited on
Commit
c6e7c0e
1 Parent(s): 2bab3b0

Update career_data.py

Browse files
Files changed (1) hide show
  1. career_data.py +46 -20
career_data.py CHANGED
@@ -1,24 +1,50 @@
1
- def get_career_recommendations(skills: str, interests: str):
2
- # Mock data: mapping skills and interests to careers
3
- career_options = {
4
- "programming": "Software Engineer",
5
- "design": "Graphic Designer",
6
- "management": "Project Manager",
7
- "communication": "Marketing Specialist",
8
- }
9
 
10
- # Simple rule-based matching
11
- skills = skills.lower().split(",")
12
- interests = interests.lower().split(",")
13
- recommendations = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- for skill in skills:
16
- if skill.strip() in career_options:
17
- recommendations.append(career_options[skill.strip()])
 
 
 
18
 
19
- for interest in interests:
20
- if interest.strip() in career_options and career_options[interest.strip()] not in recommendations:
21
- recommendations.append(career_options[interest.strip()])
 
22
 
23
- # Return a list of career recommendations
24
- return recommendations if recommendations else ["No matching career found."]
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModel, AutoTokenizer
2
+ import torch
 
 
 
 
 
 
3
 
4
+ # Load model and tokenizer
5
+ model_name = "minishlab/M2V_base_output"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModel.from_pretrained(model_name)
8
+
9
+ # Career options with precomputed skills and interests
10
+ career_options = {
11
+ "Software Engineer": {
12
+ "skills": "programming, problem-solving",
13
+ "interests": "technology, innovation"
14
+ },
15
+ "Graphic Designer": {
16
+ "skills": "design, creativity",
17
+ "interests": "art, visual communication"
18
+ },
19
+ "Project Manager": {
20
+ "skills": "management, organization",
21
+ "interests": "leadership, strategy"
22
+ },
23
+ # Add more careers as needed
24
+ }
25
 
26
+ # Generate embeddings for career options
27
+ def get_embedding(text):
28
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
29
+ with torch.no_grad():
30
+ embedding = model(**inputs).last_hidden_state.mean(dim=1).squeeze()
31
+ return embedding
32
 
33
+ career_embeddings = {}
34
+ for career, attributes in career_options.items():
35
+ combined_text = attributes["skills"] + ", " + attributes["interests"]
36
+ career_embeddings[career] = get_embedding(combined_text)
37
 
38
+ # Function to recommend careers based on skills and interests
39
+ def get_career_recommendations(skills: str, interests: str):
40
+ user_input = skills + ", " + interests
41
+ user_embedding = get_embedding(user_input)
42
+
43
+ recommendations = []
44
+ for career, career_embedding in career_embeddings.items():
45
+ similarity = torch.cosine_similarity(user_embedding, career_embedding, dim=0).item()
46
+ recommendations.append((career, similarity))
47
+
48
+ recommendations.sort(key=lambda x: x[1], reverse=True)
49
+
50
+ return [f"{career} (Similarity: {similarity:.2f})" for career, similarity in recommendations[:5]]