From bb70d3064ba6923affa4b385d35a22e78c6cbb4d Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Thu, 13 Mar 2025 18:26:54 +0100 Subject: [PATCH 1/2] :coffin: deprecate: Receipt V4, US Driver License, EU Driver License --- .../code_samples/eu_driver_license_v1.txt | 17 -- .../extras/code_samples/license_plates_v1.txt | 17 -- .../code_samples/us_driver_license_v1.txt | 17 -- docs/extras/guide/license_plates_v1.md | 94 ----------- docs/product/eu/driver_license_v1.rst | 19 --- docs/product/eu/index.rst | 8 - docs/product/eu/license_plate_v1.rst | 15 -- docs/product/index.rst | 2 +- docs/product/receipt_v4.rst | 16 -- docs/product/us/driver_license_v1.rst | 19 --- mindee/commands/cli_products.py | 6 - mindee/product/__init__.py | 4 +- mindee/product/eu/__init__.py | 9 -- mindee/product/eu/driver_license/__init__.py | 5 - .../eu/driver_license/driver_license_v1.py | 42 ----- .../driver_license_v1_document.py | 112 ------------- .../driver_license/driver_license_v1_page.py | 44 ------ mindee/product/eu/license_plate/__init__.py | 4 - .../eu/license_plate/license_plate_v1.py | 39 ----- .../license_plate_v1_document.py | 37 ----- mindee/product/receipt/__init__.py | 2 - mindee/product/receipt/receipt_v4.py | 34 ---- mindee/product/receipt/receipt_v4_document.py | 88 ----------- mindee/product/us/__init__.py | 5 - mindee/product/us/driver_license/__init__.py | 5 - .../us/driver_license/driver_license_v1.py | 42 ----- .../driver_license_v1_document.py | 147 ------------------ .../driver_license/driver_license_v1_page.py | 44 ------ tests/api/test_response.py | 16 +- tests/product/eu/__init__.py | 0 tests/product/eu/driver_license/__init__.py | 0 .../driver_license/test_driver_license_v1.py | 77 --------- tests/product/eu/license_plate/__init__.py | 0 .../eu/license_plate/test_license_plate_v1.py | 46 ------ .../test_license_plate_v1_regression.py | 24 --- tests/product/receipt/test_receipt_v4.py | 69 -------- tests/product/us/driver_license/__init__.py | 0 .../driver_license/test_driver_license_v1.py | 82 ---------- .../test_driver_license_v1_regression.py | 24 --- tests/test_client.py | 12 +- 40 files changed, 16 insertions(+), 1227 deletions(-) delete mode 100644 docs/extras/code_samples/eu_driver_license_v1.txt delete mode 100644 docs/extras/code_samples/license_plates_v1.txt delete mode 100644 docs/extras/code_samples/us_driver_license_v1.txt delete mode 100644 docs/extras/guide/license_plates_v1.md delete mode 100644 docs/product/eu/driver_license_v1.rst delete mode 100644 docs/product/eu/index.rst delete mode 100644 docs/product/eu/license_plate_v1.rst delete mode 100644 docs/product/receipt_v4.rst delete mode 100644 docs/product/us/driver_license_v1.rst delete mode 100644 mindee/product/eu/__init__.py delete mode 100644 mindee/product/eu/driver_license/__init__.py delete mode 100644 mindee/product/eu/driver_license/driver_license_v1.py delete mode 100644 mindee/product/eu/driver_license/driver_license_v1_document.py delete mode 100644 mindee/product/eu/driver_license/driver_license_v1_page.py delete mode 100644 mindee/product/eu/license_plate/__init__.py delete mode 100644 mindee/product/eu/license_plate/license_plate_v1.py delete mode 100644 mindee/product/eu/license_plate/license_plate_v1_document.py delete mode 100644 mindee/product/receipt/receipt_v4.py delete mode 100644 mindee/product/receipt/receipt_v4_document.py delete mode 100644 mindee/product/us/driver_license/__init__.py delete mode 100644 mindee/product/us/driver_license/driver_license_v1.py delete mode 100644 mindee/product/us/driver_license/driver_license_v1_document.py delete mode 100644 mindee/product/us/driver_license/driver_license_v1_page.py delete mode 100644 tests/product/eu/__init__.py delete mode 100644 tests/product/eu/driver_license/__init__.py delete mode 100644 tests/product/eu/driver_license/test_driver_license_v1.py delete mode 100644 tests/product/eu/license_plate/__init__.py delete mode 100644 tests/product/eu/license_plate/test_license_plate_v1.py delete mode 100644 tests/product/eu/license_plate/test_license_plate_v1_regression.py delete mode 100644 tests/product/receipt/test_receipt_v4.py delete mode 100644 tests/product/us/driver_license/__init__.py delete mode 100644 tests/product/us/driver_license/test_driver_license_v1.py delete mode 100644 tests/product/us/driver_license/test_driver_license_v1_regression.py diff --git a/docs/extras/code_samples/eu_driver_license_v1.txt b/docs/extras/code_samples/eu_driver_license_v1.txt deleted file mode 100644 index afdc97a1..00000000 --- a/docs/extras/code_samples/eu_driver_license_v1.txt +++ /dev/null @@ -1,17 +0,0 @@ -from mindee import Client, PredictResponse, product - -# Init a new client -mindee_client = Client(api_key="my-api-key") - -# Load a file from disk -input_doc = mindee_client.source_from_path("/path/to/the/file.ext") - -# Load a file from disk and parse it. -# The endpoint name must be specified since it cannot be determined from the class. -result: PredictResponse = mindee_client.parse(product.eu.DriverLicenseV1, input_doc) - -# Print a summary of the API result -print(result.document) - -# Print the document-level summary -# print(result.document.inference.prediction) diff --git a/docs/extras/code_samples/license_plates_v1.txt b/docs/extras/code_samples/license_plates_v1.txt deleted file mode 100644 index 2d41b7be..00000000 --- a/docs/extras/code_samples/license_plates_v1.txt +++ /dev/null @@ -1,17 +0,0 @@ -from mindee import Client, PredictResponse, product - -# Init a new client -mindee_client = Client(api_key="my-api-key") - -# Load a file from disk -input_doc = mindee_client.source_from_path("/path/to/the/file.ext") - -# Load a file from disk and parse it. -# The endpoint name must be specified since it cannot be determined from the class. -result: PredictResponse = mindee_client.parse(product.eu.LicensePlateV1, input_doc) - -# Print a summary of the API result -print(result.document) - -# Print the document-level summary -# print(result.document.inference.prediction) diff --git a/docs/extras/code_samples/us_driver_license_v1.txt b/docs/extras/code_samples/us_driver_license_v1.txt deleted file mode 100644 index 094b6616..00000000 --- a/docs/extras/code_samples/us_driver_license_v1.txt +++ /dev/null @@ -1,17 +0,0 @@ -from mindee import Client, PredictResponse, product - -# Init a new client -mindee_client = Client(api_key="my-api-key") - -# Load a file from disk -input_doc = mindee_client.source_from_path("/path/to/the/file.ext") - -# Load a file from disk and parse it. -# The endpoint name must be specified since it cannot be determined from the class. -result: PredictResponse = mindee_client.parse(product.us.DriverLicenseV1, input_doc) - -# Print a summary of the API result -print(result.document) - -# Print the document-level summary -# print(result.document.inference.prediction) diff --git a/docs/extras/guide/license_plates_v1.md b/docs/extras/guide/license_plates_v1.md deleted file mode 100644 index 44908e27..00000000 --- a/docs/extras/guide/license_plates_v1.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: EU License Plate OCR Python -category: 622b805aaec68102ea7fcbc2 -slug: python-eu-license-plate-ocr -parentDoc: 609808f773b0b90051d839de ---- -The Python OCR SDK supports the [License Plate API](https://platform.mindee.com/mindee/license_plates). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/license_plates/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![License Plate sample](https://github.com/mindee/client-lib-test-data/blob/main/products/license_plates/default_sample.jpg?raw=true) - -# Quick-Start -```py -from mindee import Client, PredictResponse, product - -# Init a new client -mindee_client = Client(api_key="my-api-key") - -# Load a file from disk -input_doc = mindee_client.source_from_path("/path/to/the/file.ext") - -# Load a file from disk and parse it. -# The endpoint name must be specified since it cannot be determined from the class. -result: PredictResponse = mindee_client.parse(product.eu.LicensePlateV1, input_doc) - -# Print a summary of the API result -print(result.document) - -# Print the document-level summary -# print(result.document.inference.prediction) - -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: f0f48232-2c80-4473-9c6f-88a09111b84d -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/license_plates v1.0 -:Rotation applied: No - -Prediction -========== -:License Plates: BY-323-YB - -Page Predictions -================ - -Page 0 ------- -:License Plates: BY-323-YB -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### BaseField -Each prediction object contains a set of fields that inherit from the generic `BaseField` class. -A typical `BaseField` object will have the following attributes: - -* **value** (`Union[float, str]`): corresponds to the field value. Can be `None` if no value was extracted. -* **confidence** (`float`): the confidence score of the field prediction. -* **bounding_box** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`List[Point]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **page_id** (`int`): the ID of the page, always `None` when at document-level. -* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to a List of two numbers (`[float, float]`). - - -Aside from the previous attributes, all basic fields have access to a custom `__str__` method that can be used to print their value as a string. - -### StringField -The text field `StringField` only has one constraint: its **value** is an `Optional[str]`. - -# Attributes -The following fields are extracted for License Plate V1: - -## License Plates -**license_plates** (List[[StringField](#stringfield)]): List of all license plates found in the image. - -```py -for license_plates_elem in result.document.inference.prediction.license_plates: - print(license_plates_elem.value) -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/product/eu/driver_license_v1.rst b/docs/product/eu/driver_license_v1.rst deleted file mode 100644 index cc80c653..00000000 --- a/docs/product/eu/driver_license_v1.rst +++ /dev/null @@ -1,19 +0,0 @@ -Driver License V1 ------------------ - -**Sample Code:** - -.. literalinclude:: /extras/code_samples/eu_driver_license_v1.txt - :language: Python - -.. autoclass:: mindee.product.eu.driver_license.driver_license_v1.DriverLicenseV1 - :members: - :inherited-members: - -.. autoclass:: mindee.product.eu.driver_license.driver_license_v1_document.DriverLicenseV1Document - :members: - :inherited-members: - -.. autoclass:: mindee.product.eu.driver_license.driver_license_v1_page.DriverLicenseV1Page - :members: - :inherited-members: diff --git a/docs/product/eu/index.rst b/docs/product/eu/index.rst deleted file mode 100644 index 2b81379e..00000000 --- a/docs/product/eu/index.rst +++ /dev/null @@ -1,8 +0,0 @@ -Europe ------- - -.. toctree:: - :maxdepth: 1 - :glob: - - ./* diff --git a/docs/product/eu/license_plate_v1.rst b/docs/product/eu/license_plate_v1.rst deleted file mode 100644 index 29adb635..00000000 --- a/docs/product/eu/license_plate_v1.rst +++ /dev/null @@ -1,15 +0,0 @@ -License Plate V1 ----------------- - -**Sample Code:** - -.. literalinclude:: /extras/code_samples/license_plates_v1.txt - :language: Python - -.. autoclass:: mindee.product.eu.license_plate.license_plate_v1.LicensePlateV1 - :members: - :inherited-members: - -.. autoclass:: mindee.product.eu.license_plate.license_plate_v1_document.LicensePlateV1Document - :members: - :inherited-members: diff --git a/docs/product/index.rst b/docs/product/index.rst index c2b5c293..a63ff603 100644 --- a/docs/product/index.rst +++ b/docs/product/index.rst @@ -10,7 +10,7 @@ Region-Specific :maxdepth: 1 ./fr/index - ./eu/index + ./ind/index ./us/index International diff --git a/docs/product/receipt_v4.rst b/docs/product/receipt_v4.rst deleted file mode 100644 index 92bdfda5..00000000 --- a/docs/product/receipt_v4.rst +++ /dev/null @@ -1,16 +0,0 @@ -Receipt V4 ----------- - -**Sample Code:** - -.. literalinclude:: /extras/code_samples/expense_receipts_v4.txt - :language: Python - -.. autoclass:: mindee.product.receipt.receipt_v4.ReceiptV4 - :members: - :inherited-members: - -.. autoclass:: mindee.product.receipt.receipt_v4_document.ReceiptV4Document - :members: - :inherited-members: - diff --git a/docs/product/us/driver_license_v1.rst b/docs/product/us/driver_license_v1.rst deleted file mode 100644 index fd57bbe5..00000000 --- a/docs/product/us/driver_license_v1.rst +++ /dev/null @@ -1,19 +0,0 @@ -Driver License V1 ------------------ - -**Sample Code:** - -.. literalinclude:: /extras/code_samples/us_driver_license_v1.txt - :language: Python - -.. autoclass:: mindee.product.us.driver_license.driver_license_v1.DriverLicenseV1 - :members: - :inherited-members: - -.. autoclass:: mindee.product.us.driver_license.driver_license_v1_document.DriverLicenseV1Document - :members: - :inherited-members: - -.. autoclass:: mindee.product.us.driver_license.driver_license_v1_page.DriverLicenseV1Page - :members: - :inherited-members: diff --git a/mindee/commands/cli_products.py b/mindee/commands/cli_products.py index f7498c76..7bb377ea 100644 --- a/mindee/commands/cli_products.py +++ b/mindee/commands/cli_products.py @@ -40,12 +40,6 @@ class CommandConfig(Generic[TypeInference]): is_sync=True, is_async=False, ), - "eu-license-plate": CommandConfig( - help="EU License Plate", - doc_class=product.eu.LicensePlateV1, - is_sync=True, - is_async=False, - ), "driver-license": CommandConfig( help="Driver License", doc_class=product.DriverLicenseV1, diff --git a/mindee/product/__init__.py b/mindee/product/__init__.py index 84b61c23..98f6188c 100644 --- a/mindee/product/__init__.py +++ b/mindee/product/__init__.py @@ -1,4 +1,4 @@ -from mindee.product import eu, fr, ind, us +from mindee.product import fr, ind, us from mindee.product.barcode_reader import BarcodeReaderV1, BarcodeReaderV1Document from mindee.product.bill_of_lading import ( BillOfLadingV1, @@ -51,8 +51,6 @@ from mindee.product.passport import PassportV1, PassportV1Document from mindee.product.proof_of_address import ProofOfAddressV1, ProofOfAddressV1Document from mindee.product.receipt import ( - ReceiptV4, - ReceiptV4Document, ReceiptV5, ReceiptV5Document, ReceiptV5LineItem, diff --git a/mindee/product/eu/__init__.py b/mindee/product/eu/__init__.py deleted file mode 100644 index 72cd828e..00000000 --- a/mindee/product/eu/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -from mindee.product.eu.driver_license.driver_license_v1 import DriverLicenseV1 -from mindee.product.eu.driver_license.driver_license_v1_document import ( - DriverLicenseV1Document, -) -from mindee.product.eu.driver_license.driver_license_v1_page import DriverLicenseV1Page -from mindee.product.eu.license_plate.license_plate_v1 import LicensePlateV1 -from mindee.product.eu.license_plate.license_plate_v1_document import ( - LicensePlateV1Document, -) diff --git a/mindee/product/eu/driver_license/__init__.py b/mindee/product/eu/driver_license/__init__.py deleted file mode 100644 index af844240..00000000 --- a/mindee/product/eu/driver_license/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from mindee.product.eu.driver_license.driver_license_v1 import DriverLicenseV1 -from mindee.product.eu.driver_license.driver_license_v1_document import ( - DriverLicenseV1Document, -) -from mindee.product.eu.driver_license.driver_license_v1_page import DriverLicenseV1Page diff --git a/mindee/product/eu/driver_license/driver_license_v1.py b/mindee/product/eu/driver_license/driver_license_v1.py deleted file mode 100644 index ece001ed..00000000 --- a/mindee/product/eu/driver_license/driver_license_v1.py +++ /dev/null @@ -1,42 +0,0 @@ -from typing import List - -from mindee.parsing.common.inference import Inference -from mindee.parsing.common.page import Page -from mindee.parsing.common.string_dict import StringDict -from mindee.product.eu.driver_license.driver_license_v1_document import ( - DriverLicenseV1Document, -) -from mindee.product.eu.driver_license.driver_license_v1_page import ( - DriverLicenseV1Page, -) - - -class DriverLicenseV1(Inference): - """Driver License API version 1 inference prediction.""" - - prediction: DriverLicenseV1Document - """Document-level prediction.""" - pages: List[Page[DriverLicenseV1Page]] - """Page-level prediction(s).""" - endpoint_name = "eu_driver_license" - """Name of the endpoint.""" - endpoint_version = "1" - """Version of the endpoint.""" - - def __init__(self, raw_prediction: StringDict): - """ - Driver License v1 inference. - - :param raw_prediction: Raw prediction from the HTTP response. - """ - super().__init__(raw_prediction) - - self.prediction = DriverLicenseV1Document(raw_prediction["prediction"]) - self.pages = [] - for page in raw_prediction["pages"]: - try: - page_prediction = page["prediction"] - except KeyError: - continue - if page_prediction: - self.pages.append(Page(DriverLicenseV1Page, page)) diff --git a/mindee/product/eu/driver_license/driver_license_v1_document.py b/mindee/product/eu/driver_license/driver_license_v1_document.py deleted file mode 100644 index 6754dec1..00000000 --- a/mindee/product/eu/driver_license/driver_license_v1_document.py +++ /dev/null @@ -1,112 +0,0 @@ -from typing import Optional - -from mindee.parsing.common.prediction import Prediction -from mindee.parsing.common.string_dict import StringDict -from mindee.parsing.common.summary_helper import clean_out_string -from mindee.parsing.standard.date import DateField -from mindee.parsing.standard.text import StringField - - -class DriverLicenseV1Document(Prediction): - """Driver License API version 1.0 document data.""" - - address: StringField - """EU driver license holders address""" - category: StringField - """EU driver license holders categories""" - country_code: StringField - """Country code extracted as a string.""" - date_of_birth: DateField - """The date of birth of the document holder""" - document_id: StringField - """ID number of the Document.""" - expiry_date: DateField - """Date the document expires""" - first_name: StringField - """First name(s) of the driver license holder""" - issue_authority: StringField - """Authority that issued the document""" - issue_date: DateField - """Date the document was issued""" - last_name: StringField - """Last name of the driver license holder.""" - mrz: StringField - """Machine-readable license number""" - place_of_birth: StringField - """Place where the driver license holder was born""" - - def __init__( - self, - raw_prediction: StringDict, - page_id: Optional[int] = None, - ): - """ - Driver License document. - - :param raw_prediction: Raw prediction from HTTP response - :param page_id: Page number for multi pages pdf input - """ - super().__init__(raw_prediction, page_id) - self.address = StringField( - raw_prediction["address"], - page_id=page_id, - ) - self.category = StringField( - raw_prediction["category"], - page_id=page_id, - ) - self.country_code = StringField( - raw_prediction["country_code"], - page_id=page_id, - ) - self.date_of_birth = DateField( - raw_prediction["date_of_birth"], - page_id=page_id, - ) - self.document_id = StringField( - raw_prediction["document_id"], - page_id=page_id, - ) - self.expiry_date = DateField( - raw_prediction["expiry_date"], - page_id=page_id, - ) - self.first_name = StringField( - raw_prediction["first_name"], - page_id=page_id, - ) - self.issue_authority = StringField( - raw_prediction["issue_authority"], - page_id=page_id, - ) - self.issue_date = DateField( - raw_prediction["issue_date"], - page_id=page_id, - ) - self.last_name = StringField( - raw_prediction["last_name"], - page_id=page_id, - ) - self.mrz = StringField( - raw_prediction["mrz"], - page_id=page_id, - ) - self.place_of_birth = StringField( - raw_prediction["place_of_birth"], - page_id=page_id, - ) - - def __str__(self) -> str: - out_str: str = f":Country Code: {self.country_code}\n" - out_str += f":Document ID: {self.document_id}\n" - out_str += f":Driver License Category: {self.category}\n" - out_str += f":Last Name: {self.last_name}\n" - out_str += f":First Name: {self.first_name}\n" - out_str += f":Date Of Birth: {self.date_of_birth}\n" - out_str += f":Place Of Birth: {self.place_of_birth}\n" - out_str += f":Expiry Date: {self.expiry_date}\n" - out_str += f":Issue Date: {self.issue_date}\n" - out_str += f":Issue Authority: {self.issue_authority}\n" - out_str += f":MRZ: {self.mrz}\n" - out_str += f":Address: {self.address}\n" - return clean_out_string(out_str) diff --git a/mindee/product/eu/driver_license/driver_license_v1_page.py b/mindee/product/eu/driver_license/driver_license_v1_page.py deleted file mode 100644 index 0b1d35c5..00000000 --- a/mindee/product/eu/driver_license/driver_license_v1_page.py +++ /dev/null @@ -1,44 +0,0 @@ -from typing import Optional - -from mindee.parsing.common.string_dict import StringDict -from mindee.parsing.common.summary_helper import clean_out_string -from mindee.parsing.standard.position import PositionField -from mindee.product.eu.driver_license.driver_license_v1_document import ( - DriverLicenseV1Document, -) - - -class DriverLicenseV1Page(DriverLicenseV1Document): - """Driver License API version 1.0 page data.""" - - photo: PositionField - """Has a photo of the EU driver license holder""" - signature: PositionField - """Has a signature of the EU driver license holder""" - - def __init__( - self, - raw_prediction: StringDict, - page_id: Optional[int] = None, - ): - """ - Driver License page. - - :param raw_prediction: Raw prediction from HTTP response - :param page_id: Page number for multi pages pdf input - """ - super().__init__(raw_prediction=raw_prediction, page_id=page_id) - self.photo = PositionField( - raw_prediction["photo"], - page_id=page_id, - ) - self.signature = PositionField( - raw_prediction["signature"], - page_id=page_id, - ) - - def __str__(self) -> str: - out_str: str = f":Photo: {self.photo}\n" - out_str += f":Signature: {self.signature}\n" - out_str += f"{super().__str__()}" - return clean_out_string(out_str) diff --git a/mindee/product/eu/license_plate/__init__.py b/mindee/product/eu/license_plate/__init__.py deleted file mode 100644 index f86d3f6d..00000000 --- a/mindee/product/eu/license_plate/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from mindee.product.eu.license_plate.license_plate_v1 import LicensePlateV1 -from mindee.product.eu.license_plate.license_plate_v1_document import ( - LicensePlateV1Document, -) diff --git a/mindee/product/eu/license_plate/license_plate_v1.py b/mindee/product/eu/license_plate/license_plate_v1.py deleted file mode 100644 index 7a52f192..00000000 --- a/mindee/product/eu/license_plate/license_plate_v1.py +++ /dev/null @@ -1,39 +0,0 @@ -from typing import List - -from mindee.parsing.common.inference import Inference -from mindee.parsing.common.page import Page -from mindee.parsing.common.string_dict import StringDict -from mindee.product.eu.license_plate.license_plate_v1_document import ( - LicensePlateV1Document, -) - - -class LicensePlateV1(Inference): - """License Plate API version 1 inference prediction.""" - - prediction: LicensePlateV1Document - """Document-level prediction.""" - pages: List[Page[LicensePlateV1Document]] - """Page-level prediction(s).""" - endpoint_name = "license_plates" - """Name of the endpoint.""" - endpoint_version = "1" - """Version of the endpoint.""" - - def __init__(self, raw_prediction: StringDict): - """ - License Plate v1 inference. - - :param raw_prediction: Raw prediction from the HTTP response. - """ - super().__init__(raw_prediction) - - self.prediction = LicensePlateV1Document(raw_prediction["prediction"]) - self.pages = [] - for page in raw_prediction["pages"]: - try: - page_prediction = page["prediction"] - except KeyError: - continue - if page_prediction: - self.pages.append(Page(LicensePlateV1Document, page)) diff --git a/mindee/product/eu/license_plate/license_plate_v1_document.py b/mindee/product/eu/license_plate/license_plate_v1_document.py deleted file mode 100644 index 7d38a646..00000000 --- a/mindee/product/eu/license_plate/license_plate_v1_document.py +++ /dev/null @@ -1,37 +0,0 @@ -from typing import List, Optional - -from mindee.parsing.common.prediction import Prediction -from mindee.parsing.common.string_dict import StringDict -from mindee.parsing.common.summary_helper import clean_out_string -from mindee.parsing.standard.text import StringField - - -class LicensePlateV1Document(Prediction): - """License Plate API version 1.1 document data.""" - - license_plates: List[StringField] - """List of all license plates found in the image.""" - - def __init__( - self, - raw_prediction: StringDict, - page_id: Optional[int] = None, - ): - """ - License Plate document. - - :param raw_prediction: Raw prediction from HTTP response - :param page_id: Page number for multi pages pdf input - """ - super().__init__(raw_prediction, page_id) - self.license_plates = [ - StringField(prediction, page_id=page_id) - for prediction in raw_prediction["license_plates"] - ] - - def __str__(self) -> str: - license_plates = f"\n { ' ' * 16 }".join( - [str(item) for item in self.license_plates], - ) - out_str: str = f":License Plates: {license_plates}\n" - return clean_out_string(out_str) diff --git a/mindee/product/receipt/__init__.py b/mindee/product/receipt/__init__.py index 3ad765ad..c3d83410 100644 --- a/mindee/product/receipt/__init__.py +++ b/mindee/product/receipt/__init__.py @@ -1,5 +1,3 @@ -from mindee.product.receipt.receipt_v4 import ReceiptV4 -from mindee.product.receipt.receipt_v4_document import ReceiptV4Document from mindee.product.receipt.receipt_v5 import ReceiptV5 from mindee.product.receipt.receipt_v5_document import ReceiptV5Document from mindee.product.receipt.receipt_v5_line_item import ReceiptV5LineItem diff --git a/mindee/product/receipt/receipt_v4.py b/mindee/product/receipt/receipt_v4.py deleted file mode 100644 index 8bbf7ecd..00000000 --- a/mindee/product/receipt/receipt_v4.py +++ /dev/null @@ -1,34 +0,0 @@ -from typing import List - -from mindee.parsing.common.inference import Inference -from mindee.parsing.common.page import Page -from mindee.parsing.common.string_dict import StringDict -from mindee.product.receipt.receipt_v4_document import ReceiptV4Document - - -class ReceiptV4(Inference): - """Inference prediction for Receipt, API version 4.""" - - prediction: ReceiptV4Document - """Document-level prediction.""" - pages: List[Page[ReceiptV4Document]] - """Page-level prediction(s).""" - endpoint_name = "expense_receipts" - """Name of the endpoint.""" - endpoint_version = "4" - """Version of the endpoint.""" - - def __init__( - self, - raw_prediction: StringDict, - ) -> None: - """ - Invoice Splitter v1 inference. - - :param raw_prediction: Raw prediction from the HTTP response. - """ - super().__init__(raw_prediction=raw_prediction) - self.prediction = ReceiptV4Document(raw_prediction["prediction"]) - self.pages = [] - for page in raw_prediction["pages"]: - self.pages.append(Page(ReceiptV4Document, page)) diff --git a/mindee/product/receipt/receipt_v4_document.py b/mindee/product/receipt/receipt_v4_document.py deleted file mode 100644 index 374083e7..00000000 --- a/mindee/product/receipt/receipt_v4_document.py +++ /dev/null @@ -1,88 +0,0 @@ -from typing import Optional - -from mindee.parsing.common.prediction import Prediction -from mindee.parsing.common.string_dict import StringDict -from mindee.parsing.common.summary_helper import clean_out_string -from mindee.parsing.standard.amount import AmountField -from mindee.parsing.standard.classification import ClassificationField -from mindee.parsing.standard.date import DateField -from mindee.parsing.standard.locale import LocaleField -from mindee.parsing.standard.tax import Taxes -from mindee.parsing.standard.text import StringField - - -class ReceiptV4Document(Prediction): - """Document data for Receipt, API version 4.""" - - locale: LocaleField - """locale information""" - total_amount: AmountField - """Total including taxes""" - date: DateField - """Date the receipt was issued""" - time: StringField - """Time the receipt was issued, in HH: MM format.""" - category: ClassificationField - """The type, or service category, of the purchase.""" - subcategory: ClassificationField - """The receipt sub category among predefined classes.""" - document_type: ClassificationField - """Whether the document is an expense receipt or a credit card receipt.""" - supplier: StringField - """The merchant, or supplier, as found on the receipt.""" - taxes: Taxes - """List of all taxes.""" - total_tax: AmountField - """Total tax amount of the purchase.""" - total_net: AmountField - "Total amount of the purchase excluding taxes." - tip: AmountField - """Total amount of tip and gratuity.""" - - def __init__( - self, - raw_prediction: StringDict, - page_id: Optional[int] = None, - ): - """ - Receipt document. - - :param raw_prediction: Raw prediction from HTTP response - :param page_id: Page number for multi pages pdf input - """ - self.locale = LocaleField(raw_prediction["locale"], page_id=page_id) - self.total_amount = AmountField(raw_prediction["total_amount"], page_id=page_id) - self.total_net = AmountField(raw_prediction["total_net"], page_id=page_id) - self.total_tax = AmountField(raw_prediction["total_tax"], page_id=page_id) - self.tip = AmountField(raw_prediction["tip"], page_id=page_id) - self.date = DateField(raw_prediction["date"], page_id=page_id) - self.category = ClassificationField(raw_prediction["category"], page_id=page_id) - self.subcategory = ClassificationField( - raw_prediction["subcategory"], page_id=page_id - ) - self.document_type = ClassificationField( - raw_prediction["document_type"], page_id=page_id - ) - self.supplier = StringField( - raw_prediction["supplier"], value_key="value", page_id=page_id - ) - self.time = StringField( - raw_prediction["time"], value_key="value", page_id=page_id - ) - self.taxes = Taxes(raw_prediction["taxes"], page_id=page_id) - - def __str__(self) -> str: - return clean_out_string( - f":Locale: {self.locale}\n" - f":Date: {self.date}\n" - f":Category: {self.category}\n" - f":Subcategory: {self.subcategory}\n" - f":Document type: {self.document_type}\n" - f":Time: {self.time}\n" - f":Supplier name: {self.supplier}\n" - f":Taxes: {self.taxes}\n" - f":Total net: {self.total_net}\n" - f":Total tax: {self.total_tax}\n" - f":Tip: {self.tip}\n" - f":Total amount: {self.total_amount}" - ) diff --git a/mindee/product/us/__init__.py b/mindee/product/us/__init__.py index 14d32f0f..5d84f728 100644 --- a/mindee/product/us/__init__.py +++ b/mindee/product/us/__init__.py @@ -1,11 +1,6 @@ from mindee.product.us.bank_check.bank_check_v1 import BankCheckV1 from mindee.product.us.bank_check.bank_check_v1_document import BankCheckV1Document from mindee.product.us.bank_check.bank_check_v1_page import BankCheckV1Page -from mindee.product.us.driver_license.driver_license_v1 import DriverLicenseV1 -from mindee.product.us.driver_license.driver_license_v1_document import ( - DriverLicenseV1Document, -) -from mindee.product.us.driver_license.driver_license_v1_page import DriverLicenseV1Page from mindee.product.us.healthcare_card.healthcare_card_v1 import HealthcareCardV1 from mindee.product.us.healthcare_card.healthcare_card_v1_copay import ( HealthcareCardV1Copay, diff --git a/mindee/product/us/driver_license/__init__.py b/mindee/product/us/driver_license/__init__.py deleted file mode 100644 index d27b61df..00000000 --- a/mindee/product/us/driver_license/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from mindee.product.us.driver_license.driver_license_v1 import DriverLicenseV1 -from mindee.product.us.driver_license.driver_license_v1_document import ( - DriverLicenseV1Document, -) -from mindee.product.us.driver_license.driver_license_v1_page import DriverLicenseV1Page diff --git a/mindee/product/us/driver_license/driver_license_v1.py b/mindee/product/us/driver_license/driver_license_v1.py deleted file mode 100644 index 87d4af30..00000000 --- a/mindee/product/us/driver_license/driver_license_v1.py +++ /dev/null @@ -1,42 +0,0 @@ -from typing import List - -from mindee.parsing.common.inference import Inference -from mindee.parsing.common.page import Page -from mindee.parsing.common.string_dict import StringDict -from mindee.product.us.driver_license.driver_license_v1_document import ( - DriverLicenseV1Document, -) -from mindee.product.us.driver_license.driver_license_v1_page import ( - DriverLicenseV1Page, -) - - -class DriverLicenseV1(Inference): - """Driver License API version 1 inference prediction.""" - - prediction: DriverLicenseV1Document - """Document-level prediction.""" - pages: List[Page[DriverLicenseV1Page]] - """Page-level prediction(s).""" - endpoint_name = "us_driver_license" - """Name of the endpoint.""" - endpoint_version = "1" - """Version of the endpoint.""" - - def __init__(self, raw_prediction: StringDict): - """ - Driver License v1 inference. - - :param raw_prediction: Raw prediction from the HTTP response. - """ - super().__init__(raw_prediction) - - self.prediction = DriverLicenseV1Document(raw_prediction["prediction"]) - self.pages = [] - for page in raw_prediction["pages"]: - try: - page_prediction = page["prediction"] - except KeyError: - continue - if page_prediction: - self.pages.append(Page(DriverLicenseV1Page, page)) diff --git a/mindee/product/us/driver_license/driver_license_v1_document.py b/mindee/product/us/driver_license/driver_license_v1_document.py deleted file mode 100644 index 38f0905a..00000000 --- a/mindee/product/us/driver_license/driver_license_v1_document.py +++ /dev/null @@ -1,147 +0,0 @@ -from typing import Optional - -from mindee.parsing.common.prediction import Prediction -from mindee.parsing.common.string_dict import StringDict -from mindee.parsing.common.summary_helper import clean_out_string -from mindee.parsing.standard.date import DateField -from mindee.parsing.standard.text import StringField - - -class DriverLicenseV1Document(Prediction): - """Driver License API version 1.1 document data.""" - - address: StringField - """US driver license holders address""" - date_of_birth: DateField - """US driver license holders date of birth""" - dd_number: StringField - """Document Discriminator Number of the US Driver License""" - dl_class: StringField - """US driver license holders class""" - driver_license_id: StringField - """ID number of the US Driver License.""" - endorsements: StringField - """US driver license holders endorsements""" - expiry_date: DateField - """Date on which the documents expires.""" - eye_color: StringField - """US driver license holders eye colour""" - first_name: StringField - """US driver license holders first name(s)""" - hair_color: StringField - """US driver license holders hair colour""" - height: StringField - """US driver license holders hight""" - issued_date: DateField - """Date on which the documents was issued.""" - last_name: StringField - """US driver license holders last name""" - restrictions: StringField - """US driver license holders restrictions""" - sex: StringField - """US driver license holders gender""" - state: StringField - """US State""" - weight: StringField - """US driver license holders weight""" - - def __init__( - self, - raw_prediction: StringDict, - page_id: Optional[int] = None, - ): - """ - Driver License document. - - :param raw_prediction: Raw prediction from HTTP response - :param page_id: Page number for multi pages pdf input - """ - super().__init__(raw_prediction, page_id) - self.address = StringField( - raw_prediction["address"], - page_id=page_id, - ) - self.date_of_birth = DateField( - raw_prediction["date_of_birth"], - page_id=page_id, - ) - self.dd_number = StringField( - raw_prediction["dd_number"], - page_id=page_id, - ) - self.dl_class = StringField( - raw_prediction["dl_class"], - page_id=page_id, - ) - self.driver_license_id = StringField( - raw_prediction["driver_license_id"], - page_id=page_id, - ) - self.endorsements = StringField( - raw_prediction["endorsements"], - page_id=page_id, - ) - self.expiry_date = DateField( - raw_prediction["expiry_date"], - page_id=page_id, - ) - self.eye_color = StringField( - raw_prediction["eye_color"], - page_id=page_id, - ) - self.first_name = StringField( - raw_prediction["first_name"], - page_id=page_id, - ) - self.hair_color = StringField( - raw_prediction["hair_color"], - page_id=page_id, - ) - self.height = StringField( - raw_prediction["height"], - page_id=page_id, - ) - self.issued_date = DateField( - raw_prediction["issued_date"], - page_id=page_id, - ) - self.last_name = StringField( - raw_prediction["last_name"], - page_id=page_id, - ) - self.restrictions = StringField( - raw_prediction["restrictions"], - page_id=page_id, - ) - self.sex = StringField( - raw_prediction["sex"], - page_id=page_id, - ) - self.state = StringField( - raw_prediction["state"], - page_id=page_id, - ) - self.weight = StringField( - raw_prediction["weight"], - page_id=page_id, - ) - - def __str__(self) -> str: - out_str: str = f":State: {self.state}\n" - out_str += f":Driver License ID: {self.driver_license_id}\n" - out_str += f":Expiry Date: {self.expiry_date}\n" - out_str += f":Date Of Issue: {self.issued_date}\n" - out_str += f":Last Name: {self.last_name}\n" - out_str += f":First Name: {self.first_name}\n" - out_str += f":Address: {self.address}\n" - out_str += f":Date Of Birth: {self.date_of_birth}\n" - out_str += f":Restrictions: {self.restrictions}\n" - out_str += f":Endorsements: {self.endorsements}\n" - out_str += f":Driver License Class: {self.dl_class}\n" - out_str += f":Sex: {self.sex}\n" - out_str += f":Height: {self.height}\n" - out_str += f":Weight: {self.weight}\n" - out_str += f":Hair Color: {self.hair_color}\n" - out_str += f":Eye Color: {self.eye_color}\n" - out_str += f":Document Discriminator: {self.dd_number}\n" - return clean_out_string(out_str) diff --git a/mindee/product/us/driver_license/driver_license_v1_page.py b/mindee/product/us/driver_license/driver_license_v1_page.py deleted file mode 100644 index ded1b300..00000000 --- a/mindee/product/us/driver_license/driver_license_v1_page.py +++ /dev/null @@ -1,44 +0,0 @@ -from typing import Optional - -from mindee.parsing.common.string_dict import StringDict -from mindee.parsing.common.summary_helper import clean_out_string -from mindee.parsing.standard.position import PositionField -from mindee.product.us.driver_license.driver_license_v1_document import ( - DriverLicenseV1Document, -) - - -class DriverLicenseV1Page(DriverLicenseV1Document): - """Driver License API version 1.1 page data.""" - - photo: PositionField - """Has a photo of the US driver license holder""" - signature: PositionField - """Has a signature of the US driver license holder""" - - def __init__( - self, - raw_prediction: StringDict, - page_id: Optional[int] = None, - ): - """ - Driver License page. - - :param raw_prediction: Raw prediction from HTTP response - :param page_id: Page number for multi pages pdf input - """ - super().__init__(raw_prediction=raw_prediction, page_id=page_id) - self.photo = PositionField( - raw_prediction["photo"], - page_id=page_id, - ) - self.signature = PositionField( - raw_prediction["signature"], - page_id=page_id, - ) - - def __str__(self) -> str: - out_str: str = f":Photo: {self.photo}\n" - out_str += f":Signature: {self.signature}\n" - out_str += f"{super().__str__()}" - return clean_out_string(out_str) diff --git a/tests/api/test_response.py b/tests/api/test_response.py index bea6548f..7db98bc2 100644 --- a/tests/api/test_response.py +++ b/tests/api/test_response.py @@ -12,11 +12,11 @@ from mindee.product.invoice.invoice_v4_document import InvoiceV4Document from mindee.product.passport.passport_v1 import PassportV1 from mindee.product.passport.passport_v1_document import PassportV1Document -from mindee.product.receipt.receipt_v4 import ReceiptV4 -from mindee.product.receipt.receipt_v4_document import ReceiptV4Document +from mindee.product.receipt.receipt_v5 import ReceiptV5 +from mindee.product.receipt.receipt_v5_document import ReceiptV5Document -def test_invoice_receipt_v4(): +def test_invoice_receipt_v5(): response = json.load( open("./tests/data/products/invoices/response_v4/complete.json") ) @@ -27,14 +27,14 @@ def test_invoice_receipt_v4(): assert parsed_response.document.n_pages == 2 -def test_response_receipt_v4(): +def test_response_receipt_v5(): response = json.load( - open("./tests/data/products/expense_receipts/response_v4/complete.json") + open("./tests/data/products/expense_receipts/response_v5/complete.json") ) - parsed_response = PredictResponse(ReceiptV4, response) - assert isinstance(parsed_response.document.inference, ReceiptV4) + parsed_response = PredictResponse(ReceiptV5, response) + assert isinstance(parsed_response.document.inference, ReceiptV5) for page in parsed_response.document.inference.pages: - assert isinstance(page.prediction, ReceiptV4Document) + assert isinstance(page.prediction, ReceiptV5Document) assert parsed_response.document.n_pages == 1 diff --git a/tests/product/eu/__init__.py b/tests/product/eu/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/product/eu/driver_license/__init__.py b/tests/product/eu/driver_license/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/product/eu/driver_license/test_driver_license_v1.py b/tests/product/eu/driver_license/test_driver_license_v1.py deleted file mode 100644 index ce525240..00000000 --- a/tests/product/eu/driver_license/test_driver_license_v1.py +++ /dev/null @@ -1,77 +0,0 @@ -import json - -import pytest - -from mindee.parsing.common.document import Document -from mindee.parsing.common.page import Page -from mindee.product.eu.driver_license.driver_license_v1 import DriverLicenseV1 -from mindee.product.eu.driver_license.driver_license_v1_document import ( - DriverLicenseV1Document, -) -from mindee.product.eu.driver_license.driver_license_v1_page import ( - DriverLicenseV1Page, -) -from tests.product import PRODUCT_DATA_DIR - -RESPONSE_DIR = PRODUCT_DATA_DIR / "eu_driver_license" / "response_v1" - -DriverLicenseV1DocumentType = Document[ - DriverLicenseV1Document, - Page[DriverLicenseV1Page], -] - - -@pytest.fixture -def complete_doc() -> DriverLicenseV1DocumentType: - file_path = RESPONSE_DIR / "complete.json" - with open(file_path, "r", encoding="utf-8") as open_file: - json_data = json.load(open_file) - return Document(DriverLicenseV1, json_data["document"]) - - -@pytest.fixture -def empty_doc() -> DriverLicenseV1DocumentType: - file_path = RESPONSE_DIR / "empty.json" - with open(file_path, "r", encoding="utf-8") as open_file: - json_data = json.load(open_file) - return Document(DriverLicenseV1, json_data["document"]) - - -@pytest.fixture -def complete_page0() -> Page[DriverLicenseV1Page]: - file_path = RESPONSE_DIR / "complete.json" - with open(file_path, "r", encoding="utf-8") as open_file: - json_data = json.load(open_file) - page0 = json_data["document"]["inference"]["pages"][0] - return Page(DriverLicenseV1Page, page0) - - -def test_complete_doc(complete_doc: DriverLicenseV1DocumentType): - file_path = RESPONSE_DIR / "summary_full.rst" - with open(file_path, "r", encoding="utf-8") as open_file: - reference_str = open_file.read() - assert str(complete_doc) == reference_str - - -def test_empty_doc(empty_doc: DriverLicenseV1DocumentType): - prediction = empty_doc.inference.prediction - assert prediction.country_code.value is None - assert prediction.document_id.value is None - assert prediction.category.value is None - assert prediction.last_name.value is None - assert prediction.first_name.value is None - assert prediction.date_of_birth.value is None - assert prediction.place_of_birth.value is None - assert prediction.expiry_date.value is None - assert prediction.issue_date.value is None - assert prediction.issue_authority.value is None - assert prediction.mrz.value is None - assert prediction.address.value is None - - -def test_complete_page0(complete_page0: Page[DriverLicenseV1Page]): - file_path = RESPONSE_DIR / "summary_page0.rst" - with open(file_path, "r", encoding="utf-8") as open_file: - reference_str = open_file.read() - assert complete_page0.id == 0 - assert str(complete_page0) == reference_str diff --git a/tests/product/eu/license_plate/__init__.py b/tests/product/eu/license_plate/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/product/eu/license_plate/test_license_plate_v1.py b/tests/product/eu/license_plate/test_license_plate_v1.py deleted file mode 100644 index 89d5ba04..00000000 --- a/tests/product/eu/license_plate/test_license_plate_v1.py +++ /dev/null @@ -1,46 +0,0 @@ -import json - -import pytest - -from mindee.parsing.common.document import Document -from mindee.parsing.common.page import Page -from mindee.product.eu.license_plate.license_plate_v1 import LicensePlateV1 -from mindee.product.eu.license_plate.license_plate_v1_document import ( - LicensePlateV1Document, -) -from tests.product import PRODUCT_DATA_DIR - -RESPONSE_DIR = PRODUCT_DATA_DIR / "license_plates" / "response_v1" - -LicensePlateV1DocumentType = Document[ - LicensePlateV1Document, - Page[LicensePlateV1Document], -] - - -@pytest.fixture -def complete_doc() -> LicensePlateV1DocumentType: - file_path = RESPONSE_DIR / "complete.json" - with open(file_path, "r", encoding="utf-8") as open_file: - json_data = json.load(open_file) - return Document(LicensePlateV1, json_data["document"]) - - -@pytest.fixture -def empty_doc() -> LicensePlateV1DocumentType: - file_path = RESPONSE_DIR / "empty.json" - with open(file_path, "r", encoding="utf-8") as open_file: - json_data = json.load(open_file) - return Document(LicensePlateV1, json_data["document"]) - - -def test_complete_doc(complete_doc: LicensePlateV1DocumentType): - file_path = RESPONSE_DIR / "summary_full.rst" - with open(file_path, "r", encoding="utf-8") as open_file: - reference_str = open_file.read() - assert str(complete_doc) == reference_str - - -def test_empty_doc(empty_doc: LicensePlateV1DocumentType): - prediction = empty_doc.inference.prediction - assert len(prediction.license_plates) == 0 diff --git a/tests/product/eu/license_plate/test_license_plate_v1_regression.py b/tests/product/eu/license_plate/test_license_plate_v1_regression.py deleted file mode 100644 index deacd9c0..00000000 --- a/tests/product/eu/license_plate/test_license_plate_v1_regression.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest - -from mindee.client import Client -from mindee.product.eu.license_plate.license_plate_v1 import LicensePlateV1 -from tests.product import PRODUCT_DATA_DIR, get_id, get_version - - -@pytest.mark.regression -def test_default_sample(): - client = Client() - with open( - PRODUCT_DATA_DIR / "license_plates" / "response_v1" / "default_sample.rst", - encoding="utf-8", - ) as rst_file: - rst_ref = rst_file.read() - - sample = client.source_from_path( - PRODUCT_DATA_DIR / "license_plates" / "default_sample.jpg", - ) - response = client.parse(LicensePlateV1, sample) - doc_response = response.document - doc_response.id = get_id(rst_ref) - doc_response.inference.product.version = get_version(rst_ref) - assert str(doc_response) == rst_ref diff --git a/tests/product/receipt/test_receipt_v4.py b/tests/product/receipt/test_receipt_v4.py deleted file mode 100644 index ec7bec13..00000000 --- a/tests/product/receipt/test_receipt_v4.py +++ /dev/null @@ -1,69 +0,0 @@ -import json - -import pytest - -from mindee.parsing.common.document import Document -from mindee.parsing.common.page import Page -from mindee.product.receipt.receipt_v4 import ReceiptV4 -from mindee.product.receipt.receipt_v4_document import ReceiptV4Document -from tests.product import PRODUCT_DATA_DIR - - -@pytest.fixture -def complete_doc() -> Document[ReceiptV4Document, Page[ReceiptV4Document]]: - json_data = json.load( - open(PRODUCT_DATA_DIR / "expense_receipts" / "response_v4" / "complete.json") - ) - return Document(ReceiptV4, json_data["document"]) - - -@pytest.fixture -def empty_doc() -> Document[ReceiptV4Document, Page[ReceiptV4Document]]: - json_data = json.load( - open(PRODUCT_DATA_DIR / "expense_receipts" / "response_v4" / "empty.json") - ) - return Document(ReceiptV4, json_data["document"]) - - -@pytest.fixture -def complete_page_0() -> Page[ReceiptV4Document]: - json_data = json.load( - open(PRODUCT_DATA_DIR / "expense_receipts" / "response_v4" / "complete.json") - ) - return Page(ReceiptV4Document, json_data["document"]["inference"]["pages"][0]) - - -def test_complete_doc( - complete_doc: Document[ReceiptV4Document, Page[ReceiptV4Document]] -): - reference_str = open( - PRODUCT_DATA_DIR / "expense_receipts" / "response_v4" / "summary_full.rst", - "r", - encoding="utf-8", - ).read() - assert str(complete_doc) == reference_str - - -def test_empty_doc(empty_doc: Document[ReceiptV4Document, Page[ReceiptV4Document]]): - prediction = empty_doc.inference.prediction - assert prediction.locale.value is None - assert prediction.date.value is None - assert prediction.time.value is None - assert prediction.total_amount.value is None - assert prediction.total_net.value is None - assert prediction.total_tax.value is None - assert prediction.tip.value is None - assert len(prediction.taxes) == 0 - assert prediction.supplier.value is None - - -def test_complete_page_0(complete_page_0: Page[ReceiptV4Document]): - reference_str = open( - PRODUCT_DATA_DIR / "expense_receipts" / "response_v4" / "summary_page0.rst", - "r", - encoding="utf-8", - ).read() - assert complete_page_0.orientation - assert complete_page_0.orientation.value == 0 - assert complete_page_0.id == 0 - assert str(complete_page_0) == reference_str diff --git a/tests/product/us/driver_license/__init__.py b/tests/product/us/driver_license/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/product/us/driver_license/test_driver_license_v1.py b/tests/product/us/driver_license/test_driver_license_v1.py deleted file mode 100644 index 189ace20..00000000 --- a/tests/product/us/driver_license/test_driver_license_v1.py +++ /dev/null @@ -1,82 +0,0 @@ -import json - -import pytest - -from mindee.parsing.common.document import Document -from mindee.parsing.common.page import Page -from mindee.product.us.driver_license.driver_license_v1 import DriverLicenseV1 -from mindee.product.us.driver_license.driver_license_v1_document import ( - DriverLicenseV1Document, -) -from mindee.product.us.driver_license.driver_license_v1_page import ( - DriverLicenseV1Page, -) -from tests.product import PRODUCT_DATA_DIR - -RESPONSE_DIR = PRODUCT_DATA_DIR / "us_driver_license" / "response_v1" - -DriverLicenseV1DocumentType = Document[ - DriverLicenseV1Document, - Page[DriverLicenseV1Page], -] - - -@pytest.fixture -def complete_doc() -> DriverLicenseV1DocumentType: - file_path = RESPONSE_DIR / "complete.json" - with open(file_path, "r", encoding="utf-8") as open_file: - json_data = json.load(open_file) - return Document(DriverLicenseV1, json_data["document"]) - - -@pytest.fixture -def empty_doc() -> DriverLicenseV1DocumentType: - file_path = RESPONSE_DIR / "empty.json" - with open(file_path, "r", encoding="utf-8") as open_file: - json_data = json.load(open_file) - return Document(DriverLicenseV1, json_data["document"]) - - -@pytest.fixture -def complete_page0() -> Page[DriverLicenseV1Page]: - file_path = RESPONSE_DIR / "complete.json" - with open(file_path, "r", encoding="utf-8") as open_file: - json_data = json.load(open_file) - page0 = json_data["document"]["inference"]["pages"][0] - return Page(DriverLicenseV1Page, page0) - - -def test_complete_doc(complete_doc: DriverLicenseV1DocumentType): - file_path = RESPONSE_DIR / "summary_full.rst" - with open(file_path, "r", encoding="utf-8") as open_file: - reference_str = open_file.read() - assert str(complete_doc) == reference_str - - -def test_empty_doc(empty_doc: DriverLicenseV1DocumentType): - prediction = empty_doc.inference.prediction - assert prediction.state.value is None - assert prediction.driver_license_id.value is None - assert prediction.expiry_date.value is None - assert prediction.issued_date.value is None - assert prediction.last_name.value is None - assert prediction.first_name.value is None - assert prediction.address.value is None - assert prediction.date_of_birth.value is None - assert prediction.restrictions.value is None - assert prediction.endorsements.value is None - assert prediction.dl_class.value is None - assert prediction.sex.value is None - assert prediction.height.value is None - assert prediction.weight.value is None - assert prediction.hair_color.value is None - assert prediction.eye_color.value is None - assert prediction.dd_number.value is None - - -def test_complete_page0(complete_page0: Page[DriverLicenseV1Page]): - file_path = RESPONSE_DIR / "summary_page0.rst" - with open(file_path, "r", encoding="utf-8") as open_file: - reference_str = open_file.read() - assert complete_page0.id == 0 - assert str(complete_page0) == reference_str diff --git a/tests/product/us/driver_license/test_driver_license_v1_regression.py b/tests/product/us/driver_license/test_driver_license_v1_regression.py deleted file mode 100644 index 43b1d0f4..00000000 --- a/tests/product/us/driver_license/test_driver_license_v1_regression.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest - -from mindee.client import Client -from mindee.product.us.driver_license.driver_license_v1 import DriverLicenseV1 -from tests.product import PRODUCT_DATA_DIR, get_id, get_version - - -@pytest.mark.regression -def test_default_sample(): - client = Client() - with open( - PRODUCT_DATA_DIR / "us_driver_license" / "response_v1" / "default_sample.rst", - encoding="utf-8", - ) as rst_file: - rst_ref = rst_file.read() - - sample = client.source_from_path( - PRODUCT_DATA_DIR / "us_driver_license" / "default_sample.jpg", - ) - response = client.parse(DriverLicenseV1, sample) - doc_response = response.document - doc_response.id = get_id(rst_ref) - doc_response.inference.product.version = get_version(rst_ref) - assert str(doc_response) == rst_ref diff --git a/tests/test_client.py b/tests/test_client.py index 599e244c..4d2771e0 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -10,7 +10,7 @@ from mindee.product.international_id.international_id_v2 import InternationalIdV2 from mindee.product.invoice.invoice_v4 import InvoiceV4 from mindee.product.invoice_splitter.invoice_splitter_v1 import InvoiceSplitterV1 -from mindee.product.receipt.receipt_v4 import ReceiptV4 +from mindee.product.receipt.receipt_v5 import ReceiptV5 from tests.mindee_http.test_error import ERROR_DATA_DIR from tests.test_inputs import FILE_TYPES_DIR, PRODUCT_DATA_DIR from tests.utils import clear_envvars, dummy_envvars @@ -36,13 +36,13 @@ def dummy_client() -> Client: def test_parse_path_without_token(empty_client: Client): with pytest.raises(RuntimeError): input_doc = empty_client.source_from_path(FILE_TYPES_DIR / "pdf" / "blank.pdf") - empty_client.parse(product.ReceiptV4, input_doc) + empty_client.parse(product.ReceiptV5, input_doc) def test_parse_path_with_env_token(env_client: Client): with pytest.raises(MindeeHTTPError): input_doc = env_client.source_from_path(FILE_TYPES_DIR / "pdf" / "blank.pdf") - env_client.parse(product.ReceiptV4, input_doc) + env_client.parse(product.ReceiptV5, input_doc) def test_parse_path_with_wrong_filetype(dummy_client: Client): @@ -53,7 +53,7 @@ def test_parse_path_with_wrong_filetype(dummy_client: Client): def test_parse_path_with_wrong_token(dummy_client: Client): with pytest.raises(MindeeHTTPError): input_doc = dummy_client.source_from_path(FILE_TYPES_DIR / "pdf" / "blank.pdf") - dummy_client.parse(product.ReceiptV4, input_doc) + dummy_client.parse(product.ReceiptV5, input_doc) def test_request_with_wrong_type(dummy_client: Client): @@ -79,7 +79,7 @@ def test_keep_file_open(dummy_client: Client): f"{FILE_TYPES_DIR}/receipt.jpg" ) try: - dummy_client.parse(product.ReceiptV4, input_doc, close_file=False) + dummy_client.parse(product.ReceiptV5, input_doc, close_file=False) except MindeeHTTPError: pass assert not input_doc.file_object.closed @@ -94,7 +94,7 @@ def test_cut_options(dummy_client: Client): try: # need to keep file open to count the pages after parsing dummy_client.parse( - ReceiptV4, + ReceiptV5, input_doc, close_file=False, page_options=PageOptions(page_indexes=range(5)), From 4041e3e0a1e8a5eae6d2912bfee72ba4cbf32a1c Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Thu, 13 Mar 2025 20:56:45 +0100 Subject: [PATCH 2/2] remove invalid sample file --- .../code_samples/expense_receipts_v4.txt | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 docs/extras/code_samples/expense_receipts_v4.txt diff --git a/docs/extras/code_samples/expense_receipts_v4.txt b/docs/extras/code_samples/expense_receipts_v4.txt deleted file mode 100644 index b9e830a5..00000000 --- a/docs/extras/code_samples/expense_receipts_v4.txt +++ /dev/null @@ -1,18 +0,0 @@ -from mindee import Client, PredictResponse, product - -# Init a new client -mindee_client = Client(api_key="my-api-key") - -# Load a file from disk -input_doc = mindee_client.source_from_path("/path/to/the/file.ext") - -# Load a file from disk and parse it. -# The endpoint name must be specified since it cannot be determined from the class. -result: PredictResponse = mindee_client.parse(product.ReceiptV4, input_doc) - -# Print a brief summary of the parsed data -print(result.document) - -# # Iterate over all the fields in the document -# for field_name, field_values in result.document.inference.prediction.fields.items(): -# print(field_name, "=", field_values)