QuentinL52 commited on
Commit
833f869
·
verified ·
1 Parent(s): 4fee74f

Update src/cv_parsing_agents.py

Browse files
Files changed (1) hide show
  1. src/cv_parsing_agents.py +49 -49
src/cv_parsing_agents.py CHANGED
@@ -1,50 +1,50 @@
1
- import os
2
- import json
3
-
4
- from src.crew.crew_pool import analyse_cv
5
- from src.config import load_pdf
6
-
7
- def clean_dict_keys(data):
8
- if isinstance(data, dict):
9
- return {str(key): clean_dict_keys(value) for key, value in data.items()}
10
- elif isinstance(data, list):
11
- return [clean_dict_keys(element) for element in data]
12
- else:
13
- return data
14
-
15
- class CvParserAgent:
16
- def __init__(self, pdf_path: str):
17
- self.pdf_path = pdf_path
18
-
19
- def process(self) -> dict:
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
- try:
30
- cv_text_content = load_pdf(self.pdf_path)
31
- crew_output = analyse_cv(cv_text_content)
32
-
33
- if not crew_output or not hasattr(crew_output, 'raw') or not crew_output.raw.strip():
34
- print("Erreur : L'analyse par le crew n'a pas retourné de résultat.")
35
- return None
36
- raw_string = crew_output.raw
37
- json_string_cleaned = raw_string
38
- if '```' in raw_string:
39
- json_part = raw_string.split('```json')[1].split('```')[0]
40
- json_string_cleaned = json_part.strip()
41
- profile_data = json.loads(json_string_cleaned)
42
- return clean_dict_keys(profile_data)
43
-
44
- except json.JSONDecodeError as e:
45
- print(f"Erreur de décodage JSON : {e}")
46
- print(f"Données brutes reçues : {crew_output.raw}")
47
- return None
48
- except Exception as e:
49
- print(f"Une erreur inattendue est survenue dans CvParserAgent : {e}")
50
  return None
 
1
+ import os
2
+ import json
3
+
4
+ from src.crew.crew_pool import analyse_cv
5
+ from src.config import load_pdf
6
+
7
+ def clean_dict_keys(data):
8
+ if isinstance(data, dict):
9
+ return {str(key): clean_dict_keys(value) for key, value in data.items()}
10
+ elif isinstance(data, list):
11
+ return [clean_dict_keys(element) for element in data]
12
+ else:
13
+ return data
14
+
15
+ class CvParserAgent:
16
+ def __init__(self, pdf_path: str):
17
+ self.pdf_path = pdf_path
18
+
19
+ def process(self) -> dict:
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
+ try:
30
+ cv_text_content = load_pdf(self.pdf_path)
31
+ crew_output = analyse_cv(cv_text_content)
32
+
33
+ if not crew_output or not hasattr(crew_output, 'raw') or not crew_output.raw.strip():
34
+ print("Erreur : L'analyse par le crew n'a pas retourné de résultat.")
35
+ return None
36
+ raw_string = crew_output.raw
37
+ json_string_cleaned = raw_string
38
+ if '```' in raw_string:
39
+ json_part = raw_string.split('```json')[1].split('```')[0]
40
+ json_string_cleaned = json_part.strip()
41
+ profile_data = json.loads(json_string_cleaned)
42
+ return clean_dict_keys(profile_data)
43
+
44
+ except json.JSONDecodeError as e:
45
+ print(f"Erreur de décodage JSON : {e}")
46
+ print(f"Données brutes reçues : {crew_output.raw}")
47
+ return None
48
+ except Exception as e:
49
+ print(f"Une erreur inattendue est survenue dans CvParserAgent : {e}")
50
  return None