


"""simple docstring"""
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCAmelCase				=						{
    """configuration_whisper""": ["""WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP""", """WhisperConfig""", """WhisperOnnxConfig"""],
    """feature_extraction_whisper""": ["""WhisperFeatureExtractor"""],
    """processing_whisper""": ["""WhisperProcessor"""],
    """tokenization_whisper""": ["""WhisperTokenizer"""],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase				=						["""WhisperTokenizerFast"""]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase				=						[
     """WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST""",
     """WhisperForConditionalGeneration""",
     """WhisperModel""",
     """WhisperPreTrainedModel""",
     """WhisperForAudioClassification""",
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase				=						[
     """TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST""",
     """TFWhisperForConditionalGeneration""",
     """TFWhisperModel""",
     """TFWhisperPreTrainedModel""",
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase				=						[
     """FlaxWhisperForConditionalGeneration""",
     """FlaxWhisperModel""",
     """FlaxWhisperPreTrainedModel""",
     """FlaxWhisperForAudioClassification""",
 ]


if TYPE_CHECKING:
 from .configuration_whisper import WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP, WhisperConfig, WhisperOnnxConfig
 from .feature_extraction_whisper import WhisperFeatureExtractor
 from .processing_whisper import WhisperProcessor
 from .tokenization_whisper import WhisperTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_whisper_fast import WhisperTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_whisper import (
      WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
      WhisperForAudioClassification,
      WhisperForConditionalGeneration,
      WhisperModel,
      WhisperPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_whisper import (
      TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFWhisperForConditionalGeneration,
      TFWhisperModel,
      TFWhisperPreTrainedModel,
  )

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_whisper import (
      FlaxWhisperForAudioClassification,
      FlaxWhisperForConditionalGeneration,
      FlaxWhisperModel,
      FlaxWhisperPreTrainedModel,
  )

else:
 import sys

 UpperCAmelCase				=						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



"""simple docstring"""





import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad



class __lowerCAmelCase					(       unittest.TestCase   ):




			"""simple docstring"""







			def   lowerCamelCase__  (					self    :       Optional[int]						)   ->			List[str]:







								"""simple docstring"""
								A_								=    10




			def   lowerCamelCase__  (					self    :       Union[str, Any]						)   ->			Union[str, Any]:







								"""simple docstring"""
								A_								=    [1, 2, 3, 4]
								A_								=    [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       List[str]						)   ->			List[Any]:







								"""simple docstring"""
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       str						)   ->			Dict:







								"""simple docstring"""
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       Dict						)   ->			Dict:







								"""simple docstring"""
								A_								=    "It was the year of Our Lord one thousand seven hundred and\n        seventy-five.\n\nSpiritual revelations were conceded to England at that\n        favoured period, as at this."
								A_			,     A_								=    process_story(_snake_case						)
								self.assertEqual(_snake_case							, []						)




			def   lowerCamelCase__  (					self    :       str						)   ->			str:







								"""simple docstring"""
								A_								=    ""
								A_			,     A_								=    process_story(_snake_case						)
								self.assertEqual(_snake_case							, []						)
								self.assertEqual(_snake_case							, []						)




			def   lowerCamelCase__  (					self    :       Tuple						)   ->			Optional[Any]:







								"""simple docstring"""
								A_								=    (
								    "It was the year of Our Lord one thousand seven hundred and "
								    "seventy-five\n\nSpiritual revelations were conceded to England "
								    "at that favoured period, as at this.\n@highlight\n\nIt was the best of times"
								)
								A_			,     A_								=    process_story(_snake_case						)

								A_								=    [
								    "It was the year of Our Lord one thousand seven hundred and seventy-five.",
								    "Spiritual revelations were conceded to England at that favoured period, as at this.",
								]
								self.assertEqual(_snake_case							, _snake_case						)

								A_								=    ["It was the best of times."]
								self.assertEqual(_snake_case							, _snake_case						)




			def   lowerCamelCase__  (					self    :       List[str]						)   ->			Optional[Any]:







								"""simple docstring"""
								A_								=    torch.tensor([1, 2, 3, 4]						)
								A_								=    torch.tensor([1, 1, 1, 1]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 0						).numpy()							, expected.numpy()						)




			def   lowerCamelCase__  (					self    :       List[Any]						)   ->			Optional[int]:







								"""simple docstring"""
								A_								=    torch.tensor([1, 2, 3, 4, 23, 23, 23]						)
								A_								=    torch.tensor([1, 1, 1, 1, 0, 0, 0]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 23						).numpy()							, expected.numpy()						)




			def   lowerCamelCase__  (					self    :       str						)   ->			Union[str, Any]:







								"""simple docstring"""
								A_								=    torch.tensor([8, 2, 3, 4, 1, 1, 1]						)
								A_								=    torch.tensor([1, 1, 1, 1, 0, 0, 0]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 1						).numpy()							, expected.numpy()						)






			def   lowerCamelCase__  (					self    :       int						)   ->			List[str]:







								"""simple docstring"""
								A_								=    101
								A_								=    torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]						)
								A_								=    torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]						)

								A_								=    compute_token_type_ids(_snake_case							, _snake_case						)
								np.testing.assert_array_equal(_snake_case							, _snake_case						)




