Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/extras/code_samples/bank_check_v1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mindee_client = Client(api_key="my-api-key")
# Load a file from disk
input_doc = mindee_client.doc_from_path("/path/to/the/file.ext")

# Parse the US Bank Check Details by passing the appropriate type
# Parse the Bank Check by passing the appropriate type
result = input_doc.parse(documents.us.TypeBankCheckV1)

# Print a brief summary of the parsed data
Expand Down
1 change: 0 additions & 1 deletion docs/predictions/standard/documents/us/bank_check_v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ Bank Check V1

.. autoclass:: mindee.documents.us.BankCheckV1
:members:
:undoc-members:
45 changes: 25 additions & 20 deletions mindee/documents/cropper/cropper_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
class CropperV1(Document):
"""Cropper v1 prediction results."""

cropping: List[PositionField]
"""List of all detected cropped elements in the image"""
cropping: List[PositionField] = []
"""List of documents found in the image."""

def __init__(
self,
api_prediction: TypeApiPrediction,
api_prediction=None,
input_source=None,
page_n: Optional[int] = None,
):
"""
Custom document object.
Cropper v1 prediction results.

:param document_type: Document type
:param api_prediction: Raw prediction from HTTP response
:param input_source: Input object
:param page_n: Page number for multi pages pdf input
Expand All @@ -35,27 +34,33 @@ def __init__(
def _build_from_api_prediction(
self, api_prediction: TypeApiPrediction, page_n: Optional[int] = None
) -> None:
"""Build the document from an API response JSON."""
self.cropping = []
"""
Build the object from the prediction API JSON.

# cropping is only present on pages
:param api_prediction: Raw prediction from HTTP response
:param page_n: Page number
"""
if page_n is None:
return

for crop in api_prediction["cropping"]:
self.cropping.append(PositionField(prediction=crop))
self.cropping = [
PositionField(prediction, page_id=page_n)
for prediction in api_prediction["cropping"]
]

def _checklist(self) -> None:
pass

def __str__(self):
cropping = "\n ".join([str(crop) for crop in self.cropping])
def __str__(self) -> str:
cropping = f"\n { ' ' * 18 }".join(
[str(item) for item in self.cropping],
)
return clean_out_string(
"----- Cropper Data -----\n"
f"Filename: {self.filename or ''}\n"
f"Cropping: {cropping}\n"
"------------------------"
"Cropper V1 Prediction\n"
"=====================\n"
f":Filename: {self.filename or ''}\n"
f":Document Cropper: {cropping}\n"
)


TypeCropperV1 = TypeVar("TypeCropperV1", bound=CropperV1)
TypeCropperV1 = TypeVar(
"TypeCropperV1",
bound=CropperV1,
)
10 changes: 6 additions & 4 deletions mindee/documents/custom/custom_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ def _build_from_api_prediction(
self.fields[field_name] = ListField(prediction=field, page_n=page_n)

def __str__(self) -> str:
custom_doc_str = f"----- {self.type} -----\nFilename: {self.filename or ''}\n"
custom_doc_str = f"{self.type} V1 Prediction"
custom_doc_str += "\n" + "=" * len(custom_doc_str)
custom_doc_str += f"\n:Filename: {self.filename or ''}\n"

for class_name, class_info in self.classifications.items():
custom_doc_str += f"{class_name}: {class_info}\n"
custom_doc_str += f":{class_name}: {class_info}\n"
for field_name, field_info in self.fields.items():
custom_doc_str += f"{field_name}: {field_info}\n"
custom_doc_str += "----------------------"
custom_doc_str += f":{field_name}: {field_info}\n"
return clean_out_string(custom_doc_str)


Expand Down
17 changes: 10 additions & 7 deletions mindee/documents/eu/license_plate/license_plate_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ def _build_from_api_prediction(
]

def __str__(self) -> str:
license_plates = f"\n { ' ' * 15 }".join(
[str(item) for item in self.license_plates]
license_plates = f"\n { ' ' * 16 }".join(
[str(item) for item in self.license_plates],
)
return clean_out_string(
"----- EU License Plate V1 -----\n"
f"Filename: {self.filename or ''}\n"
f"License Plates: { license_plates }\n"
"----------------------"
"EU License Plate V1 Prediction\n"
"==============================\n"
f":Filename: {self.filename or ''}\n"
f":License Plates: {license_plates}\n"
)


TypeLicensePlateV1 = TypeVar("TypeLicensePlateV1", bound=LicensePlateV1)
TypeLicensePlateV1 = TypeVar(
"TypeLicensePlateV1",
bound=LicensePlateV1,
)
13 changes: 8 additions & 5 deletions mindee/documents/financial_document/financial_document_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ def _line_items_to_str(self) -> str:
return out_str

def __str__(self) -> str:
customer_company_registrations = f"\n { ' ' * 31 }".join(
customer_company_registrations = f"\n { ' ' * 32 }".join(
[str(item) for item in self.customer_company_registrations],
)
reference_numbers = f"\n { ' ' * 18 }".join(
reference_numbers = f"\n { ' ' * 19 }".join(
[str(item) for item in self.reference_numbers],
)
supplier_company_registrations = f"\n { ' ' * 31 }".join(
supplier_company_registrations = f"\n { ' ' * 32 }".join(
[str(item) for item in self.supplier_company_registrations],
)
supplier_payment_details = f"\n { ' ' * 25 }".join(
supplier_payment_details = f"\n { ' ' * 26 }".join(
[str(item) for item in self.supplier_payment_details],
)
return clean_out_string(
Expand Down Expand Up @@ -259,4 +259,7 @@ def __str__(self) -> str:
)


TypeFinancialDocumentV1 = TypeVar("TypeFinancialDocumentV1", bound=FinancialDocumentV1)
TypeFinancialDocumentV1 = TypeVar(
"TypeFinancialDocumentV1",
bound=FinancialDocumentV1,
)
27 changes: 14 additions & 13 deletions mindee/documents/fr/bank_account_details/bank_account_details_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
class BankAccountDetailsV1(Document):
"""Bank Account Details v1 prediction results."""

iban: TextField
"""The International Bank Account Number (IBAN)."""
account_holder_name: TextField
"""The name of the account holder as seen on the document."""
iban: TextField
"""The International Bank Account Number (IBAN)."""
swift: TextField
"""The bank's SWIFT Business Identifier Code (BIC)."""

Expand Down Expand Up @@ -44,30 +44,31 @@ def _build_from_api_prediction(
:param api_prediction: Raw prediction from HTTP response
:param page_n: Page number
"""
self.iban = TextField(
api_prediction["iban"],
page_id=page_n,
)
self.account_holder_name = TextField(
api_prediction["account_holder_name"],
page_id=page_n,
)
self.iban = TextField(
api_prediction["iban"],
page_id=page_n,
)
self.swift = TextField(
api_prediction["swift"],
page_id=page_n,
)

def __str__(self) -> str:
return clean_out_string(
"----- FR Bank Account Details V1 -----\n"
f"Filename: {self.filename or ''}\n"
f"IBAN: { self.iban }\n"
f"Account Holder's Name: { self.account_holder_name }\n"
f"SWIFT Code: { self.swift }\n"
"----------------------"
"FR Bank Account Details V1 Prediction\n"
"=====================================\n"
f":Filename: {self.filename or ''}\n"
f":IBAN: {self.iban}\n"
f":Account Holder's Name: {self.account_holder_name}\n"
f":SWIFT Code: {self.swift}\n"
)


TypeBankAccountDetailsV1 = TypeVar(
"TypeBankAccountDetailsV1", bound=BankAccountDetailsV1
"TypeBankAccountDetailsV1",
bound=BankAccountDetailsV1,
)
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ def __str__(self) -> str:


TypeBankAccountDetailsV2 = TypeVar(
"TypeBankAccountDetailsV2", bound=BankAccountDetailsV2
"TypeBankAccountDetailsV2",
bound=BankAccountDetailsV2,
)
39 changes: 22 additions & 17 deletions mindee/documents/fr/carte_vitale/carte_vitale_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class CarteVitaleV1(Document):

given_names: List[TextField]
"""The given name(s) of the card holder."""
surname: TextField
"""The surname of the card holder."""
social_security: TextField
"""The Social Security Number (Numéro de Sécurité Sociale) of the card holder"""
issuance_date: DateField
"""The date the card was issued."""
social_security: TextField
"""The Social Security Number (Numéro de Sécurité Sociale) of the card holder"""
surname: TextField
"""The surname of the card holder."""

def __init__(
self,
Expand Down Expand Up @@ -51,30 +51,35 @@ def _build_from_api_prediction(
TextField(prediction, page_id=page_n)
for prediction in api_prediction["given_names"]
]
self.surname = TextField(
api_prediction["surname"],
self.issuance_date = DateField(
api_prediction["issuance_date"],
page_id=page_n,
)
self.social_security = TextField(
api_prediction["social_security"],
page_id=page_n,
)
self.issuance_date = DateField(
api_prediction["issuance_date"],
self.surname = TextField(
api_prediction["surname"],
page_id=page_n,
)

def __str__(self) -> str:
given_names = "\n".join([str(item) for item in self.given_names])
given_names = f"\n { ' ' * 15 }".join(
[str(item) for item in self.given_names],
)
return clean_out_string(
"----- FR Carte Vitale V1 -----\n"
f"Filename: {self.filename or ''}\n"
f"Given Name(s): { given_names }\n"
f"Surname: { self.surname }\n"
f"Social Security Number: { self.social_security }\n"
f"Issuance Date: { self.issuance_date }\n"
"----------------------"
"FR Carte Vitale V1 Prediction\n"
"=============================\n"
f":Filename: {self.filename or ''}\n"
f":Given Name(s): {given_names}\n"
f":Surname: {self.surname}\n"
f":Social Security Number: {self.social_security}\n"
f":Issuance Date: {self.issuance_date}\n"
)


TypeCarteVitaleV1 = TypeVar("TypeCarteVitaleV1", bound=CarteVitaleV1)
TypeCarteVitaleV1 = TypeVar(
"TypeCarteVitaleV1",
bound=CarteVitaleV1,
)
37 changes: 21 additions & 16 deletions mindee/documents/fr/id_card/id_card_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,28 @@ def _build_from_api_prediction(
)

def __str__(self) -> str:
given_names = "\n".join([str(item) for item in self.given_names])
given_names = f"\n { ' ' * 15 }".join(
[str(item) for item in self.given_names],
)
return clean_out_string(
"----- FR Carte Nationale d'Identité V1 -----\n"
f"Filename: {self.filename or ''}\n"
f"Document Side: { self.document_side }\n"
f"Identity Number: { self.id_number }\n"
f"Given Name(s): { given_names }\n"
f"Surname: { self.surname }\n"
f"Date of Birth: { self.birth_date }\n"
f"Place of Birth: { self.birth_place }\n"
f"Expiry Date: { self.expiry_date }\n"
f"Issuing Authority: { self.authority }\n"
f"Gender: { self.gender }\n"
f"MRZ Line 1: { self.mrz1 }\n"
f"MRZ Line 2: { self.mrz2 }\n"
"----------------------"
"FR Carte Nationale d'Identité V1 Prediction\n"
"===========================================\n"
f":Filename: {self.filename or ''}\n"
f":Document Side: {self.document_side}\n"
f":Identity Number: {self.id_number}\n"
f":Given Name(s): {given_names}\n"
f":Surname: {self.surname}\n"
f":Date of Birth: {self.birth_date}\n"
f":Place of Birth: {self.birth_place}\n"
f":Expiry Date: {self.expiry_date}\n"
f":Issuing Authority: {self.authority}\n"
f":Gender: {self.gender}\n"
f":MRZ Line 1: {self.mrz1}\n"
f":MRZ Line 2: {self.mrz2}\n"
)


TypeIdCardV1 = TypeVar("TypeIdCardV1", bound=IdCardV1)
TypeIdCardV1 = TypeVar(
"TypeIdCardV1",
bound=IdCardV1,
)
11 changes: 6 additions & 5 deletions mindee/documents/invoice_splitter/invoice_splitter_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, prediction: Dict[str, Any]):
pass

def __str__(self) -> str:
return f"page indexes: {', '.join([str(page_index) for page_index in self.page_indexes])}"
return f":Page indexes: {', '.join([str(page_index) for page_index in self.page_indexes])}"


class InvoiceSplitterV1(Document):
Expand Down Expand Up @@ -61,17 +61,18 @@ def _build_from_api_prediction(
]

def __str__(self) -> str:
invoice_page_groups = ""
if len(self.invoice_page_groups) > 0:
invoice_page_groups = "\n "
invoice_page_groups += f"\n{ ' ' * 2 }".join(
[str(ivp) for ivp in self.invoice_page_groups]
)

return clean_out_string(
f"----- Invoice Splitter V1 -----\n"
f"Filename: {self.filename or ''}\n"
f"Invoice Page Groups: {invoice_page_groups}\n"
f"----------------------"
"Invoice Splitter V1 Prediction\n"
"==============================\n"
f":Filename: {self.filename or ''}\n"
f":Invoice Page Groups: {invoice_page_groups}\n"
)


Expand Down
Loading