Skip to content

Commit 190fa12

Browse files
committed
✨ add International ID (beta)
1 parent 788851e commit 190fa12

File tree

9 files changed

+232
-36
lines changed

9 files changed

+232
-36
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from mindee import Client, product, AsyncPredictResponse
2+
from time import sleep
3+
4+
# Init a new client
5+
mindee_client = Client(api_key="my-api-key")
6+
7+
# Load a file from disk
8+
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
9+
10+
# Load a file from disk and enqueue it.
11+
result: AsyncPredictResponse = mindee_client.enqueue_and_parse(
12+
product.InternationalIdV1,
13+
input_doc,
14+
)
15+
16+
# Print a brief summary of the parsed data
17+
print(result.document)

docs/extras/guide/invoice_splitter_v1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ The following fields are extracted for Invoice Splitter V1:
8585

8686
```py
8787
for invoice_page_groups_elem in page.prediction.invoice_page_groups):
88-
print(invoice_page_groups_elem.polygon)
88+
print(invoice_page_groups_elem)
8989
```
9090

9191
# Questions?

docs/product/international_id_v1.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
International ID V1
2+
-------------------
3+
4+
**Sample Code:**
5+
6+
.. literalinclude:: /extras/code_samples/international_id_v1.txt
7+
:language: Python
8+
9+
.. autoclass:: mindee.product.international_id.international_id_v1.InternationalIdV1
10+
:members:
11+
:inherited-members:
12+
13+
.. autoclass:: mindee.product.international_id.international_id_v1_document.InternationalIdV1Document
14+
:members:
15+
:inherited-members:

mindee/product/__init__.py

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,29 @@
11
from mindee.product import eu, fr, us
2-
from mindee.product.barcode_reader.barcode_reader_v1 import BarcodeReaderV1
3-
from mindee.product.barcode_reader.barcode_reader_v1_document import (
4-
BarcodeReaderV1Document,
5-
)
6-
from mindee.product.cropper.cropper_v1 import CropperV1
7-
from mindee.product.cropper.cropper_v1_document import CropperV1Document
8-
from mindee.product.custom.custom_v1 import CustomV1
9-
from mindee.product.custom.custom_v1_document import CustomV1Document
10-
from mindee.product.custom.custom_v1_page import CustomV1Page
11-
from mindee.product.financial_document.financial_document_v1 import FinancialDocumentV1
12-
from mindee.product.financial_document.financial_document_v1_document import (
2+
from mindee.product.barcode_reader import BarcodeReaderV1, BarcodeReaderV1Document
3+
from mindee.product.cropper import CropperV1, CropperV1Document
4+
from mindee.product.custom import CustomV1, CustomV1Document, CustomV1Page
5+
from mindee.product.financial_document import (
6+
FinancialDocumentV1,
137
FinancialDocumentV1Document,
14-
)
15-
from mindee.product.financial_document.financial_document_v1_line_item import (
168
FinancialDocumentV1LineItem,
179
)
18-
from mindee.product.invoice.invoice_v4 import InvoiceV4
19-
from mindee.product.invoice.invoice_v4_document import InvoiceV4Document
20-
from mindee.product.invoice_splitter.invoice_splitter_v1 import InvoiceSplitterV1
21-
from mindee.product.invoice_splitter.invoice_splitter_v1_document import (
22-
InvoiceSplitterV1Document,
23-
)
24-
from mindee.product.material_certificate.material_certificate_v1 import (
10+
from mindee.product.international_id import InternationalIdV1, InternationalIdV1Document
11+
from mindee.product.invoice import InvoiceV4, InvoiceV4Document, InvoiceV4LineItem
12+
from mindee.product.invoice_splitter import InvoiceSplitterV1, InvoiceSplitterV1Document
13+
from mindee.product.material_certificate import (
2514
MaterialCertificateV1,
26-
)
27-
from mindee.product.material_certificate.material_certificate_v1_document import (
2815
MaterialCertificateV1Document,
2916
)
30-
from mindee.product.multi_receipts_detector.multi_receipts_detector_v1 import (
17+
from mindee.product.multi_receipts_detector import (
3118
MultiReceiptsDetectorV1,
32-
)
33-
from mindee.product.multi_receipts_detector.multi_receipts_detector_v1_document import (
3419
MultiReceiptsDetectorV1Document,
3520
)
36-
from mindee.product.passport.passport_v1 import PassportV1
37-
from mindee.product.passport.passport_v1_document import PassportV1Document
38-
from mindee.product.proof_of_address.proof_of_address_v1 import ProofOfAddressV1
39-
from mindee.product.proof_of_address.proof_of_address_v1_document import (
40-
ProofOfAddressV1Document,
21+
from mindee.product.passport import PassportV1, PassportV1Document
22+
from mindee.product.proof_of_address import ProofOfAddressV1, ProofOfAddressV1Document
23+
from mindee.product.receipt import (
24+
ReceiptV4,
25+
ReceiptV4Document,
26+
ReceiptV5,
27+
ReceiptV5Document,
28+
ReceiptV5LineItem,
4129
)
42-
from mindee.product.receipt.receipt_v4 import ReceiptV4
43-
from mindee.product.receipt.receipt_v4_document import ReceiptV4Document
44-
from mindee.product.receipt.receipt_v5 import ReceiptV5
45-
from mindee.product.receipt.receipt_v5_document import ReceiptV5Document
46-
from mindee.product.receipt.receipt_v5_line_item import ReceiptV5LineItem
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from mindee.product.international_id.international_id_v1 import InternationalIdV1
2+
from mindee.product.international_id.international_id_v1_document import (
3+
InternationalIdV1Document,
4+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from typing import List
2+
3+
from mindee.parsing.common import Inference, Page, StringDict
4+
from mindee.product.international_id.international_id_v1_document import (
5+
InternationalIdV1Document,
6+
)
7+
8+
9+
class InternationalIdV1(Inference):
10+
"""Inference prediction for International ID, API version 1."""
11+
12+
prediction: InternationalIdV1Document
13+
"""Document-level prediction."""
14+
pages: List[Page[InternationalIdV1Document]]
15+
"""Page-level prediction(s)."""
16+
endpoint_name = "international_id"
17+
"""Name of the endpoint."""
18+
endpoint_version = "1"
19+
"""Version of the endpoint."""
20+
21+
def __init__(self, raw_prediction: StringDict):
22+
"""
23+
International ID v1 inference.
24+
25+
:param raw_prediction: Raw prediction from the HTTP response.
26+
"""
27+
super().__init__(raw_prediction)
28+
29+
self.prediction = InternationalIdV1Document(raw_prediction["prediction"])
30+
self.pages = []
31+
for page in raw_prediction["pages"]:
32+
self.pages.append(Page(InternationalIdV1Document, page))
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
from typing import List, Optional
2+
3+
from mindee.parsing.common import Prediction, StringDict, clean_out_string
4+
from mindee.parsing.standard import ClassificationField, StringField
5+
6+
7+
class InternationalIdV1Document(Prediction):
8+
"""Document data for International ID, API version 1."""
9+
10+
address: StringField
11+
"""The physical location of the document holder's residence."""
12+
birth_date: StringField
13+
"""The date of birth of the document holder."""
14+
birth_place: StringField
15+
"""The location where the document holder was born."""
16+
country_of_issue: StringField
17+
"""The country that issued the identification document."""
18+
document_number: StringField
19+
"""The unique identifier assigned to the identification document."""
20+
document_type: ClassificationField
21+
"""The type of identification document being used."""
22+
expiry_date: StringField
23+
"""The date when the document will no longer be valid for use."""
24+
given_names: List[StringField]
25+
"""The first names or given names of the document holder."""
26+
issue_date: StringField
27+
"""The date when the document was issued."""
28+
mrz1: StringField
29+
"""First line of information in a standardized format for easy machine reading and processing."""
30+
mrz2: StringField
31+
"""Second line of information in a standardized format for easy machine reading and processing."""
32+
mrz3: StringField
33+
"""Third line of information in a standardized format for easy machine reading and processing."""
34+
nationality: StringField
35+
"""Indicates the country of citizenship or nationality of the document holder."""
36+
sex: StringField
37+
"""The document holder's biological sex, such as male or female."""
38+
surnames: List[StringField]
39+
"""The surnames of the document holder."""
40+
41+
def __init__(
42+
self,
43+
raw_prediction: StringDict,
44+
page_id: Optional[int] = None,
45+
):
46+
"""
47+
International ID document.
48+
49+
:param raw_prediction: Raw prediction from HTTP response
50+
:param page_id: Page number for multi pages pdf input
51+
"""
52+
super().__init__(raw_prediction, page_id)
53+
self.address = StringField(
54+
raw_prediction["address"],
55+
page_id=page_id,
56+
)
57+
self.birth_date = StringField(
58+
raw_prediction["birth_date"],
59+
page_id=page_id,
60+
)
61+
self.birth_place = StringField(
62+
raw_prediction["birth_place"],
63+
page_id=page_id,
64+
)
65+
self.country_of_issue = StringField(
66+
raw_prediction["country_of_issue"],
67+
page_id=page_id,
68+
)
69+
self.document_number = StringField(
70+
raw_prediction["document_number"],
71+
page_id=page_id,
72+
)
73+
self.document_type = ClassificationField(
74+
raw_prediction["document_type"],
75+
page_id=page_id,
76+
)
77+
self.expiry_date = StringField(
78+
raw_prediction["expiry_date"],
79+
page_id=page_id,
80+
)
81+
self.given_names = [
82+
StringField(prediction, page_id=page_id)
83+
for prediction in raw_prediction["given_names"]
84+
]
85+
self.issue_date = StringField(
86+
raw_prediction["issue_date"],
87+
page_id=page_id,
88+
)
89+
self.mrz1 = StringField(
90+
raw_prediction["mrz1"],
91+
page_id=page_id,
92+
)
93+
self.mrz2 = StringField(
94+
raw_prediction["mrz2"],
95+
page_id=page_id,
96+
)
97+
self.mrz3 = StringField(
98+
raw_prediction["mrz3"],
99+
page_id=page_id,
100+
)
101+
self.nationality = StringField(
102+
raw_prediction["nationality"],
103+
page_id=page_id,
104+
)
105+
self.sex = StringField(
106+
raw_prediction["sex"],
107+
page_id=page_id,
108+
)
109+
self.surnames = [
110+
StringField(prediction, page_id=page_id)
111+
for prediction in raw_prediction["surnames"]
112+
]
113+
114+
def __str__(self) -> str:
115+
given_names = f"\n { ' ' * 13 }".join(
116+
[str(item) for item in self.given_names],
117+
)
118+
surnames = f"\n { ' ' * 10 }".join(
119+
[str(item) for item in self.surnames],
120+
)
121+
out_str: str = f":Document Type: {self.document_type}\n"
122+
out_str += f":Document Number: {self.document_number}\n"
123+
out_str += f":Country of Issue: {self.country_of_issue}\n"
124+
out_str += f":Surnames: {surnames}\n"
125+
out_str += f":Given Names: {given_names}\n"
126+
out_str += f":Gender: {self.sex}\n"
127+
out_str += f":Birth date: {self.birth_date}\n"
128+
out_str += f":Birth Place: {self.birth_place}\n"
129+
out_str += f":Nationality: {self.nationality}\n"
130+
out_str += f":Issue Date: {self.issue_date}\n"
131+
out_str += f":Expiry Date: {self.expiry_date}\n"
132+
out_str += f":Address: {self.address}\n"
133+
out_str += f":Machine Readable Zone Line 1: {self.mrz1}\n"
134+
out_str += f":Machine Readable Zone Line 2: {self.mrz2}\n"
135+
out_str += f":Machine Readable Zone Line 3: {self.mrz3}\n"
136+
return clean_out_string(out_str)

mindee/product/invoice/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from mindee.product.invoice.invoice_v4 import InvoiceV4
2+
from mindee.product.invoice.invoice_v4_document import InvoiceV4Document
3+
from mindee.product.invoice.invoice_v4_line_item import InvoiceV4LineItem
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
from mindee.product.invoice_splitter.invoice_splitter_v1 import InvoiceSplitterV1
2+
from mindee.product.invoice_splitter.invoice_splitter_v1_document import (
3+
InvoiceSplitterV1Document,
4+
)
5+
from mindee.product.invoice_splitter.invoice_splitter_v1_page_group import (
6+
InvoiceSplitterV1PageGroup,
7+
)

0 commit comments

Comments
 (0)