zhangyubo0722 10 сар өмнө
parent
commit
369d8ee3a1
36 өөрчлөгдсөн 187 нэмэгдсэн , 170 устгасан
  1. 3 3
      paddlex/inference/models_new/base/predictor/base_predictor.py
  2. 13 13
      paddlex/inference/models_new/common/tokenizer/tokenizer_utils.py
  3. 3 3
      paddlex/inference/pipelines_new/anomaly_detection/pipeline.py
  4. 6 6
      paddlex/inference/pipelines_new/components/common/crop_image_regions.py
  5. 3 2
      paddlex/inference/pipelines_new/components/common/sort_boxes.py
  6. 4 4
      paddlex/inference/pipelines_new/components/retriever/ernie_bot_retriever.py
  7. 4 4
      paddlex/inference/pipelines_new/components/retriever/openai_bot_retriever.py
  8. 3 3
      paddlex/inference/pipelines_new/doc_preprocessor/pipeline.py
  9. 3 3
      paddlex/inference/pipelines_new/formula_recognition/pipeline.py
  10. 3 3
      paddlex/inference/pipelines_new/image_classification/pipeline.py
  11. 4 4
      paddlex/inference/pipelines_new/image_multilabel_classification/pipeline.py
  12. 3 3
      paddlex/inference/pipelines_new/instance_segmentation/pipeline.py
  13. 3 3
      paddlex/inference/pipelines_new/keypoint_detection/pipeline.py
  14. 3 3
      paddlex/inference/pipelines_new/layout_parsing/pipeline.py
  15. 5 7
      paddlex/inference/pipelines_new/layout_parsing/pipeline_v2.py
  16. 5 4
      paddlex/inference/pipelines_new/layout_parsing/utils.py
  17. 3 3
      paddlex/inference/pipelines_new/multilingual_speech_recognition/pipeline.py
  18. 13 10
      paddlex/inference/pipelines_new/object_detection/pipeline.py
  19. 3 3
      paddlex/inference/pipelines_new/ocr/pipeline.py
  20. 3 3
      paddlex/inference/pipelines_new/open_vocabulary_detection/pipeline.py
  21. 4 4
      paddlex/inference/pipelines_new/open_vocabulary_segmentation/pipeline.py
  22. 11 11
      paddlex/inference/pipelines_new/pp_chatocr/pipeline_v3.py
  23. 12 12
      paddlex/inference/pipelines_new/pp_chatocr/pipeline_v4.py
  24. 3 3
      paddlex/inference/pipelines_new/rotated_object_detection/pipeline.py
  25. 2 2
      paddlex/inference/pipelines_new/seal_recognition/pipeline.py
  26. 3 3
      paddlex/inference/pipelines_new/semantic_segmentation/pipeline.py
  27. 3 3
      paddlex/inference/pipelines_new/small_object_detection/pipeline.py
  28. 4 4
      paddlex/inference/pipelines_new/table_recognition/pipeline.py
  29. 30 18
      paddlex/inference/pipelines_new/table_recognition/pipeline_v2.py
  30. 3 3
      paddlex/inference/pipelines_new/ts_anomaly_detection/pipeline.py
  31. 3 3
      paddlex/inference/pipelines_new/ts_classification/pipeline.py
  32. 3 3
      paddlex/inference/pipelines_new/ts_forecasting/pipeline.py
  33. 3 3
      paddlex/inference/pipelines_new/video_classification/pipeline.py
  34. 3 3
      paddlex/inference/pipelines_new/video_detection/pipeline.py
  35. 5 4
      paddlex/repo_apis/PaddleDetection_api/instance_seg/config.py
  36. 5 4
      paddlex/repo_apis/PaddleDetection_api/object_det/config.py

+ 3 - 3
paddlex/inference/models_new/base/predictor/base_predictor.py

@@ -56,7 +56,7 @@ class BasePredictor(ABC):
 
     MODEL_FILE_PREFIX = "inference"
 
-    def __init__(self, model_dir: str, config: dict = None) -> None:
+    def __init__(self, model_dir: str, config: Dict = None) -> None:
         """Initializes the BasePredictor.
 
         Args:
@@ -106,7 +106,7 @@ class BasePredictor(ABC):
         return model_dir / f"{cls.MODEL_FILE_PREFIX}.yml"
 
     @classmethod
-    def load_config(cls, model_dir) -> dict:
+    def load_config(cls, model_dir) -> Dict:
         """Load the configuration from the specified model directory.
 
         Args:
@@ -119,7 +119,7 @@ class BasePredictor(ABC):
         return yaml_reader.read(cls.get_config_path(model_dir))
 
     @abstractmethod
-    def __call__(self, input: Any, **kwargs: dict[str, Any]) -> Iterator[Any]:
+    def __call__(self, input: Any, **kwargs: Dict[str, Any]) -> Iterator[Any]:
         """Predict with the given input and additional keyword arguments."""
         raise NotImplementedError
 

+ 13 - 13
paddlex/inference/models_new/common/tokenizer/tokenizer_utils.py

@@ -66,8 +66,8 @@ __all__ = [
 
 @dataclass
 class ChatTemplate:
-    conversation: list[str] | None = None
-    system: str | None = None
+    conversation: Union[List[str], None] = None
+    system: Union[str, None] = None
     query: str = None
 
     @staticmethod
@@ -84,10 +84,10 @@ class ChatTemplate:
 
     def render_conversation(
         self,
-        conversation_data: list[str] | dict[str, str],
+        conversation_data: Union[List[str], Dict[str, str]],
         index: int = 0,
         context_data: Dict[str, Any] = {},
-    ) -> list[str]:
+    ) -> List[str]:
         """
         Args:
             conversation_data (list[str]): the conversation data which must be two parts
@@ -145,7 +145,7 @@ class ChatTemplate:
 
     def __call__(
         self,
-        conversations: list[list[str]] | str,
+        conversations: Union[List[List[str]], str],
         context_data: Dict[str, Union[int, str]] = {},
     ) -> str:
         """render the conversations by chat-template
@@ -188,7 +188,7 @@ class ChatTemplate:
         return final_query
 
     @classmethod
-    def from_dict(cls, config: dict):
+    def from_dict(cls, config: Dict):
         return cls(**config)
 
     @classmethod
@@ -641,11 +641,11 @@ class ChatTemplateMixin:
 
     def apply_chat_template(
         self,
-        conversation: Union[Dict[str, str] | Dict[str, str]] | str,
+        conversation: Union[Dict[str, str], str],
         tokenize: bool = True,
         context_data: Dict[str, Any] = {},
         **tokenizer_kwargs,
-    ) -> str | dict[str, Union["numpy.ndarray", "paddle.Tensor"]]:
+    ) -> Union[str, Dict[str, Union["numpy.ndarray", "paddle.Tensor"]]]:
         """apply chat_template rules to conversation which should not be batched data
 
         Args:
@@ -677,9 +677,9 @@ class ChatTemplateMixin:
 
     def _apply_chat_template_paddle(
         self,
-        conversation: List[Dict[str, str]] | str,
+        conversation: Union[List[Dict[str, str]], str],
         context_data: Dict[str, Any] = {},
-    ) -> str | dict[str, Union["numpy.ndarray", "paddle.Tensor"]]:
+    ) -> Union[str, Dict[str, Union["numpy.ndarray", "paddle.Tensor"]]]:
         context_data = self.chat_template._init_context_data(context_data)
 
         if isinstance(conversation, str):
@@ -695,9 +695,9 @@ class ChatTemplateMixin:
 
     def _apply_chat_template(
         self,
-        conversation: Union[Dict[str, str] | Dict[str, str]] | str,
+        conversation: Union[Dict[str, str], str],
         add_generation_prompt=True,
-    ) -> str | dict[str, Union["numpy.ndarray", "paddle.Tensor"]]:
+    ) -> Union[str, Dict[str, Union["numpy.ndarray", "paddle.Tensor"]]]:
         if isinstance(conversation, str):
             conversations = [{"role": "user", "content": conversation}]
         elif isinstance(conversation, list):
@@ -893,7 +893,7 @@ class ChatTemplateMixin:
         tokenizer.init_chat_template(chat_template_file)
         return tokenizer
 
-    def init_chat_template(self, chat_template: str | dict):
+    def init_chat_template(self, chat_template: Union[str, Dict]):
         """init chat_tempalte by file_path or template dict data
 
         Args:

+ 3 - 3
paddlex/inference/pipelines_new/anomaly_detection/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 
 from ...utils.pp_option import PaddlePredictorOption
@@ -49,12 +49,12 @@ class AnomalyDetectionPipeline(BasePipeline):
         self.anomaly_detetion_model = self.create_model(anomaly_detetion_model_config)
 
     def predict(
-        self, input: str | list[str] | np.ndarray | list[np.ndarray], **kwargs
+        self, input: Union[str, List[str], np.ndarray, List[np.ndarray]], **kwargs
     ) -> UadResult:
         """Predicts anomaly detection results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 6 - 6
paddlex/inference/pipelines_new/components/common/crop_image_regions.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Tuple
+from typing import Tuple, List
 import copy
 import numpy as np
 import cv2
@@ -32,7 +32,7 @@ class CropByBoxes(BaseOperator):
         """Initializes the class."""
         super().__init__()
 
-    def __call__(self, img: np.ndarray, boxes: list[dict]) -> list[dict]:
+    def __call__(self, img: np.ndarray, boxes: List[dict]) -> List[dict]:
         """
         Process the input image and bounding boxes to produce a list of cropped images
         with their corresponding bounding box coordinates and labels.
@@ -74,7 +74,7 @@ class CropByPolys(BaseOperator):
         super().__init__()
         self.det_box_type = det_box_type
 
-    def __call__(self, img: np.ndarray, dt_polys: list[list]) -> list[dict]:
+    def __call__(self, img: np.ndarray, dt_polys: List[list]) -> List[dict]:
         """
         Call method to crop images based on detection boxes.
 
@@ -187,7 +187,7 @@ class CropByPolys(BaseOperator):
 
     def reorder_poly_edge(
         self, points: np.ndarray
-    ) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
+    ) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
         """Get the respective points composing head edge, tail edge, top
         sideline and bottom sideline.
 
@@ -239,7 +239,7 @@ class CropByPolys(BaseOperator):
 
     def find_head_tail(
         self, points: np.ndarray, orientation_thr: float
-    ) -> tuple[list, list]:
+    ) -> Tuple[list, list]:
         """Find the head edge and tail edge of a text polygon.
 
         Args:
@@ -370,7 +370,7 @@ class CropByPolys(BaseOperator):
 
     def get_minarea_rect(
         self, img: np.ndarray, points: np.ndarray
-    ) -> tuple[np.ndarray, list]:
+    ) -> Tuple[np.ndarray, list]:
         """
         Get the minimum area rectangle for the given points and crop the image accordingly.
 

+ 3 - 2
paddlex/inference/pipelines_new/components/common/sort_boxes.py

@@ -13,6 +13,7 @@
 # limitations under the License.
 
 import numpy as np
+from typing import List
 from .base_operator import BaseOperator
 
 
@@ -25,7 +26,7 @@ class SortQuadBoxes(BaseOperator):
         """Initializes the class."""
         super().__init__()
 
-    def __call__(self, dt_polys: list[np.ndarray]) -> np.ndarray:
+    def __call__(self, dt_polys: List[np.ndarray]) -> np.ndarray:
         """
         Sort quad boxes in order from top to bottom, left to right
         args:
@@ -60,7 +61,7 @@ class SortPolyBoxes(BaseOperator):
         """Initializes the class."""
         super().__init__()
 
-    def __call__(self, dt_polys: list[np.ndarray]) -> np.ndarray:
+    def __call__(self, dt_polys: List[np.ndarray]) -> np.ndarray:
         """
         Sort poly boxes in order from top to bottom, left to right
         args:

+ 4 - 4
paddlex/inference/pipelines_new/components/retriever/ernie_bot_retriever.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Dict
+from typing import Dict, List
 import time
 import os
 from langchain.docstore.document import Document
@@ -88,9 +88,9 @@ class ErnieBotRetriever(BaseRetriever):
 
     def generate_vector_database(
         self,
-        text_list: list[str],
+        text_list: List[str],
         block_size: int = 300,
-        separators: list[str] = ["\t", "\n", "。", "\n\n", ""],
+        separators: List[str] = ["\t", "\n", "。", "\n\n", ""],
         sleep_time: float = 0.5,
     ) -> FAISS:
         """
@@ -193,7 +193,7 @@ class ErnieBotRetriever(BaseRetriever):
 
     def similarity_retrieval(
         self,
-        query_text_list: list[str],
+        query_text_list: List[str],
         vectorstore: FAISS,
         sleep_time: float = 0.5,
         topk: int = 2,

+ 4 - 4
paddlex/inference/pipelines_new/components/retriever/openai_bot_retriever.py

@@ -21,7 +21,7 @@ from langchain_community import vectorstores
 
 import time
 
-from typing import Dict
+from typing import Dict, List
 
 
 class OpenAIBotRetriever(BaseRetriever):
@@ -85,9 +85,9 @@ class OpenAIBotRetriever(BaseRetriever):
 
     def generate_vector_database(
         self,
-        text_list: list[str],
+        text_list: List[str],
         block_size: int = 300,
-        separators: list[str] = ["\t", "\n", "。", "\n\n", ""],
+        separators: List[str] = ["\t", "\n", "。", "\n\n", ""],
         sleep_time: float = 0.5,
     ) -> FAISS:
         """
@@ -155,7 +155,7 @@ class OpenAIBotRetriever(BaseRetriever):
         return vector
 
     def similarity_retrieval(
-        self, query_text_list: list[str], vectorstore: FAISS, sleep_time: float = 0.5
+        self, query_text_list: List[str], vectorstore: FAISS, sleep_time: float = 0.5
     ) -> str:
         """
         Retrieve similar contexts based on a list of query texts.

+ 3 - 3
paddlex/inference/pipelines_new/doc_preprocessor/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 from scipy.ndimage import rotate
 import numpy as np
 from ..base import BasePipeline
@@ -139,7 +139,7 @@ class DocPreprocessorPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
     ) -> DocPreprocessorResult:
@@ -147,7 +147,7 @@ class DocPreprocessorPipeline(BasePipeline):
         Predict the preprocessing result for the input image or images.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images or pdfs.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images or pdfs.
             use_doc_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_unwarping (bool): Whether to use document unwarping.
             **kwargs: Additional keyword arguments.

+ 3 - 3
paddlex/inference/pipelines_new/formula_recognition/pipeline.py

@@ -13,7 +13,7 @@
 # limitations under the License.
 
 import os, sys
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import cv2
 from ..base import BasePipeline
@@ -177,7 +177,7 @@ class FormulaRecognitionPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         use_layout_detection: Optional[bool] = None,
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
@@ -188,7 +188,7 @@ class FormulaRecognitionPipeline(BasePipeline):
         This function predicts the layout parsing result for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) of pdf(s) to be processed.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) of pdf(s) to be processed.
             use_layout_detection (Optional[bool]): Whether to use layout detection.
             use_doc_orientation_classify (Optional[bool]): Whether to use document orientation classification.
             use_doc_unwarping (Optional[bool]): Whether to use document unwarping.

+ 3 - 3
paddlex/inference/pipelines_new/image_classification/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 from ...common.reader import ReadImage
 from ...common.batch_sampler import ImageBatchSampler
@@ -56,12 +56,12 @@ class ImageClassificationPipeline(BasePipeline):
         self.topk = image_classification_model_config.get("topk", 5)
 
     def predict(
-        self, input: str | list[str] | np.ndarray | list[np.ndarray], **kwargs
+        self, input: Union[str, List[str], np.ndarray, List[np.ndarray]], **kwargs
     ) -> TopkResult:
         """Predicts image classification results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 4 - 4
paddlex/inference/pipelines_new/image_multilabel_classification/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 from ...common.reader import ReadImage
 from ...common.batch_sampler import ImageBatchSampler
@@ -59,14 +59,14 @@ class ImageMultiLabelClassificationPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
-        threshold: float | dict | list | None = None,
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
+        threshold: Union[float, dict, list, None] = None,
         **kwargs
     ) -> MLClassResult:
         """Predicts image classification results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 3 - 3
paddlex/inference/pipelines_new/instance_segmentation/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
@@ -53,12 +53,12 @@ class InstanceSegmentationPipeline(BasePipeline):
         self.threshold = instance_segmentation_model_config["threshold"]
 
     def predict(
-        self, input: str | list[str] | np.ndarray | list[np.ndarray], **kwargs
+        self, input: Union[str, List[str], np.ndarray, List[np.ndarray]], **kwargs
     ) -> InstanceSegResult:
         """Predicts instance segmentation results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 3 - 3
paddlex/inference/pipelines_new/keypoint_detection/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional, Union, Tuple
+from typing import Any, Dict, Optional, Union, Tuple, List
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
@@ -95,12 +95,12 @@ class KeypointDetectionPipeline(BasePipeline):
         return center, scale
 
     def predict(
-        self, input: str | list[str] | np.ndarray | list[np.ndarray], **kwargs
+        self, input: Union[str, List[str], np.ndarray, List[np.ndarray]], **kwargs
     ) -> KptResult:
         """Predicts image classification results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 3 - 3
paddlex/inference/pipelines_new/layout_parsing/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import os, sys
 import numpy as np
 import cv2
@@ -243,7 +243,7 @@ class LayoutParsingPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_general_ocr: Optional[bool] = None,
@@ -268,7 +268,7 @@ class LayoutParsingPipeline(BasePipeline):
         This function predicts the layout parsing result for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or pdf(s) to be processed.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or pdf(s) to be processed.
             use_doc_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_unwarping (bool): Whether to use document unwarping.
             use_general_ocr (bool): Whether to use general OCR.

+ 5 - 7
paddlex/inference/pipelines_new/layout_parsing/pipeline_v2.py

@@ -15,9 +15,7 @@ from __future__ import annotations
 
 import os
 import sys
-from typing import Any
-from typing import Dict
-from typing import Optional
+from typing import Any, Dict, Optional, Union
 
 import cv2
 import numpy as np
@@ -261,7 +259,7 @@ class LayoutParsingPipelineV2(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, list[str], np.ndarray, list[np.ndarray]],
         use_doc_orientation_classify: bool | None = None,
         use_doc_unwarping: bool | None = None,
         use_general_ocr: bool | None = None,
@@ -269,13 +267,13 @@ class LayoutParsingPipelineV2(BasePipeline):
         use_table_recognition: bool | None = None,
         use_formula_recognition: bool | None = None,
         text_det_limit_side_len: int | None = None,
-        text_det_limit_type: str | None = None,
+        text_det_limit_type: Union[str, None] = None,
         text_det_thresh: float | None = None,
         text_det_box_thresh: float | None = None,
         text_det_unclip_ratio: float | None = None,
         text_rec_score_thresh: float | None = None,
         seal_det_limit_side_len: int | None = None,
-        seal_det_limit_type: str | None = None,
+        seal_det_limit_type: Union[str, None] = None,
         seal_det_thresh: float | None = None,
         seal_det_box_thresh: float | None = None,
         seal_det_unclip_ratio: float | None = None,
@@ -286,7 +284,7 @@ class LayoutParsingPipelineV2(BasePipeline):
         This function predicts the layout parsing result for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or pdf(s) to be processed.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or pdf(s) to be processed.
             use_doc_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_unwarping (bool): Whether to use document unwarping.
             use_general_ocr (bool): Whether to use general OCR.

+ 5 - 4
paddlex/inference/pipelines_new/layout_parsing/utils.py

@@ -24,11 +24,12 @@ import copy
 import cv2
 import uuid
 from pathlib import Path
+from typing import List
 from ..ocr.result import OCRResult
 from ...models_new.object_detection.result import DetResult
 
 
-def get_overlap_boxes_idx(src_boxes: np.ndarray, ref_boxes: np.ndarray) -> list:
+def get_overlap_boxes_idx(src_boxes: np.ndarray, ref_boxes: np.ndarray) -> List:
     """
     Get the indices of source boxes that overlap with reference boxes based on a specified threshold.
 
@@ -56,7 +57,7 @@ def get_overlap_boxes_idx(src_boxes: np.ndarray, ref_boxes: np.ndarray) -> list:
 
 
 def get_sub_regions_ocr_res(
-    overall_ocr_res: OCRResult, object_boxes: list, flag_within: bool = True
+    overall_ocr_res: OCRResult, object_boxes: List, flag_within: bool = True
 ) -> OCRResult:
     """
     Filters OCR results to only include text boxes within specified object boxes based on a flag.
@@ -362,7 +363,7 @@ def split_projection_profile(arr_values: np.ndarray, min_value: float, min_gap:
     return segment_starts, segment_ends
 
 
-def recursive_yx_cut(boxes: np.ndarray, indices: list[int], res: list[int], min_gap=1):
+def recursive_yx_cut(boxes: np.ndarray, indices: List[int], res: List[int], min_gap=1):
     """
     Recursively project and segment bounding boxes, starting with Y-axis and followed by X-axis.
 
@@ -423,7 +424,7 @@ def recursive_yx_cut(boxes: np.ndarray, indices: list[int], res: list[int], min_
             )
 
 
-def recursive_xy_cut(boxes: np.ndarray, indices: list[int], res: list[int], min_gap=1):
+def recursive_xy_cut(boxes: np.ndarray, indices: List[int], res: List[int], min_gap=1):
     """
     Recursively performs X-axis projection followed by Y-axis projection to segment bounding boxes.
 

+ 3 - 3
paddlex/inference/pipelines_new/multilingual_speech_recognition/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 
 from ...utils.pp_option import PaddlePredictorOption
@@ -53,12 +53,12 @@ class MultilingualSpeechRecognitionPipeline(BasePipeline):
         batch_size = multilingual_speech_recognition_model_config["batch_size"]
 
     def predict(
-        self, input: str | list[str] | np.ndarray | list[np.ndarray], **kwargs
+        self, input: Union[str, List[str], np.ndarray, List[np.ndarray]], **kwargs
     ) -> WhisperResult:
         """Predicts speech recognition results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input audio or path.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input audio or path.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 13 - 10
paddlex/inference/pipelines_new/object_detection/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional, Union, Tuple
+from typing import Any, Dict, Optional, Union, Tuple, List
 import numpy as np
 
 from ...utils.pp_option import PaddlePredictorOption
@@ -55,12 +55,14 @@ class ObjectDetectionPipeline(BasePipeline):
         if "layout_unclip_ratio" in model_cfg:
             model_kwargs["layout_unclip_ratio"] = model_cfg["layout_unclip_ratio"]
         if "layout_merge_bboxes_mode" in model_cfg:
-            model_kwargs["layout_merge_bboxes_mode"] = model_cfg["layout_merge_bboxes_mode"]
+            model_kwargs["layout_merge_bboxes_mode"] = model_cfg[
+                "layout_merge_bboxes_mode"
+            ]
         self.det_model = self.create_model(model_cfg, **model_kwargs)
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         threshold: Optional[Union[float, dict]] = None,
         layout_nms: bool = False,
         layout_unclip_ratio: Optional[Union[float, Tuple[float, float]]] = None,
@@ -70,7 +72,7 @@ class ObjectDetectionPipeline(BasePipeline):
         """Predicts object detection results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             img_size (Optional[Union[int, Tuple[int, int]]]): The size of the input image. Default is None.
             threshold (Optional[float]): The threshold value to filter out low-confidence predictions. Default is None.
             layout_nms (bool, optional): Whether to use layout-aware NMS. Defaults to False.
@@ -85,9 +87,10 @@ class ObjectDetectionPipeline(BasePipeline):
             DetResult: The predicted detection results.
         """
         yield from self.det_model(
-                input, 
-                threshold=threshold, 
-                layout_nms=layout_nms, 
-                layout_unclip_ratio=layout_unclip_ratio, 
-                layout_merge_bboxes_mode=layout_merge_bboxes_mode,
-                **kwargs)
+            input,
+            threshold=threshold,
+            layout_nms=layout_nms,
+            layout_unclip_ratio=layout_unclip_ratio,
+            layout_merge_bboxes_mode=layout_merge_bboxes_mode,
+            **kwargs,
+        )

+ 3 - 3
paddlex/inference/pipelines_new/ocr/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, List, Optional
+from typing import Any, Dict, List, Optional, Union
 import numpy as np
 from scipy.ndimage import rotate
 from ...common.reader import ReadImage
@@ -265,7 +265,7 @@ class OCRPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_textline_orientation: Optional[bool] = None,
@@ -280,7 +280,7 @@ class OCRPipeline(BasePipeline):
         Predict OCR results based on input images or arrays with optional preprocessing steps.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): Input image of pdf path(s) or numpy array(s).
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): Input image of pdf path(s) or numpy array(s).
             use_doc_orientation_classify (Optional[bool]): Whether to use document orientation classification.
             use_doc_unwarping (Optional[bool]): Whether to use document unwarping.
             use_textline_orientation (Optional[bool]): Whether to use textline orientation prediction.

+ 3 - 3
paddlex/inference/pipelines_new/open_vocabulary_detection/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
@@ -55,14 +55,14 @@ class OpenVocabularyDetectionPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         prompt: str,
         **kwargs
     ) -> DetResult:
         """Predicts open vocabulary detection results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             prompt (str): The text prompt used to describe the objects.
             **kwargs: Additional keyword arguments that can be passed to the function.
 

+ 4 - 4
paddlex/inference/pipelines_new/open_vocabulary_segmentation/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional, Union, Tuple
+from typing import Any, Dict, Optional, Union, Tuple, List
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
@@ -62,15 +62,15 @@ class OpenVocabularySegmentationPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
-        prompt: list[list[float]] | np.ndarray,
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
+        prompt: Union[List[List[float]], np.ndarray],
         prompt_type: str = "box",
         **kwargs
     ) -> SAMSegResult:
         """Predicts image segmentation results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             prompt (list[list[int]] | np.ndarray): The prompt for the input image(s).
             prompt_type (str): The type of prompt, either 'box' or 'point'. Default is 'box'.
             **kwargs: Additional keyword arguments that can be passed to the function.

+ 11 - 11
paddlex/inference/pipelines_new/pp_chatocr/pipeline_v3.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List, Tuple
 import re
 import json
 import numpy as np
@@ -162,7 +162,7 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
     # Function to perform visual prediction on input images
     def visual_predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_general_ocr: Optional[bool] = None,
@@ -188,7 +188,7 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
         general OCR, seal recognition, and table recognition based on the provided flags.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): Input image path, list of image paths,
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): Input image path, list of image paths,
                                                                         numpy array of an image, or list of numpy arrays.
             use_doc_orientation_classify (bool): Flag to use document orientation classification.
             use_doc_unwarping (bool): Flag to use document unwarping.
@@ -254,7 +254,7 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
             fout.write(json.dumps(visual_info_list, ensure_ascii=False) + "\n")
         return
 
-    def load_visual_info_list(self, data_path: str) -> list[dict]:
+    def load_visual_info_list(self, data_path: str) -> List[dict]:
         """
         Loads visual info list from a JSON file.
 
@@ -270,8 +270,8 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
         return visual_info_list
 
     def merge_visual_info_list(
-        self, visual_info_list: list[dict]
-    ) -> tuple[list, list, list]:
+        self, visual_info_list: List[dict]
+    ) -> Tuple[list, list, list]:
         """
         Merge visual info lists.
 
@@ -379,7 +379,7 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
                 )
         return vector_info
 
-    def format_key(self, key_list: str | list[str]) -> list[str]:
+    def format_key(self, key_list: Union[str, List[str]]) -> List[str]:
         """
         Formats the key list.
 
@@ -438,7 +438,7 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
         self,
         use_vector_retrieval: bool,
         vector_info: dict,
-        key_list: list[str],
+        key_list: List[str],
         all_normal_text_list: list,
         min_characters: int,
     ) -> str:
@@ -482,8 +482,8 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
 
     def chat(
         self,
-        key_list: str | list[str],
-        visual_info: list[dict],
+        key_list: Union[str, List[str]],
+        visual_info: List[dict],
         use_vector_retrieval: bool = True,
         vector_info: dict = None,
         min_characters: int = 3500,
@@ -502,7 +502,7 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
         Generates chat results based on the provided key list and visual information.
 
         Args:
-            key_list (str | list[str]): A single key or a list of keys to extract information.
+            key_list (Union[str, list[str]]): A single key or a list of keys to extract information.
             visual_info (dict): The visual information result.
             use_vector_retrieval (bool): Whether to use vector retrieval.
             vector_info (dict): The vector information for retrieval.

+ 12 - 12
paddlex/inference/pipelines_new/pp_chatocr/pipeline_v4.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List, Tuple
 import re
 import cv2
 import json
@@ -184,7 +184,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
     # Function to perform visual prediction on input images
     def visual_predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_general_ocr: Optional[bool] = None,
@@ -210,7 +210,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
         general OCR, seal recognition, and table recognition based on the provided flags.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): Input image path, list of image paths,
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): Input image path, list of image paths,
                                                                         numpy array of an image, or list of numpy arrays.
             use_doc_orientation_classify (bool): Flag to use document orientation classification.
             use_doc_unwarping (bool): Flag to use document unwarping.
@@ -275,7 +275,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
             fout.write(json.dumps(visual_info_list, ensure_ascii=False) + "\n")
         return
 
-    def load_visual_info_list(self, data_path: str) -> list[dict]:
+    def load_visual_info_list(self, data_path: str) -> List[dict]:
         """
         Loads visual info list from a JSON file.
 
@@ -291,8 +291,8 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
         return visual_info_list
 
     def merge_visual_info_list(
-        self, visual_info_list: list[dict]
-    ) -> tuple[list, list, list, list]:
+        self, visual_info_list: List[dict]
+    ) -> Tuple[list, list, list, list]:
         """
         Merge visual info lists.
 
@@ -411,7 +411,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
                 )
         return vector_info
 
-    def format_key(self, key_list: str | list[str]) -> list[str]:
+    def format_key(self, key_list: Union[str, List[str]]) -> List[str]:
         """
         Formats the key list.
 
@@ -437,7 +437,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
 
     def mllm_pred(
         self,
-        input: str | np.ndarray,
+        input: Union[str, np.ndarray],
         key_list,
         **kwargs,
     ) -> dict:
@@ -512,7 +512,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
         self,
         use_vector_retrieval: bool,
         vector_info: dict,
-        key_list: list[str],
+        key_list: List[str],
         all_normal_text_list: list,
         min_characters: int,
     ) -> str:
@@ -555,7 +555,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
         return related_text
 
     def ensemble_ocr_llm_mllm(
-        self, key_list: list[str], ocr_llm_predict_dict: dict, mllm_predict_dict: dict
+        self, key_list: List[str], ocr_llm_predict_dict: dict, mllm_predict_dict: dict
     ) -> dict:
         """
         Ensemble OCR_LLM and LMM predictions based on given key list.
@@ -604,7 +604,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
 
     def chat(
         self,
-        key_list: str | list[str],
+        key_list: Union[str, List[str]],
         visual_info: dict,
         use_vector_retrieval: bool = True,
         vector_info: dict = None,
@@ -626,7 +626,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
         Generates chat results based on the provided key list and visual information.
 
         Args:
-            key_list (str | list[str]): A single key or a list of keys to extract information.
+            key_list (Union[str, list[str]]): A single key or a list of keys to extract information.
             visual_info (dict): The visual information result.
             use_vector_retrieval (bool): Whether to use vector retrieval.
             vector_info (dict): The vector information for retrieval.

+ 3 - 3
paddlex/inference/pipelines_new/rotated_object_detection/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
@@ -53,12 +53,12 @@ class RotatedObjectDetectionPipeline(BasePipeline):
         self.threshold = rotated_object_detection_model_config["threshold"]
 
     def predict(
-        self, input: str | list[str] | np.ndarray | list[np.ndarray], **kwargs
+        self, input: Union[str, List[str], np.ndarray, List[np.ndarray]], **kwargs
     ) -> DetResult:
         """Predicts rotated object detection results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 2 - 2
paddlex/inference/pipelines_new/seal_recognition/pipeline.py

@@ -13,7 +13,7 @@
 # limitations under the License.
 
 import os, sys
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import cv2
 from ..base import BasePipeline
@@ -151,7 +151,7 @@ class SealRecognitionPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_layout_detection: Optional[bool] = None,

+ 3 - 3
paddlex/inference/pipelines_new/semantic_segmentation/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
@@ -53,12 +53,12 @@ class SemanticSegmentationPipeline(BasePipeline):
         self.target_size = semantic_segmentation_model_config["target_size"]
 
     def predict(
-        self, input: str | list[str] | np.ndarray | list[np.ndarray], **kwargs
+        self, input: Union[str, List[str], np.ndarray, List[np.ndarray]], **kwargs
     ) -> SegResult:
         """Predicts semantic segmentation results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 3 - 3
paddlex/inference/pipelines_new/small_object_detection/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
@@ -53,12 +53,12 @@ class SmallObjectDetectionPipeline(BasePipeline):
         self.threshold = small_object_detection_model_config["threshold"]
 
     def predict(
-        self, input: str | list[str] | np.ndarray | list[np.ndarray], **kwargs
+        self, input: Union[str, List[str], np.ndarray, List[np.ndarray]], **kwargs
     ) -> DetResult:
         """Predicts small object detection results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 4 - 4
paddlex/inference/pipelines_new/table_recognition/pipeline.py

@@ -13,7 +13,7 @@
 # limitations under the License.
 
 import os, sys
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, Tuple, List
 import numpy as np
 import cv2
 from ..base import BasePipeline
@@ -190,7 +190,7 @@ class TableRecognitionPipeline(BasePipeline):
 
     def predict_doc_preprocessor_res(
         self, image_array: np.ndarray, input_params: dict
-    ) -> tuple[DocPreprocessorResult, np.ndarray]:
+    ) -> Tuple[DocPreprocessorResult, np.ndarray]:
         """
         Preprocess the document image based on input parameters.
 
@@ -254,7 +254,7 @@ class TableRecognitionPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_layout_detection: Optional[bool] = None,
@@ -273,7 +273,7 @@ class TableRecognitionPipeline(BasePipeline):
         This function predicts the layout parsing result for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) of pdf(s) to be processed.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) of pdf(s) to be processed.
             use_layout_detection (bool): Whether to use layout detection.
             use_doc_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_unwarping (bool): Whether to use document unwarping.

+ 30 - 18
paddlex/inference/pipelines_new/table_recognition/pipeline_v2.py

@@ -13,7 +13,7 @@
 # limitations under the License.
 
 import os, sys
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List, Tuple
 import numpy as np
 import cv2
 from ..base import BasePipeline
@@ -96,19 +96,27 @@ class TableRecognitionPipelineV2(BasePipeline):
             {"model_config_error": "config error for wireless_table_structure_model!"},
         )
         self.wireless_table_rec_model = self.create_model(wireless_table_rec_config)
-        
+
         wired_table_cells_det_config = config.get("SubModules", {}).get(
             "WiredTableCellsDetection",
-            {"model_config_error": "config error for wired_table_cells_detection_model!"},
+            {
+                "model_config_error": "config error for wired_table_cells_detection_model!"
+            },
+        )
+        self.wired_table_cells_detection_model = self.create_model(
+            wired_table_cells_det_config
         )
-        self.wired_table_cells_detection_model = self.create_model(wired_table_cells_det_config)
 
         wireless_table_cells_det_config = config.get("SubModules", {}).get(
             "WirelessTableCellsDetection",
-            {"model_config_error": "config error for wireless_table_cells_detection_model!"},
+            {
+                "model_config_error": "config error for wireless_table_cells_detection_model!"
+            },
+        )
+        self.wireless_table_cells_detection_model = self.create_model(
+            wireless_table_cells_det_config
         )
-        self.wireless_table_cells_detection_model = self.create_model(wireless_table_cells_det_config)
-    
+
         self.use_ocr_model = config.get("use_ocr_model", True)
         if self.use_ocr_model:
             general_ocr_config = config.get("SubPipelines", {}).get(
@@ -218,7 +226,7 @@ class TableRecognitionPipelineV2(BasePipeline):
 
     def predict_doc_preprocessor_res(
         self, image_array: np.ndarray, input_params: dict
-    ) -> tuple[DocPreprocessorResult, np.ndarray]:
+    ) -> Tuple[DocPreprocessorResult, np.ndarray]:
         """
         Preprocess the document image based on input parameters.
 
@@ -248,15 +256,15 @@ class TableRecognitionPipelineV2(BasePipeline):
 
     def extract_results(self, pred, task):
         if task == "cls":
-            return pred['label_names'][np.argmax(pred['scores'])]
+            return pred["label_names"][np.argmax(pred["scores"])]
         elif task == "det":
             threshold = 0.0
             result = []
-            if 'boxes' in pred and isinstance(pred['boxes'], list):
-                for box in pred['boxes']:
-                    if isinstance(box, dict) and 'score' in box and 'coordinate' in box:
-                        score = box['score']
-                        coordinate = box['coordinate']
+            if "boxes" in pred and isinstance(pred["boxes"], list):
+                for box in pred["boxes"]:
+                    if isinstance(box, dict) and "score" in box and "coordinate" in box:
+                        score = box["score"]
+                        coordinate = box["coordinate"]
                         if isinstance(score, float) and score > threshold:
                             result.append(coordinate)
             return result
@@ -291,8 +299,12 @@ class TableRecognitionPipelineV2(BasePipeline):
             table_cells_pred = next(self.wired_table_cells_detection_model(image_array))
         elif table_cls_result == "wireless_table":
             table_structure_pred = next(self.wireless_table_rec_model(image_array))
-            table_cells_pred = next(self.wireless_table_cells_detection_model(image_array))
-        table_structure_result = self.extract_results(table_structure_pred, "table_stru")
+            table_cells_pred = next(
+                self.wireless_table_cells_detection_model(image_array)
+            )
+        table_structure_result = self.extract_results(
+            table_structure_pred, "table_stru"
+        )
         table_cells_result = self.extract_results(table_cells_pred, "det")
         single_table_recognition_res = get_table_recognition_res(
             table_box, table_structure_result, table_cells_result, overall_ocr_res
@@ -310,7 +322,7 @@ class TableRecognitionPipelineV2(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_layout_detection: Optional[bool] = None,
@@ -329,7 +341,7 @@ class TableRecognitionPipelineV2(BasePipeline):
         This function predicts the layout parsing result for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) of pdf(s) to be processed.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) of pdf(s) to be processed.
             use_layout_detection (bool): Whether to use layout detection.
             use_doc_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_unwarping (bool): Whether to use document unwarping.

+ 3 - 3
paddlex/inference/pipelines_new/ts_anomaly_detection/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import pandas as pd
 
 from ...utils.pp_option import PaddlePredictorOption
@@ -49,12 +49,12 @@ class TSAnomalyDetPipeline(BasePipeline):
         self.ts_ad_model = self.create_model(ts_ad_model_config)
 
     def predict(
-        self, input: str | list[str] | pd.DataFrame | list[pd.DataFrame], **kwargs
+        self, input: Union[str, List[str], pd.DataFrame, List[pd.DataFrame]], **kwargs
     ) -> TSAdResult:
         """Predicts time series anomaly detection results for the given input.
 
         Args:
-            input (str | list[str] | pd.DataFrame | list[pd.DataFrame]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], pd.DataFrame, list[pd.DataFrame]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 3 - 3
paddlex/inference/pipelines_new/ts_classification/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import pandas as pd
 
 from ...utils.pp_option import PaddlePredictorOption
@@ -49,12 +49,12 @@ class TSClsPipeline(BasePipeline):
         self.ts_classification_model = self.create_model(ts_classification_model_config)
 
     def predict(
-        self, input: str | list[str] | pd.DataFrame | list[pd.DataFrame], **kwargs
+        self, input: Union[str, List[str], pd.DataFrame, List[pd.DataFrame]], **kwargs
     ) -> TSClsResult:
         """Predicts time series classification results for the given input.
 
         Args:
-            input (str | list[str] | pd.DataFrame | list[pd.DataFrame]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], pd.DataFrame, list[pd.DataFrame]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 3 - 3
paddlex/inference/pipelines_new/ts_forecasting/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import pandas as pd
 
 from ...utils.pp_option import PaddlePredictorOption
@@ -49,12 +49,12 @@ class TSFcPipeline(BasePipeline):
         self.ts_forecast_model = self.create_model(ts_forecast_model_config)
 
     def predict(
-        self, input: str | list[str] | pd.DataFrame | list[pd.DataFrame], **kwargs
+        self, input: Union[str, List[str], pd.DataFrame, List[pd.DataFrame]], **kwargs
     ) -> TSFcResult:
         """Predicts time series forecast results for the given input.
 
         Args:
-            input (str | list[str] | pd.DataFrame | list[pd.DataFrame]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], pd.DataFrame, list[pd.DataFrame]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 3 - 3
paddlex/inference/pipelines_new/video_classification/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional, Union
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
@@ -51,14 +51,14 @@ class VideoClassificationPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         topk: Union[int, None] = 1,
         **kwargs
     ) -> TopkVideoResult:
         """Predicts video classification results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             topk: Union[int, None]: The number of top predictions to return. Defaults to 1.
             **kwargs: Additional keyword arguments that can be passed to the function.
 

+ 3 - 3
paddlex/inference/pipelines_new/video_detection/pipeline.py

@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Any, Dict, Optional, Union
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
@@ -49,7 +49,7 @@ class VideoDetectionPipeline(BasePipeline):
 
     def predict(
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         nms_thresh: float = 0.5,
         score_thresh: float = 0.4,
         **kwargs
@@ -57,7 +57,7 @@ class VideoDetectionPipeline(BasePipeline):
         """Predicts video detection results for the given input.
 
         Args:
-            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
+            input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or path(s) to the images.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
         Returns:

+ 5 - 4
paddlex/repo_apis/PaddleDetection_api/instance_seg/config.py

@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from typing import List
 from ...base import BaseConfig
 from ....utils.misc import abspath
 from ..config_helper import PPDetConfigMixin
@@ -51,7 +52,7 @@ class InstanceSegConfig(DetConfig):
         dataset_path: str,
         dataset_type: str = None,
         *,
-        data_fields: list[str] = None,
+        data_fields: List[str] = None,
         image_dir: str = "images",
         train_anno_path: str = "annotations/instance_train.json",
         val_anno_path: str = "annotations/instance_val.json",
@@ -95,7 +96,7 @@ class InstanceSegConfig(DetConfig):
     def _make_dataset_config(
         self,
         dataset_root_path: str,
-        data_fields: list[str,] = None,
+        data_fields: List[str,] = None,
         image_dir: str = "images",
         train_anno_path: str = "annotations/instance_train.json",
         val_anno_path: str = "annotations/instance_val.json",
@@ -210,7 +211,7 @@ class InstanceSegConfig(DetConfig):
             if sch[key] == "CosineDecay":
                 sch["max_epochs"] = max_epochs
 
-    def update_milestone(self, milestones: list[int]):
+    def update_milestone(self, milestones: List[int]):
         """update milstone of `PiecewiseDecay` learning scheduler
 
         Args:
@@ -346,7 +347,7 @@ class InstanceSegConfig(DetConfig):
         """
         self["num_classes"] = num_classes
 
-    def update_random_size(self, randomsize: list[list[int, int]]):
+    def update_random_size(self, randomsize):
         """update `target_size` of `BatchRandomResize` op in TestReader
 
         Args:

+ 5 - 4
paddlex/repo_apis/PaddleDetection_api/object_det/config.py

@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from typing import List
 from ...base import BaseConfig
 from ....utils.misc import abspath
 from ....utils import logging
@@ -51,7 +52,7 @@ class DetConfig(BaseConfig, PPDetConfigMixin):
         dataset_path: str,
         dataset_type: str = None,
         *,
-        data_fields: list[str] = None,
+        data_fields: List[str] = None,
         image_dir: str = "images",
         train_anno_path: str = "annotations/instance_train.json",
         val_anno_path: str = "annotations/instance_val.json",
@@ -113,7 +114,7 @@ class DetConfig(BaseConfig, PPDetConfigMixin):
     def _make_dataset_config(
         self,
         dataset_root_path: str,
-        data_fields: list[str,] = None,
+        data_fields: List[str,] = None,
         image_dir: str = "images",
         train_anno_path: str = "annotations/instance_train.json",
         val_anno_path: str = "annotations/instance_val.json",
@@ -229,7 +230,7 @@ class DetConfig(BaseConfig, PPDetConfigMixin):
             if sch[key] == "CosineDecay":
                 sch["max_epochs"] = max_epochs
 
-    def update_milestone(self, milestones: list[int]):
+    def update_milestone(self, milestones: List[int]):
         """update milstone of `PiecewiseDecay` learning scheduler
 
         Args:
@@ -398,7 +399,7 @@ class DetConfig(BaseConfig, PPDetConfigMixin):
                         "num_classes"
                     ] = num_classes
 
-    def update_random_size(self, randomsize: list[list[int, int]]):
+    def update_random_size(self, randomsize):
         """update `target_size` of `BatchRandomResize` op in TestReader
 
         Args: