

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


lowerCAmelCase     :   Optional[int]						     =  logging.get_logger(__name__)
class  _A		(  __magic_name__):
  SCREAMING_SNAKE_CASE    :      Tuple       =  ['''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 = 1 / 255 ,					_SCREAMING_SNAKE_CASE = True ,					_SCREAMING_SNAKE_CASE = None ,					_SCREAMING_SNAKE_CASE = None ,					_SCREAMING_SNAKE_CASE = True ,					**_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        super().__init__(**_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     size if size is not None else {'height': 384, 'width': 384}
        SCREAMING_SNAKE_CASE_				:  Any           =     get_size_dict(_SCREAMING_SNAKE_CASE ,					default_to_square=_SCREAMING_SNAKE_CASE					)

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

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE = PILImageResampling.BICUBIC ,					_SCREAMING_SNAKE_CASE = None ,					**_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[Any]           =     get_size_dict(_SCREAMING_SNAKE_CASE ,					default_to_square=_SCREAMING_SNAKE_CASE					)
        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()}"					)
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     (size['height'], size['width'])
        return resize(_SCREAMING_SNAKE_CASE ,					size=_SCREAMING_SNAKE_CASE ,					resample=_SCREAMING_SNAKE_CASE ,					data_format=_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					)

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE = None ,					**_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







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

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE = None ,					**_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







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



  def  UpperCAmelCase    (				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 = ChannelDimension.FIRST ,					**_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







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

        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     size if size is not None else self.size
        SCREAMING_SNAKE_CASE_				:  List[str]           =     get_size_dict(_SCREAMING_SNAKE_CASE ,					default_to_square=_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  Tuple           =     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 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:
              SCREAMING_SNAKE_CASE_				:  Optional[int]           =     [convert_to_rgb(_SCREAMING_SNAKE_CASE					) for image in images]

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

        if do_resize:
              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     [self.resize(image=_SCREAMING_SNAKE_CASE ,					size=_SCREAMING_SNAKE_CASE ,					resample=_SCREAMING_SNAKE_CASE					) for image in images]

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

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

        SCREAMING_SNAKE_CASE_				:  int           =     [to_channel_dimension_format(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					) for image in images]

        SCREAMING_SNAKE_CASE_				:  Any           =     BatchFeature(data={'pixel_values': images} ,					tensor_type=_SCREAMING_SNAKE_CASE					)

        return encoded_outputs









import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, Features, Value
from .base import TaskTemplate
@dataclass(frozen=__magic_name__)
class  _A		(  __magic_name__):
  SCREAMING_SNAKE_CASE    :      str       =  field(default='''automatic-speech-recognition'''   ,     metadata={'''include_in_asdict_even_if_is_default''': True})
  SCREAMING_SNAKE_CASE    :      ClassVar[Features]       =  Features({'''audio''': Audio()})
  SCREAMING_SNAKE_CASE    :      ClassVar[Features]       =  Features({'''transcription''': Value('''string''')})
  SCREAMING_SNAKE_CASE    :      str       =  "audio"
  SCREAMING_SNAKE_CASE    :      str       =  "transcription"

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        if self.audio_column not in features:
              raise ValueError(f"Column {self.audio_column} is not present in features."					)
        if not isinstance(features[self.audio_column] ,					_SCREAMING_SNAKE_CASE					):
              raise ValueError(f"Column {self.audio_column} is not an Audio type."					)
        SCREAMING_SNAKE_CASE_				:  int           =     copy.deepcopy(self					)
        SCREAMING_SNAKE_CASE_				:  int           =     self.input_schema.copy()
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     features[self.audio_column]
        SCREAMING_SNAKE_CASE_				:  List[str]           =     input_schema
        return task_template



  @property
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        return {self.audio_column: "audio", self.transcription_column: "transcription"}






