




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,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_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_		      = logging.get_logger(__name__)
class 						_A					(  lowercase__      ):
  _UpperCamelCase   :			Any =			['pixel_values']






  def __init__(  self		:	Optional[int]      ,						_A		:	bool = True      ,						_A		:	Dict[str, int] = None      ,						_A		:	int = 0.9      ,						_A		:	PILImageResampling = PILImageResampling.BICUBIC      ,						_A		:	bool = True      ,						_A		:	Dict[str, int] = None      ,						_A		:	Union[int, float] = 1 / 255      ,						_A		:	bool = True      ,						_A		:	bool = True      ,						_A		:	Optional[Union[float, List[float]]] = None      ,						_A		:	Optional[Union[float, List[float]]] = None      ,						**_A		:	Any      ,						)		->    None:






       """simple docstring"""







       super().__init__(**__lowercase      )
       lowercase					:   Tuple								= size if size is not None else {"""shortest_edge""": 224}
       lowercase					:   Union[str, Any]								= get_size_dict(__lowercase      ,						default_to_square=__lowercase      )
       lowercase					:   Union[str, Any]								= crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
       lowercase					:   Any								= get_size_dict(__lowercase      ,						param_name='''crop_size'''      )

       lowercase					:   Dict								= do_resize
       lowercase					:   Dict								= size
       lowercase					:   Tuple								= crop_pct
       lowercase					:   List[Any]								= resample
       lowercase					:   List[Any]								= do_center_crop
       lowercase					:   List[Any]								= crop_size
       lowercase					:   Any								= do_rescale
       lowercase					:   Tuple								= rescale_factor
       lowercase					:   int								= do_normalize
       lowercase					:   List[Any]								= image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
       lowercase					:   List[str]								= image_std if image_std is not None else IMAGENET_DEFAULT_STD






  def 					__a			(  self		:	Tuple      ,						_A		:	np.ndarray      ,						_A		:	Dict[str, int]      ,						_A		:	Optional[float] = None      ,						_A		:	PILImageResampling = PILImageResampling.BICUBIC      ,						_A		:	Optional[Union[str, ChannelDimension]] = None      ,						**_A		:	Optional[int]      ,						)		->    np.ndarray:






       """simple docstring"""







       lowercase					:   Tuple								= get_size_dict(__lowercase      ,						default_to_square=__lowercase      )
       if "shortest_edge" not in size and ("height" not in size or "width" not in size):
            raise ValueError(f"""size must contain 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}"""      )
       if crop_pct is not None:
            if "shortest_edge" in size:
                 lowercase					:   Union[str, Any]								= int(size['''shortest_edge'''] / crop_pct      )
            elif "height" in size and "width" in size:
                 if size["height"] == size["width"]:
                      lowercase					:   Tuple								= int(size['''height'''] / crop_pct      )
                 else:
                      lowercase					:   str								= (int(size['''height'''] / crop_pct      ), int(size['''width'''] / crop_pct      ))
            else:
                 raise ValueError('''Invalid size for resize: {}'''.format(__lowercase      )      )

            lowercase					:   str								= get_resize_output_image_size(__lowercase      ,						size=__lowercase      ,						default_to_square=__lowercase      )
       else:
            if "shortest_edge" in size:
                 lowercase					:   List[str]								= get_resize_output_image_size(__lowercase      ,						size=size['''shortest_edge''']      ,						default_to_square=__lowercase      )
            elif "height" in size and "width" in size:
                 lowercase					:   int								= (size["""height"""], size["""width"""])
            else:
                 raise ValueError('''Invalid size for resize: {}'''.format(__lowercase      )      )

       return resize(__lowercase      ,						size=__lowercase      ,						resample=__lowercase      ,						data_format=__lowercase      ,						**__lowercase      )






  def 					__a			(  self		:	Dict      ,						_A		:	np.ndarray      ,						_A		:	Dict[str, int]      ,						_A		:	Optional[Union[str, ChannelDimension]] = None      ,						**_A		:	Union[str, Any]      ,						)		->    np.ndarray:






       """simple docstring"""







       lowercase					:   Optional[Any]								= get_size_dict(__lowercase      )
       if "height" not in size or "width" not in size:
            raise ValueError(f"""size must contain 'height' and 'width' as keys. Got {size.keys()}"""      )
       return center_crop(__lowercase      ,						size=(size['''height'''], size['''width'''])      ,						data_format=__lowercase      ,						**__lowercase      )






  def 					__a			(  self		:	List[str]      ,						_A		:	np.ndarray      ,						_A		:	Union[int, float]      ,						_A		:	Optional[Union[str, ChannelDimension]] = None      ,						**_A		:	int      ,						)		->    int:






       """simple docstring"""







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






  def 					__a			(  self		:	List[Any]      ,						_A		:	np.ndarray      ,						_A		:	Union[float, List[float]]      ,						_A		:	Union[float, List[float]]      ,						_A		:	Optional[Union[str, ChannelDimension]] = None      ,						**_A		:	List[Any]      ,						)		->    np.ndarray:






       """simple docstring"""







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






  def 					__a			(  self		:	Any      ,						_A		:	ImageInput      ,						_A		:	bool = None      ,						_A		:	Dict[str, int] = None      ,						_A		:	int = None      ,						_A		:	PILImageResampling = None      ,						_A		:	bool = None      ,						_A		:	Dict[str, int] = None      ,						_A		:	bool = None      ,						_A		:	float = None      ,						_A		:	bool = None      ,						_A		:	Optional[Union[float, List[float]]] = None      ,						_A		:	Optional[Union[float, List[float]]] = None      ,						_A		:	Optional[Union[str, TensorType]] = None      ,						_A		:	ChannelDimension = ChannelDimension.FIRST      ,						**_A		:	List[str]      ,						)		->    PIL.Image.Image:






       """simple docstring"""







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

       lowercase					:   Optional[int]								= size if size is not None else self.size
       lowercase					:   Dict								= get_size_dict(__lowercase      ,						default_to_square=__lowercase      )
       lowercase					:   Tuple								= crop_size if crop_size is not None else self.crop_size
       lowercase					:   Tuple								= get_size_dict(__lowercase      ,						param_name='''crop_size'''      )

       lowercase					:   Dict								= make_list_of_images(__lowercase      )

       if not valid_images(__lowercase      ):
            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_center_crop and crop_pct is None:
            raise ValueError('''Crop_pct 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.'''      )

       # All transformations expect numpy arrays.
       lowercase					:   str								= [to_numpy_array(__lowercase      ) for image in images]

       if do_resize:
            lowercase					:   str								= [self.resize(image=__lowercase      ,						size=__lowercase      ,						crop_pct=__lowercase      ,						resample=__lowercase      ) for image in images]

       if do_center_crop:
            lowercase					:   Any								= [self.center_crop(image=__lowercase      ,						size=__lowercase      ) for image in images]

       if do_rescale:
            lowercase					:   List[str]								= [self.rescale(image=__lowercase      ,						scale=__lowercase      ) for image in images]

       if do_normalize:
            lowercase					:   str								= [self.normalize(image=__lowercase      ,						mean=__lowercase      ,						std=__lowercase      ) for image in images]

       lowercase					:   List[str]								= [to_channel_dimension_format(__lowercase      ,						__lowercase      ) for image in images]

       lowercase					:   Any								= {"""pixel_values""": images}
       return BatchFeature(data=__lowercase      ,						tensor_type=__lowercase      )







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

from ..features import Audio, Features, Value
from .base import TaskTemplate
@dataclass(frozen=lowercase__   )
class     a    ( lowercase__   ):



      """simple docstring"""


      a  : str							       =	field(default='automatic-speech-recognition'							,       metadata={'include_in_asdict_even_if_is_default': True}   )
      a  : ClassVar[Features]							       =	Features({'audio': Audio()}   )
      a  : ClassVar[Features]							       =	Features({'transcription': Value('string'   )}   )
      a  : str							       =	"audio"
      a  : str							       =	"transcription"
      def 	UpperCAmelCase      (      self					:			Optional[Any]		,      __lowercase					:			Optional[int]					)							->      str:
        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]		,      __lowercase					):
          raise ValueError(f"""Column {self.audio_column} is not an Audio type."""					)
        __UpperCAmelCase							:	int           =  copy.deepcopy(self					)
        __UpperCAmelCase							:	str           =  self.input_schema.copy()
        __UpperCAmelCase							:	List[str]           =  features[self.audio_column]
        __UpperCAmelCase							:	Optional[Any]           =  input_schema
        return task_template




      @property
      def 	UpperCAmelCase      (      self					:			Union[str, Any]					)							->      Dict[str, str]:
        return {self.audio_column: "audio", self.transcription_column: "transcription"}


