






import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin


class       __SCREAMING_SNAKE_CASE   (				__lowercase):
						_SCREAMING_SNAKE_CASE		:    Any						=   '''MCTCTFeatureExtractor'''
						_SCREAMING_SNAKE_CASE		:    List[str]						=   '''AutoTokenizer'''






						def __init__(		self       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												super().__init__(_UpperCamelCase       ,  _UpperCamelCase				)
												lowerCAmelCase__        =  self.feature_extractor
												lowerCAmelCase__        =  False






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






												"""simple docstring"""
												# For backward compatibility
												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.'				)
																		lowerCAmelCase__        =  kwargs.pop('raw_speech'				)
												else:
																		lowerCAmelCase__        =  kwargs.pop('audio'       ,  _UpperCamelCase				)
												lowerCAmelCase__        =  kwargs.pop('sampling_rate'       ,  _UpperCamelCase				)
												lowerCAmelCase__        =  kwargs.pop('text'       ,  _UpperCamelCase				)
												if len(_UpperCamelCase				) > 0:
																		lowerCAmelCase__        =  args[0]
																		lowerCAmelCase__        =  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:
																		lowerCAmelCase__        =  self.feature_extractor(_UpperCamelCase       ,  *_UpperCamelCase       ,  sampling_rate=_UpperCamelCase       ,  **_UpperCamelCase				)
												if text is not None:
																		lowerCAmelCase__        =  self.tokenizer(_UpperCamelCase       ,  **_UpperCamelCase				)

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






						def  UpperCamelCase__ (		self       ,  *_UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												return self.tokenizer.batch_decode(*_UpperCamelCase       ,  **_UpperCamelCase				)






						def  UpperCamelCase__ (		self       ,  *_UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												# For backward compatibility
												if self._in_target_context_manager:
																		return self.current_processor.pad(*_UpperCamelCase       ,  **_UpperCamelCase				)

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

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

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






						def  UpperCamelCase__ (		self       ,  *_UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												return self.tokenizer.decode(*_UpperCamelCase       ,  **_UpperCamelCase				)







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













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,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


__snake_case      :      Any             =       logging.get_logger(__name__)


class       __SCREAMING_SNAKE_CASE   (				__lowercase):
						_SCREAMING_SNAKE_CASE		:    List[Any]						=   ['''pixel_values''']






						def __init__(		self       ,  _UpperCamelCase = True       ,  _UpperCamelCase = None       ,  _UpperCamelCase = PILImageResampling.BILINEAR       ,  _UpperCamelCase = True       ,  _UpperCamelCase = None       ,  _UpperCamelCase = True       ,  _UpperCamelCase = 1 / 2_55       ,  _UpperCamelCase = True       ,  _UpperCamelCase = None       ,  _UpperCamelCase = None       ,  **_UpperCamelCase       ,  ):






												"""simple docstring"""
												super().__init__(**_UpperCamelCase				)
												lowerCAmelCase__        =  size if size is not None else {'shortest_edge': 2_56}
												lowerCAmelCase__        =  get_size_dict(_UpperCamelCase       ,  default_to_square=_UpperCamelCase				)
												lowerCAmelCase__        =  crop_size if crop_size is not None else {'height': 2_24, 'width': 2_24}
												lowerCAmelCase__        =  get_size_dict(_UpperCamelCase				)
												lowerCAmelCase__        =  do_resize
												lowerCAmelCase__        =  size
												lowerCAmelCase__        =  resample
												lowerCAmelCase__        =  do_center_crop
												lowerCAmelCase__        =  crop_size
												lowerCAmelCase__        =  do_rescale
												lowerCAmelCase__        =  rescale_factor
												lowerCAmelCase__        =  do_normalize
												lowerCAmelCase__        =  image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
												lowerCAmelCase__        =  image_std if image_std is not None else IMAGENET_STANDARD_STD






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase = PILImageResampling.BICUBIC       ,  _UpperCamelCase = None       ,  **_UpperCamelCase       ,  ):






												"""simple docstring"""
												lowerCAmelCase__        =  get_size_dict(_UpperCamelCase       ,  default_to_square=_UpperCamelCase				)
												if "shortest_edge" not in size:
																		raise ValueError(F"The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"				)
												lowerCAmelCase__        =  get_resize_output_image_size(_UpperCamelCase       ,  size=size['shortest_edge']       ,  default_to_square=_UpperCamelCase				)
												return resize(_UpperCamelCase       ,  size=_UpperCamelCase       ,  resample=_UpperCamelCase       ,  data_format=_UpperCamelCase       ,  **_UpperCamelCase				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase = None       ,  **_UpperCamelCase       ,  ):






												"""simple docstring"""
												lowerCAmelCase__        =  get_size_dict(_UpperCamelCase				)
												return center_crop(_UpperCamelCase       ,  size=(size['height'], size['width'])       ,  data_format=_UpperCamelCase       ,  **_UpperCamelCase				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase = None       ,  **_UpperCamelCase				):






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






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase = None       ,  **_UpperCamelCase       ,  ):






												"""simple docstring"""
												return normalize(_UpperCamelCase       ,  mean=_UpperCamelCase       ,  std=_UpperCamelCase       ,  data_format=_UpperCamelCase       ,  **_UpperCamelCase				)







						def  UpperCamelCase__ (		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"""
												lowerCAmelCase__        =  do_resize if do_resize is not None else self.do_resize
												lowerCAmelCase__        =  size if size is not None else self.size
												lowerCAmelCase__        =  get_size_dict(_UpperCamelCase       ,  default_to_square=_UpperCamelCase				)
												lowerCAmelCase__        =  resample if resample is not None else self.resample
												lowerCAmelCase__        =  do_center_crop if do_center_crop is not None else self.do_center_crop
												lowerCAmelCase__        =  crop_size if crop_size is not None else self.crop_size
												lowerCAmelCase__        =  get_size_dict(_UpperCamelCase				)
												lowerCAmelCase__        =  do_rescale if do_rescale is not None else self.do_rescale
												lowerCAmelCase__        =  rescale_factor if rescale_factor is not None else self.rescale_factor
												lowerCAmelCase__        =  do_normalize if do_normalize is not None else self.do_normalize
												lowerCAmelCase__        =  image_mean if image_mean is not None else self.image_mean
												lowerCAmelCase__        =  image_std if image_std is not None else self.image_std

												lowerCAmelCase__        =  make_list_of_images(_UpperCamelCase				)

												if not valid_images(_UpperCamelCase				):
																		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.
												lowerCAmelCase__        =  [to_numpy_array(_UpperCamelCase				) for image in images]

												if do_resize:
																		lowerCAmelCase__        =  [self.resize(image=_UpperCamelCase       ,  size=_UpperCamelCase       ,  resample=_UpperCamelCase				) for image in images]

												if do_center_crop:
																		lowerCAmelCase__        =  [self.center_crop(image=_UpperCamelCase       ,  size=_UpperCamelCase				) for image in images]

												if do_rescale:
																		lowerCAmelCase__        =  [self.rescale(image=_UpperCamelCase       ,  scale=_UpperCamelCase				) for image in images]

												if do_normalize:
																		lowerCAmelCase__        =  [self.normalize(image=_UpperCamelCase       ,  mean=_UpperCamelCase       ,  std=_UpperCamelCase				) for image in images]

												lowerCAmelCase__        =  [to_channel_dimension_format(_UpperCamelCase       ,  _UpperCamelCase				) for image in images]

												lowerCAmelCase__        =  {'pixel_values': images}
												return BatchFeature(data=_UpperCamelCase       ,  tensor_type=_UpperCamelCase				)





