Spaces:
Sleeping
Sleeping
Delete src/deep_learning_analyzer.py
Browse files
src/deep_learning_analyzer.py
DELETED
|
@@ -1,57 +0,0 @@
|
|
| 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 |
-
return cosine_score.item()
|
| 33 |
-
|
| 34 |
-
def classify_candidate_intent(self, messages):
|
| 35 |
-
user_answers = [msg['content'] for msg in messages if msg['role'] == 'user']
|
| 36 |
-
if not user_answers:
|
| 37 |
-
return []
|
| 38 |
-
candidate_labels = [
|
| 39 |
-
"parle de son expérience technique",
|
| 40 |
-
"exprime sa motivation",
|
| 41 |
-
"pose une question",
|
| 42 |
-
"exprime de l’incertitude ou du stress"
|
| 43 |
-
]
|
| 44 |
-
classifications = self.intent_classifier(user_answers, candidate_labels, multi_label=False)
|
| 45 |
-
return classifications
|
| 46 |
-
|
| 47 |
-
def run_full_analysis(self, conversation_history, job_requirements):
|
| 48 |
-
sentiment_results = self.analyze_sentiment(conversation_history)
|
| 49 |
-
similarity_score = self.compute_semantic_similarity(conversation_history, job_requirements)
|
| 50 |
-
intent_results = self.classify_candidate_intent(conversation_history)
|
| 51 |
-
analysis_output = {
|
| 52 |
-
"overall_similarity_score": round(similarity_score, 2),
|
| 53 |
-
"sentiment_analysis": sentiment_results,
|
| 54 |
-
"intent_analysis": intent_results,
|
| 55 |
-
"raw_transcript": conversation_history
|
| 56 |
-
}
|
| 57 |
-
return analysis_output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|