





'''simple docstring'''



import warnings
from contextlib import contextmanager

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


class       __SCREAMING_SNAKE_CASE	(						__UpperCamelCase			):



     '''simple docstring'''






     UpperCAmelCase__       :						Union[str, Any]      =   '''Wav2Vec2FeatureExtractor'''
     UpperCAmelCase__       :						List[str]      =   '''AutoTokenizer'''

     def __init__(					self						,   lowerCamelCase						,   lowerCamelCase	):
       super().__init__(lowerCamelCase						,   lowerCamelCase	)
       _snake_case     		=				self.feature_extractor
       _snake_case     		=				False

     @classmethod
     def 	UpperCamelCase(					cls						,   lowerCamelCase						,   **lowerCamelCase	):
       try:
         return super().from_pretrained(lowerCamelCase						,   **lowerCamelCase	)
       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: "						,   lowerCamelCase						,   )

         _snake_case     		=				WavaVecaFeatureExtractor.from_pretrained(lowerCamelCase						,   **lowerCamelCase	)
         _snake_case     		=				WavaVecaCTCTokenizer.from_pretrained(lowerCamelCase						,   **lowerCamelCase	)

         return cls(feature_extractor=lowerCamelCase						,   tokenizer=lowerCamelCase	)

     def __call__(					self						,   *lowerCamelCase						,   **lowerCamelCase	):
       # For backward compatibility
       if self._in_target_context_manager:
         return self.current_processor(*lowerCamelCase						,   **lowerCamelCase	)

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

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

     def 	UpperCamelCase(					self						,   *lowerCamelCase						,   **lowerCamelCase	):
       # For backward compatibility
       if self._in_target_context_manager:
         return self.current_processor.pad(*lowerCamelCase						,   **lowerCamelCase	)

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

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

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

     def 	UpperCamelCase(					self						,   *lowerCamelCase						,   **lowerCamelCase	):
       return self.tokenizer.batch_decode(*lowerCamelCase						,   **lowerCamelCase	)

     def 	UpperCamelCase(					self						,   *lowerCamelCase						,   **lowerCamelCase	):
       return self.tokenizer.decode(*lowerCamelCase						,   **lowerCamelCase	)






     @contextmanager
     def 	UpperCamelCase(					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."	)
       _snake_case     		=				True
       _snake_case     		=				self.tokenizer
       yield
       _snake_case     		=				self.feature_extractor
       _snake_case     		=				False









'''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 (
    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


__magic_name__   :						Tuple    =			logging.get_logger(__name__)


if is_vision_available():
 import PIL


class       __SCREAMING_SNAKE_CASE	(						__UpperCamelCase			):



     '''simple docstring'''






     UpperCAmelCase__       :						str      =   ['''pixel_values''']

     def __init__(					self						,   lowerCamelCase = True						,   lowerCamelCase = None						,   lowerCamelCase = PILImageResampling.BICUBIC						,   lowerCamelCase = True						,   lowerCamelCase = None						,   lowerCamelCase = True						,   lowerCamelCase = 1 / 255						,   lowerCamelCase = True						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = True						,   **lowerCamelCase						,   ):
       super().__init__(**lowerCamelCase	)
       _snake_case     		=				size if size is not None else {"shortest_edge": 224}
       _snake_case     		=				get_size_dict(lowerCamelCase						,   default_to_square=lowerCamelCase	)
       _snake_case     		=				crop_size if crop_size is not None else {"height": 224, "width": 224}
       _snake_case     		=				get_size_dict(lowerCamelCase						,   default_to_square=lowerCamelCase						,   param_name="crop_size"	)

       _snake_case     		=				do_resize
       _snake_case     		=				size
       _snake_case     		=				resample
       _snake_case     		=				do_center_crop
       _snake_case     		=				crop_size
       _snake_case     		=				do_rescale
       _snake_case     		=				rescale_factor
       _snake_case     		=				do_normalize
       _snake_case     		=				image_mean if image_mean is not None else OPENAI_CLIP_MEAN
       _snake_case     		=				image_std if image_std is not None else OPENAI_CLIP_STD
       _snake_case     		=				do_convert_rgb

     def 	UpperCamelCase(					self						,   lowerCamelCase						,   lowerCamelCase						,   lowerCamelCase = PILImageResampling.BICUBIC						,   lowerCamelCase = None						,   **lowerCamelCase						,   ):
       _snake_case     		=				get_size_dict(lowerCamelCase						,   default_to_square=lowerCamelCase	)
       if "shortest_edge" not in size:
         raise ValueError(F'''The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'''	)
       _snake_case     		=				get_resize_output_image_size(lowerCamelCase						,   size=size["shortest_edge"]						,   default_to_square=lowerCamelCase	)
       return resize(lowerCamelCase						,   size=lowerCamelCase						,   resample=lowerCamelCase						,   data_format=lowerCamelCase						,   **lowerCamelCase	)

     def 	UpperCamelCase(					self						,   lowerCamelCase						,   lowerCamelCase						,   lowerCamelCase = None						,   **lowerCamelCase						,   ):
       _snake_case     		=				get_size_dict(lowerCamelCase	)
       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(lowerCamelCase						,   size=(size["height"], size["width"])						,   data_format=lowerCamelCase						,   **lowerCamelCase	)

     def 	UpperCamelCase(					self						,   lowerCamelCase						,   lowerCamelCase						,   lowerCamelCase = None						,   **lowerCamelCase						,   ):
       return rescale(lowerCamelCase						,   scale=lowerCamelCase						,   data_format=lowerCamelCase						,   **lowerCamelCase	)

     def 	UpperCamelCase(					self						,   lowerCamelCase						,   lowerCamelCase						,   lowerCamelCase						,   lowerCamelCase = None						,   **lowerCamelCase						,   ):
       return normalize(lowerCamelCase						,   mean=lowerCamelCase						,   std=lowerCamelCase						,   data_format=lowerCamelCase						,   **lowerCamelCase	)






     def 	UpperCamelCase(					self						,   lowerCamelCase						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = None						,   lowerCamelCase = ChannelDimension.FIRST						,   **lowerCamelCase						,   ):
       _snake_case     		=				do_resize if do_resize is not None else self.do_resize
       _snake_case     		=				size if size is not None else self.size
       _snake_case     		=				get_size_dict(lowerCamelCase						,   param_name="size"						,   default_to_square=lowerCamelCase	)
       _snake_case     		=				resample if resample is not None else self.resample
       _snake_case     		=				do_center_crop if do_center_crop is not None else self.do_center_crop
       _snake_case     		=				crop_size if crop_size is not None else self.crop_size
       _snake_case     		=				get_size_dict(lowerCamelCase						,   param_name="crop_size"						,   default_to_square=lowerCamelCase	)
       _snake_case     		=				do_rescale if do_rescale is not None else self.do_rescale
       _snake_case     		=				rescale_factor if rescale_factor is not None else self.rescale_factor
       _snake_case     		=				do_normalize if do_normalize is not None else self.do_normalize
       _snake_case     		=				image_mean if image_mean is not None else self.image_mean
       _snake_case     		=				image_std if image_std is not None else self.image_std
       _snake_case     		=				do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

       _snake_case     		=				make_list_of_images(lowerCamelCase	)

       if not valid_images(lowerCamelCase	):
         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:
         _snake_case     		=				[convert_to_rgb(lowerCamelCase	) for image in images]

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

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

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

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

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

       _snake_case     		=				[to_channel_dimension_format(lowerCamelCase						,   lowerCamelCase	) for image in images]

       _snake_case     		=				{"pixel_values": images}
       return BatchFeature(data=lowerCamelCase						,   tensor_type=lowerCamelCase	)


