


"""simple docstring"""


from typing import Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import get_image_size, pad, rescale, to_channel_dimension_format
from ...image_utils import ChannelDimension, ImageInput, make_list_of_images, to_numpy_array, valid_images
from ...utils import TensorType, logging


A	:  Union[str, Any]            =     logging.get_logger(__name__)
class     _UpperCamelCase    (  lowerCAmelCase__						):
							'''simple docstring'''







							__UpperCAmelCase		:       Any							 =["""pixel_values"""]

							def __init__(	self       ,  __a = True       ,  __a = 1 / 2_55       ,  __a = True       ,  __a = 8       ,  **__a       ,  ):
										super().__init__(**__a      )

										__lowerCAmelCase							       =     do_rescale
										__lowerCAmelCase							       =     rescale_factor
										__lowerCAmelCase							       =     do_pad
										__lowerCAmelCase							       =     pad_size

							def      snake_case							(	self       ,  __a       ,  __a       ,  __a = None       ,  **__a      ):
										return rescale(__a       ,  scale=__a       ,  data_format=__a       ,  **__a      )

							def      snake_case							(	self       ,  __a       ,  __a       ,  __a = None      ):
										__lowerCAmelCase       ,      __lowerCAmelCase							       =     get_image_size(__a      )
										__lowerCAmelCase							       =     (old_height // size + 1) * size - old_height
										__lowerCAmelCase							       =     (old_width // size + 1) * size - old_width

										return pad(__a       ,  ((0, pad_height), (0, pad_width))       ,  mode="symmetric"       ,  data_format=__a      )



							def      snake_case							(	self       ,  __a       ,  __a = None       ,  __a = None       ,  __a = None       ,  __a = None       ,  __a = None       ,  __a = ChannelDimension.FIRST       ,  **__a       ,  ):
										__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_pad if do_pad is not None else self.do_pad
										__lowerCAmelCase							       =     pad_size if pad_size is not None else self.pad_size

										__lowerCAmelCase							       =     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_rescale and rescale_factor is None:
													raise ValueError("Rescale factor must be specified if do_rescale is True."      )

										# All transformations expect numpy arrays.
										__lowerCAmelCase							       =     [to_numpy_array(__a      ) for image in images]

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

										if do_pad:
													__lowerCAmelCase							       =     [self.pad(__a       ,  size=__a      ) for image in images]

										__lowerCAmelCase							       =     [to_channel_dimension_format(__a       ,  __a      ) for image in images]

										__lowerCAmelCase							       =     {"pixel_values": images}
										return BatchFeature(data=__a       ,  tensor_type=__a      )








"""simple docstring"""


import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
class     _UpperCamelCase    (  lowerCAmelCase__						):
							'''simple docstring'''







							__UpperCAmelCase		:       List[str]							 ="""Speech2TextFeatureExtractor"""
							__UpperCAmelCase		:       Union[str, Any]							 ="""Speech2TextTokenizer"""

							def __init__(	self       ,  __a       ,  __a      ):
										super().__init__(__a       ,  __a      )
										__lowerCAmelCase							       =     self.feature_extractor
										__lowerCAmelCase							       =     False

							def __call__(	self       ,  *__a       ,  **__a      ):
										# For backward compatibility
										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."      )
													__lowerCAmelCase							       =     kwargs.pop("raw_speech"      )
										else:
													__lowerCAmelCase							       =     kwargs.pop("audio"       ,  __a      )
										__lowerCAmelCase							       =     kwargs.pop("sampling_rate"       ,  __a      )
										__lowerCAmelCase							       =     kwargs.pop("text"       ,  __a      )
										if len(__a      ) > 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(__a       ,  *__a       ,  sampling_rate=__a       ,  **__a      )
										if text is not None:
													__lowerCAmelCase							       =     self.tokenizer(__a       ,  **__a      )

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

							def      snake_case							(	self       ,  *__a       ,  **__a      ):
										return self.tokenizer.batch_decode(*__a       ,  **__a      )

							def      snake_case							(	self       ,  *__a       ,  **__a      ):
										return self.tokenizer.decode(*__a       ,  **__a      )



							@contextmanager
							def      snake_case							(	self      ):
										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




