



'''simple docstring'''




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 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, logging


a  :     Optional[int]       =       logging.get_logger(__name__)

class      UpperCamelCase_					(				__magic_name__     ):
	lowercase		=					['pixel_values']





	def __init__(    self						,						A = True						,						A = None						,						A = PILImageResampling.BILINEAR						,						A = True						,						A = 1 / 255						,						A = True						,						A = None						,						A = None						,						**A						,						)     ->     None:
								super().__init__(**A       )
								UpperCAmelCase	:						Dict					=						size if size is not None else {"""height""": 224, """width""": 224}
								UpperCAmelCase	:						Dict					=						get_size_dict(A       )
								UpperCAmelCase	:						Tuple					=						do_resize
								UpperCAmelCase	:						Dict					=						do_rescale
								UpperCAmelCase	:						List[Any]					=						do_normalize
								UpperCAmelCase	:						Tuple					=						size
								UpperCAmelCase	:						int					=						resample
								UpperCAmelCase	:						List[str]					=						rescale_factor
								UpperCAmelCase	:						Tuple					=						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
								UpperCAmelCase	:						int					=						image_std if image_std is not None else IMAGENET_STANDARD_STD





	def 					_lowercase(    self						,						A						,						A						,						A = PILImageResampling.BILINEAR						,						A = None						,						**A						,						)     ->     np.ndarray:
								UpperCAmelCase	:						int					=						get_size_dict(A       )
								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()}'''       )
								return resize(
								    A						,						size=(size["""height"""], size["""width"""])						,						resample=A						,						data_format=A						,						**A       )





	def 					_lowercase(    self						,						A						,						A						,						A = None						,						**A       )     ->     np.ndarray:
								return rescale(A						,						scale=A						,						data_format=A						,						**A       )





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






	def 					_lowercase(    self						,						A						,						A = None						,						A = None						,						A = None						,						A = None						,						A = None						,						A = None						,						A = None						,						A = None						,						A = None						,						A = ChannelDimension.FIRST						,						**A						,						)     ->     Optional[int]:
								UpperCAmelCase	:						Tuple					=						do_resize if do_resize is not None else self.do_resize
								UpperCAmelCase	:						str					=						do_rescale if do_rescale is not None else self.do_rescale
								UpperCAmelCase	:						Optional[int]					=						do_normalize if do_normalize is not None else self.do_normalize
								UpperCAmelCase	:						Tuple					=						resample if resample is not None else self.resample
								UpperCAmelCase	:						Optional[int]					=						rescale_factor if rescale_factor is not None else self.rescale_factor
								UpperCAmelCase	:						Optional[int]					=						image_mean if image_mean is not None else self.image_mean
								UpperCAmelCase	:						List[str]					=						image_std if image_std is not None else self.image_std

								UpperCAmelCase	:						Tuple					=						size if size is not None else self.size
								UpperCAmelCase	:						Union[str, Any]					=						get_size_dict(A       )

								UpperCAmelCase	:						List[Any]					=						make_list_of_images(A       )

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

								if do_resize and size is None:
															raise ValueError("""Size 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."""       )

								# All transformations expect numpy arrays.
								UpperCAmelCase	:						List[str]					=						[to_numpy_array(A       ) for image in images]

								if do_resize:
															UpperCAmelCase	:						str					=						[self.resize(image=A						,						size=A						,						resample=A       ) for image in images]

								if do_rescale:
															UpperCAmelCase	:						Tuple					=						[self.rescale(image=A						,						scale=A       ) for image in images]

								if do_normalize:
															UpperCAmelCase	:						List[str]					=						[self.normalize(image=A						,						mean=A						,						std=A       ) for image in images]

								UpperCAmelCase	:						Dict					=						[to_channel_dimension_format(A						,						A       ) for image in images]

								UpperCAmelCase	:						Any					=						{"""pixel_values""": images}
								return BatchFeature(data=A						,						tensor_type=A       )






'''simple docstring'''




# 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 typing import TYPE_CHECKING

from ..utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


a  :     Optional[Any]       =       {
    """agents""": ["""Agent""", """AzureOpenAiAgent""", """HfAgent""", """LocalAgent""", """OpenAiAgent"""],
    """base""": ["""PipelineTool""", """RemoteTool""", """Tool""", """launch_gradio_demo""", """load_tool"""],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a  :     Dict       =       ["""DocumentQuestionAnsweringTool"""]
							a  :     List[str]       =       ["""ImageCaptioningTool"""]
							a  :     Tuple       =       ["""ImageQuestionAnsweringTool"""]
							a  :     Tuple       =       ["""ImageSegmentationTool"""]
							a  :     List[str]       =       ["""SpeechToTextTool"""]
							a  :     Dict       =       ["""TextClassificationTool"""]
							a  :     Union[str, Any]       =       ["""TextQuestionAnsweringTool"""]
							a  :     List[str]       =       ["""TextSummarizationTool"""]
							a  :     Optional[Any]       =       ["""TextToSpeechTool"""]
							a  :     str       =       ["""TranslationTool"""]

if TYPE_CHECKING:
							from .agents import Agent, AzureOpenAiAgent, HfAgent, LocalAgent, OpenAiAgent
							from .base import PipelineTool, RemoteTool, Tool, launch_gradio_demo, load_tool

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .document_question_answering import DocumentQuestionAnsweringTool
														from .image_captioning import ImageCaptioningTool
														from .image_question_answering import ImageQuestionAnsweringTool
														from .image_segmentation import ImageSegmentationTool
														from .speech_to_text import SpeechToTextTool
														from .text_classification import TextClassificationTool
														from .text_question_answering import TextQuestionAnsweringTool
														from .text_summarization import TextSummarizationTool
														from .text_to_speech import TextToSpeechTool
														from .translation import TranslationTool
else:
							import sys

							a  :     Dict       =       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

