






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


UpperCAmelCase_ :						Tuple      =      logging.get_logger(__name__)


if is_vision_available():
	import PIL

class     _SCREAMING_SNAKE_CASE       (			_a      ):
	snake_case__							:     Dict     	=  ["""pixel_values"""]





	def __init__(		self				:					List[str] ,  __lowerCamelCase				:					bool = True ,  __lowerCamelCase				:					Dict[str, int] = None ,  __lowerCamelCase				:					PILImageResampling = PILImageResampling.BICUBIC ,  __lowerCamelCase				:					bool = True ,  __lowerCamelCase				:					Dict[str, int] = None ,  __lowerCamelCase				:					bool = True ,  __lowerCamelCase				:					Union[int, float] = 1 / 255 ,  __lowerCamelCase				:					bool = True ,  __lowerCamelCase				:					Optional[Union[float, List[float]]] = None ,  __lowerCamelCase				:					Optional[Union[float, List[float]]] = None ,  __lowerCamelCase				:					bool = True ,  **__lowerCamelCase				:					Optional[int] ,  ):
		super().__init__(**__lowerCamelCase	)
		UpperCamelCase     :Tuple          =	size if size is not None else {"""shortest_edge""": 224}
		UpperCamelCase     :Any          =	get_size_dict(__lowerCamelCase ,  default_to_square=__lowerCamelCase	)
		UpperCamelCase     :Any          =	crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
		UpperCamelCase     :int          =	get_size_dict(__lowerCamelCase ,  default_to_square=__lowerCamelCase ,  param_name="""crop_size"""	)

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





	def 						_A (		self				:					Dict ,  __lowerCamelCase				:					np.ndarray ,  __lowerCamelCase				:					Dict[str, int] ,  __lowerCamelCase				:					PILImageResampling = PILImageResampling.BICUBIC ,  __lowerCamelCase				:					Optional[Union[str, ChannelDimension]] = None ,  **__lowerCamelCase				:					Optional[int] ,  ):
		UpperCamelCase     :Tuple          =	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()}"""	)
		UpperCamelCase     :int          =	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 						_A (		self				:					List[str] ,  __lowerCamelCase				:					np.ndarray ,  __lowerCamelCase				:					Dict[str, int] ,  __lowerCamelCase				:					Optional[Union[str, ChannelDimension]] = None ,  **__lowerCamelCase				:					Tuple ,  ):
		UpperCamelCase     :str          =	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 						_A (		self				:					List[str] ,  __lowerCamelCase				:					np.ndarray ,  __lowerCamelCase				:					Union[int, float] ,  __lowerCamelCase				:					Optional[Union[str, ChannelDimension]] = None ,  **__lowerCamelCase				:					Optional[int] ,  ):
		return rescale(__lowerCamelCase ,  scale=__lowerCamelCase ,  data_format=__lowerCamelCase ,  **__lowerCamelCase	)





	def 						_A (		self				:					Optional[int] ,  __lowerCamelCase				:					np.ndarray ,  __lowerCamelCase				:					Union[float, List[float]] ,  __lowerCamelCase				:					Union[float, List[float]] ,  __lowerCamelCase				:					Optional[Union[str, ChannelDimension]] = None ,  **__lowerCamelCase				:					str ,  ):
		return normalize(__lowerCamelCase ,  mean=__lowerCamelCase ,  std=__lowerCamelCase ,  data_format=__lowerCamelCase ,  **__lowerCamelCase	)





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

		UpperCamelCase     :Dict          =	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:
			UpperCamelCase     :Optional[int]          =	[convert_to_rgb(__lowerCamelCase	) for image in images]

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

		if do_resize:
			UpperCamelCase     :Tuple          =	[self.resize(image=__lowerCamelCase ,  size=__lowerCamelCase ,  resample=__lowerCamelCase	) for image in images]

		if do_center_crop:
			UpperCamelCase     :str          =	[self.center_crop(image=__lowerCamelCase ,  size=__lowerCamelCase	) for image in images]

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

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

		UpperCamelCase     :Optional[Any]          =	[to_channel_dimension_format(__lowerCamelCase ,  __lowerCamelCase	) for image in images]

		UpperCamelCase     :str          =	{"""pixel_values""": images}
		return BatchFeature(data=__lowerCamelCase ,  tensor_type=__lowerCamelCase	)








# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor
from .base import PipelineTool

class     _SCREAMING_SNAKE_CASE       (			_a      ):
	snake_case__							:     Any     	=  """openai/whisper-base"""
	snake_case__							:     Optional[int]     	=  (
	    """This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the """
	    """transcribed text."""
	)
	snake_case__							:     Any     	=  """transcriber"""
	snake_case__							:     Optional[int]     	=  WhisperProcessor
	snake_case__							:     str     	=  WhisperForConditionalGeneration

	snake_case__							:     Optional[Any]     	=  ["""audio"""]
	snake_case__							:     Any     	=  ["""text"""]





	def 						_A (		self				:					str ,  __lowerCamelCase				:					Dict	):
		return self.pre_processor(__lowerCamelCase ,  return_tensors="""pt"""	).input_features





	def 						_A (		self				:					Dict ,  __lowerCamelCase				:					List[Any]	):
		return self.model.generate(inputs=__lowerCamelCase	)





	def 						_A (		self				:					Any ,  __lowerCamelCase				:					Optional[Any]	):
		return self.pre_processor.batch_decode(__lowerCamelCase ,  skip_special_tokens=__lowerCamelCase	)[0]
