Spaces:
Sleeping
Sleeping
Update personal_information.py
Browse files- personal_information.py +9 -11
personal_information.py
CHANGED
@@ -29,15 +29,15 @@ def extract_location(text):
|
|
29 |
if response:
|
30 |
try:
|
31 |
location_data = json.loads(response)
|
32 |
-
|
33 |
-
|
34 |
except json.JSONDecodeError:
|
35 |
print("Failed to parse JSON from response")
|
36 |
-
|
37 |
else:
|
38 |
-
|
39 |
|
40 |
-
return
|
41 |
|
42 |
def calculate_score(email_exists, phone_exists, city_exists, country_exists):
|
43 |
score = 0
|
@@ -56,20 +56,18 @@ def analyze_personal_info(file_path):
|
|
56 |
|
57 |
email = extract_email(text)
|
58 |
phone = extract_phone(text)
|
59 |
-
|
60 |
|
61 |
email_exists = email is not None
|
62 |
phone_exists = phone is not None
|
63 |
-
city_exists = city is not None
|
64 |
-
country_exists = country
|
65 |
|
66 |
-
score = calculate_score(email_exists, phone_exists,
|
67 |
|
68 |
result = {
|
69 |
"email": email_exists,
|
70 |
"phone": phone_exists,
|
71 |
-
"city":
|
72 |
-
"country":
|
73 |
"personal_info_score": score
|
74 |
}
|
75 |
|
|
|
29 |
if response:
|
30 |
try:
|
31 |
location_data = json.loads(response)
|
32 |
+
city_present = any(location_data.get('city', {}).values())
|
33 |
+
country_present = any(location_data.get('country', {}).values())
|
34 |
except json.JSONDecodeError:
|
35 |
print("Failed to parse JSON from response")
|
36 |
+
city_present, country_present = False, False
|
37 |
else:
|
38 |
+
city_present, country_present = False, False
|
39 |
|
40 |
+
return city_present, country_present
|
41 |
|
42 |
def calculate_score(email_exists, phone_exists, city_exists, country_exists):
|
43 |
score = 0
|
|
|
56 |
|
57 |
email = extract_email(text)
|
58 |
phone = extract_phone(text)
|
59 |
+
city_present, country_present = extract_location(text)
|
60 |
|
61 |
email_exists = email is not None
|
62 |
phone_exists = phone is not None
|
|
|
|
|
63 |
|
64 |
+
score = calculate_score(email_exists, phone_exists, city_present, country_present)
|
65 |
|
66 |
result = {
|
67 |
"email": email_exists,
|
68 |
"phone": phone_exists,
|
69 |
+
"city": city_present,
|
70 |
+
"country": country_present,
|
71 |
"personal_info_score": score
|
72 |
}
|
73 |
|