



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


lowerCAmelCase__		:					Dict							=logging.get_logger(__name__)






def      __lowercase       (			a__       )    ->			Any:







							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        UpperCAmelCase_  (       UpperCamelCase_	):

						'''simple docstring'''




						UpperCamelCase__      :			List[Any]      =  ['''pixel_values''']






						def __init__(   self				,							_A = True				,							_A = None				,							_A = PILImageResampling.BILINEAR				,							_A = True				,							_A = None				,							_A = True				,							_A = 1 / 255				,							_A = True				,							_A = None				,							_A = None				,							**_A				,							):







													'''simple docstring'''

													super().__init__(**_a		)
													__SCREAMING_SNAKE_CASE									= size if size is not None else {'shortest_edge': 224}
													__SCREAMING_SNAKE_CASE									= get_size_dict(_a				,							default_to_square=_a		)
													__SCREAMING_SNAKE_CASE									= crop_size if crop_size is not None else {'height': 224, 'width': 224}
													__SCREAMING_SNAKE_CASE									= get_size_dict(_a				,							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									= 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 	_A     (   self				,							_A				,							_A				,							_A = PILImageResampling.BILINEAR				,							_A = None				,							**_A				,							):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= get_size_dict(_a				,							default_to_square=_a		)
													if "shortest_edge" in size:
																				__SCREAMING_SNAKE_CASE									= get_resize_output_image_size(_a				,							size['shortest_edge']				,							default_to_square=_a		)
													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(_a				,							size=_a				,							resample=_a				,							data_format=_a				,							**_a		)






						def 	_A     (   self				,							_A				,							_A				,							_A = None				,							**_A				,							):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= 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 	_A     (   self				,							_A				,							_A				,							_A = None				,							**_A				,							):







													'''simple docstring'''

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






						def 	_A     (   self				,							_A				,							_A				,							_A				,							_A = None				,							**_A				,							):







													'''simple docstring'''

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






						def 	_A     (   self				,							_A				,							_A = None				,							_A = None				,							_A = None				,							_A = None				,							_A = None				,							_A = None				,							_A = None				,							_A = None				,							_A = None				,							_A = None				,							_A = ChannelDimension.FIRST				,							):







													'''simple docstring'''

													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.
													__SCREAMING_SNAKE_CASE									= to_numpy_array(_a		)

													if do_resize:
																				__SCREAMING_SNAKE_CASE									= self.resize(image=_a				,							size=_a				,							resample=_a		)

													if do_center_crop:
																				__SCREAMING_SNAKE_CASE									= self.center_crop(_a				,							size=_a		)

													if do_rescale:
																				__SCREAMING_SNAKE_CASE									= self.rescale(image=_a				,							scale=_a		)

													if do_normalize:
																				__SCREAMING_SNAKE_CASE									= self.normalize(image=_a				,							mean=_a				,							std=_a		)

													__SCREAMING_SNAKE_CASE									= to_channel_dimension_format(_a				,							_a		)
													return image






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







													'''simple docstring'''

													__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									= 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(_a				,							default_to_square=_a		)
													__SCREAMING_SNAKE_CASE									= crop_size if crop_size is not None else self.crop_size
													__SCREAMING_SNAKE_CASE									= 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.'		)

													__SCREAMING_SNAKE_CASE									= make_batched(_a		)

													__SCREAMING_SNAKE_CASE									= [
													    [
													        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
													]

													__SCREAMING_SNAKE_CASE									= {'pixel_values': videos}
													return BatchFeature(data=_a				,							tensor_type=_a		)










import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
from .tokenization_wavaveca import WavaVecaCTCTokenizer

class        UpperCAmelCase_  (       UpperCamelCase_	):

						'''simple docstring'''




						UpperCamelCase__      :			Union[str, Any]      =  '''Wav2Vec2FeatureExtractor'''
						UpperCamelCase__      :			Union[str, Any]      =  '''AutoTokenizer'''






						def __init__(   self				,							_A				,							_A		):







													'''simple docstring'''

													super().__init__(_A				,							_A		)
													__SCREAMING_SNAKE_CASE									= self.feature_extractor
													__SCREAMING_SNAKE_CASE									= False






						@classmethod
						def 	_A     (   cls				,							_A				,							**_A		):







													'''simple docstring'''

													try:
																				return super().from_pretrained(_A				,							**_A		)
													except OSError:
																				warnings.warn(
																				    f"""Loading a tokenizer inside {cls.__name__} from a config that does not"""
																				    ' include a `tokenizer_class` attribute is deprecated and will be '
																				    'removed in v5. Please add `\'tokenizer_class\': \'Wav2Vec2CTCTokenizer\'`'
																				    ' attribute to either your `config.json` or `tokenizer_config.json` '
																				    'file to suppress this warning: '				,							_A				,							)

																				__SCREAMING_SNAKE_CASE									= WavaVecaFeatureExtractor.from_pretrained(_A				,							**_A		)
																				__SCREAMING_SNAKE_CASE									= WavaVecaCTCTokenizer.from_pretrained(_A				,							**_A		)

																				return cls(feature_extractor=_A				,							tokenizer=_A		)






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







													'''simple docstring'''

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

													if "raw_speech" in kwargs:
																				warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'		)
																				__SCREAMING_SNAKE_CASE									= kwargs.pop('raw_speech'		)
													else:
																				__SCREAMING_SNAKE_CASE									= kwargs.pop('audio'				,							_A		)
													__SCREAMING_SNAKE_CASE									= kwargs.pop('sampling_rate'				,							_A		)
													__SCREAMING_SNAKE_CASE									= kwargs.pop('text'				,							_A		)
													if len(_A		) > 0:
																				__SCREAMING_SNAKE_CASE									= args[0]
																				__SCREAMING_SNAKE_CASE									= 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:
																				__SCREAMING_SNAKE_CASE									= self.feature_extractor(_A				,							*_A				,							sampling_rate=_A				,							**_A		)
													if text is not None:
																				__SCREAMING_SNAKE_CASE									= self.tokenizer(_A				,							**_A		)

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






						def 	_A     (   self				,							*_A				,							**_A		):







													'''simple docstring'''

													if self._in_target_context_manager:
																				return self.current_processor.pad(*_A				,							**_A		)

													__SCREAMING_SNAKE_CASE									= kwargs.pop('input_features'				,							_A		)
													__SCREAMING_SNAKE_CASE									= kwargs.pop('labels'				,							_A		)
													if len(_A		) > 0:
																				__SCREAMING_SNAKE_CASE									= args[0]
																				__SCREAMING_SNAKE_CASE									= args[1:]

													if input_features is not None:
																				__SCREAMING_SNAKE_CASE									= self.feature_extractor.pad(_A				,							*_A				,							**_A		)
													if labels is not None:
																				__SCREAMING_SNAKE_CASE									= self.tokenizer.pad(_A				,							**_A		)

													if labels is None:
																				return input_features
													elif input_features is None:
																				return labels
													else:
																				__SCREAMING_SNAKE_CASE									= labels['input_ids']
																				return input_features






						def 	_A     (   self				,							*_A				,							**_A		):







													'''simple docstring'''

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






						def 	_A     (   self				,							*_A				,							**_A		):







													'''simple docstring'''

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






						@contextmanager
						def 	_A     (   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.'		)
													__SCREAMING_SNAKE_CASE									= True
													__SCREAMING_SNAKE_CASE									= self.tokenizer
													yield
													__SCREAMING_SNAKE_CASE									= self.feature_extractor
													__SCREAMING_SNAKE_CASE									= False






