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
13 changes: 13 additions & 0 deletions docs/extras/code_samples/expense_receipts_v5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from mindee import Client, documents

# Init a new client
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 Receipt by passing the appropriate type
result = input_doc.parse(documents.TypeReceiptV5)

# Print a brief summary of the parsed data
print(result.document)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ License Plate V1

**Sample Code:**

.. literalinclude:: /extras/code_samples/eu/license_plate_v1.txt
.. literalinclude:: /extras/code_samples/license_plate_v1.txt
:language: Python

.. autoclass:: mindee.documents.eu.LicensePlateV1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bank Account Details V1

**Sample Code:**

.. literalinclude:: /extras/code_samples/fr/bank_account_details_v1.txt
.. literalinclude:: /extras/code_samples/bank_account_details_v1.txt
:language: Python

.. autoclass:: mindee.documents.fr.BankAccountDetailsV1
Expand Down
2 changes: 1 addition & 1 deletion docs/predictions/standard/documents/fr/carte_grise_v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Carte Grise V1

**Sample Code:**

.. literalinclude:: /extras/code_samples/fr/carte_grise_v1.txt
.. literalinclude:: /extras/code_samples/carte_grise_v1.txt
:language: Python

.. autoclass:: mindee.documents.fr.CarteGriseV1
Expand Down
2 changes: 1 addition & 1 deletion docs/predictions/standard/documents/fr/carte_vitale_v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Carte Vitale V1

**Sample Code:**

.. literalinclude:: /extras/code_samples/fr/carte_vitale_v1.txt
.. literalinclude:: /extras/code_samples/carte_vitale_v1.txt
:language: Python

.. autoclass:: mindee.documents.fr.CarteVitaleV1
Expand Down
2 changes: 1 addition & 1 deletion docs/predictions/standard/documents/fr/id_card_v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Carte Nationale d'Identité V1

**Sample Code:**

.. literalinclude:: /extras/code_samples/fr/id_card_v1.txt
.. literalinclude:: /extras/code_samples/id_card_v1.txt
:language: Python

.. autoclass:: mindee.documents.fr.IdCardV1
Expand Down
4 changes: 2 additions & 2 deletions docs/predictions/standard/documents/receipt_v3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Receipt V3

**Sample Code:**

.. literalinclude:: /extras/code_samples/receipt_v3.txt
.. literalinclude:: /extras/code_samples/expense_receipts_v3.txt
:language: Python

.. autoclass:: mindee.documents.ReceiptV3
.. autoclass:: mindee.documents.ReceiptV4
:members:
2 changes: 1 addition & 1 deletion docs/predictions/standard/documents/receipt_v4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Receipt V4

**Sample Code:**

.. literalinclude:: /extras/code_samples/receipt_v4.txt
.. literalinclude:: /extras/code_samples/expense_receipts_v4.txt
:language: Python

.. autoclass:: mindee.documents.ReceiptV4
Expand Down
10 changes: 10 additions & 0 deletions docs/predictions/standard/documents/receipt_v5.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Receipt V5
----------

**Sample Code:**

.. literalinclude:: /extras/code_samples/expense_receipts_v5.txt
:language: Python

.. autoclass:: mindee.documents.ReceiptV5
:members:
2 changes: 1 addition & 1 deletion docs/predictions/standard/documents/us/bank_check_v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bank Check V1

**Sample Code:**

.. literalinclude:: /extras/code_samples/us/bank_check_v1.txt
.. literalinclude:: /extras/code_samples/bank_check_v1.txt
:language: Python

.. autoclass:: mindee.documents.us.BankCheckV1
Expand Down
8 changes: 5 additions & 3 deletions docs/predictions/standard/international.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
International
=============

.. include:: ./documents/financial_document_v1.rst
.. include:: ./documents/passport_v1.rst
.. include:: ./documents/shipping_container_v1.rst
.. include:: ./documents/invoice_v3.rst
.. include:: ./documents/invoice_v4.rst
.. include:: ./documents/receipt_v3.rst
.. include:: ./documents/receipt_v4.rst
.. include:: ./documents/receipt_v5.rst
.. include:: ./documents/financial_document_v1.rst
.. include:: ./documents/passport_v1.rst
.. include:: ./documents/shipping_container_v1.rst
.. include:: ./documents/proof_of_address_v1.rst
2 changes: 1 addition & 1 deletion mindee/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CommandConfig(Generic[TypeDoc]):
),
"receipt": CommandConfig(
help="Expense Receipt",
doc_class=documents.TypeReceiptV4,
doc_class=documents.TypeReceiptV5,
),
"passport": CommandConfig(
help="Passport",
Expand Down
5 changes: 5 additions & 0 deletions mindee/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ def _init_default_endpoints(self) -> None:
url_name="expense_receipts",
version="4",
),
ConfigSpec(
doc_class=documents.ReceiptV5,
url_name="expense_receipts",
version="5",
),
ConfigSpec(
doc_class=documents.FinancialDocumentV1,
url_name="financial_document",
Expand Down
9 changes: 8 additions & 1 deletion mindee/documents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
from mindee.documents.invoice import InvoiceV3, InvoiceV4, TypeInvoiceV3, TypeInvoiceV4
from mindee.documents.passport import PassportV1, TypePassportV1
from mindee.documents.proof_of_address import ProofOfAddressV1, TypeProofOfAddressV1
from mindee.documents.receipt import ReceiptV3, ReceiptV4, TypeReceiptV3, TypeReceiptV4
from mindee.documents.receipt import (
ReceiptV3,
ReceiptV4,
ReceiptV5,
TypeReceiptV3,
TypeReceiptV4,
TypeReceiptV5,
)
from mindee.documents.shipping_container import (
ShippingContainerV1,
TypeShippingContainerV1,
Expand Down
6 changes: 3 additions & 3 deletions mindee/documents/financial/financial_document_v1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Optional, TypeVar

from mindee.documents.base import Document, TypeApiPrediction, clean_out_string
from mindee.documents.invoice.line_item import InvoiceLineItem
from mindee.documents.invoice.line_item_v4 import InvoiceLineItemV4
from mindee.fields.amount import AmountField
from mindee.fields.company_registration import CompanyRegistrationField
from mindee.fields.date import DateField
Expand Down Expand Up @@ -44,7 +44,7 @@ class FinancialDocumentV1(Document):
"""Customer company registration numbers"""
supplier_payment_details: List[PaymentDetails]
"""Payment details"""
line_items: List[InvoiceLineItem]
line_items: List[InvoiceLineItemV4]
"""Details of line items"""
tip: AmountField
"""Total amount of tip and gratuity."""
Expand Down Expand Up @@ -126,7 +126,7 @@ def _build_from_api_prediction(
for payment_detail in api_prediction["supplier_payment_details"]
]
self.line_items = [
InvoiceLineItem(prediction=line_item, page_n=page_n)
InvoiceLineItemV4(prediction=line_item, page_n=page_n)
for line_item in api_prediction["line_items"]
]
self.total_amount = AmountField(api_prediction["total_amount"], page_n=page_n)
Expand Down
6 changes: 3 additions & 3 deletions mindee/documents/invoice/invoice_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from mindee.documents.base import Document, TypeApiPrediction, clean_out_string
from mindee.documents.invoice import checks, reconstruct
from mindee.documents.invoice.line_item import InvoiceLineItem
from mindee.documents.invoice.line_item_v4 import InvoiceLineItemV4
from mindee.fields.amount import AmountField
from mindee.fields.company_registration import CompanyRegistrationField
from mindee.fields.date import DateField
Expand Down Expand Up @@ -45,7 +45,7 @@ class InvoiceV4(Document):
"""Customer company registration numbers"""
supplier_payment_details: List[PaymentDetails]
"""Payment details"""
line_items: List[InvoiceLineItem]
line_items: List[InvoiceLineItemV4]
"""Details of line items"""

def __init__(
Expand Down Expand Up @@ -116,7 +116,7 @@ def _build_from_api_prediction(
for payment_detail in api_prediction["supplier_payment_details"]
]
self.line_items = [
InvoiceLineItem(prediction=line_item, page_n=page_n)
InvoiceLineItemV4(prediction=line_item, page_n=page_n)
for line_item in api_prediction["line_items"]
]
self.total_amount = AmountField(api_prediction["total_amount"], page_n=page_n)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mindee.fields.base import FieldPositionMixin, TypePrediction, float_to_string


class InvoiceLineItem(FieldPositionMixin):
class InvoiceLineItemV4(FieldPositionMixin):
product_code: Optional[str]
"""The product code referring to the item."""
description: Optional[str]
Expand Down
1 change: 1 addition & 0 deletions mindee/documents/receipt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .receipt_v3 import ReceiptV3, TypeReceiptV3
from .receipt_v4 import ReceiptV4, TypeReceiptV4
from .receipt_v5 import ReceiptV5, TypeReceiptV5
58 changes: 58 additions & 0 deletions mindee/documents/receipt/line_item_v5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from typing import Optional

from mindee.fields.base import FieldPositionMixin, TypePrediction, float_to_string


class ReceiptV5LineItem(FieldPositionMixin):
description: Optional[str]
"""The item description."""
quantity: Optional[float]
"""The item quantity"""
unit_price: Optional[float]
"""The item unit price."""
total_amount: Optional[float]
"""The item total amount."""
confidence: float = 0.0
"""Confidence score"""
page_n: int
"""The document page on which the information was found."""

def __init__(
self,
prediction: TypePrediction,
page_n: Optional[int] = None,
):
self._set_position(prediction)

if page_n is None:
self.page_n = prediction["page_id"]
else:
self.page_n = page_n

try:
self.confidence = float(prediction["confidence"])
except (KeyError, TypeError):
pass

def to_opt_float(key: str) -> Optional[float]:
try:
return float(prediction[key])
except TypeError:
return None

self.description = prediction["description"]
self.quantity = to_opt_float("quantity")
self.unit_price = to_opt_float("unit_price")
self.total_amount = to_opt_float("total_amount")

def __str__(self) -> str:
description = self.description or ""
if len(description) > 32:
description = description[:32] + "..."
row = [
float_to_string(self.quantity),
float_to_string(self.unit_price),
float_to_string(self.total_amount),
description,
]
return "| {:<8} | {:<8} | {:<9} | {:<34} |".format(*row)
Loading