File size: 2,251 Bytes
d0016c1
 
6d4869c
d0016c1
1ef03e4
d0016c1
b16cf34
d0016c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddcadec
 
d0016c1
 
ddcadec
d0016c1
ddcadec
d0016c1
ddcadec
d0016c1
 
 
 
 
 
 
 
 
 
 
 
 
 
1ef03e4
 
d0016c1
 
 
ddcadec
d0016c1
 
 
 
ddcadec
d0016c1
 
 
 
ddcadec
 
d0016c1
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
import re
from openai_utils import get_ai_response
from cv_prompt import get_personal_info_prompt
from cv_quality import CV


# Load the scoring data
with open('personal_info_scores.json', 'r') as f:
    score_data = json.load(f)

def extract_email(text):
    email_pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
    emails = re.findall(email_pattern, text)
    return emails[0] if emails else None

def extract_phone(text):
    phone_pattern = r'\b(?:\+?1[-.\s]?)?(?:\(\d{3}\)|\d{3})[-.\s]?\d{3}[-.\s]?\d{4}\b'
    phones = re.findall(phone_pattern, text)
    return phones[0] if phones else None

def extract_location(text):
    prompt = get_personal_info_prompt(text)
    messages = [
        {"role": "user", "content": prompt}
    ]
    
    response = get_ai_response(messages)
    
    if response:
        try:
            location_data = json.loads(response)
            city_present = any(location_data.get('city', {}).values())
            country_present = any(location_data.get('country', {}).values())
        except json.JSONDecodeError:
            print("Failed to parse JSON from response")
            city_present, country_present = False, False
    else:
        city_present, country_present = False, False
    
    return city_present, country_present

def calculate_score(email_exists, phone_exists, city_exists, country_exists):
    score = 0
    if email_exists:
        score += score_data['email']
    if phone_exists:
        score += score_data['phone']
    if city_exists:
        score += score_data['city']
    if country_exists:
        score += score_data['country']
    return score

def analyze_personal_info(file_path):
    cv = CV(file_path)
    text = cv.get_cv_text()
    
    email = extract_email(text)
    phone = extract_phone(text)
    city_present, country_present = extract_location(text)
    
    email_exists = email is not None
    phone_exists = phone is not None
    
    score = calculate_score(email_exists, phone_exists, city_present, country_present)
    
    result = {
        "email": email_exists,
        "phone": phone_exists,
        "city": city_present,
        "country": country_present,
        "personal_info_score": score
    }
    
    return result