Spaces:
Sleeping
Sleeping
Update src/cv_parsing_agents.py
Browse files- src/cv_parsing_agents.py +52 -44
src/cv_parsing_agents.py
CHANGED
|
@@ -1,50 +1,58 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
return data
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
self.
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
"""
|
| 21 |
-
Traite le fichier PDF pour en extraire le contenu sous forme de JSON.
|
| 22 |
-
Ne se connecte à aucune base de données.
|
| 23 |
-
|
| 24 |
-
Retourne :
|
| 25 |
-
Un dictionnaire contenant les données extraites du CV, ou None en cas d'erreur.
|
| 26 |
-
"""
|
| 27 |
-
print(f"Début du traitement du CV : {self.pdf_path}")
|
| 28 |
|
| 29 |
-
|
| 30 |
-
cv_text_content = load_pdf(self.pdf_path)
|
| 31 |
-
crew_output = analyse_cv(cv_text_content)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from sentence_transformers import SentenceTransformer, util
|
| 4 |
|
| 5 |
+
class MultiModelInterviewAnalyzer:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.sentiment_analyzer = pipeline(
|
| 8 |
+
"text-classification",
|
| 9 |
+
model="astrosbd/french_emotion_camembert",
|
| 10 |
+
return_all_scores=True,
|
| 11 |
+
device=0 if torch.cuda.is_available() else -1,
|
| 12 |
+
)
|
| 13 |
+
self.similarity_model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 14 |
+
self.intent_classifier = pipeline(
|
| 15 |
+
"zero-shot-classification",
|
| 16 |
+
model="joeddav/xlm-roberta-large-xnli"
|
| 17 |
+
#device=0 if torch.cuda.is_available() else -1,
|
| 18 |
+
)
|
| 19 |
|
| 20 |
+
def analyze_sentiment(self, messages):
|
| 21 |
+
user_messages = [msg['content'] for msg in messages if msg['role'] == 'user']
|
| 22 |
+
if not user_messages:
|
| 23 |
+
return []
|
| 24 |
+
sentiments = self.sentiment_analyzer(user_messages)
|
| 25 |
+
return sentiments
|
|
|
|
| 26 |
|
| 27 |
+
def compute_semantic_similarity(self, messages, job_requirements):
|
| 28 |
+
user_answers = " ".join([msg['content'] for msg in messages if msg['role'] == 'user'])
|
| 29 |
+
embedding_answers = self.similarity_model.encode(user_answers, convert_to_tensor=True)
|
| 30 |
+
embedding_requirements = self.similarity_model.encode(job_requirements, convert_to_tensor=True)
|
| 31 |
+
cosine_score = util.cos_sim(embedding_answers, embedding_requirements)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
return cosine_score.max().item()
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
def classify_candidate_intent(self, messages):
|
| 36 |
+
user_answers = [msg['content'] for msg in messages if msg['role'] == 'user']
|
| 37 |
+
if not user_answers:
|
| 38 |
+
return []
|
| 39 |
+
candidate_labels = [
|
| 40 |
+
"parle de son expérience technique",
|
| 41 |
+
"exprime sa motivation",
|
| 42 |
+
"pose une question",
|
| 43 |
+
"exprime de l’incertitude ou du stress"
|
| 44 |
+
]
|
| 45 |
+
classifications = self.intent_classifier(user_answers, candidate_labels, multi_label=False)
|
| 46 |
+
return classifications
|
| 47 |
|
| 48 |
+
def run_full_analysis(self, conversation_history, job_requirements):
|
| 49 |
+
sentiment_results = self.analyze_sentiment(conversation_history)
|
| 50 |
+
similarity_score = self.compute_semantic_similarity(conversation_history, job_requirements)
|
| 51 |
+
intent_results = self.classify_candidate_intent(conversation_history)
|
| 52 |
+
analysis_output = {
|
| 53 |
+
"overall_similarity_score": round(similarity_score, 2),
|
| 54 |
+
"sentiment_analysis": sentiment_results,
|
| 55 |
+
"intent_analysis": intent_results,
|
| 56 |
+
"raw_transcript": conversation_history
|
| 57 |
+
}
|
| 58 |
+
return analysis_output
|