Skip to content

Commit cb03354

Browse files
committed
✨ add eu license plate v1
1 parent 5c4dcfd commit cb03354

File tree

12 files changed

+145
-2
lines changed

12 files changed

+145
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from mindee import Client, documents
2+
3+
# Init a new client
4+
mindee_client = Client(api_key="my-api-key")
5+
6+
# Load a file from disk
7+
input_doc = mindee_client.doc_from_path("/path/to/the/file.ext")
8+
9+
# Parse the License Plate by passing the appropriate type
10+
result = input_doc.parse(documents.eu.TypeLicensePlateV1)
11+
12+
# Print a brief summary of the parsed data
13+
print(result.document)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
License Plate V1
2+
----------------
3+
4+
**Sample Code:**
5+
6+
.. literalinclude:: /code_samples/eu/license_plate_v1.py
7+
:language: Python
8+
9+
.. autoclass:: mindee.documents.eu.LicensePlateV1
10+
:members:

docs/predictions/standard/eu.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
European Union
2+
##############
3+
4+
.. include:: ./documents/eu/license_plate_v1.rst

docs/predictions/standard/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ Off the Shelf
77
./field_types
88
./international
99
./us
10+
./eu
1011
./fr

mindee/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ class CommandConfig(Generic[TypeDoc]):
4646
help="Shipping Container",
4747
doc_class=documents.fr.TypeIdCardV1,
4848
),
49-
"us-check": CommandConfig(
49+
"us-bank-check": CommandConfig(
5050
help="US Bank Check",
5151
doc_class=documents.us.TypeBankCheckV1,
5252
),
53+
"eu-license-plate": CommandConfig(
54+
help="EU License Plate",
55+
doc_class=documents.eu.TypeLicensePlateV1,
56+
),
5357
"fr-carte-grise": CommandConfig(
5458
help="FR Carte Grise",
5559
doc_class=documents.fr.TypeCarteGriseV1,

mindee/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ def _init_default_endpoints(self) -> None:
263263
url_name="shipping_containers",
264264
version="1",
265265
),
266+
ConfigSpec(
267+
doc_class=documents.eu.LicensePlateV1,
268+
url_name="license_plates",
269+
version="1",
270+
),
266271
]
267272
for config in configs:
268273
config_key = (OTS_OWNER, config.doc_class.__name__)

mindee/documents/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from mindee.documents import fr, us
22
from mindee.documents.cropper import CropperV1, TypeCropperV1
33
from mindee.documents.custom import CustomV1, TypeCustomV1
4+
from mindee.documents.eu import LicensePlateV1, TypeLicensePlateV1
45
from mindee.documents.financial import (
56
FinancialDocumentV1,
67
FinancialV1,

mindee/documents/eu/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .license_plate.license_plate_v1 import LicensePlateV1, TypeLicensePlateV1

mindee/documents/eu/license_plate/__init__.py

Whitespace-only changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from typing import List, Optional, TypeVar
2+
3+
from mindee.documents.base import Document, TypeApiPrediction, clean_out_string
4+
from mindee.fields.text import TextField
5+
6+
7+
class LicensePlateV1(Document):
8+
"""License Plate v1 prediction results."""
9+
10+
license_plates: List[TextField]
11+
"""List of all license plates found in the image."""
12+
13+
def __init__(
14+
self,
15+
api_prediction=None,
16+
input_source=None,
17+
page_n: Optional[int] = None,
18+
):
19+
"""
20+
License Plate v1 prediction results.
21+
22+
:param api_prediction: Raw prediction from HTTP response
23+
:param input_source: Input object
24+
:param page_n: Page number for multi pages pdf input
25+
"""
26+
super().__init__(
27+
input_source=input_source,
28+
document_type="license_plate",
29+
api_prediction=api_prediction,
30+
page_n=page_n,
31+
)
32+
self._build_from_api_prediction(api_prediction["prediction"], page_n=page_n)
33+
34+
def _build_from_api_prediction(
35+
self, api_prediction: TypeApiPrediction, page_n: Optional[int] = None
36+
) -> None:
37+
"""
38+
Build the object from the prediction API JSON.
39+
40+
:param api_prediction: Raw prediction from HTTP response
41+
:param page_n: Page number
42+
"""
43+
self.license_plates = [
44+
TextField(prediction, page_n=page_n)
45+
for prediction in api_prediction["license_plates"]
46+
]
47+
48+
def __str__(self) -> str:
49+
license_plates = f"\n { ' ' * 15 }".join(
50+
[str(item) for item in self.license_plates]
51+
)
52+
return clean_out_string(
53+
"----- EU License Plate V1 -----\n"
54+
f"Filename: {self.filename or ''}\n"
55+
f"License Plates: { license_plates }\n"
56+
"----------------------"
57+
)
58+
59+
60+
TypeLicensePlateV1 = TypeVar("TypeLicensePlateV1", bound=LicensePlateV1)

0 commit comments

Comments
 (0)