_doc_vlm.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (c) 2025 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. import abc
  15. from .._utils.cli import (
  16. get_subcommand_args,
  17. perform_simple_inference,
  18. )
  19. from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
  20. from paddlex.utils.pipeline_arguments import custom_type
  21. class BaseDocVLM(PaddleXPredictorWrapper):
  22. def __init__(
  23. self,
  24. *args,
  25. **kwargs,
  26. ):
  27. self._extra_init_args = {}
  28. super().__init__(*args, **kwargs)
  29. def _get_extra_paddlex_predictor_init_args(self):
  30. return self._extra_init_args
  31. class BaseDocVLMSubcommandExecutor(PredictorCLISubcommandExecutor):
  32. input_validator = staticmethod(custom_type(dict))
  33. @property
  34. @abc.abstractmethod
  35. def wrapper_cls(self):
  36. raise NotImplementedError
  37. def execute_with_args(self, args):
  38. params = get_subcommand_args(args)
  39. params["input"] = self.input_validator(params["input"])
  40. perform_simple_inference(self.wrapper_cls, params)