

'''simple docstring'''






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 convert_to_rgb, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
 import PIL


__SCREAMING_SNAKE_CASE     =						logging.get_logger(__name__)






class 			lowerCAmelCase__     (					snake_case_						):




     """simple docstring"""





     __UpperCamelCase									= ["pixel_values"]







     def __init__(		self						:	List[Any]      ,						A__						:	str = True      ,						A__						:	Optional[Any] = None      ,						A__						:	Union[str, Any] = PILImageResampling.BICUBIC      ,						A__						:	Tuple = True      ,						A__						:	Optional[Any] = 1 / 2_5_5      ,						A__						:	Any = True      ,						A__						:	str = None      ,						A__						:	Optional[int] = None      ,						A__						:	int = True      ,						**A__						:	Optional[Any]      ,						)       ->			None:
          '''simple docstring'''




          super().__init__(**A__	)
          a__   :      Any     =						size if size is not None else {'''height''': 3_8_4, '''width''': 3_8_4}
          a__   :      Dict     =						get_size_dict(A__      ,						default_to_square=A__	)

          a__   :      str     =						do_resize
          a__   :      Union[str, Any]     =						size
          a__   :      Dict     =						resample
          a__   :      int     =						do_rescale
          a__   :      Dict     =						rescale_factor
          a__   :      Optional[int]     =						do_normalize
          a__   :      int     =						image_mean if image_mean is not None else OPENAI_CLIP_MEAN
          a__   :      Tuple     =						image_std if image_std is not None else OPENAI_CLIP_STD
          a__   :      Tuple     =						do_convert_rgb







     def 			__lowerCAmelCase	(		self						:	Any      ,						A__						:	str      ,						A__						:	List[str]      ,						A__						:	str = PILImageResampling.BICUBIC      ,						A__						:	List[Any] = None      ,						**A__						:	str      ,						)       ->			np.ndarray:
          '''simple docstring'''




          a__   :      List[Any]     =						get_size_dict(A__      ,						default_to_square=A__	)
          if "height" not in size or "width" not in size:
               raise ValueError(F'The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'	)
          a__   :      int     =						(size['''height'''], size['''width'''])
          return resize(A__      ,						size=A__      ,						resample=A__      ,						data_format=A__      ,						**A__	)







     def 			__lowerCAmelCase	(		self						:	List[Any]      ,						A__						:	str      ,						A__						:	Optional[int]      ,						A__						:	str = None      ,						**A__						:	List[str]      ,						)       ->			Union[str, Any]:
          '''simple docstring'''




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







     def 			__lowerCAmelCase	(		self						:	Optional[int]      ,						A__						:	Any      ,						A__						:	Tuple      ,						A__						:	Tuple      ,						A__						:	Tuple = None      ,						**A__						:	Optional[int]      ,						)       ->			np.ndarray:
          '''simple docstring'''




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







     def 			__lowerCAmelCase	(		self						:	List[str]      ,						A__						:	Tuple      ,						A__						:	Union[str, Any] = None      ,						A__						:	Optional[int] = None      ,						A__						:	List[Any] = None      ,						A__						:	List[Any] = None      ,						A__						:	Any = None      ,						A__						:	Tuple = None      ,						A__						:	Optional[int] = None      ,						A__						:	Optional[Any] = None      ,						A__						:	Any = None      ,						A__						:	int = None      ,						A__						:	List[Any] = ChannelDimension.FIRST      ,						**A__						:	List[str]      ,						)       ->			PIL.Image.Image:
          '''simple docstring'''




          a__   :      List[str]     =						do_resize if do_resize is not None else self.do_resize
          a__   :      Any     =						resample if resample is not None else self.resample
          a__   :      Optional[Any]     =						do_rescale if do_rescale is not None else self.do_rescale
          a__   :      Any     =						rescale_factor if rescale_factor is not None else self.rescale_factor
          a__   :      int     =						do_normalize if do_normalize is not None else self.do_normalize
          a__   :      Tuple     =						image_mean if image_mean is not None else self.image_mean
          a__   :      Any     =						image_std if image_std is not None else self.image_std
          a__   :      List[str]     =						do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

          a__   :      int     =						size if size is not None else self.size
          a__   :      Tuple     =						get_size_dict(A__      ,						default_to_square=A__	)

          a__   :      List[str]     =						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 or resample is None:
               raise ValueError('''Size and resample must be specified if do_resize 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.'''	)

          # PIL RGBA images are converted to RGB
          if do_convert_rgb:
               a__   :      Tuple     =						[convert_to_rgb(A__	) for image in images]

          # All transformations expect numpy arrays.
          a__   :      Any     =						[to_numpy_array(A__	) for image in images]

          if do_resize:
               a__   :      List[Any]     =						[self.resize(image=A__      ,						size=A__      ,						resample=A__	) for image in images]

          if do_rescale:
               a__   :      Any     =						[self.rescale(image=A__      ,						scale=A__	) for image in images]

          if do_normalize:
               a__   :      str     =						[self.normalize(image=A__      ,						mean=A__      ,						std=A__	) for image in images]

          a__   :      Tuple     =						[to_channel_dimension_format(A__      ,						A__	) for image in images]

          a__   :      int     =						BatchFeature(data={'''pixel_values''': images}      ,						tensor_type=A__	)

          return encoded_outputs


import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin




class        _SCREAMING_SNAKE_CASE	( snake_case_		):
	lowerCAmelCase__   =					'MCTCTFeatureExtractor'
	lowerCAmelCase__   =					'AutoTokenizer'



	def __init__(       self		,    lowercase		,    lowercase					)							->			str:
					super().__init__(lowercase		,    lowercase					)
					lowerCamelCase_         =     self.feature_extractor
					lowerCamelCase_         =     False



	def __call__(       self		,    *lowercase		,    **lowercase					)							->			List[str]:
					# For backward compatibility
					if self._in_target_context_manager:
									return self.current_processor(*lowercase		,    **lowercase					)

					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"		,    lowercase					)
					lowerCamelCase_         =     kwargs.pop("sampling_rate"		,    lowercase					)
					lowerCamelCase_         =     kwargs.pop("text"		,    lowercase					)
					if len(lowercase					) > 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(lowercase		,    *lowercase		,    sampling_rate=lowercase		,    **lowercase					)
					if text is not None:
									lowerCamelCase_         =     self.tokenizer(lowercase		,    **lowercase					)

					if text is None:
									return inputs
					elif audio is None:
									return encodings
					else:
									lowerCamelCase_         =     encodings["input_ids"]
									return inputs



	def        SCREAMING_SNAKE_CASE_(       self		,    *lowercase		,    **lowercase					)							->			Optional[Any]:
					return self.tokenizer.batch_decode(*lowercase		,    **lowercase					)



	def        SCREAMING_SNAKE_CASE_(       self		,    *lowercase		,    **lowercase					)							->			Optional[Any]:
					# For backward compatibility
					if self._in_target_context_manager:
									return self.current_processor.pad(*lowercase		,    **lowercase					)

					lowerCamelCase_         =     kwargs.pop("input_features"		,    lowercase					)
					lowerCamelCase_         =     kwargs.pop("labels"		,    lowercase					)
					if len(lowercase					) > 0:
									lowerCamelCase_         =     args[0]
									lowerCamelCase_         =     args[1:]

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

					if labels is None:
									return input_features
					elif input_features is None:
									return labels
					else:
									lowerCamelCase_         =     labels["input_ids"]
									return input_features



	def        SCREAMING_SNAKE_CASE_(       self		,    *lowercase		,    **lowercase					)							->			List[str]:
					return self.tokenizer.decode(*lowercase		,    **lowercase					)



	@contextmanager
	def        SCREAMING_SNAKE_CASE_(       self					)							->			Optional[int]:
					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


