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

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -16
main.py CHANGED
@@ -45,29 +45,26 @@ def get_skills():
45
  def health():
46
  return jsonify({'status': 'Worked'})
47
 
48
- @app.route('/compare', methods=['POST'])
49
- def compare():
50
- employee_skills = request.json.get('employee_skills')
51
- jobs_skills = request.json.get('jobs_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
- job_embeddings = model.encode(jobs_skills)
59
- employee_embeddings = model.encode(employee_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
 
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__':