





'''simple docstring'''







from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

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


if is_vision_available():
   import PIL

_lowercase       						=			logging.get_logger(__name__)

def    __UpperCamelCase	(	a    : Optional[Any]     ) ->List[List[ImageInput]]:
 if isinstance(a					,   (list, tuple)     ) and isinstance(videos[0]					,   (list, tuple)     ) and is_valid_image(videos[0][0]     ):
  return videos

 elif isinstance(a					,   (list, tuple)     ) and is_valid_image(videos[0]     ):
  return [videos]

 elif is_valid_image(a     ):
  return [[videos]]

 raise ValueError(f"""Could not make batched video from {videos}"""     )






class 			_lowercase						(       __a					):
     _UpperCAmelCase										=					['''pixel_values''']







     def __init__( self    ,   A__ = True    ,   A__ = None    ,   A__ = PILImageResampling.BILINEAR    ,   A__ = True    ,   A__ = None    ,   A__ = True    ,   A__ = 1 / 2_55    ,   A__ = True    ,   A__ = True    ,   A__ = None    ,   A__ = None    ,   **A__    ,   ) ->	None:
      super().__init__(**A__    )
      snake_case				=			size if size is not None else {'''shortest_edge''': 2_56}
      snake_case				=			get_size_dict(A__    ,   default_to_square=A__    )
      snake_case				=			crop_size if crop_size is not None else {'''height''': 2_24, '''width''': 2_24}
      snake_case				=			get_size_dict(A__    ,   param_name='''crop_size'''    )

      snake_case				=			do_resize
      snake_case				=			size
      snake_case				=			do_center_crop
      snake_case				=			crop_size
      snake_case				=			resample
      snake_case				=			do_rescale
      snake_case				=			rescale_factor
      snake_case				=			offset
      snake_case				=			do_normalize
      snake_case				=			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
      snake_case				=			image_std if image_std is not None else IMAGENET_STANDARD_STD







     def     UpperCamelCase			( self    ,   A__    ,   A__    ,   A__ = PILImageResampling.BILINEAR    ,   A__ = None    ,   **A__    ,   ) ->	np.ndarray:
      snake_case				=			get_size_dict(A__    ,   default_to_square=A__    )
      if "shortest_edge" in size:
       snake_case				=			get_resize_output_image_size(A__    ,   size['''shortest_edge''']    ,   default_to_square=A__    )
      elif "height" in size and "width" in size:
       snake_case				=			(size['''height'''], size['''width'''])
      else:
       raise ValueError(F"""Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}"""    )
      return resize(A__    ,   size=A__    ,   resample=A__    ,   data_format=A__    ,   **A__    )







     def     UpperCamelCase			( self    ,   A__    ,   A__    ,   A__ = None    ,   **A__    ,   ) ->	np.ndarray:
      snake_case				=			get_size_dict(A__    )
      if "height" not in size or "width" not in size:
       raise ValueError(F"""Size must have 'height' and 'width' as keys. Got {size.keys()}"""    )
      return center_crop(A__    ,   size=(size['''height'''], size['''width'''])    ,   data_format=A__    ,   **A__    )







     def     UpperCamelCase			( self    ,   A__    ,   A__    ,   A__ = True    ,   A__ = None    ,   **A__    ,   ) ->	List[Any]:
      snake_case				=			image.astype(np.floataa    )
      if offset:
       snake_case				=			image - (scale / 2)
      return rescale(A__    ,   scale=A__    ,   data_format=A__    ,   **A__    )







     def     UpperCamelCase			( self    ,   A__    ,   A__    ,   A__    ,   A__ = None    ,   **A__    ,   ) ->	np.ndarray:
      return normalize(A__    ,   mean=A__    ,   std=A__    ,   data_format=A__    ,   **A__    )







     def     UpperCamelCase			( self    ,   A__    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = ChannelDimension.FIRST    ,   ) ->	np.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_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.'''    )

      if offset and not do_rescale:
       raise ValueError('''For offset, do_rescale must also be set to True.'''    )

      # All transformations expect numpy arrays.
      snake_case				=			to_numpy_array(A__    )

      if do_resize:
       snake_case				=			self.resize(image=A__    ,   size=A__    ,   resample=A__    )

      if do_center_crop:
       snake_case				=			self.center_crop(A__    ,   size=A__    )

      if do_rescale:
       snake_case				=			self.rescale(image=A__    ,   scale=A__    ,   offset=A__    )

      if do_normalize:
       snake_case				=			self.normalize(image=A__    ,   mean=A__    ,   std=A__    )

      snake_case				=			to_channel_dimension_format(A__    ,   A__    )
      return image







     def     UpperCamelCase			( self    ,   A__    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = None    ,   A__ = ChannelDimension.FIRST    ,   **A__    ,   ) ->	PIL.Image.Image:
      snake_case				=			do_resize if do_resize is not None else self.do_resize
      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				=			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				=			offset if offset is not None else self.offset
      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				=			size if size is not None else self.size
      snake_case				=			get_size_dict(A__    ,   default_to_square=A__    )
      snake_case				=			crop_size if crop_size is not None else self.crop_size
      snake_case				=			get_size_dict(A__    ,   param_name='''crop_size'''    )

      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.'''    )

      snake_case				=			make_batched(A__    )

      snake_case				=			[
          [
              self._preprocess_image(
                  image=A__    ,   do_resize=A__    ,   size=A__    ,   resample=A__    ,   do_center_crop=A__    ,   crop_size=A__    ,   do_rescale=A__    ,   rescale_factor=A__    ,   offset=A__    ,   do_normalize=A__    ,   image_mean=A__    ,   image_std=A__    ,   data_format=A__    ,   )
              for img in video
          ]
          for video in videos
      ]

      snake_case				=			{'''pixel_values''': videos}
      return BatchFeature(data=A__    ,   tensor_type=A__    )








'''simple docstring'''







from ...processing_utils import ProcessorMixin
class 			_lowercase						(       __a					):
     _UpperCAmelCase										=					'''WhisperFeatureExtractor'''
     _UpperCAmelCase										=					'''WhisperTokenizer'''







     def __init__( self    ,   A__    ,   A__    ) ->	Optional[Any]:
      super().__init__(A__    ,   A__    )
      snake_case				=			self.feature_extractor
      snake_case				=			False







     def     UpperCamelCase			( self    ,   A__=None    ,   A__=None    ,   A__=True    ) ->	Union[str, Any]:
      return self.tokenizer.get_decoder_prompt_ids(task=A__    ,   language=A__    ,   no_timestamps=A__    )







     def __call__( self    ,   *A__    ,   **A__    ) ->	Dict:
      # For backward compatibility
      if self._in_target_context_manager:
       return self.current_processor(*A__    ,   **A__    )

      snake_case				=			kwargs.pop('''audio'''    ,   A__    )
      snake_case				=			kwargs.pop('''sampling_rate'''    ,   A__    )
      snake_case				=			kwargs.pop('''text'''    ,   A__    )
      if len(A__    ) > 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(A__    ,   *A__    ,   sampling_rate=A__    ,   **A__    )
      if text is not None:
       snake_case				=			self.tokenizer(A__    ,   **A__    )

      if text is None:
       return inputs

      elif audio is None:
       return encodings
      else:
       snake_case				=			encodings['''input_ids''']
       return inputs







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







     def     UpperCamelCase			( self    ,   *A__    ,   **A__    ) ->	str:
      return self.tokenizer.decode(*A__    ,   **A__    )







     def     UpperCamelCase			( self    ,   A__    ,   A__="np"    ) ->	Optional[Any]:
      return self.tokenizer.get_prompt_ids(A__    ,   return_tensors=A__    )

