pipeline_base.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  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 typing import Any, Dict, Optional, Union
  15. from ....utils import logging
  16. from ...utils.hpi import HPIConfig
  17. from ...utils.pp_option import PaddlePredictorOption
  18. from ..base import BasePipeline
  19. class PP_ChatOCR_Pipeline(BasePipeline):
  20. """PP-ChatOCR Pipeline"""
  21. def __init__(
  22. self,
  23. device: str = None,
  24. pp_option: PaddlePredictorOption = None,
  25. use_hpip: bool = False,
  26. hpi_config: Optional[Union[Dict[str, Any], HPIConfig]] = None,
  27. ) -> None:
  28. """Initializes the pp-chatocrv3-doc pipeline.
  29. Args:
  30. config (Dict): Configuration dictionary containing various settings.
  31. device (str, optional): Device to run the predictions on. Defaults to None.
  32. pp_option (PaddlePredictorOption, optional): PaddlePredictor options. Defaults to None.
  33. use_hpip (bool, optional): Whether to use the high-performance
  34. inference plugin (HPIP) by default. Defaults to False.
  35. hpi_config (Optional[Union[Dict[str, Any], HPIConfig]], optional):
  36. The default high-performance inference configuration dictionary.
  37. Defaults to None.
  38. """
  39. super().__init__(
  40. device=device, pp_option=pp_option, use_hpip=use_hpip, hpi_config=hpi_config
  41. )
  42. def visual_predict(self):
  43. """
  44. This function takes an input image or a list of images and performs various visual
  45. prediction tasks such as document orientation classification, document unwarping,
  46. general OCR, seal recognition, and table recognition based on the provided flags.
  47. """
  48. raise NotImplementedError(
  49. "The method `visual_predict` has not been implemented yet."
  50. )
  51. def save_visual_info_list(self):
  52. """
  53. Save the visual info list to the specified file path.
  54. """
  55. raise NotImplementedError(
  56. "The method `save_visual_info_list` has not been implemented yet."
  57. )
  58. def load_visual_info_list(self):
  59. """
  60. Loads visual info list from a file.
  61. """
  62. raise NotImplementedError(
  63. "The method `load_visual_info_list` has not been implemented yet."
  64. )
  65. def build_vector(self):
  66. """
  67. Build a vector representation from visual information.
  68. """
  69. raise NotImplementedError(
  70. "The method `build_vector` has not been implemented yet."
  71. )
  72. def save_vector(self):
  73. """
  74. Save the vector information to a specified path.
  75. """
  76. raise NotImplementedError(
  77. "The method `save_vector` has not been implemented yet."
  78. )
  79. def load_vector(self):
  80. """
  81. Loads vector information from a file.
  82. """
  83. raise NotImplementedError(
  84. "The method `load_vector` has not been implemented yet."
  85. )
  86. def chat(self):
  87. """
  88. Generates chat results based on the provided key list and visual information.
  89. """
  90. raise NotImplementedError("The method `chat` has not been implemented yet.")
  91. def predict(self, *args, **kwargs) -> None:
  92. logging.error(
  93. "PP-ChatOCR Pipeline do not support to call `predict()` directly! Please invoke `visual_predict`, `build_vector`, `chat` sequentially to obtain the result."
  94. )
  95. return