
from typing import Dict, List, Optional, Union

import numpy as np

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 TensorType, is_vision_available, logging


if is_vision_available():
		import PIL


lowercase						:      Dict									= logging.get_logger(__name__)




def 			_SCREAMING_SNAKE_CASE      (	_lowerCamelCase				:    Union[str, Any])      ->					List[List[ImageInput]]:






							'''simple docstring'''





							if isinstance(_lowerCamelCase		,						(list, tuple)) and isinstance(videos[0]		,						(list, tuple)) and is_valid_image(videos[0][0]):
														return videos

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

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

							raise ValueError(F'Could not make batched video from {videos}')




class 				lowerCamelCase__							(       __lowercase):




	'''simple docstring'''




	_A			=  ['pixel_values']







	def __init__(      self	:Any  ,     a	:bool = True  ,     a	:Dict[str, int] = None  ,     a	:PILImageResampling = PILImageResampling.BILINEAR  ,     a	:bool = True  ,     a	:Dict[str, int] = None  ,     a	:bool = True  ,     a	:Union[int, float] = 1 / 2_5_5  ,     a	:bool = True  ,     a	:Optional[Union[float, List[float]]] = None  ,     a	:Optional[Union[float, List[float]]] = None  ,     **a	:Union[str, Any]  ,     )	->				None:
								super().__init__(**a		)
								__UpperCamelCase			:     Union[str, Any]         =      size if size is not None else {"shortest_edge": 2_2_4}
								__UpperCamelCase			:     Optional[int]         =      get_size_dict(a  ,     default_to_square=a		)
								__UpperCamelCase			:     List[str]         =      crop_size if crop_size is not None else {"height": 2_2_4, "width": 2_2_4}
								__UpperCamelCase			:     Optional[int]         =      get_size_dict(a  ,     param_name="crop_size"		)

								__UpperCamelCase			:     int         =      do_resize
								__UpperCamelCase			:     List[str]         =      size
								__UpperCamelCase			:     str         =      do_center_crop
								__UpperCamelCase			:     Tuple         =      crop_size
								__UpperCamelCase			:     Optional[int]         =      resample
								__UpperCamelCase			:     str         =      do_rescale
								__UpperCamelCase			:     str         =      rescale_factor
								__UpperCamelCase			:     Tuple         =      do_normalize
								__UpperCamelCase			:     Dict         =      image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
								__UpperCamelCase			:     int         =      image_std if image_std is not None else IMAGENET_STANDARD_STD







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







	def      _lowerCamelCase       (      self	:Any  ,     a	:np.ndarray  ,     a	:Dict[str, int]  ,     a	:Optional[Union[str, ChannelDimension]] = None  ,     **a	:str  ,     )	->				np.ndarray:
								__UpperCamelCase			:     List[str]         =      get_size_dict(a		)
								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(a  ,     size=(size["height"], size["width"])  ,     data_format=a  ,     **a		)







	def      _lowerCamelCase       (      self	:Any  ,     a	:np.ndarray  ,     a	:Union[int, float]  ,     a	:Optional[Union[str, ChannelDimension]] = None  ,     **a	:Tuple  ,     )	->				Optional[Any]:
								return rescale(a  ,     scale=a  ,     data_format=a  ,     **a		)







	def      _lowerCamelCase       (      self	:Optional[Any]  ,     a	:np.ndarray  ,     a	:Union[float, List[float]]  ,     a	:Union[float, List[float]]  ,     a	:Optional[Union[str, ChannelDimension]] = None  ,     **a	:List[str]  ,     )	->				np.ndarray:
								return normalize(a  ,     mean=a  ,     std=a  ,     data_format=a  ,     **a		)







	def      _lowerCamelCase       (      self	:List[str]  ,     a	:ImageInput  ,     a	:bool = None  ,     a	:Dict[str, int] = None  ,     a	:PILImageResampling = None  ,     a	:bool = None  ,     a	:Dict[str, int] = None  ,     a	:bool = None  ,     a	:float = None  ,     a	:bool = None  ,     a	:Optional[Union[float, List[float]]] = None  ,     a	:Optional[Union[float, List[float]]] = None  ,     a	:Optional[ChannelDimension] = ChannelDimension.FIRST  ,     )	->				np.ndarray:
								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."		)

								# All transformations expect numpy arrays.
								__UpperCamelCase			:     Optional[Any]         =      to_numpy_array(a		)

								if do_resize:
															__UpperCamelCase			:     List[str]         =      self.resize(image=a  ,     size=a  ,     resample=a		)

								if do_center_crop:
															__UpperCamelCase			:     Optional[int]         =      self.center_crop(a  ,     size=a		)

								if do_rescale:
															__UpperCamelCase			:     Optional[Any]         =      self.rescale(image=a  ,     scale=a		)

								if do_normalize:
															__UpperCamelCase			:     Dict         =      self.normalize(image=a  ,     mean=a  ,     std=a		)

								__UpperCamelCase			:     Tuple         =      to_channel_dimension_format(a  ,     a		)
								return image







	def      _lowerCamelCase       (      self	:Optional[Any]  ,     a	:ImageInput  ,     a	:bool = None  ,     a	:Dict[str, int] = None  ,     a	:PILImageResampling = None  ,     a	:bool = None  ,     a	:Dict[str, int] = None  ,     a	:bool = None  ,     a	:float = None  ,     a	:bool = None  ,     a	:Optional[Union[float, List[float]]] = None  ,     a	:Optional[Union[float, List[float]]] = None  ,     a	:Optional[Union[str, TensorType]] = None  ,     a	:ChannelDimension = ChannelDimension.FIRST  ,     **a	:Optional[Any]  ,     )	->				PIL.Image.Image:
								__UpperCamelCase			:     int         =      do_resize if do_resize is not None else self.do_resize
								__UpperCamelCase			:     str         =      resample if resample is not None else self.resample
								__UpperCamelCase			:     Any         =      do_center_crop if do_center_crop is not None else self.do_center_crop
								__UpperCamelCase			:     int         =      do_rescale if do_rescale is not None else self.do_rescale
								__UpperCamelCase			:     str         =      rescale_factor if rescale_factor is not None else self.rescale_factor
								__UpperCamelCase			:     Optional[Any]         =      do_normalize if do_normalize is not None else self.do_normalize
								__UpperCamelCase			:     Any         =      image_mean if image_mean is not None else self.image_mean
								__UpperCamelCase			:     Optional[int]         =      image_std if image_std is not None else self.image_std

								__UpperCamelCase			:     List[str]         =      size if size is not None else self.size
								__UpperCamelCase			:     List[Any]         =      get_size_dict(a  ,     default_to_square=a		)
								__UpperCamelCase			:     str         =      crop_size if crop_size is not None else self.crop_size
								__UpperCamelCase			:     str         =      get_size_dict(a  ,     param_name="crop_size"		)

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

								__UpperCamelCase			:     Optional[Any]         =      make_batched(a		)

								__UpperCamelCase			:     List[str]         =      [
								    [
								        self._preprocess_image(
								            image=a  ,     do_resize=a  ,     size=a  ,     resample=a  ,     do_center_crop=a  ,     crop_size=a  ,     do_rescale=a  ,     rescale_factor=a  ,     do_normalize=a  ,     image_mean=a  ,     image_std=a  ,     data_format=a  ,     )
								        for img in video
								    ]
								    for video in videos
								]

								__UpperCamelCase			:     Union[str, Any]         =      {"pixel_values": videos}
								return BatchFeature(data=a  ,     tensor_type=a		)

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


lowercase						:      Dict									= logging.get_logger(__name__)

lowercase						:      Optional[Any]									= {
    'facebook/s2t-wav2vec2-large-en-de': (
        'https://huggingface.co/facebook/s2t-wav2vec2-large-en-de/resolve/main/config.json'
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech2text2
}




class 				lowerCamelCase__							(       __lowercase):




	'''simple docstring'''




	_A			=  'speech_to_text_2'
	_A			=  ['past_key_values']
	_A			=  {'num_attention_heads': 'decoder_attention_heads', 'hidden_size': 'd_model'}







	def __init__(      self	:Dict  ,     a	:Tuple=1_0_0_0_0  ,     a	:Optional[int]=6  ,     a	:List[str]=2_0_4_8  ,     a	:Tuple=4  ,     a	:List[Any]=0.0  ,     a	:str=True  ,     a	:Any="relu"  ,     a	:Any=2_5_6  ,     a	:Optional[int]=0.1  ,     a	:Any=0.0  ,     a	:int=0.0  ,     a	:int=0.02  ,     a	:List[Any]=2  ,     a	:Tuple=True  ,     a	:str=1  ,     a	:Optional[int]=0  ,     a	:List[Any]=2  ,     a	:Any=1_0_2_4  ,     **a	:str  ,     )	->				int:
								__UpperCamelCase			:     List[str]         =      vocab_size
								__UpperCamelCase			:     int         =      d_model
								__UpperCamelCase			:     Optional[int]         =      decoder_ffn_dim
								__UpperCamelCase			:     Any         =      decoder_layers
								__UpperCamelCase			:     Any         =      decoder_attention_heads
								__UpperCamelCase			:     Tuple         =      dropout
								__UpperCamelCase			:     Any         =      attention_dropout
								__UpperCamelCase			:     Any         =      activation_dropout
								__UpperCamelCase			:     Dict         =      activation_function
								__UpperCamelCase			:     int         =      init_std
								__UpperCamelCase			:     List[str]         =      decoder_layerdrop
								__UpperCamelCase			:     Optional[Any]         =      use_cache
								__UpperCamelCase			:     int         =      decoder_layers
								__UpperCamelCase			:     Union[str, Any]         =      scale_embedding  # scale factor will be sqrt(d_model) if True
								__UpperCamelCase			:     Dict         =      max_target_positions

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