


import warnings
from contextlib import contextmanager

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






class   _lowerCamelCase (					UpperCamelCase			):




       """simple docstring"""
       snake_case      =    "Wav2Vec2FeatureExtractor"
       snake_case      =    "AutoTokenizer"



       def __init__(      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)->Union[str, Any]:




         '''simple docstring'''





         super().__init__(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         A_      :				Union[str, Any]		     =					self.feature_extractor
         A_      :				Union[str, Any]		     =					False



       @classmethod
       def        _snake_case       (      cls				,       _SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->List[Any]:




         '''simple docstring'''





         try:
           return super().from_pretrained(_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)
         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: '''				,       _SCREAMING_SNAKE_CASE				,       )

           A_      :				int		     =					WavaVecaFeatureExtractor.from_pretrained(_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)
           A_      :				Optional[Any]		     =					WavaVecaCTCTokenizer.from_pretrained(_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)

           return cls(feature_extractor=_SCREAMING_SNAKE_CASE				,       tokenizer=_SCREAMING_SNAKE_CASE		)



       def __call__(      self				,       *_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->Dict:




         '''simple docstring'''





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

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

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



       def        _snake_case       (      self				,       *_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->Tuple:




         '''simple docstring'''





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

         A_      :				Any		     =					kwargs.pop('''input_features'''				,       _SCREAMING_SNAKE_CASE		)
         A_      :				Tuple		     =					kwargs.pop('''labels'''				,       _SCREAMING_SNAKE_CASE		)
         if len(_SCREAMING_SNAKE_CASE		) > 0:
           A_      :				Any		     =					args[0]
           A_      :				Any		     =					args[1:]

         if input_features is not None:
           A_      :				Tuple		     =					self.feature_extractor.pad(_SCREAMING_SNAKE_CASE				,       *_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)
         if labels is not None:
           A_      :				Union[str, Any]		     =					self.tokenizer.pad(_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)

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



       def        _snake_case       (      self				,       *_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->Tuple:




         '''simple docstring'''





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



       def        _snake_case       (      self				,       *_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->List[str]:




         '''simple docstring'''





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







       @contextmanager
       def        _snake_case       (      self		)->Optional[int]:




         '''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.'''		)
         A_      :				Tuple		     =					True
         A_      :				Optional[int]		     =					self.tokenizer
         yield
         A_      :				Optional[int]		     =					self.feature_extractor
         A_      :				Union[str, Any]		     =					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,
    convert_to_rgb,
    get_resize_output_image_size,
    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


UpperCamelCase								=	logging.get_logger(__name__)


if is_vision_available():
     import PIL






class   _lowerCamelCase (					UpperCamelCase			):




       """simple docstring"""
       snake_case      =    ["pixel_values"]



       def __init__(      self				,       _SCREAMING_SNAKE_CASE = True				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = PILImageResampling.BICUBIC				,       _SCREAMING_SNAKE_CASE = True				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = True				,       _SCREAMING_SNAKE_CASE = 1 / 255				,       _SCREAMING_SNAKE_CASE = True				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = True				,       **_SCREAMING_SNAKE_CASE				,       )->None:




         '''simple docstring'''





         super().__init__(**_SCREAMING_SNAKE_CASE		)
         A_      :				Tuple		     =					size if size is not None else {'''shortest_edge''': 224}
         A_      :				Any		     =					get_size_dict(_SCREAMING_SNAKE_CASE				,       default_to_square=_SCREAMING_SNAKE_CASE		)
         A_      :				Tuple		     =					crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
         A_      :				Dict		     =					get_size_dict(_SCREAMING_SNAKE_CASE				,       default_to_square=_SCREAMING_SNAKE_CASE				,       param_name='''crop_size'''		)

         A_      :				str		     =					do_resize
         A_      :				Tuple		     =					size
         A_      :				Optional[Any]		     =					resample
         A_      :				Tuple		     =					do_center_crop
         A_      :				List[Any]		     =					crop_size
         A_      :				Optional[int]		     =					do_rescale
         A_      :				Tuple		     =					rescale_factor
         A_      :				Any		     =					do_normalize
         A_      :				int		     =					image_mean if image_mean is not None else OPENAI_CLIP_MEAN
         A_      :				Any		     =					image_std if image_std is not None else OPENAI_CLIP_STD
         A_      :				Any		     =					do_convert_rgb



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE = PILImageResampling.BICUBIC				,       _SCREAMING_SNAKE_CASE = None				,       **_SCREAMING_SNAKE_CASE				,       )->np.ndarray:




         '''simple docstring'''





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



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE = None				,       **_SCREAMING_SNAKE_CASE				,       )->np.ndarray:




         '''simple docstring'''





         A_      :				str		     =					get_size_dict(_SCREAMING_SNAKE_CASE		)
         if "height" not in size or "width" not in size:
           raise ValueError(F'''The `size` parameter must contain the keys (height, width). Got {size.keys()}'''		)
         return center_crop(_SCREAMING_SNAKE_CASE				,       size=(size['''height'''], size['''width'''])				,       data_format=_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE = None				,       **_SCREAMING_SNAKE_CASE				,       )->int:




         '''simple docstring'''





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



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE = None				,       **_SCREAMING_SNAKE_CASE				,       )->np.ndarray:




         '''simple docstring'''





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







       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = ChannelDimension.FIRST				,       **_SCREAMING_SNAKE_CASE				,       )->PIL.Image.Image:




         '''simple docstring'''





         A_      :				Optional[int]		     =					do_resize if do_resize is not None else self.do_resize
         A_      :				int		     =					size if size is not None else self.size
         A_      :				Optional[int]		     =					get_size_dict(_SCREAMING_SNAKE_CASE				,       param_name='''size'''				,       default_to_square=_SCREAMING_SNAKE_CASE		)
         A_      :				List[Any]		     =					resample if resample is not None else self.resample
         A_      :				Any		     =					do_center_crop if do_center_crop is not None else self.do_center_crop
         A_      :				List[str]		     =					crop_size if crop_size is not None else self.crop_size
         A_      :				int		     =					get_size_dict(_SCREAMING_SNAKE_CASE				,       param_name='''crop_size'''				,       default_to_square=_SCREAMING_SNAKE_CASE		)
         A_      :				Optional[int]		     =					do_rescale if do_rescale is not None else self.do_rescale
         A_      :				int		     =					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_      :				Tuple		     =					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_      :				Optional[int]		     =					make_list_of_images(_SCREAMING_SNAKE_CASE		)

         if not valid_images(_SCREAMING_SNAKE_CASE		):
           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.'''		)

         # PIL RGBA images are converted to RGB
         if do_convert_rgb:
           A_      :				List[str]		     =					[convert_to_rgb(_SCREAMING_SNAKE_CASE		) for image in images]

         # All transformations expect numpy arrays.
         A_      :				int		     =					[to_numpy_array(_SCREAMING_SNAKE_CASE		) for image in images]

         if do_resize:
           A_      :				Tuple		     =					[self.resize(image=_SCREAMING_SNAKE_CASE				,       size=_SCREAMING_SNAKE_CASE				,       resample=_SCREAMING_SNAKE_CASE		) for image in images]

         if do_center_crop:
           A_      :				Union[str, Any]		     =					[self.center_crop(image=_SCREAMING_SNAKE_CASE				,       size=_SCREAMING_SNAKE_CASE		) for image in images]

         if do_rescale:
           A_      :				Tuple		     =					[self.rescale(image=_SCREAMING_SNAKE_CASE				,       scale=_SCREAMING_SNAKE_CASE		) for image in images]

         if do_normalize:
           A_      :				List[Any]		     =					[self.normalize(image=_SCREAMING_SNAKE_CASE				,       mean=_SCREAMING_SNAKE_CASE				,       std=_SCREAMING_SNAKE_CASE		) for image in images]

         A_      :				str		     =					[to_channel_dimension_format(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		) for image in images]

         A_      :				Optional[Any]		     =					{'''pixel_values''': images}
         return BatchFeature(data=_SCREAMING_SNAKE_CASE				,       tensor_type=_SCREAMING_SNAKE_CASE		)




