Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -45,60 +45,6 @@ def get_skills():
|
|
45 |
def health():
|
46 |
return jsonify({'status': 'Worked'})
|
47 |
|
48 |
-
# Endpoint to compare between employee skills and job skills
|
49 |
-
@app.route('/compare', methods=['POST'])
|
50 |
-
def compare():
|
51 |
-
employee_skills = request.json.get('employee_skills')
|
52 |
-
jobs_skills = request.json.get('jobs_skills')
|
53 |
-
|
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 |
-
if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
|
58 |
-
raise ValueError("jobs_skills must be a list of strings")
|
59 |
-
|
60 |
-
job_embeddings = model.encode(jobs_skills)
|
61 |
-
employee_embeddings = model.encode(employee_skills)
|
62 |
-
|
63 |
-
similarity_scores = []
|
64 |
-
employee_embeddings_tensor = torch.from_numpy(employee_embeddings).unsqueeze(0)
|
65 |
-
|
66 |
-
for i, job_e in enumerate(job_embeddings):
|
67 |
-
job_e_tensor = torch.from_numpy(job_e).unsqueeze(0)
|
68 |
-
similarity_score = cosine_similarity(employee_embeddings_tensor, job_e_tensor, dim=1)
|
69 |
-
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.tolist()[0]})
|
70 |
-
|
71 |
-
return jsonify(similarity_scores)
|
72 |
-
|
73 |
-
# Endpoint to compare job posts with employee skills
|
74 |
-
@app.route('/compare_jop', methods=['POST'])
|
75 |
-
def compare_jop():
|
76 |
-
employee_skills = request.json.get('employee_skills')
|
77 |
-
jobs_skills = request.json.get('jobs_skills')
|
78 |
-
|
79 |
-
if not isinstance(employee_skills, list) or not all(isinstance(skill, str) for skill in employee_skills):
|
80 |
-
raise ValueError("employee_skills must be a list of strings")
|
81 |
-
|
82 |
-
if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
|
83 |
-
raise ValueError("jobs_skills must be a list of strings")
|
84 |
-
|
85 |
-
job_embeddings = model.encode(jobs_skills)
|
86 |
-
employee_embeddings = model.encode(employee_skills)
|
87 |
-
|
88 |
-
similarity_scores = []
|
89 |
-
employee_embeddings_tensor = torch.from_numpy(employee_embeddings).unsqueeze(0)
|
90 |
-
|
91 |
-
for i, job_e in enumerate(job_embeddings):
|
92 |
-
job_e_tensor = torch.from_numpy(job_e).unsqueeze(0)
|
93 |
-
similarity_score = cosine_similarity(employee_embeddings_tensor, job_e_tensor, dim=1)
|
94 |
-
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.tolist()[0]})
|
95 |
-
|
96 |
-
return jsonify(similarity_scores)
|
97 |
-
|
98 |
-
if __name__ == '__main__':
|
99 |
-
app.run()
|
100 |
-
|
101 |
-
|
102 |
# Endpoint to compare between employee skills and job skills
|
103 |
@app.route('/compare', methods=['POST'])
|
104 |
def compare():
|
@@ -150,4 +96,4 @@ def compare_jop():
|
|
150 |
return jsonify(similarity_scores)
|
151 |
|
152 |
if __name__ == '__main__':
|
153 |
-
app.run()
|
|
|
45 |
def health():
|
46 |
return jsonify({'status': 'Worked'})
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
# Endpoint to compare between employee skills and job skills
|
49 |
@app.route('/compare', methods=['POST'])
|
50 |
def compare():
|
|
|
96 |
return jsonify(similarity_scores)
|
97 |
|
98 |
if __name__ == '__main__':
|
99 |
+
app.run()
|