Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -27,22 +27,16 @@ print("model size ====> :", file_size.st_size, "bytes")
|
|
27 |
|
28 |
# Assume 'model' is already defined somewhere else
|
29 |
|
|
|
30 |
@app.route('/compare', methods=['POST'])
|
31 |
def compare():
|
32 |
-
|
33 |
-
|
34 |
-
# Validation and data extraction
|
35 |
-
if 'jobs_skills' not in data or 'employee_skills' not in data:
|
36 |
-
return jsonify({"error": "Missing 'jobs_skills' or 'employee_skills' in request"}), 400
|
37 |
|
38 |
-
jobs_skills = data['jobs_skills']
|
39 |
-
employee_skills = data['employee_skills']
|
40 |
|
|
|
41 |
if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
|
42 |
-
|
43 |
-
|
44 |
-
if not isinstance(employee_skills, list) or not all(isinstance(skill, str) for skill in employee_skills):
|
45 |
-
return jsonify({"error": "'employee_skills' must be a list of strings"}), 400
|
46 |
|
47 |
# Encoding skills into embeddings
|
48 |
job_embeddings = model.encode(jobs_skills)
|
@@ -54,10 +48,9 @@ def compare():
|
|
54 |
|
55 |
for i, job_e in enumerate(job_embeddings):
|
56 |
job_e_tensor = torch.from_numpy(job_e).unsqueeze(0)
|
57 |
-
similarity_score = cosine_similarity(employee_embeddings_tensor, job_e_tensor,
|
58 |
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.item()})
|
59 |
|
60 |
return jsonify(similarity_scores)
|
61 |
-
|
62 |
if __name__ == '__main__':
|
63 |
-
app.run(
|
|
|
27 |
|
28 |
# Assume 'model' is already defined somewhere else
|
29 |
|
30 |
+
@app.route('/compare', methods=['POST'])
|
31 |
@app.route('/compare', methods=['POST'])
|
32 |
def compare():
|
33 |
+
employee_skills = request.json.get('jobs_skills')
|
34 |
+
jobs_skills = request.json.get('employee_skills')
|
|
|
|
|
|
|
35 |
|
|
|
|
|
36 |
|
37 |
+
# Validation
|
38 |
if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
|
39 |
+
raise ValueError("jobs_skills must be a list of strings")
|
|
|
|
|
|
|
40 |
|
41 |
# Encoding skills into embeddings
|
42 |
job_embeddings = model.encode(jobs_skills)
|
|
|
48 |
|
49 |
for i, job_e in enumerate(job_embeddings):
|
50 |
job_e_tensor = torch.from_numpy(job_e).unsqueeze(0)
|
51 |
+
similarity_score = cosine_similarity(employee_embeddings_tensor, job_e_tensor, dim=1)
|
52 |
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.item()})
|
53 |
|
54 |
return jsonify(similarity_scores)
|
|
|
55 |
if __name__ == '__main__':
|
56 |
+
app.run()
|