Update app.py
Browse files
app.py
CHANGED
|
@@ -19,14 +19,30 @@ llm = Llama(
|
|
| 19 |
n_gpu_layers=2,
|
| 20 |
)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
def extract_email_and_phone(text):
|
| 24 |
-
|
| 25 |
-
|
| 26 |
email_matches = re.findall(email_regex, text)
|
|
|
|
|
|
|
|
|
|
| 27 |
phone_matches = re.findall(phone_regex, text)
|
|
|
|
|
|
|
| 28 |
email = email_matches[0] if email_matches else None
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
return email, phone
|
| 31 |
|
| 32 |
# Function to prompt LLM for location information
|
|
|
|
| 19 |
n_gpu_layers=2,
|
| 20 |
)
|
| 21 |
|
| 22 |
+
# Improved function to extract email and phone
|
| 23 |
def extract_email_and_phone(text):
|
| 24 |
+
# More robust email regex
|
| 25 |
+
email_regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
|
| 26 |
email_matches = re.findall(email_regex, text)
|
| 27 |
+
|
| 28 |
+
# More robust phone regex
|
| 29 |
+
phone_regex = r'\b(?:\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b'
|
| 30 |
phone_matches = re.findall(phone_regex, text)
|
| 31 |
+
|
| 32 |
+
# Validate email
|
| 33 |
email = email_matches[0] if email_matches else None
|
| 34 |
+
if email and '.' not in email.split('@')[1]:
|
| 35 |
+
email = None
|
| 36 |
+
|
| 37 |
+
# Validate and format phone
|
| 38 |
+
phone = None
|
| 39 |
+
if phone_matches:
|
| 40 |
+
# Keep only digits and '+'
|
| 41 |
+
phone = ''.join(char for char in phone_matches[0] if char.isdigit() or char == '+')
|
| 42 |
+
# Ensure the number has a reasonable length
|
| 43 |
+
if len(phone) < 7 or len(phone) > 15:
|
| 44 |
+
phone = None
|
| 45 |
+
|
| 46 |
return email, phone
|
| 47 |
|
| 48 |
# Function to prompt LLM for location information
|