__init__.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright 2023 The HuggingFace Team. 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 TYPE_CHECKING
  15. from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available
  16. _import_structure = {
  17. "configuration_pix2struct": [
  18. "Pix2StructConfig",
  19. "Pix2StructTextConfig",
  20. "Pix2StructVisionConfig",
  21. ],
  22. "processing_pix2struct": ["Pix2StructProcessor"],
  23. }
  24. try:
  25. if not is_vision_available():
  26. raise OptionalDependencyNotAvailable()
  27. except OptionalDependencyNotAvailable:
  28. pass
  29. else:
  30. _import_structure["image_processing_pix2struct"] = ["Pix2StructImageProcessor"]
  31. try:
  32. if not is_torch_available():
  33. raise OptionalDependencyNotAvailable()
  34. except OptionalDependencyNotAvailable:
  35. pass
  36. else:
  37. _import_structure["modeling_pix2struct"] = [
  38. "Pix2StructPreTrainedModel",
  39. "Pix2StructForConditionalGeneration",
  40. "Pix2StructVisionModel",
  41. "Pix2StructTextModel",
  42. ]
  43. if TYPE_CHECKING:
  44. from .configuration_pix2struct import (
  45. Pix2StructConfig,
  46. Pix2StructTextConfig,
  47. Pix2StructVisionConfig,
  48. )
  49. from .processing_pix2struct import Pix2StructProcessor
  50. try:
  51. if not is_vision_available():
  52. raise OptionalDependencyNotAvailable()
  53. except OptionalDependencyNotAvailable:
  54. pass
  55. else:
  56. from .image_processing_pix2struct import Pix2StructImageProcessor
  57. try:
  58. if not is_torch_available():
  59. raise OptionalDependencyNotAvailable()
  60. except OptionalDependencyNotAvailable:
  61. pass
  62. else:
  63. from .modeling_pix2struct import (
  64. Pix2StructForConditionalGeneration,
  65. Pix2StructPreTrainedModel,
  66. Pix2StructTextModel,
  67. Pix2StructVisionModel,
  68. )
  69. else:
  70. import sys
  71. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)