|
from sentence_transformers import SentenceTransformer, util |
|
from flask import Flask, request |
|
import json |
|
import logging |
|
class JobOffer: |
|
def __init__(self, title, description, skills): |
|
self.title = title |
|
self.description = description |
|
self.skills = skills |
|
|
|
class JobApplicant: |
|
def __init__(self, id, skills): |
|
self.id = id |
|
self.skills = skills |
|
self.score = 0 |
|
|
|
class JobApplicantEncoder(json.JSONEncoder): |
|
def default(self, o): |
|
return o.__dict__ |
|
|
|
app = Flask(__name__) |
|
|
|
model_name = "Sahajtomar/french_semantic" |
|
model_name = "dangvantuan/sentence-camembert-base" |
|
model_name = "dangvantuan/sentence-camembert-large" |
|
model = SentenceTransformer(model_name) |
|
|
|
|
|
def get_cosine_score(job_applicant, job_offer): |
|
embeddings1 = model.encode(job_applicant, convert_to_tensor=True) |
|
embeddings2 = model.encode(job_offer, convert_to_tensor=True) |
|
cosine_scores = util.pytorch_cos_sim(embeddings1, embeddings2) |
|
return cosine_scores[0][0].item() |
|
|
|
@app.route('/process/', methods=['POST']) |
|
def get_cosinos(): |
|
|
|
data = request.get_json() |
|
temp_job_offer = data["job_offer"] |
|
temp_job_applicant = data["job_applicant"] |
|
assert temp_job_offer is not None |
|
assert temp_job_applicant is not None |
|
job_offer = JobOffer(temp_job_offer["title"], temp_job_offer["description"], temp_job_offer["skills"]) |
|
job_applicant_list = [] |
|
for job_applicant in temp_job_applicant: |
|
job_applicant_list.append(JobApplicant(job_applicant["id"], job_applicant["skills"])) |
|
|
|
|
|
for job_applicant in job_applicant_list: |
|
job_applicant.score = get_cosine_score(job_applicant.skills, job_offer.skills) |
|
|
|
return json.dumps(job_applicant_list, cls=JobApplicantEncoder) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
logging.info("Starting server...") |
|
resp = get_cosine_score("Je ne suis pas un développeur web", "Nous recherchons un développeur web qui sache faire du React, du NodeJS et du MongoDB") |
|
print(f"0 : {resp}") |
|
resp = get_cosine_score("Je ne suis pas un développeur web, j'ai aucune compétences en React", "Nous recherchons un développeur web qui sache faire du React, du NodeJS et du MongoDB") |
|
print(f"1 : {resp}") |
|
resp = get_cosine_score("Je ne suis pas un développeur web, j'ai aucune compétences en React et MongoDB", "Nous recherchons un développeur web qui sache faire du React, du NodeJS et du MongoDB") |
|
print(f"2 : {resp}") |
|
resp = get_cosine_score("Je ne suis pas un développeur web, j'ai aucune compétences en React, MongoDB et NodeJS", "Nous recherchons un développeur web qui sache faire du React, du NodeJS et du MongoDB") |
|
print(f"3 : {resp}") |
|
|