zayanomar5 commited on
Commit
27d2b1f
·
verified ·
1 Parent(s): f934933

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +17 -16
main.py CHANGED
@@ -45,27 +45,28 @@ def get_skills():
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__':
71
- app.run()
 
45
  def health():
46
  return jsonify({'status': 'Worked'})
47
 
48
+ @app.route('/compare', methods=['POST'])
49
+ def compare():
50
+ jobs_skill = request.json.get('job_skills')
51
+ employee_skills = request.json.get('employee_skills')
52
 
53
  # Validation
54
+ if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
55
+ raise ValueError("jobs_skills must be a list of strings")
56
 
57
  # Encoding skills into embeddings
58
+ employee_embeddings = model.encode(employee_skills)
59
+ job_embeddings = model.encode(job_skills)
 
 
 
 
 
 
 
60
 
61
+ # Computing cosine similarity between employee skills and each job
62
+ similarity_scores = []
63
+ employee_embeddings_tensor = torch.from_numpy(employee_embeddings).unsqueeze(0)
64
 
65
+ for i, job_e in enumerate(job_embeddings):
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
  if __name__ == '__main__':
72
+ app.run()