




from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
   import PIL

lowerCamelCase__ :   str					=							logging.get_logger(__name__)

def 					UpperCAmelCase_							(      __UpperCAmelCase						:	str							)					-> List[List[ImageInput]]:
      if isinstance(__UpperCAmelCase			,			(list, tuple)							) and isinstance(videos[0]			,			(list, tuple)							) and is_valid_image(videos[0][0]							):
            return videos

      elif isinstance(__UpperCAmelCase			,			(list, tuple)							) and is_valid_image(videos[0]							):
            return [videos]

      elif is_valid_image(__UpperCAmelCase							):
            return [[videos]]

      raise ValueError(f"Could not make batched video from {videos}"							)





class        lowerCamelCase_							(      _SCREAMING_SNAKE_CASE					):


 '''simple docstring'''







 lowercase_				    =    ["pixel_values"]



 def __init__(							self  :		List[str]				,				_lowerCAmelCase  :		bool = True				,				_lowerCAmelCase  :		Dict[str, int] = None				,				_lowerCAmelCase  :		PILImageResampling = PILImageResampling.BILINEAR				,				_lowerCAmelCase  :		bool = True				,				_lowerCAmelCase  :		Dict[str, int] = None				,				_lowerCAmelCase  :		bool = True				,				_lowerCAmelCase  :		Union[int, float] = 1 / 255				,				_lowerCAmelCase  :		bool = True				,				_lowerCAmelCase  :		bool = True				,				_lowerCAmelCase  :		Optional[Union[float, List[float]]] = None				,				_lowerCAmelCase  :		Optional[Union[float, List[float]]] = None				,				**_lowerCAmelCase  :		Optional[int]				,				):
       super().__init__(**_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			size if size is not None else {'shortest_edge': 256}
       SCREAMING_SNAKE_CASE_							=			get_size_dict(_lowerCAmelCase				,				default_to_square=_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			crop_size if crop_size is not None else {'height': 224, 'width': 224}
       SCREAMING_SNAKE_CASE_							=			get_size_dict(_lowerCAmelCase				,				param_name='crop_size'						)

       SCREAMING_SNAKE_CASE_							=			do_resize
       SCREAMING_SNAKE_CASE_							=			size
       SCREAMING_SNAKE_CASE_							=			do_center_crop
       SCREAMING_SNAKE_CASE_							=			crop_size
       SCREAMING_SNAKE_CASE_							=			resample
       SCREAMING_SNAKE_CASE_							=			do_rescale
       SCREAMING_SNAKE_CASE_							=			rescale_factor
       SCREAMING_SNAKE_CASE_							=			offset
       SCREAMING_SNAKE_CASE_							=			do_normalize
       SCREAMING_SNAKE_CASE_							=			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
       SCREAMING_SNAKE_CASE_							=			image_std if image_std is not None else IMAGENET_STANDARD_STD



 def       lowerCAmelCase_  (							self  :		Union[str, Any]				,				_lowerCAmelCase  :		np.ndarray				,				_lowerCAmelCase  :		Dict[str, int]				,				_lowerCAmelCase  :		PILImageResampling = PILImageResampling.BILINEAR				,				_lowerCAmelCase  :		Optional[Union[str, ChannelDimension]] = None				,				**_lowerCAmelCase  :		List[Any]				,				):
       SCREAMING_SNAKE_CASE_							=			get_size_dict(_lowerCAmelCase				,				default_to_square=_lowerCAmelCase						)
       if "shortest_edge" in size:
             SCREAMING_SNAKE_CASE_							=			get_resize_output_image_size(_lowerCAmelCase				,				size['shortest_edge']				,				default_to_square=_lowerCAmelCase						)
       elif "height" in size and "width" in size:
             SCREAMING_SNAKE_CASE_							=			(size['height'], size['width'])
       else:
             raise ValueError(F"Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}"						)
       return resize(_lowerCAmelCase				,				size=_lowerCAmelCase				,				resample=_lowerCAmelCase				,				data_format=_lowerCAmelCase				,				**_lowerCAmelCase						)



 def       lowerCAmelCase_  (							self  :		Union[str, Any]				,				_lowerCAmelCase  :		np.ndarray				,				_lowerCAmelCase  :		Dict[str, int]				,				_lowerCAmelCase  :		Optional[Union[str, ChannelDimension]] = None				,				**_lowerCAmelCase  :		Any				,				):
       SCREAMING_SNAKE_CASE_							=			get_size_dict(_lowerCAmelCase						)
       if "height" not in size or "width" not in size:
             raise ValueError(F"Size must have 'height' and 'width' as keys. Got {size.keys()}"						)
       return center_crop(_lowerCAmelCase				,				size=(size['height'], size['width'])				,				data_format=_lowerCAmelCase				,				**_lowerCAmelCase						)



 def       lowerCAmelCase_  (							self  :		Optional[int]				,				_lowerCAmelCase  :		np.ndarray				,				_lowerCAmelCase  :		Union[int, float]				,				_lowerCAmelCase  :		bool = True				,				_lowerCAmelCase  :		Optional[Union[str, ChannelDimension]] = None				,				**_lowerCAmelCase  :		Tuple				,				):
       SCREAMING_SNAKE_CASE_							=			image.astype(np.floataa						)
       if offset:
             SCREAMING_SNAKE_CASE_							=			image - (scale / 2)
       return rescale(_lowerCAmelCase				,				scale=_lowerCAmelCase				,				data_format=_lowerCAmelCase				,				**_lowerCAmelCase						)



 def       lowerCAmelCase_  (							self  :		Optional[Any]				,				_lowerCAmelCase  :		np.ndarray				,				_lowerCAmelCase  :		Union[float, List[float]]				,				_lowerCAmelCase  :		Union[float, List[float]]				,				_lowerCAmelCase  :		Optional[Union[str, ChannelDimension]] = None				,				**_lowerCAmelCase  :		Dict				,				):
       return normalize(_lowerCAmelCase				,				mean=_lowerCAmelCase				,				std=_lowerCAmelCase				,				data_format=_lowerCAmelCase				,				**_lowerCAmelCase						)



 def       lowerCAmelCase_  (							self  :		List[Any]				,				_lowerCAmelCase  :		ImageInput				,				_lowerCAmelCase  :		bool = None				,				_lowerCAmelCase  :		Dict[str, int] = None				,				_lowerCAmelCase  :		PILImageResampling = None				,				_lowerCAmelCase  :		bool = None				,				_lowerCAmelCase  :		Dict[str, int] = None				,				_lowerCAmelCase  :		bool = None				,				_lowerCAmelCase  :		float = None				,				_lowerCAmelCase  :		bool = None				,				_lowerCAmelCase  :		bool = None				,				_lowerCAmelCase  :		Optional[Union[float, List[float]]] = None				,				_lowerCAmelCase  :		Optional[Union[float, List[float]]] = None				,				_lowerCAmelCase  :		Optional[ChannelDimension] = ChannelDimension.FIRST				,				):
       if do_resize and size is None or resample is None:
             raise ValueError('Size and resample must be specified if do_resize is True.'						)

       if do_center_crop and crop_size is None:
             raise ValueError('Crop size must be specified if do_center_crop is True.'						)

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

       if do_normalize and (image_mean is None or image_std is None):
             raise ValueError('Image mean and std must be specified if do_normalize is True.'						)

       if offset and not do_rescale:
             raise ValueError('For offset, do_rescale must also be set to True.'						)

       # All transformations expect numpy arrays.
       SCREAMING_SNAKE_CASE_							=			to_numpy_array(_lowerCAmelCase						)

       if do_resize:
             SCREAMING_SNAKE_CASE_							=			self.resize(image=_lowerCAmelCase				,				size=_lowerCAmelCase				,				resample=_lowerCAmelCase						)

       if do_center_crop:
             SCREAMING_SNAKE_CASE_							=			self.center_crop(_lowerCAmelCase				,				size=_lowerCAmelCase						)

       if do_rescale:
             SCREAMING_SNAKE_CASE_							=			self.rescale(image=_lowerCAmelCase				,				scale=_lowerCAmelCase				,				offset=_lowerCAmelCase						)

       if do_normalize:
             SCREAMING_SNAKE_CASE_							=			self.normalize(image=_lowerCAmelCase				,				mean=_lowerCAmelCase				,				std=_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			to_channel_dimension_format(_lowerCAmelCase				,				_lowerCAmelCase						)
       return image




 def       lowerCAmelCase_  (							self  :		Optional[Any]				,				_lowerCAmelCase  :		ImageInput				,				_lowerCAmelCase  :		bool = None				,				_lowerCAmelCase  :		Dict[str, int] = None				,				_lowerCAmelCase  :		PILImageResampling = None				,				_lowerCAmelCase  :		bool = None				,				_lowerCAmelCase  :		Dict[str, int] = None				,				_lowerCAmelCase  :		bool = None				,				_lowerCAmelCase  :		float = None				,				_lowerCAmelCase  :		bool = None				,				_lowerCAmelCase  :		bool = None				,				_lowerCAmelCase  :		Optional[Union[float, List[float]]] = None				,				_lowerCAmelCase  :		Optional[Union[float, List[float]]] = None				,				_lowerCAmelCase  :		Optional[Union[str, TensorType]] = None				,				_lowerCAmelCase  :		ChannelDimension = ChannelDimension.FIRST				,				**_lowerCAmelCase  :		List[Any]				,				):
       SCREAMING_SNAKE_CASE_							=			do_resize if do_resize is not None else self.do_resize
       SCREAMING_SNAKE_CASE_							=			resample if resample is not None else self.resample
       SCREAMING_SNAKE_CASE_							=			do_center_crop if do_center_crop is not None else self.do_center_crop
       SCREAMING_SNAKE_CASE_							=			do_rescale if do_rescale is not None else self.do_rescale
       SCREAMING_SNAKE_CASE_							=			rescale_factor if rescale_factor is not None else self.rescale_factor
       SCREAMING_SNAKE_CASE_							=			offset if offset is not None else self.offset
       SCREAMING_SNAKE_CASE_							=			do_normalize if do_normalize is not None else self.do_normalize
       SCREAMING_SNAKE_CASE_							=			image_mean if image_mean is not None else self.image_mean
       SCREAMING_SNAKE_CASE_							=			image_std if image_std is not None else self.image_std

       SCREAMING_SNAKE_CASE_							=			size if size is not None else self.size
       SCREAMING_SNAKE_CASE_							=			get_size_dict(_lowerCAmelCase				,				default_to_square=_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			crop_size if crop_size is not None else self.crop_size
       SCREAMING_SNAKE_CASE_							=			get_size_dict(_lowerCAmelCase				,				param_name='crop_size'						)

       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.'						)

       SCREAMING_SNAKE_CASE_							=			make_batched(_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			[
           [
               self._preprocess_image(
                   image=_lowerCAmelCase				,				do_resize=_lowerCAmelCase				,				size=_lowerCAmelCase				,				resample=_lowerCAmelCase				,				do_center_crop=_lowerCAmelCase				,				crop_size=_lowerCAmelCase				,				do_rescale=_lowerCAmelCase				,				rescale_factor=_lowerCAmelCase				,				offset=_lowerCAmelCase				,				do_normalize=_lowerCAmelCase				,				image_mean=_lowerCAmelCase				,				image_std=_lowerCAmelCase				,				data_format=_lowerCAmelCase				,				)
               for img in video
           ]
           for video in videos
       ]

       SCREAMING_SNAKE_CASE_							=			{'pixel_values': videos}
       return BatchFeature(data=_lowerCAmelCase				,				tensor_type=_lowerCAmelCase						)





from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase__ :   List[str]					=							logging.get_logger(__name__)

lowerCamelCase__ :   List[str]					=							{
    'facebook/s2t-small-librispeech-asr': (
        'https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json'
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}





class        lowerCamelCase_							(      _SCREAMING_SNAKE_CASE					):


 '''simple docstring'''







 lowercase_				    =    "speech_to_text"
 lowercase_				    =    ["past_key_values"]
 lowercase_				    =    {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}



 def __init__(							self  :		Tuple				,				_lowerCAmelCase  :		List[Any]=10_000				,				_lowerCAmelCase  :		List[Any]=12				,				_lowerCAmelCase  :		Union[str, Any]=2_048				,				_lowerCAmelCase  :		Optional[int]=4				,				_lowerCAmelCase  :		Union[str, Any]=6				,				_lowerCAmelCase  :		Optional[int]=2_048				,				_lowerCAmelCase  :		Optional[Any]=4				,				_lowerCAmelCase  :		Any=0.0				,				_lowerCAmelCase  :		Optional[Any]=0.0				,				_lowerCAmelCase  :		List[str]=True				,				_lowerCAmelCase  :		List[Any]=True				,				_lowerCAmelCase  :		int="relu"				,				_lowerCAmelCase  :		Union[str, Any]=256				,				_lowerCAmelCase  :		List[str]=0.1				,				_lowerCAmelCase  :		str=0.0				,				_lowerCAmelCase  :		Tuple=0.0				,				_lowerCAmelCase  :		List[str]=0.02				,				_lowerCAmelCase  :		List[str]=2				,				_lowerCAmelCase  :		Tuple=True				,				_lowerCAmelCase  :		List[str]=1				,				_lowerCAmelCase  :		str=0				,				_lowerCAmelCase  :		str=2				,				_lowerCAmelCase  :		Union[str, Any]=6_000				,				_lowerCAmelCase  :		List[str]=1_024				,				_lowerCAmelCase  :		str=2				,				_lowerCAmelCase  :		Optional[Any]=(5, 5)				,				_lowerCAmelCase  :		str=1_024				,				_lowerCAmelCase  :		str=80				,				_lowerCAmelCase  :		Tuple=1				,				**_lowerCAmelCase  :		Any				,				):
       SCREAMING_SNAKE_CASE_							=			vocab_size
       SCREAMING_SNAKE_CASE_							=			d_model
       SCREAMING_SNAKE_CASE_							=			encoder_ffn_dim
       SCREAMING_SNAKE_CASE_							=			encoder_layers
       SCREAMING_SNAKE_CASE_							=			encoder_attention_heads
       SCREAMING_SNAKE_CASE_							=			decoder_ffn_dim
       SCREAMING_SNAKE_CASE_							=			decoder_layers
       SCREAMING_SNAKE_CASE_							=			decoder_attention_heads
       SCREAMING_SNAKE_CASE_							=			dropout
       SCREAMING_SNAKE_CASE_							=			attention_dropout
       SCREAMING_SNAKE_CASE_							=			activation_dropout
       SCREAMING_SNAKE_CASE_							=			activation_function
       SCREAMING_SNAKE_CASE_							=			init_std
       SCREAMING_SNAKE_CASE_							=			encoder_layerdrop
       SCREAMING_SNAKE_CASE_							=			decoder_layerdrop
       SCREAMING_SNAKE_CASE_							=			use_cache
       SCREAMING_SNAKE_CASE_							=			encoder_layers
       SCREAMING_SNAKE_CASE_							=			scale_embedding  # scale factor will be sqrt(d_model) if True
       SCREAMING_SNAKE_CASE_							=			max_source_positions
       SCREAMING_SNAKE_CASE_							=			max_target_positions
       SCREAMING_SNAKE_CASE_							=			num_conv_layers
       SCREAMING_SNAKE_CASE_							=			list(_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			conv_channels
       SCREAMING_SNAKE_CASE_							=			input_feat_per_channel
       SCREAMING_SNAKE_CASE_							=			input_channels

       if len(self.conv_kernel_sizes						) != self.num_conv_layers:
             raise ValueError(
                 'Configuration for convolutional module is incorrect. '
                 'It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '
                 F"but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes						)}`, "
                 F"`config.num_conv_layers = {self.num_conv_layers}`."						)

       super().__init__(
           pad_token_id=_lowerCAmelCase				,				bos_token_id=_lowerCAmelCase				,				eos_token_id=_lowerCAmelCase				,				is_encoder_decoder=_lowerCAmelCase				,				decoder_start_token_id=_lowerCAmelCase				,				**_lowerCAmelCase				,				)