__init__.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from pathlib import Path
  15. from typing import Any, Dict, Optional
  16. from ...utils.config import parse_config
  17. from .base import BasePipeline
  18. from .single_model_pipeline import SingleModelPipeline
  19. from .ocr import OCRPipeline
  20. from .table_recognition import TableRecPipeline
  21. def create_pipeline(
  22. pipeline: str,
  23. use_hpip: bool = False,
  24. hpi_params: Optional[Dict[str, Any]] = None,
  25. **kwargs,
  26. ) -> BasePipeline:
  27. """build model evaluater
  28. Args:
  29. pipeline (str): the pipeline name, that is name of pipeline class
  30. Returns:
  31. BasePipeline: the pipeline, which is subclass of BasePipeline.
  32. """
  33. if not Path(pipeline).exists():
  34. # XXX: using dict class to handle all pipeline configs
  35. pipeline = (
  36. Path(__file__).parent.parent.parent / "pipelines" / f"{pipeline}.yaml"
  37. )
  38. if not Path(pipeline).exists():
  39. raise Exception(f"The pipeline don't exist! ({pipeline})")
  40. config = parse_config(pipeline)
  41. pipeline_name = config["Global"]["pipeline_name"]
  42. predictor_kwargs = {"use_hpip": use_hpip}
  43. if hpi_params is not None:
  44. predictor_kwargs["hpi_params"] = hpi_params
  45. pipeline = BasePipeline.get(pipeline_name)(
  46. predictor_kwargs=predictor_kwargs, **{**config["Pipeline"], **kwargs}
  47. )
  48. return pipeline