Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -45,29 +45,26 @@ def get_skills():
|
|
45 |
def health():
|
46 |
return jsonify({'status': 'Worked'})
|
47 |
|
48 |
-
@app.route('/
|
49 |
-
def
|
50 |
-
|
51 |
-
|
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
|
62 |
-
|
63 |
-
|
|
|
64 |
|
65 |
-
|
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 |
|
72 |
|
73 |
if __name__ == '__main__':
|
|
|
45 |
def health():
|
46 |
return jsonify({'status': 'Worked'})
|
47 |
|
48 |
+
@app.route('/compare_job', methods=['POST'])
|
49 |
+
def compare_job():
|
50 |
+
job_skills = request.json.get('post')
|
51 |
+
employee_skills = request.json.get('job_skills')
|
52 |
|
53 |
# Validation
|
54 |
+
if not isinstance(employee_skills, list) or not all(isinstance(skill, str) for skill in employee_skills):
|
55 |
+
raise ValueError("employee_skills must be a list of strings")
|
56 |
|
57 |
# Encoding skills into embeddings
|
58 |
+
job_embedding = model.encode(job_skills)
|
59 |
+
employee_embedding = model.encode(employee_skills)
|
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__':
|