Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -68,5 +68,25 @@ def compare():
|
|
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()
|
|
|
68 |
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.item()})
|
69 |
|
70 |
return jsonify(similarity_scores)
|
71 |
+
@app.route('/compare_job', methods=['POST'])
|
72 |
+
def compare_job():
|
73 |
+
job_skills = request.json.get('post')
|
74 |
+
employee_skills = request.json.get('employee_skills')
|
75 |
+
|
76 |
+
# Validation
|
77 |
+
if not isinstance(employee_skills, list) or not all(isinstance(skill, str) for skill in employee_skills):
|
78 |
+
raise ValueError("employee_skills must be a list of strings")
|
79 |
+
|
80 |
+
# Encoding skills into embeddings
|
81 |
+
job_embedding = model.encode(job_skills)
|
82 |
+
employee_embedding = model.encode(employee_skills)
|
83 |
+
|
84 |
+
# Computing cosine similarity between employee skills and the job
|
85 |
+
employee_embedding_tensor = torch.from_numpy(employee_embedding).unsqueeze(0)
|
86 |
+
job_embedding_tensor = torch.from_numpy(job_embedding).unsqueeze(0)
|
87 |
+
similarity_score = cosine_similarity(employee_embedding_tensor, job_embedding_tensor, dim=1)
|
88 |
+
|
89 |
+
return jsonify({"job": job_skills, "similarity_score": similarity_score.item()})
|
90 |
+
|
91 |
if __name__ == '__main__':
|
92 |
app.run()
|