
from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxSeqaSeqConfigWithPast
from ...utils import logging


if TYPE_CHECKING:
   from ...feature_extraction_utils import FeatureExtractionMixin
   from ...tokenization_utils_base import PreTrainedTokenizerBase
   from ...utils import TensorType

UpperCAmelCase__		:     str     			=      logging.get_logger(__name__)

UpperCAmelCase__		:     Union[str, Any]     			=      {
    'openai/whisper-base': 'https://huggingface.co/openai/whisper-base/resolve/main/config.json',
}

# fmt: off
UpperCAmelCase__		:     str     			=      [
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 357, 366, 438, 532, 685,
    705, 796, 930, 1058, 1220, 1267, 1279, 1303, 1343, 1377,
    1391, 1635, 1782, 1875, 2162, 2361, 2488, 3467, 4008, 4211,
    4600, 4808, 5299, 5855, 6329, 7203, 9609, 9959, 10563, 10786,
    11420, 11709, 11907, 13163, 13697, 13700, 14808, 15306, 16410, 16791,
    17992, 19203, 19510, 20724, 22305, 22935, 27007, 30109, 30420, 33409,
    34949, 40283, 40493, 40549, 47282, 49146, 50257, 50359, 50360, 50361
]
UpperCAmelCase__		:     Optional[Any]     			=      [
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 359, 503, 522, 542, 873,
    893, 902, 918, 922, 931, 1350, 1853, 1982, 2460, 2627,
    3246, 3253, 3268, 3536, 3846, 3961, 4183, 4667, 6585, 6647,
    7273, 9061, 9383, 10428, 10929, 11938, 12033, 12331, 12562, 13793,
    14157, 14635, 15265, 15618, 16553, 16604, 18362, 18956, 20075, 21675,
    22520, 26130, 26161, 26435, 28279, 29464, 31650, 32302, 32470, 36865,
    42863, 47425, 49870, 50254, 50258, 50360, 50361, 50362
]






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''
   __UpperCamelCase		:    List[str] 				=    '''whisper'''
   __UpperCamelCase		:    str 				=    ['''past_key_values''']
   __UpperCamelCase		:    Dict 				=    {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}


   def __init__(					self     :							List[str]			,			lowerCAmelCase_     :							str=5_1_8_6_5			,			lowerCAmelCase_     :							List[str]=8_0			,			lowerCAmelCase_     :							Optional[Any]=6			,			lowerCAmelCase_     :							Dict=4			,			lowerCAmelCase_     :							List[Any]=6			,			lowerCAmelCase_     :							List[Any]=4			,			lowerCAmelCase_     :							str=1_5_3_6			,			lowerCAmelCase_     :							Optional[int]=1_5_3_6			,			lowerCAmelCase_     :							str=0.0			,			lowerCAmelCase_     :							Tuple=0.0			,			lowerCAmelCase_     :							Any=5_0_2_5_7			,			lowerCAmelCase_     :							Tuple=True			,			lowerCAmelCase_     :							Tuple=True			,			lowerCAmelCase_     :							Dict="gelu"			,			lowerCAmelCase_     :							List[Any]=2_5_6			,			lowerCAmelCase_     :							Optional[int]=0.0			,			lowerCAmelCase_     :							List[str]=0.0			,			lowerCAmelCase_     :							Tuple=0.0			,			lowerCAmelCase_     :							Any=0.02			,			lowerCAmelCase_     :							List[str]=False			,			lowerCAmelCase_     :							List[str]=1_5_0_0			,			lowerCAmelCase_     :							Union[str, Any]=4_4_8			,			lowerCAmelCase_     :							List[Any]=5_0_2_5_6			,			lowerCAmelCase_     :							Tuple=5_0_2_5_6			,			lowerCAmelCase_     :							int=5_0_2_5_6			,			lowerCAmelCase_     :							List[str]=None			,			lowerCAmelCase_     :							Tuple=[2_2_0, 5_0_2_5_6]			,			lowerCAmelCase_     :							Any=False			,			lowerCAmelCase_     :							Dict=2_5_6			,			lowerCAmelCase_     :							int=False			,			lowerCAmelCase_     :							List[Any]=0.05			,			lowerCAmelCase_     :							str=1_0			,			lowerCAmelCase_     :							Dict=2			,			lowerCAmelCase_     :							str=0.0			,			lowerCAmelCase_     :							Optional[Any]=1_0			,			lowerCAmelCase_     :							Optional[int]=0			,			lowerCAmelCase_     :							int=7			,			**lowerCAmelCase_     :							Optional[Any]			,			):

      """simple docstring"""
      _A:  Optional[Any]					=       vocab_size
      _A:  str					=       num_mel_bins
      _A:  Dict					=       d_model
      _A:  str					=       encoder_layers
      _A:  List[str]					=       encoder_attention_heads
      _A:  Optional[int]					=       decoder_layers
      _A:  Any					=       decoder_attention_heads
      _A:  Union[str, Any]					=       decoder_ffn_dim
      _A:  Any					=       encoder_ffn_dim
      _A:  List[Any]					=       dropout
      _A:  List[str]					=       attention_dropout
      _A:  Dict					=       activation_dropout
      _A:  str					=       activation_function
      _A:  int					=       init_std
      _A:  Dict					=       encoder_layerdrop
      _A:  Dict					=       decoder_layerdrop
      _A:  Dict					=       use_cache
      _A:  Union[str, Any]					=       encoder_layers
      _A:  Optional[int]					=       scale_embedding  # scale factor will be sqrt(d_model) if True
      _A:  str					=       max_source_positions
      _A:  Tuple					=       max_target_positions

      # Audio Classification-specific parameters. Feel free to ignore for other classes.
      _A:  int					=       classifier_proj_size
      _A:  Any					=       use_weighted_layer_sum

      # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
      _A:  Union[str, Any]					=       apply_spec_augment
      _A:  Optional[Any]					=       mask_time_prob
      _A:  int					=       mask_time_length
      _A:  Any					=       mask_time_min_masks
      _A:  Union[str, Any]					=       mask_feature_prob
      _A:  int					=       mask_feature_length
      _A:  Optional[int]					=       mask_feature_min_masks

      _A:  Any					=       median_filter_width

      super().__init__(
          pad_token_id=lowerCAmelCase_			,			bos_token_id=lowerCAmelCase_			,			eos_token_id=lowerCAmelCase_			,			is_encoder_decoder=lowerCAmelCase_			,			decoder_start_token_id=lowerCAmelCase_			,			suppress_tokens=lowerCAmelCase_			,			begin_suppress_tokens=lowerCAmelCase_			,			**lowerCAmelCase_			,			)






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''


   @property
   def  __magic_name__				(					self     :							Optional[int]     ):

      """simple docstring"""
      _A:  int					=       OrderedDict(
          [
              ('''input_features''', {0: '''batch''', 1: '''feature_size''', 2: '''encoder_sequence'''}),
          ]     )
      if self.use_past:
         _A:  Any					=       {0: '''batch'''}
      else:
         _A:  Dict					=       {0: '''batch''', 1: '''decoder_sequence'''}

      if self.use_past:
         self.fill_with_past_key_values_(lowerCAmelCase_			,			direction='''inputs'''     )

      return common_inputs


   def  __magic_name__				(					self     :							Optional[int]			,			lowerCAmelCase_     :							Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]			,			lowerCAmelCase_     :							int = -1			,			lowerCAmelCase_     :							int = -1			,			lowerCAmelCase_     :							bool = False			,			lowerCAmelCase_     :							Optional["TensorType"] = None			,			lowerCAmelCase_     :							int = 2_2_0_5_0			,			lowerCAmelCase_     :							float = 5.0			,			lowerCAmelCase_     :							int = 2_2_0			,			):

      """simple docstring"""
      _A:  str					=       OrderedDict()
      _A:  int					=       OnnxConfig.generate_dummy_inputs(
          self			,			preprocessor=preprocessor.feature_extractor			,			batch_size=lowerCAmelCase_			,			framework=lowerCAmelCase_			,			sampling_rate=lowerCAmelCase_			,			time_duration=lowerCAmelCase_			,			frequency=lowerCAmelCase_			,			)
      _A:  str					=       encoder_inputs['''input_features'''].shape[2]
      _A:  List[str]					=       encoder_sequence_length // 2 if self.use_past else seq_length

      _A:  List[str]					=       super().generate_dummy_inputs(
          preprocessor.tokenizer			,			lowerCAmelCase_			,			lowerCAmelCase_			,			lowerCAmelCase_			,			lowerCAmelCase_     )

      _A:  Union[str, Any]					=       encoder_inputs.pop('''input_features'''     )
      _A:  List[str]					=       decoder_inputs.pop('''decoder_input_ids'''     )

      if "past_key_values" in decoder_inputs:
         _A:  Any					=       decoder_inputs.pop('''past_key_values'''     )

      return dummy_inputs


   @property
   def  __magic_name__				(					self     :							List[str]     ):

      """simple docstring"""
      return 1e-3





from typing import Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import get_image_size, pad, rescale, to_channel_dimension_format
from ...image_utils import ChannelDimension, ImageInput, make_list_of_images, to_numpy_array, valid_images
from ...utils import TensorType, logging


UpperCAmelCase__		:     Any     			=      logging.get_logger(__name__)






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''
   __UpperCamelCase		:    List[Any] 				=    ['''pixel_values''']


   def __init__(					self     :							Optional[int]			,			lowerCAmelCase_     :							bool = True			,			lowerCAmelCase_     :							Union[int, float] = 1 / 2_5_5			,			lowerCAmelCase_     :							bool = True			,			lowerCAmelCase_     :							int = 8			,			**lowerCAmelCase_     :							Tuple			,			):

      """simple docstring"""
      super().__init__(**lowerCAmelCase_     )

      _A:  List[str]					=       do_rescale
      _A:  Any					=       rescale_factor
      _A:  List[Any]					=       do_pad
      _A:  Tuple					=       pad_size


   def  __magic_name__				(					self     :							int			,			lowerCAmelCase_     :							np.ndarray			,			lowerCAmelCase_     :							float			,			lowerCAmelCase_     :							Optional[Union[str, ChannelDimension]] = None			,			**lowerCAmelCase_     :							Any     ):

      """simple docstring"""
      return rescale(lowerCAmelCase_			,			scale=lowerCAmelCase_			,			data_format=lowerCAmelCase_			,			**lowerCAmelCase_     )


   def  __magic_name__				(					self     :							Tuple			,			lowerCAmelCase_     :							np.ndarray			,			lowerCAmelCase_     :							int			,			lowerCAmelCase_     :							Optional[Union[str, ChannelDimension]] = None     ):

      """simple docstring"""
      _A			,  _A:  Optional[int]					=       get_image_size(lowerCAmelCase_     )
      _A:  Union[str, Any]					=       (old_height // size + 1) * size - old_height
      _A:  Optional[Any]					=       (old_width // size + 1) * size - old_width

      return pad(lowerCAmelCase_			,			((0, pad_height), (0, pad_width))			,			mode='''symmetric'''			,			data_format=lowerCAmelCase_     )


   def  __magic_name__				(					self     :							str			,			lowerCAmelCase_     :							ImageInput			,			lowerCAmelCase_     :							Optional[bool] = None			,			lowerCAmelCase_     :							Optional[float] = None			,			lowerCAmelCase_     :							Optional[bool] = None			,			lowerCAmelCase_     :							Optional[int] = None			,			lowerCAmelCase_     :							Optional[Union[str, TensorType]] = None			,			lowerCAmelCase_     :							Union[str, ChannelDimension] = ChannelDimension.FIRST			,			**lowerCAmelCase_     :							int			,			):

      """simple docstring"""
      _A:  List[str]					=       do_rescale if do_rescale is not None else self.do_rescale
      _A:  int					=       rescale_factor if rescale_factor is not None else self.rescale_factor
      _A:  str					=       do_pad if do_pad is not None else self.do_pad
      _A:  Union[str, Any]					=       pad_size if pad_size is not None else self.pad_size

      _A:  List[Any]					=       make_list_of_images(lowerCAmelCase_     )

      if not valid_images(lowerCAmelCase_     ):
         raise ValueError(
             '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
             '''torch.Tensor, tf.Tensor or jax.ndarray.'''     )

      if do_rescale and rescale_factor is None:
         raise ValueError('''Rescale factor must be specified if do_rescale is True.'''     )

      # All transformations expect numpy arrays.
      _A:  Union[str, Any]					=       [to_numpy_array(lowerCAmelCase_     ) for image in images]

      if do_rescale:
         _A:  str					=       [self.rescale(image=lowerCAmelCase_			,			scale=lowerCAmelCase_     ) for image in images]

      if do_pad:
         _A:  str					=       [self.pad(lowerCAmelCase_			,			size=lowerCAmelCase_     ) for image in images]

      _A:  Optional[Any]					=       [to_channel_dimension_format(lowerCAmelCase_			,			lowerCAmelCase_     ) for image in images]

      _A:  List[Any]					=       {'''pixel_values''': images}
      return BatchFeature(data=lowerCAmelCase_			,			tensor_type=lowerCAmelCase_     )



