idvpackage 3.0.11__py3-none-any.whl → 3.0.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,77 +1,6 @@
1
- # from pydantic import BaseModel, Field
2
- # import openai
3
- # import json
4
-
5
- # class UAEIDExtractionResult(BaseModel):
6
- # is_header_verified: bool = Field(..., description="Is it the front side of a UAE ID?")
7
- # id_number: str = Field(..., description="15-digit UAE ID number")
8
-
9
- # def extract_uae_front_id(base64_image: str) -> UAEIDExtractionResult:
10
- # """
11
- # Extracts UAE ID front fields using OpenAI's vision model and function calling.
12
- # Args:
13
- # openai_api_key (str): OpenAI API key.
14
- # base64_image (str): Base64-encoded image of the UAE ID front.
15
- # Returns:
16
- # UAEIDExtractionResult: Extracted fields in Pydantic model.
17
- # Raises:
18
- # Exception: If extraction or parsing fails.
19
- # """
20
-
21
- # # Define the function schema for OpenAI function calling
22
- # function_schema = {
23
- # "name": "UAEIDExtractionResult",
24
- # "description": "Extracts fields from the front side of a UAE ID card.",
25
- # "parameters": {
26
- # "type": "object",
27
- # "properties": {
28
- # "is_header_verified": {
29
- # "type": "boolean",
30
- # "description": "Is it the front side of a UAE ID?"
31
- # },
32
- # "id_number": {
33
- # "type": "string",
34
- # "description": "15-digit UAE ID number"
35
- # }
36
- # },
37
- # "required": ["is_header_verified", "id_number"]
38
- # }
39
- # }
40
- # prompt = (
41
- # "You are an expert at extracting information from UAE ID cards. "
42
- # "Given an image of the front side of a UAE ID, extract the relevant fields. "
43
- # "If the id_number is not found, set it to an empty string. "
44
- # "Set is_header_verified to true if the image is the front side of a UAE ID, else false."
45
- # )
46
- # try:
47
- # response = openai.ChatCompletion.create(
48
- # model="gpt-4o",
49
- # messages=[
50
- # {"role": "system", "content": "You are a helpful assistant."},
51
- # {"role": "user", "content": [
52
- # {"type": "text", "text": prompt},
53
- # {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}}
54
- # ]}
55
- # ],
56
- # functions=[function_schema],
57
- # function_call={"name": "UAEIDExtractionResult"},
58
- # max_tokens=300
59
- # )
60
- # message = response.choices[0].message
61
- # if message.function_call and message.function_call.arguments:
62
- # args = json.loads(message.function_call.arguments)
63
- # return UAEIDExtractionResult(**args)
64
- # else:
65
- # return {'error':'covered_photo'}
66
- # except Exception as e:
67
- # return {'error':'covered_photo'}
68
-
69
-
70
-
71
- import base64
1
+
72
2
  import time
73
3
  from io import BytesIO
74
- from typing import Optional
75
4
  import cv2
76
5
 
77
6
  from openai import OpenAI
@@ -101,8 +30,16 @@ Extract ALL fields from this UAE National ID **front side** image with high accu
101
30
 
102
31
  Return a JSON object with the following fields (use the exact field names):
103
32
 
104
- - id_number: The ID number exactly as shown on the card (example: 784-1999-1234567-1 but return without dashes, e.g., 784199912345671)
105
- - header_verified: Return True if one of the texts present in the image is "UNITED ARAB EMIRATES"; otherwise False.
33
+ - id_number: The ID number exactly as shown on the card example: 784-1999-1234567-1 but return without dashes (i.e., 784199912345671)
34
+ - name: Full name as shown on the card (extract exactly as written on the card).
35
+ - first_name: Only the First name, as shown on the card (extract exactly as written on the card).
36
+ - last_name: Only the Last name, as shown on the card (extract exactly as written on the card).
37
+ - dob: Extract date of birth exactly as shown on card. Convert date to format DD-MM-YYYY If there is no date of birth, return an empty string.
38
+ - nationality: Extract the nationality exactly as printed on the card Convert nationality to ISO 3166-1 alpha-3 code. e.g. EGY for Egypt, IND for India.
39
+ - issue_date: Extract issue date exactly as shown on card. Convert date to format DD-MM-YYYY If there is no issue date, return an empty string.
40
+ - expiry_date: Extract the expiry date exactly as shown on card. Convert date to format DD-MM-YYYY If there is no expiry date, return an empty string.
41
+ - gender: Extract gender exactly as printed on the card. If there is no gender, return an empty string. If gender is M, return "Male". If gender is F, return "Female".
42
+ - header_verified: Return True if one of the texts present in the image UNITED ARAB EMIRATES else return False.
106
43
 
107
44
  Instructions:
108
45
  - Do NOT guess or hallucinate any values. If unclear, return empty string.
@@ -116,62 +53,98 @@ Extract ALL fields from this UAE National ID **back side** image with high accur
116
53
 
117
54
  Return a JSON object with the following fields (use the exact field names):
118
55
 
119
- - gender_back: If not present as a separate field, return null. Gender as either M or F. Only extract if it is printed as a separate field on the back side of the card. Do NOT extract from the MRZ.
120
- - date_of_birth_back: If not present as a separate field, return null. Date of birth exactly as shown on the back side of the card preserve DD/MM/YY format. Only extract if it is printed as a separate field. Do NOT extract from the MRZ.
121
- - date_of_expiry_back: If not present as a separate field, return null. Expiry date exactly as shown on the back side of the card preserve DD/MM/YY format. Only extract if it is printed as a separate field. Do NOT extract from the MRZ.
122
- - employer: Employer name as shown in the image (English version; extract exactly as written on the card)
123
- - occupation: Occupation as shown in the image (English version; extract exactly as written on the card)
56
+ - employer: Employer name as shown in the image (English version; extract exactly as written on the card). If the employer is not present, return an empty string.
57
+ - occupation: Occupation as shown in the image (English version; extract exactly as written on the card). If the occupation is not present, return an empty string.
58
+ - family_sponsor : Family sponsor name as show in the image English Version(extract exactly as written on the card) If the family sponsor is not present, return an empty string.
59
+ - expiry_date: Extract the expiry date exactly as shown on card. Convert date to format DD-MM-YYYY If there is no expiry date, return an empty string.
60
+ - dob: Extract date of birth date exactly as shown on card. Convert date to format DD-MM-YYYY If there is no date of birth, return an empty string
61
+ - gender: Extract gender exactly as shown on card. If it is M, return Male If it is F, return Female If there is no gender on the card, return an empty string.
124
62
  - card_number: Card number as shown on the card (extract exactly as written, e.g., 119887248)
125
- - issuing_place: Issuing place as shown in the image (extract exactly as written on the card)
63
+ - issuing_place: Issuing place as shown in the image (extract exactly as written on the card). If the issuing place is not present, return an empty string.
126
64
  - back_header_verified: Return True if one of the texts present in the image is "ILARE" or "IDLARE"; otherwise False.
127
65
  - mrz1: First line of the MRZ
128
66
  - mrz2: Second line of the MRZ
129
67
  - mrz3: Third line of the MRZ
130
- - family_sponsor: Family sponsor name as shown in the image (English version; extract exactly as written on the card)
68
+ - family_sponsor: Family sponsor name as shown in the image (English version; extract exactly as written on the card). If the family sponsor is not present, return an empty string.
69
+ - dob_mrz: Date of birth extracted from MRZ line 2 in DD-MM-YYYY format.
70
+ - gender_mrz: Gender extracted from MRZ line 2: 'M' for Male, 'F' for Female.
71
+ - expiry_date_mrz: Expiry date extracted from MRZ line 2 in DD-MM-YYYY format.
131
72
 
132
73
  Instructions:
133
74
  - Do NOT guess or hallucinate any values. If unclear, return empty string.
134
75
  - Only use information visible on the card.
135
76
  - Return the result as a single JSON object matching the schema above.
77
+ - If any of the fields are not present on the card, return empty strings for those fields.
136
78
  """
137
79
 
138
80
  class UAEFront(BaseModel):
139
81
 
140
- id_number: str = Field(...,
82
+ id_number: str = Field(...,min_length=15, maximum=15,
141
83
  description = "The ID number exactly as shown on the card example: 784-1999-1234567-1 but return without dashes (i.e., 784199912345671)",
142
84
  )
143
85
 
86
+ name: str = Field(..., description="Full name as shown on the card (extract exactly as written on the card).")
87
+
88
+ first_name: str = Field(..., description="First name as shown on the card (extract exactly only the first name as written on the card).")
89
+
90
+ last_name: str = Field(..., description="Last name as shown on the card (extract exactly only the last name as written on the card).")
91
+
92
+ dob: str = Field(..., description="Extract date of birth exactly as shown on card."
93
+ "Convert date to format dd-mm-yyyy"
94
+ "If there is no date of birth, return an empty string.")
95
+
96
+ nationality: str = Field(..., description="Extract the nationality exactly as printed on the card"
97
+ "Convert nationality to ISO 3166-1 alpha-3 code. e.g. EGY for Egypt, IND for India.")
98
+
99
+ issue_date: str = Field(..., description="Extract issue date exactly as shown on card."
100
+ "Convert date to format dd-mm-yyyy"
101
+ "If there is no issue date, return an empty string.")
102
+
103
+ expiry_date: str = Field(..., description="Extract the expiry date exactly as shown on card."
104
+ "Convert date to format dd-mm-yyyy"
105
+ "If there is no expiry date, return an empty string.")
106
+
107
+ gender: str = Field(..., description="Extract gender exactly as printed on the card."
108
+ "If there is no gender, return an empty string.")
109
+
144
110
 
145
111
  header_verified: bool = Field(
146
112
  ...,
147
- description=" Return True if one of the texts present in the image UNITED ARAB EMIRATES",
113
+ description=" Return True if one of the texts present in the image UNITED ARAB EMIRATES else return False.",
148
114
  )
149
115
 
150
116
  class UAEBack(BaseModel):
151
117
 
152
- gender_back: str = Field(...,
153
- description=" If not present as a separate field, return null. Gender as either M or F. Only extract if it is printed as a separate field on the back side of the card. Do NOT extract from the MRZ."
118
+ employer: str = Field(...,
119
+ description = "Employer name as shown in the image English Version(extract exactly as written on the card)"
120
+ "If the employer is not present, return an empty string."
154
121
  )
155
122
 
156
- date_of_birth_back: str = Field(...,
157
- description = "If not present as a separate field, return null. Date of birth exactly as shown on the back side of the card. Only extract if it is printed as a separate field. Do NOT extract from the MRZ."
123
+ occupation: str = Field(...,
124
+ description = "Occupation as shown in the image English version(extract exactly as written on the card)"
125
+ "If the occupation is not present, return an empty string."
158
126
  )
159
127
 
160
- date_of_expiry_back: str = Field(...,
161
- description = "If not present as a separate field, return null. The expiry date exactly as shown on the back side of the card (preserve original format). Only extract if it is printed as a separate field. Do NOT extract from the MRZ."
128
+ family_sponsor : str = Field(...,
129
+ description="Family sponsor name as show in the image English Version(extract exactly as written on the card)"
130
+ "If the family sponsor is not present, return an empty string."
162
131
  )
163
-
164
132
 
165
- employer: str = Field(...,
166
- description = "Employer name as show in the image English Version(extract exactly as written on the card)",
167
- )
133
+ expiry_date: str = Field(..., description="Extract the expiry date exactly as shown on card."
134
+ "Convert date to format dd-mm-yyyy"
135
+ "If there is no expiry date, return an empty string.")
168
136
 
169
- occupation: str = Field(...,
170
- description = "Occupation as show in the image English version(extract exactly as written on the card)",
171
- )
137
+ dob: str = Field(..., description="Extract date of birth date exactly as shown on card."
138
+ "Convert date to format dd-mm-yyyy"
139
+ "If there is no date of birth, return an empty string.")
172
140
 
173
- card_number: str = Field(...,
174
- description = "Card number extract exactly as written on the card ex: 119887248"
141
+ gender: str = Field(..., description="Extract gender exactly as shown on card."
142
+ "If it is M, return Male"
143
+ "If it is F, return Female"
144
+ "If there is no gender on the card, return an empty string.")
145
+
146
+ card_number: str = Field(...,min_length=9, max_length=9,
147
+ description = "9-digit Card number extract exactly as written on the card, example: 119887248"
175
148
  )
176
149
 
177
150
  issuing_place: str = Field(...,
@@ -180,26 +153,29 @@ class UAEBack(BaseModel):
180
153
 
181
154
  back_header_verified: bool = Field(
182
155
  ...,
183
- description=" Return True if one of the texts present in the image ILARE or IDARE ",
156
+ description=" Return True if one of the texts present in the image: ILARE or IDARE else return False ",
184
157
  )
185
158
 
186
159
  mrz1: str = Field(...,
187
- description="First line of the MRZ"
160
+ description="First line of the MRZ, exactly as printed on the card."
188
161
  )
189
162
 
190
163
  mrz2: str = Field(...,
191
- description="Second line of the MRZ"
164
+ description="Second line of the MRZ, exactly as printed on the card."
192
165
  )
193
166
 
194
167
  mrz3: str = Field(...,
195
- description="Third line of the MRZ"
168
+ description="Third line of the MRZ, exactly as printed on the card."
196
169
  )
197
-
198
- family_sponsor : str = Field(...,
199
- description="Family sponsor name as show in the image English Version(extract exactly as written on the card)",
170
+ dob_mrz: str = Field(...,
171
+ description="Date of birth extracted from MRZ line 2 in dd-mm-yyyy format."
172
+ )
173
+ gender_mrz: str = Field(...,
174
+ description="Gender extracted from MRZ line 2: 'M' for Male, 'F' for female."
175
+ )
176
+ expiry_date_mrz: str = Field(...,
177
+ description="Expiry date extracted from MRZ line 2 in dd-mm-yyyy format."
200
178
  )
201
-
202
-
203
179
 
204
180
 
205
181
  def process_image(side):
@@ -217,8 +193,8 @@ def process_image(side):
217
193
 
218
194
  return model, prompt
219
195
 
220
- def get_openai_response(prompt: str, model_type, image: BytesIO, genai_key):
221
- b64_image = base64.b64encode(image.getvalue()).decode("utf-8")
196
+ def get_openai_response(prompt: str, model_type, image: str, genai_key):
197
+
222
198
  for attempt in range(3):
223
199
  try:
224
200
  client = OpenAI(api_key=genai_key)
@@ -228,7 +204,7 @@ def get_openai_response(prompt: str, model_type, image: BytesIO, genai_key):
228
204
  {"role": "system", "content": "You are an expert at extracting information from identity documents."},
229
205
  {"role": "user", "content": [
230
206
  {"type": "input_text", "text": prompt},
231
- {"type": "input_image", "image_url": f"data:image/jpeg;base64,{b64_image}", "detail": "low"},
207
+ {"type": "input_image", "image_url": f"data:image/jpeg;base64,{image}", "detail": "low"},
232
208
  ]},
233
209
  ],
234
210
  text_format=model_type,
@@ -239,50 +215,10 @@ def get_openai_response(prompt: str, model_type, image: BytesIO, genai_key):
239
215
  time.sleep(2)
240
216
  return None
241
217
 
242
- def _image_to_jpeg_bytesio(image) -> BytesIO:
243
- """
244
- Accepts: numpy.ndarray (OpenCV BGR), PIL.Image.Image, bytes/bytearray, or io.BytesIO
245
- Returns: io.BytesIO containing JPEG bytes (ready for get_openai_response)
246
- """
247
- import numpy as np
248
-
249
- if isinstance(image, BytesIO):
250
- image.seek(0)
251
- return image
252
-
253
- if isinstance(image, (bytes, bytearray)):
254
- return BytesIO(image)
255
-
256
- try:
257
- from PIL.Image import Image as _PILImage
258
-
259
- if isinstance(image, _PILImage):
260
- buf = BytesIO()
261
- image.convert("RGB").save(buf, format="JPEG", quality=95)
262
- buf.seek(0)
263
- return buf
264
- except Exception:
265
- pass
266
-
267
- if isinstance(image, np.ndarray):
268
- success, enc = cv2.imencode(".jpg", image)
269
- if not success:
270
- raise ValueError("cv2.imencode failed")
271
- return BytesIO(enc.tobytes())
272
-
273
- raise TypeError(
274
- "Unsupported image type. Provide numpy.ndarray, PIL.Image.Image, bytes, or io.BytesIO."
275
- )
276
-
277
218
  def get_response_from_openai_uae(image, side, country, openai_key):
278
219
 
279
- logging.info("Processing image for UAE passport extraction OPENAI......")
220
+ logging.info("Processing image for UAE National ID extraction OPENAI......")
280
221
  logging.info(f" and type: {type(image)}")
281
- try:
282
- image = _image_to_jpeg_bytesio(image)
283
- except Exception as e:
284
- logging.error(f"Error encoding image: {e}")
285
- return {"error": "Image encoding failed"}
286
222
  try:
287
223
  model, prompt = process_image(side)
288
224
  logging.info(f"Using model: {model.__name__} and prompt {prompt[:100]}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: idvpackage
3
- Version: 3.0.11
3
+ Version: 3.0.13
4
4
  Summary: This repository contains a Python program designed to execute Optical Character Recognition (OCR) and Facial Recognition on images.
5
5
  Home-page: https://github.com/NymCard-Payments/project_idv_package
6
6
  Classifier: Programming Language :: Python :: 3
@@ -0,0 +1,34 @@
1
+ idvpackage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ idvpackage/blur_detection.py,sha256=CtLqTtg2azE4YCM8AT1jYJq6QxGoniMO0VkQYIcMtRI,1883
3
+ idvpackage/common.py,sha256=YJUuNS7RZ_FkV7h_6oz7cqGe_EqJvMp-QEUB-7MXLOc,15251
4
+ idvpackage/constants.py,sha256=XvQy5ORGsXoQGcXcvUBC17vpFMzgzleS9S_mDN72G4c,7212
5
+ idvpackage/iraq_id_extraction_withopenai.py,sha256=j7O94q7tpn1Dq_edicsO6ItWcVuRRvuZHBf-CfSc3Vg,21912
6
+ idvpackage/jor_passport_extraction.py,sha256=O3qzYCbgm_tWzPKJc3b9qrH0VrefCQVPKNJdOHYku84,9214
7
+ idvpackage/lebanon_id_extraction.py,sha256=eqWSpfb83RRk5TEhJNOuiPLt-wCLY5L4TvrpkOckSPs,21192
8
+ idvpackage/liveness_spoofing_v2.py,sha256=G3sCu4LkzhJvL33S75sI_QTpc1nA3wo9SqG1elkaIwg,7409
9
+ idvpackage/ocr.py,sha256=EHwScH-aHgtavTCKnMQogKQADthziugB06XloRI2yZE,157208
10
+ idvpackage/ocr_utils.py,sha256=2dXYE8rFl-TnTkNcjqfp5I1MQDvjsvWgrNwwrO18dGA,77383
11
+ idvpackage/pse_passport_extraction.py,sha256=fDrvCzN9PWhqYYvULVD89EYeBWrcMazpzY02uSlus-0,8627
12
+ idvpackage/qatar_id_extraction.py,sha256=iTGB7j8b7aHi69ZlH4pekPD9klavqXxOSZvzwSZBL2M,9044
13
+ idvpackage/sudan_passport_extraction.py,sha256=fgmRLB5WdA9RqQOkP_J2lDMcgDbdKh9L9XQaWC5UQPY,17504
14
+ idvpackage/syr_passport_extraction.py,sha256=ga7wSLi3ydDxHo0GNwCf3-XLg5PqcTW40SS7F8XjLN8,9297
15
+ idvpackage/uae_id_extraction.py,sha256=_kp1FgzEoxvMTCzqXJ5Lej3rlkK6lGPKZCPyQWrscoI,11338
16
+ idvpackage/icons/battery1.png,sha256=cnc3nngw9baelwSeihjzZzAfRhhvzXpDJvrqgLeVYIw,2616
17
+ idvpackage/icons/battery3.png,sha256=2hwjcuhBaskFRuTE0i85wT82wvJ9ftm7ALydrfbMp1A,1187
18
+ idvpackage/icons/network1.png,sha256=2W_DhrNn6HfwyIe4VK-jv5MmMkhzvQ_oR1BOD3FYzmA,1303
19
+ idvpackage/icons/network2.png,sha256=0jdYKl4a41EjDAW0AxN-auPxcxB3CGoI6hTrr7iFNx4,1067
20
+ idvpackage/icons/wifi1.png,sha256=NMk17e66G8EZpYi_i0MKEsW81QfqecGaiQx1C6Y7_Uo,1670
21
+ idvpackage/icons/wifi3.png,sha256=RuHLFYhp265UWEUzsAy_V9omVxFYcPt3P8_JvUSddko,1385
22
+ idvpackage/icons/wifi4.png,sha256=jaTfaGlVu5lktb_souVF6OLuSnCsRIvpfP5gBW0951w,2565
23
+ idvpackage/spoof_resources/2.7_80x80_MiniFASNetV2.pth,sha256=pesC4YQ_GbU4a5U8xMnwEcP5hdDuK7mBnuqaFCCZvsA,1849453
24
+ idvpackage/spoof_resources/4_0_0_80x80_MiniFASNetV1SE.pth,sha256=hO4dN9lolNXoLeWlffBE74Cli-KyGLXtfN_YdewvWZA,1856130
25
+ idvpackage/spoof_resources/MiniFASNet.py,sha256=ZbOVkjsLYqsr90Ac8OV-2G7AwwDm2CUVB1H6WhmTFZ4,12345
26
+ idvpackage/spoof_resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
+ idvpackage/spoof_resources/functional.py,sha256=164aGMvBDHU6HWRyDBr-2EUPeJ4rc4cXl10NJyGB7eE,20138
28
+ idvpackage/spoof_resources/generate_patches.py,sha256=ANvJ5rDl-SXARchS8JwOxuKLhUuabbxLwvz4zsYbADE,1722
29
+ idvpackage/spoof_resources/transform.py,sha256=3Ft9S6g6N0SU24f3feHXquh5qRc85JFt2gNKnCYQwjo,11311
30
+ idvpackage-3.0.13.dist-info/licenses/LICENSE,sha256=JTmNGOPPvG2XBgkW2R2xwzJeR_OEjaFKeePN1jGYVt8,1068
31
+ idvpackage-3.0.13.dist-info/METADATA,sha256=qUpfFenawz8HV7KN7smgbU2s44UFVPOXPX8ZXTS-wq4,4800
32
+ idvpackage-3.0.13.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
33
+ idvpackage-3.0.13.dist-info/top_level.txt,sha256=8jL1PsYvKBIWWLGe8jEm7kU5yZ5sld_OCaz0Dzvi6qY,11
34
+ idvpackage-3.0.13.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
idvpackage/ekyc.py DELETED
@@ -1,78 +0,0 @@
1
- import requests
2
- from idvpackage.constants import *
3
- from idvpackage.ocr_utils import fuzzy_match_fields
4
- import openai
5
-
6
- class Ekyc:
7
-
8
- def __init__(self):
9
- self.maps_endpoint = GOOGLE_MAPS_API_ENDPOINT
10
- self.gmaps_api_key = API_KEY
11
- self.openai_key = OPENAI_API_KEY
12
-
13
- def classify_address(self, address):
14
- openai.api_key = self.openai_key
15
- prompt = f"Consider yourself as an address guide, your task is to do address classification from the address that you receive. you'll only respond in 1 word that is either residential or commercial. here is an address, tell me if this address is residential or commercial: {address}"
16
-
17
- response = openai.ChatCompletion.create(
18
- model="gpt-3.5-turbo-16k",
19
- messages=[
20
- {"role": "user", "content": prompt}
21
- ],
22
- temperature=0.2,
23
- max_tokens=1000
24
- )
25
- return response.choices[0]["message"]["content"]
26
-
27
- def verify_address(self, address):
28
- endpoint = self.maps_endpoint
29
-
30
- params = {
31
- "address": address,
32
- "key": self.gmaps_api_key,
33
- }
34
-
35
- try:
36
- response = requests.get(endpoint, params=params)
37
- data = response.json()
38
- if response.status_code == 200:
39
- if data['status'] == 'OK':
40
- for result in data['results']:
41
- for address_type in result['types']:
42
- # print(result['types'])
43
- # if address_type in ['street_address', 'subpremise', 'premise']:
44
- # return "Residential", result['formatted_address'], result['types']
45
- if address_type in ['food', 'restaurant', 'lodging', 'business', 'general_contractor', 'hair_care', 'health', 'spa']:
46
- return True, "Commercial"
47
-
48
- return True, "Residential"
49
- return False, "Unknown"
50
- else:
51
- return False, None
52
- else:
53
- return False, None
54
-
55
- except Exception as e:
56
- return False, None
57
-
58
- def address_validation(self, user_input_address, utility_bill_address, address_from_other_source):
59
- res1 = fuzzy_match_fields(user_input_address, address_from_other_source)
60
- res2 = fuzzy_match_fields(user_input_address, utility_bill_address)
61
-
62
- if res1 or res2:
63
- return True
64
- else:
65
- return False
66
-
67
- def address_verification_and_validation(self, address):
68
- address = {
69
- 'error': ''
70
- }
71
- result = self.verify_address(address)
72
- classification_result = self.classify_address(address)
73
-
74
- if result and classification_result.lower() == 'residential':
75
- return address
76
-
77
- else:
78
- address['error'] = 'address_caution'