__init__.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # Copyright 2022 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 (
  16. OptionalDependencyNotAvailable,
  17. _LazyModule,
  18. is_flax_available,
  19. is_tf_available,
  20. is_tokenizers_available,
  21. is_torch_available,
  22. )
  23. _import_structure = {
  24. "configuration_whisper": ["WhisperConfig", "WhisperOnnxConfig"],
  25. "feature_extraction_whisper": ["WhisperFeatureExtractor"],
  26. "processing_whisper": ["WhisperProcessor"],
  27. "tokenization_whisper": ["WhisperTokenizer"],
  28. }
  29. try:
  30. if not is_tokenizers_available():
  31. raise OptionalDependencyNotAvailable()
  32. except OptionalDependencyNotAvailable:
  33. pass
  34. else:
  35. _import_structure["tokenization_whisper_fast"] = ["WhisperTokenizerFast"]
  36. try:
  37. if not is_torch_available():
  38. raise OptionalDependencyNotAvailable()
  39. except OptionalDependencyNotAvailable:
  40. pass
  41. else:
  42. _import_structure["modeling_whisper"] = [
  43. "WhisperForCausalLM",
  44. "WhisperForConditionalGeneration",
  45. "WhisperModel",
  46. "WhisperPreTrainedModel",
  47. "WhisperForAudioClassification",
  48. ]
  49. try:
  50. if not is_tf_available():
  51. raise OptionalDependencyNotAvailable()
  52. except OptionalDependencyNotAvailable:
  53. pass
  54. else:
  55. _import_structure["modeling_tf_whisper"] = [
  56. "TFWhisperForConditionalGeneration",
  57. "TFWhisperModel",
  58. "TFWhisperPreTrainedModel",
  59. ]
  60. try:
  61. if not is_flax_available():
  62. raise OptionalDependencyNotAvailable()
  63. except OptionalDependencyNotAvailable:
  64. pass
  65. else:
  66. _import_structure["modeling_flax_whisper"] = [
  67. "FlaxWhisperForConditionalGeneration",
  68. "FlaxWhisperModel",
  69. "FlaxWhisperPreTrainedModel",
  70. "FlaxWhisperForAudioClassification",
  71. ]
  72. if TYPE_CHECKING:
  73. from .configuration_whisper import WhisperConfig, WhisperOnnxConfig
  74. from .feature_extraction_whisper import WhisperFeatureExtractor
  75. from .processing_whisper import WhisperProcessor
  76. from .tokenization_whisper import WhisperTokenizer
  77. try:
  78. if not is_tokenizers_available():
  79. raise OptionalDependencyNotAvailable()
  80. except OptionalDependencyNotAvailable:
  81. pass
  82. else:
  83. from .tokenization_whisper_fast import WhisperTokenizerFast
  84. try:
  85. if not is_torch_available():
  86. raise OptionalDependencyNotAvailable()
  87. except OptionalDependencyNotAvailable:
  88. pass
  89. else:
  90. from .modeling_whisper import (
  91. WhisperForAudioClassification,
  92. WhisperForCausalLM,
  93. WhisperForConditionalGeneration,
  94. WhisperModel,
  95. WhisperPreTrainedModel,
  96. )
  97. try:
  98. if not is_tf_available():
  99. raise OptionalDependencyNotAvailable()
  100. except OptionalDependencyNotAvailable:
  101. pass
  102. else:
  103. from .modeling_tf_whisper import (
  104. TFWhisperForConditionalGeneration,
  105. TFWhisperModel,
  106. TFWhisperPreTrainedModel,
  107. )
  108. try:
  109. if not is_flax_available():
  110. raise OptionalDependencyNotAvailable()
  111. except OptionalDependencyNotAvailable:
  112. pass
  113. else:
  114. from .modeling_flax_whisper import (
  115. FlaxWhisperForAudioClassification,
  116. FlaxWhisperForConditionalGeneration,
  117. FlaxWhisperModel,
  118. FlaxWhisperPreTrainedModel,
  119. )
  120. else:
  121. import sys
  122. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)