File tree Expand file tree Collapse file tree 9 files changed +31
-20
lines changed Expand file tree Collapse file tree 9 files changed +31
-20
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ def serialize_for_json(obj: Any) -> Any:
1919 return vars (obj )
2020
2121
22+ def clean_out_string (out_string : str ) -> str :
23+ """Clean up the string representation."""
24+ regexp = re .compile (r" \n" )
25+ return regexp .sub ("\n " , out_string )
26+
27+
2228class Document :
2329 type : str
2430 """Document type"""
@@ -83,11 +89,5 @@ def all_checks(self) -> bool:
8389 """Return status of all checks."""
8490 return all (self .checklist )
8591
86- @staticmethod
87- def clean_out_string (out_string : str ) -> str :
88- """Clean up the string representation."""
89- regexp = re .compile (r" \n" )
90- return regexp .sub ("\n " , out_string )
91-
9292
9393TypeDocument = TypeVar ("TypeDocument" , bound = Document )
Original file line number Diff line number Diff line change 11from typing import Dict , Optional , TypeVar
22
3- from mindee .documents .base import Document , TypeApiPrediction
3+ from mindee .documents .base import Document , TypeApiPrediction , clean_out_string
44from mindee .fields .api_builder import ClassificationField , ListField
55
66
@@ -60,7 +60,7 @@ def __str__(self) -> str:
6060 for field_name , field_info in self .fields .items ():
6161 custom_doc_str += f"{ field_name } : { field_info } \n "
6262 custom_doc_str += "----------------------"
63- return self . clean_out_string (custom_doc_str )
63+ return clean_out_string (custom_doc_str )
6464
6565 def _checklist (self ) -> None :
6666 pass
Original file line number Diff line number Diff line change 11from typing import List , Optional , TypeVar
22
3- from mindee .documents .base import Document , TypeApiPrediction
3+ from mindee .documents .base import Document , TypeApiPrediction , clean_out_string
44from mindee .documents .invoice .invoice_v3 import InvoiceV3
55from mindee .documents .receipt .receipt_v3 import ReceiptV3
66from mindee .endpoints import Endpoint
@@ -125,7 +125,7 @@ def _build_from_api_prediction(
125125 self .customer_address = TextField ({"value" : None , "confidence" : 0.0 })
126126
127127 def __str__ (self ) -> str :
128- return self . clean_out_string (
128+ return clean_out_string (
129129 "-----Financial Document data-----\n "
130130 f"Filename: { self .filename or '' } \n "
131131 f"Invoice number: { self .invoice_number .value } \n "
Original file line number Diff line number Diff line change 11from typing import List , Optional , TypeVar
22
3- from mindee .documents .base import Document , TypeApiPrediction
3+ from mindee .documents .base import Document , TypeApiPrediction , clean_out_string
44from mindee .fields .amount import AmountField
55from mindee .fields .base import field_array_confidence
66from mindee .fields .company_registration import CompanyRegistrationField
@@ -126,7 +126,7 @@ def __str__(self) -> str:
126126 [str (p ) for p in self .payment_details ]
127127 )
128128 taxes = "\n " .join (f"{ t } " for t in self .taxes )
129- return self . clean_out_string (
129+ return clean_out_string (
130130 "-----Invoice data-----\n "
131131 f"Filename: { self .filename or '' } \n "
132132 f"Invoice number: { self .invoice_number } \n "
Original file line number Diff line number Diff line change 11from datetime import datetime
22from typing import List , Optional , TypeVar
33
4- from mindee .documents .base import Document , TypeApiPrediction
4+ from mindee .documents .base import Document , TypeApiPrediction , clean_out_string
55from mindee .fields .base import field_array_confidence
66from mindee .fields .date import DateField
77from mindee .fields .text import TextField
@@ -92,7 +92,7 @@ def __str__(self) -> str:
9292 for given_name in self .given_names
9393 ]
9494 )
95- return self . clean_out_string (
95+ return clean_out_string (
9696 "-----Passport data-----\n "
9797 f"Filename: { self .filename or '' } \n "
9898 f"Full name: { self .full_name } \n "
Original file line number Diff line number Diff line change 11from typing import List , Optional , TypeVar
22
3- from mindee .documents .base import Document , TypeApiPrediction
3+ from mindee .documents .base import Document , TypeApiPrediction , clean_out_string
44from mindee .fields .amount import AmountField
55from mindee .fields .base import field_array_confidence , field_array_sum
66from mindee .fields .date import DateField
@@ -56,7 +56,7 @@ def __init__(
5656
5757 def __str__ (self ) -> str :
5858 taxes = "\n " .join (f"{ t } " for t in self .taxes )
59- return self . clean_out_string (
59+ return clean_out_string (
6060 "-----Receipt data-----\n "
6161 f"Filename: { self .filename or '' } \n "
6262 f"Total amount including taxes: { self .total_incl } \n "
Original file line number Diff line number Diff line change 11from typing import List , Optional , TypeVar
22
3- from mindee .documents .base import Document , TypeApiPrediction
3+ from mindee .documents .base import Document , TypeApiPrediction , clean_out_string
44from mindee .fields .amount import AmountField
55from mindee .fields .date import DateField
66from mindee .fields .locale import LocaleField
@@ -93,7 +93,7 @@ def _build_from_api_prediction(
9393
9494 def __str__ (self ) -> str :
9595 taxes = "\n " .join (f"{ t } " for t in self .taxes )
96- return self . clean_out_string (
96+ return clean_out_string (
9797 "----- Receipt V4 -----\n "
9898 f"Filename: { self .filename or '' } \n "
9999 f"Total amount: { self .total_amount } \n "
Original file line number Diff line number Diff line change 11from typing import List , Optional , TypeVar
22
3- from mindee .documents .base import Document , TypeApiPrediction
3+ from mindee .documents .base import Document , TypeApiPrediction , clean_out_string
44from mindee .fields .amount import AmountField
55from mindee .fields .date import DateField
66from mindee .fields .orientation import OrientationField
@@ -82,7 +82,7 @@ def __str__(self) -> str:
8282 payees = ", " .join (
8383 [payee .value if payee .value is not None else "" for payee in self .payees ]
8484 )
85- return (
85+ return clean_out_string (
8686 "----- US Bank Check -----\n "
8787 f"Filename: { self .filename or '' } " .rstrip () + "\n "
8888 f"Routing number: { self .routing_number } \n "
Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ class PredictResponse(Generic[TypeDocument]):
1717 """Raw HTTP response JSON"""
1818 document_type : str
1919 """Document type"""
20+ input_path : Optional [str ] = None
21+ """Path of the input file"""
22+ input_filename : Optional [str ] = None
23+ """Name of the input file"""
24+ input_mimetype : Optional [str ] = None
25+ """MIME type of the input file"""
2026 document : Optional [TypeDocument ]
2127 """An instance of the ``Document`` class, according to the type given."""
2228 pages : List [TypeDocument ]
@@ -42,6 +48,11 @@ def __init__(
4248 self .document_type = doc_config .document_type
4349 self .pages = []
4450
51+ if input_source :
52+ self .input_path = input_source .filepath
53+ self .input_filename = input_source .filename
54+ self .input_mimetype = input_source .file_mimetype
55+
4556 if not response_ok :
4657 self .document = None
4758 else :
You can’t perform that action at this time.
0 commit comments