-
Notifications
You must be signed in to change notification settings - Fork 6
✨ add support for V2 Classification, Crop and OCR utilities #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c3af04d
:sparkles: add support for crop utility
sebastianMindee 4a2199e
:sparkles: add support for OCR V2 (+ fix tests)
sebastianMindee 3d4a2e4
:sparkles: add support for Classification
sebastianMindee a596ee1
fix imports
sebastianMindee ef12c6c
fix typos again
sebastianMindee fdc99d9
fix mixup
sebastianMindee 4ffea7a
fixes
sebastianMindee b8be311
fix typos
sebastianMindee f68faf3
fix typo
sebastianMindee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from mindee import ( | ||
| ClientV2, | ||
| PathInput, | ||
| ClassificationParameters, | ||
| ClassificationResponse, | ||
| ) | ||
|
|
||
| input_path = "/path/to/the/file.ext" | ||
| api_key = "MY_API_KEY" | ||
| model_id = "MY_CLASSIFICATION_MODEL_ID" | ||
|
|
||
| # Init a new client | ||
| mindee_client = ClientV2(api_key) | ||
|
|
||
| # Set parameters | ||
| params = ClassificationParameters( | ||
| # ID of the model, required. | ||
| model_id=model_id, | ||
| ) | ||
|
|
||
| # Load a file from disk | ||
| input_source = PathInput(input_path) | ||
|
|
||
| # Send for processing using polling | ||
| response = mindee_client.enqueue_and_get_result( | ||
| ClassificationResponse, | ||
| input_source, | ||
| params, | ||
| ) | ||
|
|
||
| # Print a brief summary of the parsed data | ||
| print(response.inference) | ||
|
|
||
| # Access the classification result | ||
| classification: str = response.inference.result.classification.document_type |
sebastianMindee marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from mindee import ( | ||
| ClientV2, | ||
| PathInput, | ||
| CropParameters, | ||
| CropResponse, | ||
| ) | ||
|
|
||
| input_path = "/path/to/the/file.ext" | ||
| api_key = "MY_API_KEY" | ||
| model_id = "MY_CROP_MODEL_ID" | ||
|
|
||
| # Init a new client | ||
| mindee_client = ClientV2(api_key) | ||
|
|
||
| # Set parameters | ||
| params = CropParameters( | ||
| # ID of the model, required. | ||
| model_id=model_id, | ||
| ) | ||
|
|
||
| # Load a file from disk | ||
| input_source = PathInput(input_path) | ||
|
|
||
| # Send for processing using polling | ||
| response = mindee_client.enqueue_and_get_result( | ||
| CropResponse, | ||
| input_source, | ||
| params, | ||
| ) | ||
|
|
||
| # Print a brief summary of the parsed data | ||
| print(response.inference) | ||
|
|
||
| # Access the crop result | ||
| crops: list = response.inference.result.crops |
sebastianMindee marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from mindee import ( | ||
| ClientV2, | ||
| PathInput, | ||
| OCRParameters, | ||
| OCRResponse, | ||
| ) | ||
|
|
||
| input_path = "/path/to/the/file.ext" | ||
| api_key = "MY_API_KEY" | ||
| model_id = "MY_OCR_MODEL_ID" | ||
|
|
||
| # Init a new client | ||
| mindee_client = ClientV2(api_key) | ||
|
|
||
| # Set parameters | ||
| params = OCRParameters( | ||
| # ID of the model, required. | ||
| model_id=model_id, | ||
| ) | ||
|
|
||
| # Load a file from disk | ||
| input_source = PathInput(input_path) | ||
|
|
||
| # Send for processing using polling | ||
| response = mindee_client.enqueue_and_get_result( | ||
| OCRResponse, | ||
| input_source, | ||
| params, | ||
| ) | ||
|
|
||
| # Print a brief summary of the parsed data | ||
| print(response.inference) | ||
|
|
||
| # Access the ocr result | ||
| pages: list = response.inference.result.pages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,23 @@ | ||
| from mindee.v2.product.classification.classification_parameters import ( | ||
| ClassificationParameters, | ||
| ) | ||
| from mindee.v2.product.classification.classification_response import ( | ||
| ClassificationResponse, | ||
| ) | ||
| from mindee.v2.product.crop.crop_parameters import CropParameters | ||
| from mindee.v2.product.crop.crop_response import CropResponse | ||
| from mindee.v2.product.ocr.ocr_parameters import OCRParameters | ||
| from mindee.v2.product.ocr.ocr_response import OCRResponse | ||
| from mindee.v2.product.split.split_parameters import SplitParameters | ||
| from mindee.v2.product.split.split_response import SplitResponse | ||
|
|
||
| __all__ = [ | ||
| "ClassificationResponse", | ||
| "ClassificationParameters", | ||
| "CropResponse", | ||
| "CropParameters", | ||
| "OCRResponse", | ||
| "OCRParameters", | ||
| "SplitResponse", | ||
| "SplitParameters", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,23 @@ | ||
| from mindee.v2.product.classification.classification_parameters import ( | ||
| ClassificationParameters, | ||
| ) | ||
| from mindee.v2.product.classification.classification_response import ( | ||
| ClassificationResponse, | ||
| ) | ||
| from mindee.v2.product.crop.crop_parameters import CropParameters | ||
| from mindee.v2.product.crop.crop_response import CropResponse | ||
| from mindee.v2.product.ocr.ocr_parameters import OCRParameters | ||
| from mindee.v2.product.ocr.ocr_response import OCRResponse | ||
| from mindee.v2.product.split.split_parameters import SplitParameters | ||
| from mindee.v2.product.split.split_response import SplitResponse | ||
|
|
||
| __all__ = [ | ||
| "ClassificationParameters", | ||
| "ClassificationResponse", | ||
| "CropResponse", | ||
| "CropParameters", | ||
| "OCRResponse", | ||
| "OCRParameters", | ||
| "SplitResponse", | ||
| "SplitParameters", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from mindee.v2.product.classification.classification_classifier import ( | ||
| ClassificationClassifier, | ||
| ) | ||
| from mindee.v2.product.classification.classification_inference import ( | ||
| ClassificationInference, | ||
| ) | ||
| from mindee.v2.product.classification.classification_parameters import ( | ||
| ClassificationParameters, | ||
| ) | ||
| from mindee.v2.product.classification.classification_response import ( | ||
| ClassificationResponse, | ||
| ) | ||
| from mindee.v2.product.classification.classification_result import ClassificationResult | ||
|
|
||
| __all__ = [ | ||
| "ClassificationClassifier", | ||
| "ClassificationInference", | ||
| "ClassificationParameters", | ||
| "ClassificationResponse", | ||
| "ClassificationResult", | ||
| ] |
14 changes: 14 additions & 0 deletions
14
mindee/v2/product/classification/classification_classifier.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from mindee.parsing.common.string_dict import StringDict | ||
|
|
||
|
|
||
| class ClassificationClassifier: | ||
| """Document level classification.""" | ||
|
|
||
| document_type: str | ||
| """The document type, as identified on given classification values.""" | ||
|
|
||
| def __init__(self, server_response: StringDict): | ||
| self.document_type = server_response["document_type"] | ||
|
|
||
| def __str__(self) -> str: | ||
| return f":Document Type: {self.document_type}" |
19 changes: 19 additions & 0 deletions
19
mindee/v2/product/classification/classification_inference.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from mindee.parsing.common.string_dict import StringDict | ||
| from mindee.v2.parsing.inference.base_inference import BaseInference | ||
| from mindee.v2.product.classification.classification_result import ClassificationResult | ||
|
|
||
|
|
||
| class ClassificationInference(BaseInference): | ||
| """The inference result for a classification utility request.""" | ||
|
|
||
| result: ClassificationResult | ||
| """Result of a classification inference.""" | ||
| _slug: str = "classification" | ||
| """Slug of the endpoint.""" | ||
|
|
||
| def __init__(self, raw_response: StringDict) -> None: | ||
| super().__init__(raw_response) | ||
| self.result = ClassificationResult(raw_response["result"]) | ||
|
|
||
| def __str__(self) -> str: | ||
| return f"Inference\n#########\n{self.model}\n{self.file}\n{self.result}\n" |
9 changes: 9 additions & 0 deletions
9
mindee/v2/product/classification/classification_parameters.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from mindee.input.base_parameters import BaseParameters | ||
|
|
||
|
|
||
| class ClassificationParameters(BaseParameters): | ||
| """ | ||
| Parameters accepted by the classification utility v2 endpoint. | ||
| """ | ||
|
|
||
| _slug: str = "utilities/classification" |
19 changes: 19 additions & 0 deletions
19
mindee/v2/product/classification/classification_response.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from mindee.parsing.common.string_dict import StringDict | ||
| from mindee.v2.parsing.inference import BaseResponse | ||
| from mindee.v2.product.classification.classification_inference import ( | ||
| ClassificationInference, | ||
| ) | ||
|
|
||
|
|
||
| class ClassificationResponse(BaseResponse): | ||
| """Represent a classification inference response from Mindee V2 API.""" | ||
|
|
||
| inference: ClassificationInference | ||
| """Inference object for classification inference.""" | ||
|
|
||
| _slug: str = "utilities/classification" | ||
| """Slug of the inference.""" | ||
|
|
||
| def __init__(self, raw_response: StringDict) -> None: | ||
| super().__init__(raw_response) | ||
| self.inference = ClassificationInference(raw_response["inference"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from mindee.parsing.common.string_dict import StringDict | ||
| from mindee.v2.product.classification.classification_classifier import ( | ||
| ClassificationClassifier, | ||
| ) | ||
|
|
||
|
|
||
| class ClassificationResult: | ||
| """Classification result info.""" | ||
|
|
||
| classification: ClassificationClassifier | ||
|
|
||
| def __init__(self, raw_response: StringDict) -> None: | ||
| self.classification = ClassificationClassifier(raw_response["classification"]) | ||
|
|
||
| def __str__(self) -> str: | ||
| return f"Classification\n======{self.classification}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from mindee.v2.product.crop.crop_box import CropBox | ||
| from mindee.v2.product.crop.crop_inference import CropInference | ||
| from mindee.v2.product.crop.crop_parameters import CropParameters | ||
| from mindee.v2.product.crop.crop_response import CropResponse | ||
| from mindee.v2.product.crop.crop_result import CropResult | ||
|
|
||
| __all__ = [ | ||
| "CropBox", | ||
| "CropInference", | ||
| "CropParameters", | ||
| "CropResponse", | ||
| "CropResult", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from mindee.parsing.common.string_dict import StringDict | ||
| from mindee.parsing.v2.field.field_location import FieldLocation | ||
|
|
||
|
|
||
| class CropBox: | ||
| """Crop inference result.""" | ||
|
|
||
| location: FieldLocation | ||
| """Location which includes cropping coordinates for the detected object, within the source document.""" | ||
| object_type: str | ||
| """Type or classification of the detected object.""" | ||
|
|
||
| def __init__(self, server_response: StringDict): | ||
| self.location = FieldLocation(server_response["location"]) | ||
| self.object_type = server_response["object_type"] | ||
|
|
||
| def __str__(self) -> str: | ||
| return f"* :Location: {self.location}\n :Object Type: {self.object_type}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from mindee.parsing.common.string_dict import StringDict | ||
| from mindee.v2.parsing.inference.base_inference import BaseInference | ||
| from mindee.v2.product.crop.crop_result import CropResult | ||
|
|
||
|
|
||
| class CropInference(BaseInference): | ||
| """Crop inference result.""" | ||
|
|
||
| result: CropResult | ||
| """Result of a crop inference.""" | ||
| _slug: str = "crop" | ||
| """Slug of the endpoint.""" | ||
|
|
||
| def __init__(self, raw_response: StringDict) -> None: | ||
| super().__init__(raw_response) | ||
| self.result = CropResult(raw_response["result"]) | ||
|
|
||
| def __str__(self) -> str: | ||
| return f"Inference\n#########\n{self.model}\n{self.file}\n{self.result}\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from mindee.input.base_parameters import BaseParameters | ||
|
|
||
|
|
||
| class CropParameters(BaseParameters): | ||
| """ | ||
| Parameters accepted by the crop utility v2 endpoint. | ||
| """ | ||
|
|
||
| _slug: str = "utilities/crop" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.