Update cv_analyzer.py
Browse files- cv_analyzer.py +17 -13
cv_analyzer.py
CHANGED
|
@@ -1,33 +1,36 @@
|
|
| 1 |
import json
|
| 2 |
-
|
|
|
|
| 3 |
from llm_utils import get_llm_response
|
| 4 |
from ocr_utils import extract_text_aws
|
| 5 |
|
|
|
|
|
|
|
| 6 |
def analyze_cv(file_content):
|
| 7 |
try:
|
| 8 |
-
# Extract text
|
| 9 |
extracted_text = extract_text_aws(file_content)
|
|
|
|
| 10 |
|
| 11 |
-
# Step 1: Detect presence of all sections
|
| 12 |
sections_prompt = get_section_detection_prompt(extracted_text)
|
| 13 |
sections_response = get_llm_response(sections_prompt)
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
cv_completeness = json.load(f)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
verified_sections = [section['name'] for section in cv_completeness['sections']
|
| 22 |
if section['name'] in detected_sections]
|
|
|
|
| 23 |
|
| 24 |
-
# Step 3: Verify elements for detected sections
|
| 25 |
verified_elements = {}
|
| 26 |
for section in verified_sections:
|
| 27 |
-
elements_prompt = get_element_verification_prompt(extracted_text,
|
| 28 |
elements_response = get_llm_response(elements_prompt)
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
verified_elements[section] = section_elements
|
|
|
|
| 31 |
|
| 32 |
return {
|
| 33 |
"extracted_text": extracted_text,
|
|
@@ -36,4 +39,5 @@ def analyze_cv(file_content):
|
|
| 36 |
"verified_elements": verified_elements
|
| 37 |
}
|
| 38 |
except Exception as e:
|
|
|
|
| 39 |
return {"error": str(e)}
|
|
|
|
| 1 |
import json
|
| 2 |
+
import logging
|
| 3 |
+
from cv_prompt import get_section_detection_prompt, get_element_verification_prompt, cv_completeness_data
|
| 4 |
from llm_utils import get_llm_response
|
| 5 |
from ocr_utils import extract_text_aws
|
| 6 |
|
| 7 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 8 |
+
|
| 9 |
def analyze_cv(file_content):
|
| 10 |
try:
|
|
|
|
| 11 |
extracted_text = extract_text_aws(file_content)
|
| 12 |
+
logging.info("Text extracted successfully")
|
| 13 |
|
|
|
|
| 14 |
sections_prompt = get_section_detection_prompt(extracted_text)
|
| 15 |
sections_response = get_llm_response(sections_prompt)
|
| 16 |
+
if "error" in sections_response:
|
| 17 |
+
return {"error": sections_response["error"]}
|
| 18 |
+
detected_sections = sections_response.get('present_sections', [])
|
| 19 |
+
logging.info(f"Detected sections: {detected_sections}")
|
|
|
|
| 20 |
|
| 21 |
+
verified_sections = [section['name'] for section in cv_completeness_data['sections']
|
|
|
|
| 22 |
if section['name'] in detected_sections]
|
| 23 |
+
logging.info(f"Verified sections: {verified_sections}")
|
| 24 |
|
|
|
|
| 25 |
verified_elements = {}
|
| 26 |
for section in verified_sections:
|
| 27 |
+
elements_prompt = get_element_verification_prompt(extracted_text, section, cv_completeness_data)
|
| 28 |
elements_response = get_llm_response(elements_prompt)
|
| 29 |
+
if "error" in elements_response:
|
| 30 |
+
return {"error": elements_response["error"]}
|
| 31 |
+
section_elements = elements_response.get(section, {}).get('elements', [])
|
| 32 |
verified_elements[section] = section_elements
|
| 33 |
+
logging.info("Element verification completed")
|
| 34 |
|
| 35 |
return {
|
| 36 |
"extracted_text": extracted_text,
|
|
|
|
| 39 |
"verified_elements": verified_elements
|
| 40 |
}
|
| 41 |
except Exception as e:
|
| 42 |
+
logging.error(f"Error in CV analysis: {str(e)}", exc_info=True)
|
| 43 |
return {"error": str(e)}
|