Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -50,7 +50,6 @@ def health():
|
|
50 |
# we will make here post request to compare between lists of skills one has employee just one text and the other has the of jobs has many texts
|
51 |
# the llm will say the most similar job to the cv
|
52 |
@app.route('/compare', methods=['POST'])
|
53 |
-
@app.route('/compare', methods=['POST'])
|
54 |
def compare():
|
55 |
employee_skills = request.json.get('employee_skills')
|
56 |
jobs_skills = request.json.get('jobs_skills')
|
@@ -70,6 +69,26 @@ def compare():
|
|
70 |
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.item()})
|
71 |
|
72 |
return jsonify(similarity_scores)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
|
75 |
if __name__ == '__main__':
|
|
|
50 |
# we will make here post request to compare between lists of skills one has employee just one text and the other has the of jobs has many texts
|
51 |
# the llm will say the most similar job to the cv
|
52 |
@app.route('/compare', methods=['POST'])
|
|
|
53 |
def compare():
|
54 |
employee_skills = request.json.get('employee_skills')
|
55 |
jobs_skills = request.json.get('jobs_skills')
|
|
|
69 |
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.item()})
|
70 |
|
71 |
return jsonify(similarity_scores)
|
72 |
+
@app.route('/compare', methods=['POST'])
|
73 |
+
def compare_jop():
|
74 |
+
employee_skills = request.json.get('post')
|
75 |
+
jobs_skills = request.json.get('employee_skills')
|
76 |
+
|
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 |
+
job_embeddings = model.encode(employee_skills)
|
81 |
+
employee_embeddings = model.encode(emplpostoyee_skills)
|
82 |
+
|
83 |
+
similarity_scores = []
|
84 |
+
employee_embeddings_tensor = torch.from_numpy(employee_embeddings).unsqueeze(0)
|
85 |
+
|
86 |
+
for i, job_e in enumerate(job_embeddings):
|
87 |
+
job_e_tensor = torch.from_numpy(job_e).unsqueeze(0)
|
88 |
+
similarity_score = cosine_similarity(employee_embeddings_tensor, job_e_tensor, dim=1)
|
89 |
+
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.item()})
|
90 |
+
|
91 |
+
return jsonify(similarity_scores)
|
92 |
|
93 |
|
94 |
if __name__ == '__main__':
|