Skip to content

Commit 3d4a2e4

Browse files
✨ add support for Classification
1 parent 4a2199e commit 3d4a2e4

22 files changed

Lines changed: 188 additions & 2 deletions

mindee/v2/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
from mindee.v2.product.classification.classification_parameters import (
2+
ClassificationParameters,
3+
)
4+
from mindee.v2.product.classification.classification_response import (
5+
ClassificationResponse,
6+
)
17
from mindee.v2.product.crop.crop_parameters import CropParameters
28
from mindee.v2.product.crop.crop_response import CropResponse
39
from mindee.v2.product.ocr.ocr_parameters import OCRParameters
@@ -6,6 +12,8 @@
612
from mindee.v2.product.split.split_response import SplitResponse
713

814
__all__ = [
15+
"ClassificationResponse",
16+
"ClassificationParameters",
917
"CropResponse",
1018
"CropParameters",
1119
"OCRResponse",

mindee/v2/product/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
from mindee.v2.product.classification.classification_parameters import (
2+
ClassificationParameters,
3+
)
4+
from mindee.v2.product.classification.classification_response import (
5+
ClassificationResponse,
6+
)
17
from mindee.v2.product.crop.crop_parameters import CropParameters
28
from mindee.v2.product.crop.crop_response import CropResponse
39
from mindee.v2.product.ocr.ocr_parameters import OCRParameters
@@ -6,6 +12,8 @@
612
from mindee.v2.product.split.split_response import SplitResponse
713

814
__all__ = [
15+
"ClassificationParameters",
16+
"ClassificationResponse",
917
"CropResponse",
1018
"CropParameters",
1119
"OCRResponse",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from mindee.v2.product.classification.classification_classifier import (
2+
ClassificationClassifier,
3+
)
4+
from mindee.v2.product.classification.classification_inference import (
5+
ClassificationInference,
6+
)
7+
from mindee.v2.product.classification.classification_parameters import (
8+
ClassificationParameters,
9+
)
10+
from mindee.v2.product.classification.classification_response import (
11+
ClassificationResponse,
12+
)
13+
from mindee.v2.product.classification.classification_result import ClassificationResult
14+
15+
__all__ = [
16+
"ClassificationClassifier",
17+
"ClassificationInference",
18+
"ClassificationParameters",
19+
"ClassificationResponse",
20+
"ClassificationResult",
21+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from mindee.parsing.common.string_dict import StringDict
2+
3+
4+
class ClassificationClassifier:
5+
"""Document level classification."""
6+
7+
document_type: str
8+
"""The document type, as identified on given classification values."""
9+
10+
def __init__(self, server_response: StringDict):
11+
self.document_type = server_response["document_type"]
12+
13+
def __str__(self) -> str:
14+
return f":Document Type: {self.document_type}"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from mindee.parsing.common.string_dict import StringDict
2+
from mindee.v2.parsing.inference.base_inference import BaseInference
3+
from mindee.v2.product.classification.classification_result import ClassificationResult
4+
5+
6+
class ClassificationInference(BaseInference):
7+
"""The inference result for a classification utility request."""
8+
9+
result: ClassificationResult
10+
"""Result of a classification inference."""
11+
_slug: str = "classification"
12+
"""Slug of the endpoint."""
13+
14+
def __init__(self, raw_response: StringDict) -> None:
15+
super().__init__(raw_response)
16+
self.result = ClassificationResult(raw_response["result"])
17+
18+
def __str__(self) -> str:
19+
return f"Inference\n#########\n{self.model}\n{self.file}\n{self.result}\n"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from mindee.input.base_parameters import BaseParameters
2+
3+
4+
class ClassificationParameters(BaseParameters):
5+
"""
6+
Parameters accepted by the classification utility v2 endpoint.
7+
"""
8+
9+
_slug: str = "utilities/classification"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from mindee.parsing.common.string_dict import StringDict
2+
from mindee.v2.parsing.inference import BaseResponse
3+
from mindee.v2.product.classification.classification_inference import (
4+
ClassificationInference,
5+
)
6+
7+
8+
class ClassificationResponse(BaseResponse):
9+
"""Represent a classification inference response from Mindee V2 API."""
10+
11+
inference: ClassificationInference
12+
"""Inference object for classification inference."""
13+
14+
_slug: str = "utilities/classification"
15+
"""Slug of the inference."""
16+
17+
def __init__(self, raw_response: StringDict) -> None:
18+
super().__init__(raw_response)
19+
self.inference = ClassificationInference(raw_response["inference"])
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from mindee.parsing.common.string_dict import StringDict
2+
from mindee.v2.product.classification.classification_classifier import (
3+
ClassificationClassifier,
4+
)
5+
6+
7+
class ClassificationResult:
8+
"""Classification result info."""
9+
10+
classification: ClassificationClassifier
11+
12+
def __init__(self, raw_response: StringDict) -> None:
13+
self.classification = ClassificationClassifier(raw_response["classification"])
14+
15+
def __str__(self) -> str:
16+
return f"Classification\n======{self.classification}"

mindee/v2/product/split/split_range.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ class SplitRange:
77
"""Split inference result."""
88

99
page_range: List[int]
10-
"""Page range of the split inference."""
10+
"""
11+
0-based page indexes, where the first integer indicates the start page and the
12+
second integer indicates the end page.
13+
"""
1114
document_type: str
12-
"""Document type of the split inference."""
15+
"""The document type, as identified on given classification values."""
1316

1417
def __init__(self, server_response: StringDict):
1518
self.page_range = server_response["page_range"]

0 commit comments

Comments
 (0)