
"""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 center_crop, 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_vision_available, logging


if is_vision_available():
		import PIL


UpperCamelCase_					:						List[str]				= logging.get_logger(__name__)



class __lowerCAmelCase				(					_lowercase      ):




			"""simple docstring"""







			snake_case	      =				["pixel_values"]




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







								"""simple docstring"""
								super().__init__(**_snake_case	)
								A_				 =						size if size is not None else {"height": 256, "width": 256}
								A_				 =						get_size_dict(_snake_case	)
								A_				 =						crop_size if crop_size is not None else {"height": 224, "width": 224}
								A_				 =						get_size_dict(_snake_case       ,   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      lowerCamelCase__     (				self						:					List[Any]       ,   _snake_case						:					np.ndarray       ,   _snake_case						:					Dict[str, int]       ,   _snake_case						:					PILImageResampling = PIL.Image.BICUBIC       ,   _snake_case						:					Optional[Union[str, ChannelDimension]] = None       ,   **_snake_case						:					List[str]       ,   )      -> np.ndarray:







								"""simple docstring"""
								A_				 =						get_size_dict(_snake_case	)
								if "height" not in size or "width" not in size:
													raise ValueError(F'The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'	)
								return resize(
								    _snake_case       ,   size=(size["height"], size["width"])       ,   resample=_snake_case       ,   data_format=_snake_case       ,   **_snake_case	)




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







								"""simple docstring"""
								A_				 =						get_size_dict(_snake_case	)
								if "height" not in size or "width" not in size:
													raise ValueError(F'The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'	)
								return center_crop(_snake_case       ,   size=(size["height"], size["width"])       ,   data_format=_snake_case       ,   **_snake_case	)




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







								"""simple docstring"""
								return rescale(_snake_case       ,   scale=_snake_case       ,   data_format=_snake_case       ,   **_snake_case	)




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







								"""simple docstring"""
								return normalize(_snake_case       ,   mean=_snake_case       ,   std=_snake_case       ,   data_format=_snake_case       ,   **_snake_case	)






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







								"""simple docstring"""
								A_				 =						do_resize if do_resize is not None else self.do_resize
								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_				 =						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_				 =						size if size is not None else self.size
								A_				 =						get_size_dict(_snake_case	)
								A_				 =						crop_size if crop_size is not None else self.crop_size
								A_				 =						get_size_dict(_snake_case       ,   param_name="crop_size"	)

								A_				 =						make_list_of_images(_snake_case	)

								if not valid_images(_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_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(_snake_case	) for image in images]

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

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

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

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

								A_				 =						[to_channel_dimension_format(_snake_case       ,   _snake_case	) for image in images]

								A_				 =						{"pixel_values": images}
								return BatchFeature(data=_snake_case       ,   tensor_type=_snake_case	)






"""simple docstring"""





import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


UpperCamelCase_					:						int				= '''
Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
'''



class __lowerCAmelCase				(					unittest.TestCase     ,				_lowercase      ):




			"""simple docstring"""







			def      lowerCamelCase__     (				self						:					str	)      -> Dict:







								"""simple docstring"""
								A_				 =						load_tool("text-question-answering"	)
								self.tool.setup()
								A_				 =						load_tool("text-question-answering"       ,   remote=_snake_case	)




			def      lowerCamelCase__     (				self						:					Union[str, Any]	)      -> Any:







								"""simple docstring"""
								A_				 =						self.tool(_snake_case       ,   "What did Hugging Face do in April 2021?"	)
								self.assertEqual(_snake_case       ,   "launched the BigScience Research Workshop"	)




			def      lowerCamelCase__     (				self						:					Union[str, Any]	)      -> int:







								"""simple docstring"""
								A_				 =						self.remote_tool(_snake_case       ,   "What did Hugging Face do in April 2021?"	)
								self.assertEqual(_snake_case       ,   "launched the BigScience Research Workshop"	)




			def      lowerCamelCase__     (				self						:					Optional[Any]	)      -> Optional[Any]:







								"""simple docstring"""
								A_				 =						self.tool(text=_snake_case       ,   question="What did Hugging Face do in April 2021?"	)
								self.assertEqual(_snake_case       ,   "launched the BigScience Research Workshop"	)






			def      lowerCamelCase__     (				self						:					str	)      -> Optional[Any]:







								"""simple docstring"""
								A_				 =						self.remote_tool(text=_snake_case       ,   question="What did Hugging Face do in April 2021?"	)
								self.assertEqual(_snake_case       ,   "launched the BigScience Research Workshop"	)




