pipeline_base.py 3.7 KB

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