
from typing import Dict, List, Optional, Tuple, 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_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, logging


if is_torch_available():
				import torch


SCREAMING_SNAKE_CASE							:str										=    logging.get_logger(__name__)





class 							UpperCAmelCase				(  lowerCamelCase__  ):




	'''simple docstring'''





	snake_case_    =					['pixel_values']






	def __init__(	self :			Tuple							,A :			bool = True							,A :			Optional[Dict[str, int]] = None							,A :			PILImageResampling = PILImageResampling.BILINEAR							,A :			bool = True							,A :			Dict[str, int] = None							,A :			bool = True							,A :			Union[int, float] = 1 / 2_55							,A :			bool = True							,A :			Optional[Union[float, List[float]]] = None							,A :			Optional[Union[float, List[float]]] = None							,**A :			List[Any]							,):
					super().__init__(**lowercase__			)
					__A             =			size if size is not None else {"shortest_edge": 2_56}
					__A             =			get_size_dict(lowercase__							,default_to_square=lowercase__			)
					__A             =			crop_size if crop_size is not None else {"height": 2_24, "width": 2_24}
					__A             =			get_size_dict(lowercase__							,param_name="crop_size"			)
					__A             =			do_resize
					__A             =			size
					__A             =			resample
					__A             =			do_center_crop
					__A             =			crop_size
					__A             =			do_rescale
					__A             =			rescale_factor
					__A             =			do_normalize
					__A             =			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
					__A             =			image_std if image_std is not None else IMAGENET_STANDARD_STD






	def     UpperCamelCase_  (	self :			Any							,A :			np.ndarray							,A :			Dict[str, int]							,A :			PILImageResampling = PILImageResampling.BICUBIC							,A :			Optional[Union[str, ChannelDimension]] = None							,**A :			Dict							,):
					__A             =			get_size_dict(lowercase__							,default_to_square=lowercase__			)
					if "shortest_edge" not in size:
									raise ValueError(f'''The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'''			)
					__A             =			get_resize_output_image_size(lowercase__							,size=size["shortest_edge"]							,default_to_square=lowercase__			)
					return resize(lowercase__							,size=lowercase__							,resample=lowercase__							,data_format=lowercase__							,**lowercase__			)






	def     UpperCamelCase_  (	self :			Dict							,A :			np.ndarray							,A :			Dict[str, int]							,A :			Optional[Union[str, ChannelDimension]] = None							,**A :			int							,):
					__A             =			get_size_dict(lowercase__			)
					if "height" not in size or "width" not in size:
									raise ValueError(f'''The `size` parameter must contain the keys `height` and `width`. Got {size.keys()}'''			)
					return center_crop(lowercase__							,size=(size["height"], size["width"])							,data_format=lowercase__							,**lowercase__			)






	def     UpperCamelCase_  (	self :			List[str]							,A :			np.ndarray							,A :			float							,A :			Optional[Union[str, ChannelDimension]] = None							,**A :			Optional[int]			):
					return rescale(lowercase__							,scale=lowercase__							,data_format=lowercase__							,**lowercase__			)






	def     UpperCamelCase_  (	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]							,):
					return normalize(lowercase__							,mean=lowercase__							,std=lowercase__							,data_format=lowercase__							,**lowercase__			)






	def     UpperCamelCase_  (	self :			Optional[int]							,A :			ImageInput							,A :			Optional[bool] = None							,A :			Dict[str, int] = None							,A :			PILImageResampling = None							,A :			bool = None							,A :			Dict[str, int] = None							,A :			Optional[bool] = None							,A :			Optional[float] = None							,A :			Optional[bool] = None							,A :			Optional[Union[float, List[float]]] = None							,A :			Optional[Union[float, List[float]]] = None							,A :			Optional[Union[str, TensorType]] = None							,A :			Union[str, ChannelDimension] = ChannelDimension.FIRST							,**A :			Dict							,):
					__A             =			do_resize if do_resize is not None else self.do_resize
					__A             =			size if size is not None else self.size
					__A             =			get_size_dict(lowercase__							,default_to_square=lowercase__			)
					__A             =			resample if resample is not None else self.resample
					__A             =			do_center_crop if do_center_crop is not None else self.do_center_crop
					__A             =			crop_size if crop_size is not None else self.crop_size
					__A             =			get_size_dict(lowercase__							,param_name="crop_size"			)
					__A             =			do_rescale if do_rescale is not None else self.do_rescale
					__A             =			rescale_factor if rescale_factor is not None else self.rescale_factor
					__A             =			do_normalize if do_normalize is not None else self.do_normalize
					__A             =			image_mean if image_mean is not None else self.image_mean
					__A             =			image_std if image_std is not None else self.image_std

					__A             =			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:
									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."			)

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

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

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

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

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

					__A             =			[to_channel_dimension_format(lowercase__							,lowercase__			) for image in images]

					__A             =			{"pixel_values": images}
					return BatchFeature(data=lowercase__							,tensor_type=lowercase__			)







	def     UpperCamelCase_  (	self :			Optional[int]							,A :			Union[str, Any]							,A :			List[Tuple] = None			):
					__A             =			outputs.logits

					# Resize logits and compute semantic segmentation maps
					if target_sizes is not None:
									if len(lowercase__			) != len(lowercase__			):
													raise ValueError(
													    "Make sure that you pass in as many target sizes as the batch dimension of the logits"			)

									if is_torch_tensor(lowercase__			):
													__A             =			target_sizes.numpy()

									__A             =			[]

									for idx in range(len(lowercase__			)			):
													__A             =			torch.nn.functional.interpolate(
													    logits[idx].unsqueeze(dim=0			)							,size=target_sizes[idx]							,mode="bilinear"							,align_corners=lowercase__			)
													__A             =			resized_logits[0].argmax(dim=0			)
													semantic_segmentation.append(lowercase__			)
					else:
									__A             =			logits.argmax(dim=1			)
									__A             =			[semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]			)]

					return semantic_segmentation


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

from ..features import Audio, Features, Value
from .base import TaskTemplate





@dataclass(frozen=__SCREAMING_SNAKE_CASE  )
class 							UpperCAmelCase				(  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_    =					field(default="automatic-speech-recognition"      ,      metadata={"include_in_asdict_even_if_is_default": True}  )
	snake_case_    =					Features({"audio": Audio()}  )
	snake_case_    =					Features({"transcription": Value("string"  )}  )
	snake_case_    =					"audio"
	snake_case_    =					"transcription"






	def     UpperCamelCase_  (	self :			Optional[int]							,A :			Union[str, Any]			):
					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]							,A			):
									raise ValueError(f'''Column {self.audio_column} is not an Audio type.'''			)
					__A             =			copy.deepcopy(self			)
					__A             =			self.input_schema.copy()
					__A             =			features[self.audio_column]
					__A             =			input_schema
					return task_template







	@property
	def     UpperCamelCase_  (	self :			int			):
					return {self.audio_column: "audio", self.transcription_column: "transcription"}
