Spaces:
Running
Running
Update career_data.py
Browse files- career_data.py +46 -20
career_data.py
CHANGED
@@ -1,24 +1,50 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
career_options = {
|
4 |
-
"programming": "Software Engineer",
|
5 |
-
"design": "Graphic Designer",
|
6 |
-
"management": "Project Manager",
|
7 |
-
"communication": "Marketing Specialist",
|
8 |
-
}
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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]]
|