|
1 | | -from pathlib import Path |
2 | 1 | from time import sleep |
3 | | -from typing import BinaryIO, Dict, Optional, Type, Union |
| 2 | +from typing import Dict, Optional, Type, Union |
4 | 3 |
|
| 4 | +from mindee.client_mixin import ClientMixin |
5 | 5 | from mindee.error.mindee_error import MindeeClientError, MindeeError |
6 | 6 | from mindee.error.mindee_http_error import handle_error |
7 | 7 | from mindee.input import WorkflowOptions |
8 | 8 | from mindee.input.local_response import LocalResponse |
9 | 9 | from mindee.input.page_options import PageOptions |
10 | 10 | from mindee.input.predict_options import AsyncPredictOptions, PredictOptions |
11 | | -from mindee.input.sources.base_64_input import Base64Input |
12 | | -from mindee.input.sources.bytes_input import BytesInput |
13 | | -from mindee.input.sources.file_input import FileInput |
14 | 11 | from mindee.input.sources.local_input_source import LocalInputSource |
15 | | -from mindee.input.sources.path_input import PathInput |
16 | 12 | from mindee.input.sources.url_input_source import UrlInputSource |
17 | 13 | from mindee.logger import logger |
18 | 14 | from mindee.mindee_http.endpoint import CustomEndpoint, Endpoint |
@@ -55,7 +51,7 @@ def _clean_account_name(account_name: str) -> str: |
55 | 51 | return account_name |
56 | 52 |
|
57 | 53 |
|
58 | | -class Client: |
| 54 | +class Client(ClientMixin): |
59 | 55 | """ |
60 | 56 | Mindee API Client. |
61 | 57 |
|
@@ -275,23 +271,6 @@ def execute_workflow( |
275 | 271 | logger.debug("Sending document to workflow: %s", workflow_id) |
276 | 272 | return self._send_to_workflow(GeneratedV1, input_source, workflow_id, options) |
277 | 273 |
|
278 | | - def _validate_async_params( |
279 | | - self, initial_delay_sec: float, delay_sec: float, max_retries: int |
280 | | - ) -> None: |
281 | | - min_delay = 1 |
282 | | - min_initial_delay = 1 |
283 | | - min_retries = 1 |
284 | | - if delay_sec < min_delay: |
285 | | - raise MindeeClientError( |
286 | | - f"Cannot set auto-parsing delay to less than {min_delay} second(s)." |
287 | | - ) |
288 | | - if initial_delay_sec < min_initial_delay: |
289 | | - raise MindeeClientError( |
290 | | - f"Cannot set initial parsing delay to less than {min_initial_delay} second(s)." |
291 | | - ) |
292 | | - if max_retries < min_retries: |
293 | | - raise MindeeClientError(f"Cannot set retries to less than {min_retries}.") |
294 | | - |
295 | 274 | def enqueue_and_parse( # pylint: disable=too-many-locals |
296 | 275 | self, |
297 | 276 | product_class: Type[Inference], |
@@ -583,80 +562,3 @@ def create_endpoint( |
583 | 562 | ) |
584 | 563 | version = "1" |
585 | 564 | return self._build_endpoint(endpoint_name, account_name, version) |
586 | | - |
587 | | - @staticmethod |
588 | | - def source_from_path( |
589 | | - input_path: Union[Path, str], fix_pdf: bool = False |
590 | | - ) -> PathInput: |
591 | | - """ |
592 | | - Load a document from an absolute path, as a string. |
593 | | -
|
594 | | - :param input_path: Path of file to open |
595 | | - :param fix_pdf: Whether to attempt fixing PDF files before sending. |
596 | | - Setting this to `True` can modify the data sent to Mindee. |
597 | | - """ |
598 | | - input_doc = PathInput(input_path) |
599 | | - if fix_pdf: |
600 | | - input_doc.fix_pdf() |
601 | | - return input_doc |
602 | | - |
603 | | - @staticmethod |
604 | | - def source_from_file(input_file: BinaryIO, fix_pdf: bool = False) -> FileInput: |
605 | | - """ |
606 | | - Load a document from a normal Python file object/handle. |
607 | | -
|
608 | | - :param input_file: Input file handle |
609 | | - :param fix_pdf: Whether to attempt fixing PDF files before sending. |
610 | | - Setting this to `True` can modify the data sent to Mindee. |
611 | | - """ |
612 | | - input_doc = FileInput(input_file) |
613 | | - if fix_pdf: |
614 | | - input_doc.fix_pdf() |
615 | | - return input_doc |
616 | | - |
617 | | - @staticmethod |
618 | | - def source_from_b64string( |
619 | | - input_string: str, filename: str, fix_pdf: bool = False |
620 | | - ) -> Base64Input: |
621 | | - """ |
622 | | - Load a document from a base64 encoded string. |
623 | | -
|
624 | | - :param input_string: Input to parse as base64 string |
625 | | - :param filename: The name of the file (without the path) |
626 | | - :param fix_pdf: Whether to attempt fixing PDF files before sending. |
627 | | - Setting this to `True` can modify the data sent to Mindee. |
628 | | - """ |
629 | | - input_doc = Base64Input(input_string, filename) |
630 | | - if fix_pdf: |
631 | | - input_doc.fix_pdf() |
632 | | - return input_doc |
633 | | - |
634 | | - @staticmethod |
635 | | - def source_from_bytes( |
636 | | - input_bytes: bytes, filename: str, fix_pdf: bool = False |
637 | | - ) -> BytesInput: |
638 | | - """ |
639 | | - Load a document from raw bytes. |
640 | | -
|
641 | | - :param input_bytes: Raw byte input |
642 | | - :param filename: The name of the file (without the path) |
643 | | - :param fix_pdf: Whether to attempt fixing PDF files before sending. |
644 | | - Setting this to `True` can modify the data sent to Mindee. |
645 | | - """ |
646 | | - input_doc = BytesInput(input_bytes, filename) |
647 | | - if fix_pdf: |
648 | | - input_doc.fix_pdf() |
649 | | - return input_doc |
650 | | - |
651 | | - @staticmethod |
652 | | - def source_from_url( |
653 | | - url: str, |
654 | | - ) -> UrlInputSource: |
655 | | - """ |
656 | | - Load a document from a URL. |
657 | | -
|
658 | | - :param url: Raw byte input |
659 | | - """ |
660 | | - return UrlInputSource( |
661 | | - url, |
662 | | - ) |
0 commit comments