


'''simple docstring'''
from typing import Dict, Iterable, 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_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


__snake_case							   =  logging.get_logger(__name__)
class      lowercase			(							__a      ):

		"""simple docstring"""

		_a									=       ['pixel_values']




		def __init__(	self					,     UpperCamelCase_ = True					,     UpperCamelCase_ = None					,     UpperCamelCase_ = PILImageResampling.BICUBIC					,     UpperCamelCase_ = True					,     UpperCamelCase_ = None					,     UpperCamelCase_ = True					,     UpperCamelCase_ = 1 / 255					,     UpperCamelCase_ = True					,     UpperCamelCase_ = IMAGENET_DEFAULT_MEAN					,     UpperCamelCase_ = IMAGENET_DEFAULT_STD					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							super().__init__(**a_							)
							UpperCamelCase__     :Union[str, Any]							      =				size if size is not None else {"""shortest_edge""": 224}
							UpperCamelCase__     :str							      =				get_size_dict(a_					,     default_to_square=a_							)
							UpperCamelCase__     :Optional[int]							      =				crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
							UpperCamelCase__     :List[str]							      =				get_size_dict(a_					,     param_name='''crop_size'''							)

							UpperCamelCase__     :int							      =				do_resize
							UpperCamelCase__     :str							      =				size
							UpperCamelCase__     :List[Any]							      =				resample
							UpperCamelCase__     :List[Any]							      =				do_center_crop
							UpperCamelCase__     :Any							      =				crop_size
							UpperCamelCase__     :Union[str, Any]							      =				do_rescale
							UpperCamelCase__     :str							      =				rescale_factor
							UpperCamelCase__     :Union[str, Any]							      =				do_normalize
							UpperCamelCase__     :Union[str, Any]							      =				image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
							UpperCamelCase__     :int							      =				image_std if image_std is not None else IMAGENET_DEFAULT_STD




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = PILImageResampling.BICUBIC					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				get_size_dict(a_					,     default_to_square=a_							)
							# size_dict is a dict with either keys "height" and "width" or "shortest_edge"
							if "shortest_edge" in size:
												UpperCamelCase__     :List[str]							      =				int((256 / 224) * size['''shortest_edge''']							)
												UpperCamelCase__     :Tuple							      =				get_resize_output_image_size(a_					,     size=a_					,     default_to_square=a_							)
												UpperCamelCase__     :Dict							      =				{"""height""": output_size[0], """width""": output_size[1]}
							if "height" not in size_dict or "width" not in size_dict:
												raise ValueError(
												    F'''Size dict must have keys \'height\' and \'width\' or \'shortest_edge\'. Got {size_dict.keys()}'''							)
							return resize(
							    a_					,     size=(size_dict['''height'''], size_dict['''width'''])					,     resample=a_					,     data_format=a_					,     **a_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							UpperCamelCase__     :Dict							      =				get_size_dict(a_							)
							if "height" not in size or "width" not in size:
												raise ValueError(F'''Size dict must have keys \'height\' and \'width\'. Got {size.keys()}'''							)
							return center_crop(a_					,     size=(size['''height'''], size['''width'''])					,     data_format=a_					,     **a_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							return rescale(a_					,     scale=a_					,     data_format=a_					,     **a_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							return normalize(a_					,     mean=a_					,     std=a_					,     data_format=a_					,     **a_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = ChannelDimension.FIRST					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							UpperCamelCase__     :Any							      =				do_resize if do_resize is not None else self.do_resize
							UpperCamelCase__     :Union[str, Any]							      =				resample if resample is not None else self.resample
							UpperCamelCase__     :Tuple							      =				do_center_crop if do_center_crop is not None else self.do_center_crop
							UpperCamelCase__     :Dict							      =				do_rescale if do_rescale is not None else self.do_rescale
							UpperCamelCase__     :Tuple							      =				rescale_factor if rescale_factor is not None else self.rescale_factor
							UpperCamelCase__     :List[Any]							      =				do_normalize if do_normalize is not None else self.do_normalize
							UpperCamelCase__     :Tuple							      =				image_mean if image_mean is not None else self.image_mean
							UpperCamelCase__     :int							      =				image_std if image_std is not None else self.image_std

							UpperCamelCase__     :Union[str, Any]							      =				size if size is not None else self.size
							UpperCamelCase__     :Tuple							      =				get_size_dict(a_					,     default_to_square=a_							)
							UpperCamelCase__     :str							      =				crop_size if crop_size is not None else self.crop_size
							UpperCamelCase__     :int							      =				get_size_dict(a_					,     param_name='''crop_size'''							)

							UpperCamelCase__     :Optional[Any]							      =				make_list_of_images(a_							)

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

							if do_resize and size is None:
												raise ValueError('''Size 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__     :Any							      =				[to_numpy_array(a_							) for image in images]

							if do_resize:
												UpperCamelCase__     :List[Any]							      =				[self.resize(a_					,     a_					,     a_							) for image in images]

							if do_center_crop:
												UpperCamelCase__     :str							      =				[self.center_crop(a_					,     a_							) for image in images]

							if do_rescale:
												UpperCamelCase__     :Optional[Any]							      =				[self.rescale(a_					,     a_							) for image in images]

							if do_normalize:
												UpperCamelCase__     :Optional[int]							      =				[self.normalize(a_					,     a_					,     a_							) for image in images]

							UpperCamelCase__     :Tuple							      =				[to_channel_dimension_format(a_					,     a_							) for image in images]

							UpperCamelCase__     :Tuple							      =				{"""pixel_values""": images}
							return BatchFeature(data=a_					,     tensor_type=a_							)



'''simple docstring'''
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
class      lowercase			(							A__      ):

		"""simple docstring"""

		_a									=       'Speech2TextFeatureExtractor'
		_a									=       'Speech2TextTokenizer'




		def __init__(	self					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							super().__init__(UpperCamelCase_					,     UpperCamelCase_							)
							UpperCamelCase__     :List[str]							      =				self.feature_extractor
							UpperCamelCase__     :Optional[Any]							      =				False




		def __call__(	self					,     *UpperCamelCase_					,     **UpperCamelCase_							):

							'''simple docstring'''


							if self._in_target_context_manager:
												return self.current_processor(*UpperCamelCase_					,     **UpperCamelCase_							)

							if "raw_speech" in kwargs:
												warnings.warn('''Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'''							)
												UpperCamelCase__     :Optional[Any]							      =				kwargs.pop('''raw_speech'''							)
							else:
												UpperCamelCase__     :List[Any]							      =				kwargs.pop('''audio'''					,     UpperCamelCase_							)
							UpperCamelCase__     :List[Any]							      =				kwargs.pop('''sampling_rate'''					,     UpperCamelCase_							)
							UpperCamelCase__     :Dict							      =				kwargs.pop('''text'''					,     UpperCamelCase_							)
							if len(UpperCamelCase_							) > 0:
												UpperCamelCase__     :Tuple							      =				args[0]
												UpperCamelCase__     :Optional[int]							      =				args[1:]

							if audio is None and text is None:
												raise ValueError('''You need to specify either an `audio` or `text` input to process.'''							)

							if audio is not None:
												UpperCamelCase__     :Any							      =				self.feature_extractor(UpperCamelCase_					,     *UpperCamelCase_					,     sampling_rate=UpperCamelCase_					,     **UpperCamelCase_							)
							if text is not None:
												UpperCamelCase__     :Dict							      =				self.tokenizer(UpperCamelCase_					,     **UpperCamelCase_							)

							if text is None:
												return inputs
							elif audio is None:
												return encodings
							else:
												UpperCamelCase__     :Dict							      =				encodings['''input_ids''']
												return inputs




		def 					lowerCAmelCase__       (	self					,     *UpperCamelCase_					,     **UpperCamelCase_							):

							'''simple docstring'''


							return self.tokenizer.batch_decode(*UpperCamelCase_					,     **UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     *UpperCamelCase_					,     **UpperCamelCase_							):

							'''simple docstring'''


							return self.tokenizer.decode(*UpperCamelCase_					,     **UpperCamelCase_							)




		@contextmanager
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							warnings.warn(
							    '''`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '''
							    '''labels by using the argument `text` of the regular `__call__` method (either in the same call as '''
							    '''your audio inputs, or in a separate call.'''							)
							UpperCamelCase__     :Optional[Any]							      =				True
							UpperCamelCase__     :Any							      =				self.tokenizer
							yield
							UpperCamelCase__     :Any							      =				self.feature_extractor
							UpperCamelCase__     :Any							      =				False