CareerPath / career_data.py
yasserrmd's picture
Update career_data.py
8773065 verified
import json
from model2vec import StaticModel
import torch
# Load the Model2Vec pretrained model
model = StaticModel.from_pretrained("minishlab/M2V_base_output")
# Load career options from JSON file
with open("career_options.json", "r") as file:
career_options = json.load(file)
# Precompute embeddings for career options
career_embeddings = {}
for career, attributes in career_options.items():
combined_text = attributes["skills"] + ", " + attributes["interests"]
career_embeddings[career] = model.encode([combined_text])[0]
# Function to generate career recommendations
def get_career_recommendations(skills: str, interests: str):
user_input = skills + ", " + interests
user_embedding = model.encode([user_input])[0]
recommendations = []
for career, career_embedding in career_embeddings.items():
similarity = torch.cosine_similarity(torch.tensor(user_embedding), torch.tensor(career_embedding), dim=0).item()
recommendations.append((career, similarity))
# Sort by similarity score
recommendations.sort(key=lambda x: x[1], reverse=True)
return [f"{career} (Similarity: {similarity:.2f})" for career, similarity in recommendations[:5]]