Nassiraaa commited on
Commit
e5daddf
·
verified ·
1 Parent(s): b41168c

Create cv_analyzer.py

Browse files
Files changed (1) hide show
  1. cv_analyzer.py +69 -0
cv_analyzer.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import logging
3
+ from cv_prompt import (
4
+ ResumeQualityEvaluation,
5
+ get_section_detection_prompt,
6
+ get_content_quality_prompt,
7
+ calculate_section_detection_score,
8
+ calculate_overall_score
9
+ )
10
+ from hf_utils import get_ai_response
11
+ from langchain.output_parsers import PydanticOutputParser
12
+ from spelling_grammar_checker import evaluate_cv_text
13
+ from personal_information import analyze_personal_info
14
+ from cv_quality import CV
15
+
16
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
17
+
18
+ def analyze_cv(file_path):
19
+ try:
20
+ # Extract text from CV
21
+ cv = CV(file_path)
22
+ text = cv.get_cv_text()
23
+
24
+ # Personal Information Analysis
25
+ personal_info = analyze_personal_info(file_path)
26
+
27
+ # Spelling and Grammar Check
28
+ error_percentage, spelling_grammar_score = evaluate_cv_text(text)
29
+
30
+ # Section Detection
31
+ sections_prompt = get_section_detection_prompt(text)
32
+ sections_response = get_ai_response([{"role": "user", "content": sections_prompt}])
33
+ if sections_response is None:
34
+ return {"error": "Failed to get AI response for sections"}
35
+
36
+ sections_data = json.loads(sections_response)
37
+ detected_sections = sections_data.get('present_sections', [])
38
+ section_detection_score = calculate_section_detection_score(detected_sections)
39
+ logging.info(f"Detected sections: {detected_sections}")
40
+ logging.info(f"Section detection score: {section_detection_score}")
41
+
42
+ # Content Quality Analysis
43
+ quality_prompt = get_content_quality_prompt(text)
44
+ quality_response = get_ai_response([{"role": "user", "content": quality_prompt}])
45
+
46
+ if quality_response is None:
47
+ return {"error": "Failed to get AI response for content quality"}
48
+
49
+ parser = PydanticOutputParser(pydantic_object=ResumeQualityEvaluation)
50
+ evaluation_result = parser.parse(quality_response)
51
+
52
+ overall_score = calculate_overall_score(evaluation_result)
53
+
54
+ logging.info("All analyses completed")
55
+ logging.info(f"Overall score: {overall_score}")
56
+
57
+ return {
58
+ "extracted_text": text,
59
+ "personal_info": personal_info,
60
+ "spelling_grammar_error_percentage": error_percentage,
61
+ "spelling_grammar_score": spelling_grammar_score,
62
+ "detected_sections": detected_sections,
63
+ "section_detection_score": section_detection_score,
64
+ "content_analysis": evaluation_result.dict(),
65
+ "overall_score": overall_score
66
+ }
67
+ except Exception as e:
68
+ logging.error(f"Error in CV analysis: {str(e)}", exc_info=True)
69
+ return {"error": str(e)}