Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -45,27 +45,28 @@ def get_skills():
|
|
45 |
def health():
|
46 |
return jsonify({'status': 'Worked'})
|
47 |
|
48 |
-
@app.route('/
|
49 |
-
def
|
50 |
-
|
51 |
-
employee_skills = request.json.get('
|
52 |
|
53 |
# Validation
|
54 |
-
if not isinstance(
|
55 |
-
raise ValueError("
|
56 |
|
57 |
# Encoding skills into embeddings
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
# Computing cosine similarity between employee skills and the job
|
62 |
-
employee_embedding_tensor = torch.from_numpy(employee_embedding).unsqueeze(0)
|
63 |
-
job_embedding_tensor = torch.from_numpy(job_embedding).unsqueeze(0)
|
64 |
-
similarity_score = cosine_similarity(employee_embedding_tensor, job_embedding_tensor, dim=1)
|
65 |
-
|
66 |
-
return jsonify({"job": job_skills, "similarity_score": similarity_score.item()})
|
67 |
|
|
|
|
|
|
|
68 |
|
|
|
|
|
|
|
|
|
69 |
|
|
|
70 |
if __name__ == '__main__':
|
71 |
-
app.run()
|
|
|
45 |
def health():
|
46 |
return jsonify({'status': 'Worked'})
|
47 |
|
48 |
+
@app.route('/compare', methods=['POST'])
|
49 |
+
def compare():
|
50 |
+
jobs_skill = request.json.get('job_skills')
|
51 |
+
employee_skills = request.json.get('employee_skills')
|
52 |
|
53 |
# Validation
|
54 |
+
if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
|
55 |
+
raise ValueError("jobs_skills must be a list of strings")
|
56 |
|
57 |
# Encoding skills into embeddings
|
58 |
+
employee_embeddings = model.encode(employee_skills)
|
59 |
+
job_embeddings = model.encode(job_skills)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
# Computing cosine similarity between employee skills and each job
|
62 |
+
similarity_scores = []
|
63 |
+
employee_embeddings_tensor = torch.from_numpy(employee_embeddings).unsqueeze(0)
|
64 |
|
65 |
+
for i, job_e in enumerate(job_embeddings):
|
66 |
+
job_e_tensor = torch.from_numpy(job_e).unsqueeze(0)
|
67 |
+
similarity_score = cosine_similarity(employee_embeddings_tensor, job_e_tensor, dim=1)
|
68 |
+
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.item()})
|
69 |
|
70 |
+
return jsonify(similarity_scores)
|
71 |
if __name__ == '__main__':
|
72 |
+
app.run()
|