浏览代码

adapt to py38 and py39 (#2904)

zhangyubo0722 10 月之前
父节点
当前提交
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"
     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.
         """Initializes the BasePredictor.
 
 
         Args:
         Args:
@@ -106,7 +106,7 @@ class BasePredictor(ABC):
         return model_dir / f"{cls.MODEL_FILE_PREFIX}.yml"
         return model_dir / f"{cls.MODEL_FILE_PREFIX}.yml"
 
 
     @classmethod
     @classmethod
-    def load_config(cls, model_dir) -> dict:
+    def load_config(cls, model_dir) -> Dict:
         """Load the configuration from the specified model directory.
         """Load the configuration from the specified model directory.
 
 
         Args:
         Args:
@@ -119,7 +119,7 @@ class BasePredictor(ABC):
         return yaml_reader.read(cls.get_config_path(model_dir))
         return yaml_reader.read(cls.get_config_path(model_dir))
 
 
     @abstractmethod
     @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."""
         """Predict with the given input and additional keyword arguments."""
         raise NotImplementedError
         raise NotImplementedError
 
 

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

@@ -66,8 +66,8 @@ __all__ = [
 
 
 @dataclass
 @dataclass
 class ChatTemplate:
 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
     query: str = None
 
 
     @staticmethod
     @staticmethod
@@ -84,10 +84,10 @@ class ChatTemplate:
 
 
     def render_conversation(
     def render_conversation(
         self,
         self,
-        conversation_data: list[str] | dict[str, str],
+        conversation_data: Union[List[str], Dict[str, str]],
         index: int = 0,
         index: int = 0,
         context_data: Dict[str, Any] = {},
         context_data: Dict[str, Any] = {},
-    ) -> list[str]:
+    ) -> List[str]:
         """
         """
         Args:
         Args:
             conversation_data (list[str]): the conversation data which must be two parts
             conversation_data (list[str]): the conversation data which must be two parts
@@ -145,7 +145,7 @@ class ChatTemplate:
 
 
     def __call__(
     def __call__(
         self,
         self,
-        conversations: list[list[str]] | str,
+        conversations: Union[List[List[str]], str],
         context_data: Dict[str, Union[int, str]] = {},
         context_data: Dict[str, Union[int, str]] = {},
     ) -> str:
     ) -> str:
         """render the conversations by chat-template
         """render the conversations by chat-template
@@ -188,7 +188,7 @@ class ChatTemplate:
         return final_query
         return final_query
 
 
     @classmethod
     @classmethod
-    def from_dict(cls, config: dict):
+    def from_dict(cls, config: Dict):
         return cls(**config)
         return cls(**config)
 
 
     @classmethod
     @classmethod
@@ -641,11 +641,11 @@ class ChatTemplateMixin:
 
 
     def apply_chat_template(
     def apply_chat_template(
         self,
         self,
-        conversation: Union[Dict[str, str] | Dict[str, str]] | str,
+        conversation: Union[Dict[str, str], str],
         tokenize: bool = True,
         tokenize: bool = True,
         context_data: Dict[str, Any] = {},
         context_data: Dict[str, Any] = {},
         **tokenizer_kwargs,
         **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
         """apply chat_template rules to conversation which should not be batched data
 
 
         Args:
         Args:
@@ -677,9 +677,9 @@ class ChatTemplateMixin:
 
 
     def _apply_chat_template_paddle(
     def _apply_chat_template_paddle(
         self,
         self,
-        conversation: List[Dict[str, str]] | str,
+        conversation: Union[List[Dict[str, str]], str],
         context_data: Dict[str, Any] = {},
         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)
         context_data = self.chat_template._init_context_data(context_data)
 
 
         if isinstance(conversation, str):
         if isinstance(conversation, str):
@@ -695,9 +695,9 @@ class ChatTemplateMixin:
 
 
     def _apply_chat_template(
     def _apply_chat_template(
         self,
         self,
-        conversation: Union[Dict[str, str] | Dict[str, str]] | str,
+        conversation: Union[Dict[str, str], str],
         add_generation_prompt=True,
         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):
         if isinstance(conversation, str):
             conversations = [{"role": "user", "content": conversation}]
             conversations = [{"role": "user", "content": conversation}]
         elif isinstance(conversation, list):
         elif isinstance(conversation, list):
@@ -893,7 +893,7 @@ class ChatTemplateMixin:
         tokenizer.init_chat_template(chat_template_file)
         tokenizer.init_chat_template(chat_template_file)
         return tokenizer
         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
         """init chat_tempalte by file_path or template dict data
 
 
         Args:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 
 
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
@@ -49,12 +49,12 @@ class AnomalyDetectionPipeline(BasePipeline):
         self.anomaly_detetion_model = self.create_model(anomaly_detetion_model_config)
         self.anomaly_detetion_model = self.create_model(anomaly_detetion_model_config)
 
 
     def predict(
     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:
     ) -> UadResult:
         """Predicts anomaly detection results for the given input.
         """Predicts anomaly detection results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Tuple
+from typing import Tuple, List
 import copy
 import copy
 import numpy as np
 import numpy as np
 import cv2
 import cv2
@@ -32,7 +32,7 @@ class CropByBoxes(BaseOperator):
         """Initializes the class."""
         """Initializes the class."""
         super().__init__()
         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
         Process the input image and bounding boxes to produce a list of cropped images
         with their corresponding bounding box coordinates and labels.
         with their corresponding bounding box coordinates and labels.
@@ -74,7 +74,7 @@ class CropByPolys(BaseOperator):
         super().__init__()
         super().__init__()
         self.det_box_type = det_box_type
         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.
         Call method to crop images based on detection boxes.
 
 
@@ -187,7 +187,7 @@ class CropByPolys(BaseOperator):
 
 
     def reorder_poly_edge(
     def reorder_poly_edge(
         self, points: np.ndarray
         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
         """Get the respective points composing head edge, tail edge, top
         sideline and bottom sideline.
         sideline and bottom sideline.
 
 
@@ -239,7 +239,7 @@ class CropByPolys(BaseOperator):
 
 
     def find_head_tail(
     def find_head_tail(
         self, points: np.ndarray, orientation_thr: float
         self, points: np.ndarray, orientation_thr: float
-    ) -> tuple[list, list]:
+    ) -> Tuple[list, list]:
         """Find the head edge and tail edge of a text polygon.
         """Find the head edge and tail edge of a text polygon.
 
 
         Args:
         Args:
@@ -370,7 +370,7 @@ class CropByPolys(BaseOperator):
 
 
     def get_minarea_rect(
     def get_minarea_rect(
         self, img: np.ndarray, points: np.ndarray
         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.
         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.
 # limitations under the License.
 
 
 import numpy as np
 import numpy as np
+from typing import List
 from .base_operator import BaseOperator
 from .base_operator import BaseOperator
 
 
 
 
@@ -25,7 +26,7 @@ class SortQuadBoxes(BaseOperator):
         """Initializes the class."""
         """Initializes the class."""
         super().__init__()
         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
         Sort quad boxes in order from top to bottom, left to right
         args:
         args:
@@ -60,7 +61,7 @@ class SortPolyBoxes(BaseOperator):
         """Initializes the class."""
         """Initializes the class."""
         super().__init__()
         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
         Sort poly boxes in order from top to bottom, left to right
         args:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Dict
+from typing import Dict, List
 import time
 import time
 import os
 import os
 from langchain.docstore.document import Document
 from langchain.docstore.document import Document
@@ -88,9 +88,9 @@ class ErnieBotRetriever(BaseRetriever):
 
 
     def generate_vector_database(
     def generate_vector_database(
         self,
         self,
-        text_list: list[str],
+        text_list: List[str],
         block_size: int = 300,
         block_size: int = 300,
-        separators: list[str] = ["\t", "\n", "。", "\n\n", ""],
+        separators: List[str] = ["\t", "\n", "。", "\n\n", ""],
         sleep_time: float = 0.5,
         sleep_time: float = 0.5,
     ) -> FAISS:
     ) -> FAISS:
         """
         """
@@ -193,7 +193,7 @@ class ErnieBotRetriever(BaseRetriever):
 
 
     def similarity_retrieval(
     def similarity_retrieval(
         self,
         self,
-        query_text_list: list[str],
+        query_text_list: List[str],
         vectorstore: FAISS,
         vectorstore: FAISS,
         sleep_time: float = 0.5,
         sleep_time: float = 0.5,
         topk: int = 2,
         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
 import time
 
 
-from typing import Dict
+from typing import Dict, List
 
 
 
 
 class OpenAIBotRetriever(BaseRetriever):
 class OpenAIBotRetriever(BaseRetriever):
@@ -85,9 +85,9 @@ class OpenAIBotRetriever(BaseRetriever):
 
 
     def generate_vector_database(
     def generate_vector_database(
         self,
         self,
-        text_list: list[str],
+        text_list: List[str],
         block_size: int = 300,
         block_size: int = 300,
-        separators: list[str] = ["\t", "\n", "。", "\n\n", ""],
+        separators: List[str] = ["\t", "\n", "。", "\n\n", ""],
         sleep_time: float = 0.5,
         sleep_time: float = 0.5,
     ) -> FAISS:
     ) -> FAISS:
         """
         """
@@ -155,7 +155,7 @@ class OpenAIBotRetriever(BaseRetriever):
         return vector
         return vector
 
 
     def similarity_retrieval(
     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:
     ) -> str:
         """
         """
         Retrieve similar contexts based on a list of query texts.
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 from scipy.ndimage import rotate
 from scipy.ndimage import rotate
 import numpy as np
 import numpy as np
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -139,7 +139,7 @@ class DocPreprocessorPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
     ) -> DocPreprocessorResult:
     ) -> DocPreprocessorResult:
@@ -147,7 +147,7 @@ class DocPreprocessorPipeline(BasePipeline):
         Predict the preprocessing result for the input image or images.
         Predict the preprocessing result for the input image or images.
 
 
         Args:
         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_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_unwarping (bool): Whether to use document unwarping.
             use_doc_unwarping (bool): Whether to use document unwarping.
             **kwargs: Additional keyword arguments.
             **kwargs: Additional keyword arguments.

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

@@ -13,7 +13,7 @@
 # limitations under the License.
 # limitations under the License.
 
 
 import os, sys
 import os, sys
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 import cv2
 import cv2
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -177,7 +177,7 @@ class FormulaRecognitionPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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_layout_detection: Optional[bool] = None,
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: 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.
         This function predicts the layout parsing result for the given input.
 
 
         Args:
         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_layout_detection (Optional[bool]): Whether to use layout detection.
             use_doc_orientation_classify (Optional[bool]): Whether to use document orientation classification.
             use_doc_orientation_classify (Optional[bool]): Whether to use document orientation classification.
             use_doc_unwarping (Optional[bool]): Whether to use document unwarping.
             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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 from ...common.reader import ReadImage
 from ...common.reader import ReadImage
 from ...common.batch_sampler import ImageBatchSampler
 from ...common.batch_sampler import ImageBatchSampler
@@ -56,12 +56,12 @@ class ImageClassificationPipeline(BasePipeline):
         self.topk = image_classification_model_config.get("topk", 5)
         self.topk = image_classification_model_config.get("topk", 5)
 
 
     def predict(
     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:
     ) -> TopkResult:
         """Predicts image classification results for the given input.
         """Predicts image classification results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 from ...common.reader import ReadImage
 from ...common.reader import ReadImage
 from ...common.batch_sampler import ImageBatchSampler
 from ...common.batch_sampler import ImageBatchSampler
@@ -59,14 +59,14 @@ class ImageMultiLabelClassificationPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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
         **kwargs
     ) -> MLClassResult:
     ) -> MLClassResult:
         """Predicts image classification results for the given input.
         """Predicts image classification results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -53,12 +53,12 @@ class InstanceSegmentationPipeline(BasePipeline):
         self.threshold = instance_segmentation_model_config["threshold"]
         self.threshold = instance_segmentation_model_config["threshold"]
 
 
     def predict(
     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:
     ) -> InstanceSegResult:
         """Predicts instance segmentation results for the given input.
         """Predicts instance segmentation results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # 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
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -95,12 +95,12 @@ class KeypointDetectionPipeline(BasePipeline):
         return center, scale
         return center, scale
 
 
     def predict(
     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:
     ) -> KptResult:
         """Predicts image classification results for the given input.
         """Predicts image classification results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import os, sys
 import os, sys
 import numpy as np
 import numpy as np
 import cv2
 import cv2
@@ -243,7 +243,7 @@ class LayoutParsingPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_general_ocr: 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.
         This function predicts the layout parsing result for the given input.
 
 
         Args:
         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_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_unwarping (bool): Whether to use document unwarping.
             use_doc_unwarping (bool): Whether to use document unwarping.
             use_general_ocr (bool): Whether to use general OCR.
             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 os
 import sys
 import sys
-from typing import Any
-from typing import Dict
-from typing import Optional
+from typing import Any, Dict, Optional, Union
 
 
 import cv2
 import cv2
 import numpy as np
 import numpy as np
@@ -261,7 +259,7 @@ class LayoutParsingPipelineV2(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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_orientation_classify: bool | None = None,
         use_doc_unwarping: bool | None = None,
         use_doc_unwarping: bool | None = None,
         use_general_ocr: bool | None = None,
         use_general_ocr: bool | None = None,
@@ -269,13 +267,13 @@ class LayoutParsingPipelineV2(BasePipeline):
         use_table_recognition: bool | None = None,
         use_table_recognition: bool | None = None,
         use_formula_recognition: bool | None = None,
         use_formula_recognition: bool | None = None,
         text_det_limit_side_len: int | 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_thresh: float | None = None,
         text_det_box_thresh: float | None = None,
         text_det_box_thresh: float | None = None,
         text_det_unclip_ratio: float | None = None,
         text_det_unclip_ratio: float | None = None,
         text_rec_score_thresh: float | None = None,
         text_rec_score_thresh: float | None = None,
         seal_det_limit_side_len: int | 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_thresh: float | None = None,
         seal_det_box_thresh: float | None = None,
         seal_det_box_thresh: float | None = None,
         seal_det_unclip_ratio: 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.
         This function predicts the layout parsing result for the given input.
 
 
         Args:
         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_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_unwarping (bool): Whether to use document unwarping.
             use_doc_unwarping (bool): Whether to use document unwarping.
             use_general_ocr (bool): Whether to use general OCR.
             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 cv2
 import uuid
 import uuid
 from pathlib import Path
 from pathlib import Path
+from typing import List
 from ..ocr.result import OCRResult
 from ..ocr.result import OCRResult
 from ...models_new.object_detection.result import DetResult
 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.
     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(
 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:
 ) -> OCRResult:
     """
     """
     Filters OCR results to only include text boxes within specified object boxes based on a flag.
     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
     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.
     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.
     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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 
 
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
@@ -53,12 +53,12 @@ class MultilingualSpeechRecognitionPipeline(BasePipeline):
         batch_size = multilingual_speech_recognition_model_config["batch_size"]
         batch_size = multilingual_speech_recognition_model_config["batch_size"]
 
 
     def predict(
     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:
     ) -> WhisperResult:
         """Predicts speech recognition results for the given input.
         """Predicts speech recognition results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # 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
 import numpy as np
 
 
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
@@ -55,12 +55,14 @@ class ObjectDetectionPipeline(BasePipeline):
         if "layout_unclip_ratio" in model_cfg:
         if "layout_unclip_ratio" in model_cfg:
             model_kwargs["layout_unclip_ratio"] = model_cfg["layout_unclip_ratio"]
             model_kwargs["layout_unclip_ratio"] = model_cfg["layout_unclip_ratio"]
         if "layout_merge_bboxes_mode" in model_cfg:
         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)
         self.det_model = self.create_model(model_cfg, **model_kwargs)
 
 
     def predict(
     def predict(
         self,
         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,
         threshold: Optional[Union[float, dict]] = None,
         layout_nms: bool = False,
         layout_nms: bool = False,
         layout_unclip_ratio: Optional[Union[float, Tuple[float, float]]] = None,
         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.
         """Predicts object detection results for the given input.
 
 
         Args:
         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.
             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.
             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.
             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.
             DetResult: The predicted detection results.
         """
         """
         yield from self.det_model(
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, List, Optional
+from typing import Any, Dict, List, Optional, Union
 import numpy as np
 import numpy as np
 from scipy.ndimage import rotate
 from scipy.ndimage import rotate
 from ...common.reader import ReadImage
 from ...common.reader import ReadImage
@@ -265,7 +265,7 @@ class OCRPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_textline_orientation: 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.
         Predict OCR results based on input images or arrays with optional preprocessing steps.
 
 
         Args:
         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_orientation_classify (Optional[bool]): Whether to use document orientation classification.
             use_doc_unwarping (Optional[bool]): Whether to use document unwarping.
             use_doc_unwarping (Optional[bool]): Whether to use document unwarping.
             use_textline_orientation (Optional[bool]): Whether to use textline orientation prediction.
             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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -55,14 +55,14 @@ class OpenVocabularyDetectionPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         self,
-        input: str | list[str] | np.ndarray | list[np.ndarray],
+        input: Union[str, List[str], np.ndarray, List[np.ndarray]],
         prompt: str,
         prompt: str,
         **kwargs
         **kwargs
     ) -> DetResult:
     ) -> DetResult:
         """Predicts open vocabulary detection results for the given input.
         """Predicts open vocabulary detection results for the given input.
 
 
         Args:
         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.
             prompt (str): The text prompt used to describe the objects.
             **kwargs: Additional keyword arguments that can be passed to the function.
             **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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # 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
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -62,15 +62,15 @@ class OpenVocabularySegmentationPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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",
         prompt_type: str = "box",
         **kwargs
         **kwargs
     ) -> SAMSegResult:
     ) -> SAMSegResult:
         """Predicts image segmentation results for the given input.
         """Predicts image segmentation results for the given input.
 
 
         Args:
         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 (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'.
             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.
             **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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List, Tuple
 import re
 import re
 import json
 import json
 import numpy as np
 import numpy as np
@@ -162,7 +162,7 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
     # Function to perform visual prediction on input images
     # Function to perform visual prediction on input images
     def visual_predict(
     def visual_predict(
         self,
         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_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_general_ocr: 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.
         general OCR, seal recognition, and table recognition based on the provided flags.
 
 
         Args:
         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.
                                                                         numpy array of an image, or list of numpy arrays.
             use_doc_orientation_classify (bool): Flag to use document orientation classification.
             use_doc_orientation_classify (bool): Flag to use document orientation classification.
             use_doc_unwarping (bool): Flag to use document unwarping.
             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")
             fout.write(json.dumps(visual_info_list, ensure_ascii=False) + "\n")
         return
         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.
         Loads visual info list from a JSON file.
 
 
@@ -270,8 +270,8 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
         return visual_info_list
         return visual_info_list
 
 
     def merge_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.
         Merge visual info lists.
 
 
@@ -379,7 +379,7 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
                 )
                 )
         return vector_info
         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.
         Formats the key list.
 
 
@@ -438,7 +438,7 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
         self,
         self,
         use_vector_retrieval: bool,
         use_vector_retrieval: bool,
         vector_info: dict,
         vector_info: dict,
-        key_list: list[str],
+        key_list: List[str],
         all_normal_text_list: list,
         all_normal_text_list: list,
         min_characters: int,
         min_characters: int,
     ) -> str:
     ) -> str:
@@ -482,8 +482,8 @@ class PP_ChatOCRv3_Pipeline(PP_ChatOCR_Pipeline):
 
 
     def chat(
     def chat(
         self,
         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,
         use_vector_retrieval: bool = True,
         vector_info: dict = None,
         vector_info: dict = None,
         min_characters: int = 3500,
         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.
         Generates chat results based on the provided key list and visual information.
 
 
         Args:
         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.
             visual_info (dict): The visual information result.
             use_vector_retrieval (bool): Whether to use vector retrieval.
             use_vector_retrieval (bool): Whether to use vector retrieval.
             vector_info (dict): The vector information for 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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List, Tuple
 import re
 import re
 import cv2
 import cv2
 import json
 import json
@@ -184,7 +184,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
     # Function to perform visual prediction on input images
     # Function to perform visual prediction on input images
     def visual_predict(
     def visual_predict(
         self,
         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_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_general_ocr: 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.
         general OCR, seal recognition, and table recognition based on the provided flags.
 
 
         Args:
         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.
                                                                         numpy array of an image, or list of numpy arrays.
             use_doc_orientation_classify (bool): Flag to use document orientation classification.
             use_doc_orientation_classify (bool): Flag to use document orientation classification.
             use_doc_unwarping (bool): Flag to use document unwarping.
             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")
             fout.write(json.dumps(visual_info_list, ensure_ascii=False) + "\n")
         return
         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.
         Loads visual info list from a JSON file.
 
 
@@ -291,8 +291,8 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
         return visual_info_list
         return visual_info_list
 
 
     def merge_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.
         Merge visual info lists.
 
 
@@ -411,7 +411,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
                 )
                 )
         return vector_info
         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.
         Formats the key list.
 
 
@@ -437,7 +437,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
 
 
     def mllm_pred(
     def mllm_pred(
         self,
         self,
-        input: str | np.ndarray,
+        input: Union[str, np.ndarray],
         key_list,
         key_list,
         **kwargs,
         **kwargs,
     ) -> dict:
     ) -> dict:
@@ -512,7 +512,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
         self,
         self,
         use_vector_retrieval: bool,
         use_vector_retrieval: bool,
         vector_info: dict,
         vector_info: dict,
-        key_list: list[str],
+        key_list: List[str],
         all_normal_text_list: list,
         all_normal_text_list: list,
         min_characters: int,
         min_characters: int,
     ) -> str:
     ) -> str:
@@ -555,7 +555,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
         return related_text
         return related_text
 
 
     def ensemble_ocr_llm_mllm(
     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:
     ) -> dict:
         """
         """
         Ensemble OCR_LLM and LMM predictions based on given key list.
         Ensemble OCR_LLM and LMM predictions based on given key list.
@@ -604,7 +604,7 @@ class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
 
 
     def chat(
     def chat(
         self,
         self,
-        key_list: str | list[str],
+        key_list: Union[str, List[str]],
         visual_info: dict,
         visual_info: dict,
         use_vector_retrieval: bool = True,
         use_vector_retrieval: bool = True,
         vector_info: dict = None,
         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.
         Generates chat results based on the provided key list and visual information.
 
 
         Args:
         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.
             visual_info (dict): The visual information result.
             use_vector_retrieval (bool): Whether to use vector retrieval.
             use_vector_retrieval (bool): Whether to use vector retrieval.
             vector_info (dict): The vector information for 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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -53,12 +53,12 @@ class RotatedObjectDetectionPipeline(BasePipeline):
         self.threshold = rotated_object_detection_model_config["threshold"]
         self.threshold = rotated_object_detection_model_config["threshold"]
 
 
     def predict(
     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:
     ) -> DetResult:
         """Predicts rotated object detection results for the given input.
         """Predicts rotated object detection results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         Returns:

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

@@ -13,7 +13,7 @@
 # limitations under the License.
 # limitations under the License.
 
 
 import os, sys
 import os, sys
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 import cv2
 import cv2
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -151,7 +151,7 @@ class SealRecognitionPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_layout_detection: 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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -53,12 +53,12 @@ class SemanticSegmentationPipeline(BasePipeline):
         self.target_size = semantic_segmentation_model_config["target_size"]
         self.target_size = semantic_segmentation_model_config["target_size"]
 
 
     def predict(
     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:
     ) -> SegResult:
         """Predicts semantic segmentation results for the given input.
         """Predicts semantic segmentation results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -53,12 +53,12 @@ class SmallObjectDetectionPipeline(BasePipeline):
         self.threshold = small_object_detection_model_config["threshold"]
         self.threshold = small_object_detection_model_config["threshold"]
 
 
     def predict(
     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:
     ) -> DetResult:
         """Predicts small object detection results for the given input.
         """Predicts small object detection results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         Returns:

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

@@ -13,7 +13,7 @@
 # limitations under the License.
 # limitations under the License.
 
 
 import os, sys
 import os, sys
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, Tuple, List
 import numpy as np
 import numpy as np
 import cv2
 import cv2
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -190,7 +190,7 @@ class TableRecognitionPipeline(BasePipeline):
 
 
     def predict_doc_preprocessor_res(
     def predict_doc_preprocessor_res(
         self, image_array: np.ndarray, input_params: dict
         self, image_array: np.ndarray, input_params: dict
-    ) -> tuple[DocPreprocessorResult, np.ndarray]:
+    ) -> Tuple[DocPreprocessorResult, np.ndarray]:
         """
         """
         Preprocess the document image based on input parameters.
         Preprocess the document image based on input parameters.
 
 
@@ -254,7 +254,7 @@ class TableRecognitionPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_layout_detection: 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.
         This function predicts the layout parsing result for the given input.
 
 
         Args:
         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_layout_detection (bool): Whether to use layout detection.
             use_doc_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_unwarping (bool): Whether to use document unwarping.
             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.
 # limitations under the License.
 
 
 import os, sys
 import os, sys
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List, Tuple
 import numpy as np
 import numpy as np
 import cv2
 import cv2
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -96,19 +96,27 @@ class TableRecognitionPipelineV2(BasePipeline):
             {"model_config_error": "config error for wireless_table_structure_model!"},
             {"model_config_error": "config error for wireless_table_structure_model!"},
         )
         )
         self.wireless_table_rec_model = self.create_model(wireless_table_rec_config)
         self.wireless_table_rec_model = self.create_model(wireless_table_rec_config)
-        
+
         wired_table_cells_det_config = config.get("SubModules", {}).get(
         wired_table_cells_det_config = config.get("SubModules", {}).get(
             "WiredTableCellsDetection",
             "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(
         wireless_table_cells_det_config = config.get("SubModules", {}).get(
             "WirelessTableCellsDetection",
             "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)
         self.use_ocr_model = config.get("use_ocr_model", True)
         if self.use_ocr_model:
         if self.use_ocr_model:
             general_ocr_config = config.get("SubPipelines", {}).get(
             general_ocr_config = config.get("SubPipelines", {}).get(
@@ -218,7 +226,7 @@ class TableRecognitionPipelineV2(BasePipeline):
 
 
     def predict_doc_preprocessor_res(
     def predict_doc_preprocessor_res(
         self, image_array: np.ndarray, input_params: dict
         self, image_array: np.ndarray, input_params: dict
-    ) -> tuple[DocPreprocessorResult, np.ndarray]:
+    ) -> Tuple[DocPreprocessorResult, np.ndarray]:
         """
         """
         Preprocess the document image based on input parameters.
         Preprocess the document image based on input parameters.
 
 
@@ -248,15 +256,15 @@ class TableRecognitionPipelineV2(BasePipeline):
 
 
     def extract_results(self, pred, task):
     def extract_results(self, pred, task):
         if task == "cls":
         if task == "cls":
-            return pred['label_names'][np.argmax(pred['scores'])]
+            return pred["label_names"][np.argmax(pred["scores"])]
         elif task == "det":
         elif task == "det":
             threshold = 0.0
             threshold = 0.0
             result = []
             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:
                         if isinstance(score, float) and score > threshold:
                             result.append(coordinate)
                             result.append(coordinate)
             return result
             return result
@@ -291,8 +299,12 @@ class TableRecognitionPipelineV2(BasePipeline):
             table_cells_pred = next(self.wired_table_cells_detection_model(image_array))
             table_cells_pred = next(self.wired_table_cells_detection_model(image_array))
         elif table_cls_result == "wireless_table":
         elif table_cls_result == "wireless_table":
             table_structure_pred = next(self.wireless_table_rec_model(image_array))
             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")
         table_cells_result = self.extract_results(table_cells_pred, "det")
         single_table_recognition_res = get_table_recognition_res(
         single_table_recognition_res = get_table_recognition_res(
             table_box, table_structure_result, table_cells_result, overall_ocr_res
             table_box, table_structure_result, table_cells_result, overall_ocr_res
@@ -310,7 +322,7 @@ class TableRecognitionPipelineV2(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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_orientation_classify: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_doc_unwarping: Optional[bool] = None,
         use_layout_detection: 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.
         This function predicts the layout parsing result for the given input.
 
 
         Args:
         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_layout_detection (bool): Whether to use layout detection.
             use_doc_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_orientation_classify (bool): Whether to use document orientation classification.
             use_doc_unwarping (bool): Whether to use document unwarping.
             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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import pandas as pd
 import pandas as pd
 
 
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
@@ -49,12 +49,12 @@ class TSAnomalyDetPipeline(BasePipeline):
         self.ts_ad_model = self.create_model(ts_ad_model_config)
         self.ts_ad_model = self.create_model(ts_ad_model_config)
 
 
     def predict(
     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:
     ) -> TSAdResult:
         """Predicts time series anomaly detection results for the given input.
         """Predicts time series anomaly detection results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import pandas as pd
 import pandas as pd
 
 
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
@@ -49,12 +49,12 @@ class TSClsPipeline(BasePipeline):
         self.ts_classification_model = self.create_model(ts_classification_model_config)
         self.ts_classification_model = self.create_model(ts_classification_model_config)
 
 
     def predict(
     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:
     ) -> TSClsResult:
         """Predicts time series classification results for the given input.
         """Predicts time series classification results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Optional, Union, List
 import pandas as pd
 import pandas as pd
 
 
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
@@ -49,12 +49,12 @@ class TSFcPipeline(BasePipeline):
         self.ts_forecast_model = self.create_model(ts_forecast_model_config)
         self.ts_forecast_model = self.create_model(ts_forecast_model_config)
 
 
     def predict(
     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:
     ) -> TSFcResult:
         """Predicts time series forecast results for the given input.
         """Predicts time series forecast results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional, Union
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -51,14 +51,14 @@ class VideoClassificationPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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,
         topk: Union[int, None] = 1,
         **kwargs
         **kwargs
     ) -> TopkVideoResult:
     ) -> TopkVideoResult:
         """Predicts video classification results for the given input.
         """Predicts video classification results for the given input.
 
 
         Args:
         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.
             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.
             **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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from typing import Any, Dict, Optional, Union
+from typing import Any, Dict, Optional, Union, List
 import numpy as np
 import numpy as np
 from ...utils.pp_option import PaddlePredictorOption
 from ...utils.pp_option import PaddlePredictorOption
 from ..base import BasePipeline
 from ..base import BasePipeline
@@ -49,7 +49,7 @@ class VideoDetectionPipeline(BasePipeline):
 
 
     def predict(
     def predict(
         self,
         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,
         nms_thresh: float = 0.5,
         score_thresh: float = 0.4,
         score_thresh: float = 0.4,
         **kwargs
         **kwargs
@@ -57,7 +57,7 @@ class VideoDetectionPipeline(BasePipeline):
         """Predicts video detection results for the given input.
         """Predicts video detection results for the given input.
 
 
         Args:
         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.
             **kwargs: Additional keyword arguments that can be passed to the function.
 
 
         Returns:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
+from typing import List
 from ...base import BaseConfig
 from ...base import BaseConfig
 from ....utils.misc import abspath
 from ....utils.misc import abspath
 from ..config_helper import PPDetConfigMixin
 from ..config_helper import PPDetConfigMixin
@@ -51,7 +52,7 @@ class InstanceSegConfig(DetConfig):
         dataset_path: str,
         dataset_path: str,
         dataset_type: str = None,
         dataset_type: str = None,
         *,
         *,
-        data_fields: list[str] = None,
+        data_fields: List[str] = None,
         image_dir: str = "images",
         image_dir: str = "images",
         train_anno_path: str = "annotations/instance_train.json",
         train_anno_path: str = "annotations/instance_train.json",
         val_anno_path: str = "annotations/instance_val.json",
         val_anno_path: str = "annotations/instance_val.json",
@@ -95,7 +96,7 @@ class InstanceSegConfig(DetConfig):
     def _make_dataset_config(
     def _make_dataset_config(
         self,
         self,
         dataset_root_path: str,
         dataset_root_path: str,
-        data_fields: list[str,] = None,
+        data_fields: List[str,] = None,
         image_dir: str = "images",
         image_dir: str = "images",
         train_anno_path: str = "annotations/instance_train.json",
         train_anno_path: str = "annotations/instance_train.json",
         val_anno_path: str = "annotations/instance_val.json",
         val_anno_path: str = "annotations/instance_val.json",
@@ -210,7 +211,7 @@ class InstanceSegConfig(DetConfig):
             if sch[key] == "CosineDecay":
             if sch[key] == "CosineDecay":
                 sch["max_epochs"] = max_epochs
                 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
         """update milstone of `PiecewiseDecay` learning scheduler
 
 
         Args:
         Args:
@@ -346,7 +347,7 @@ class InstanceSegConfig(DetConfig):
         """
         """
         self["num_classes"] = num_classes
         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
         """update `target_size` of `BatchRandomResize` op in TestReader
 
 
         Args:
         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
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
+from typing import List
 from ...base import BaseConfig
 from ...base import BaseConfig
 from ....utils.misc import abspath
 from ....utils.misc import abspath
 from ....utils import logging
 from ....utils import logging
@@ -51,7 +52,7 @@ class DetConfig(BaseConfig, PPDetConfigMixin):
         dataset_path: str,
         dataset_path: str,
         dataset_type: str = None,
         dataset_type: str = None,
         *,
         *,
-        data_fields: list[str] = None,
+        data_fields: List[str] = None,
         image_dir: str = "images",
         image_dir: str = "images",
         train_anno_path: str = "annotations/instance_train.json",
         train_anno_path: str = "annotations/instance_train.json",
         val_anno_path: str = "annotations/instance_val.json",
         val_anno_path: str = "annotations/instance_val.json",
@@ -113,7 +114,7 @@ class DetConfig(BaseConfig, PPDetConfigMixin):
     def _make_dataset_config(
     def _make_dataset_config(
         self,
         self,
         dataset_root_path: str,
         dataset_root_path: str,
-        data_fields: list[str,] = None,
+        data_fields: List[str,] = None,
         image_dir: str = "images",
         image_dir: str = "images",
         train_anno_path: str = "annotations/instance_train.json",
         train_anno_path: str = "annotations/instance_train.json",
         val_anno_path: str = "annotations/instance_val.json",
         val_anno_path: str = "annotations/instance_val.json",
@@ -229,7 +230,7 @@ class DetConfig(BaseConfig, PPDetConfigMixin):
             if sch[key] == "CosineDecay":
             if sch[key] == "CosineDecay":
                 sch["max_epochs"] = max_epochs
                 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
         """update milstone of `PiecewiseDecay` learning scheduler
 
 
         Args:
         Args:
@@ -398,7 +399,7 @@ class DetConfig(BaseConfig, PPDetConfigMixin):
                         "num_classes"
                         "num_classes"
                     ] = 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
         """update `target_size` of `BatchRandomResize` op in TestReader
 
 
         Args:
         Args: