






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


_lowerCAmelCase            =	logging.get_logger(__name__)


if is_vision_available():
				import PIL


class      UpperCamelCase		(SCREAMING_SNAKE_CASE__     ):
						_SCREAMING_SNAKE_CASE  : Union[str, Any]												=		['''pixel_values''']






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

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






						def      __snake_case      (		self  :str			, __magic_name__  :Union[str, Any]			, __magic_name__  :Dict			, __magic_name__  :Optional[int] = PILImageResampling.BICUBIC			, __magic_name__  :Optional[Any] = None			, **__magic_name__  :Optional[int]			, )      ->str:
										lowercase    :      Dict       = 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()}"""				)
										lowercase    :      str       = 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      __snake_case      (		self  :Dict			, __magic_name__  :Dict			, __magic_name__  :List[str]			, __magic_name__  :Optional[Any] = None			, **__magic_name__  :Optional[int]			, )      ->Optional[Any]:
										lowercase    :      List[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      __snake_case      (		self  :Tuple			, __magic_name__  :Any			, __magic_name__  :Optional[int]			, __magic_name__  :List[str] = None			, **__magic_name__  :int			, )      ->Union[str, Any]:
										return rescale(__lowerCAmelCase			, scale=__lowerCAmelCase			, data_format=__lowerCAmelCase			, **__lowerCAmelCase				)






						def      __snake_case      (		self  :Any			, __magic_name__  :str			, __magic_name__  :Dict			, __magic_name__  :Union[str, Any]			, __magic_name__  :Any = None			, **__magic_name__  :Union[str, Any]			, )      ->Optional[Any]:
										return normalize(__lowerCAmelCase			, mean=__lowerCAmelCase			, std=__lowerCAmelCase			, data_format=__lowerCAmelCase			, **__lowerCAmelCase				)






						def      __snake_case      (		self  :str			, __magic_name__  :Optional[Any]			, __magic_name__  :Any = None			, __magic_name__  :Optional[Any] = None			, __magic_name__  :Optional[int] = None			, __magic_name__  :Any = None			, __magic_name__  :Optional[Any] = None			, __magic_name__  :str = None			, __magic_name__  :Optional[Any] = None			, __magic_name__  :List[Any] = None			, __magic_name__  :Dict = None			, __magic_name__  :Dict = None			, __magic_name__  :List[str] = None			, __magic_name__  :Tuple = None			, __magic_name__  :Optional[int] = ChannelDimension.FIRST			, **__magic_name__  :List[Any]			, )      ->int:
										lowercase    :      Optional[Any]       = do_resize if do_resize is not None else self.do_resize
										lowercase    :      Dict       = size if size is not None else self.size
										lowercase    :      Union[str, Any]       = get_size_dict(__lowerCAmelCase			, param_name="""size"""			, default_to_square=__lowerCAmelCase				)
										lowercase    :      Tuple       = 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       = crop_size if crop_size is not None else self.crop_size
										lowercase    :      Optional[Any]       = get_size_dict(__lowerCAmelCase			, param_name="""crop_size"""			, default_to_square=__lowerCAmelCase				)
										lowercase    :      str       = do_rescale if do_rescale is not None else self.do_rescale
										lowercase    :      List[str]       = rescale_factor if rescale_factor is not None else self.rescale_factor
										lowercase    :      int       = do_normalize if do_normalize is not None else self.do_normalize
										lowercase    :      int       = image_mean if image_mean is not None else self.image_mean
										lowercase    :      Union[str, Any]       = image_std if image_std is not None else self.image_std
										lowercase    :      Optional[int]       = do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

										lowercase    :      int       = 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:
														lowercase    :      Optional[Any]       = [convert_to_rgb(__lowerCAmelCase				) for image in images]

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

										if do_resize:
														lowercase    :      Optional[int]       = [self.resize(image=__lowerCAmelCase			, size=__lowerCAmelCase			, resample=__lowerCAmelCase				) for image in images]

										if do_center_crop:
														lowercase    :      Optional[int]       = [self.center_crop(image=__lowerCAmelCase			, size=__lowerCAmelCase				) for image in images]

										if do_rescale:
														lowercase    :      Dict       = [self.rescale(image=__lowerCAmelCase			, scale=__lowerCAmelCase				) for image in images]

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

										lowercase    :      Optional[int]       = [to_channel_dimension_format(__lowerCAmelCase			, __lowerCAmelCase				) for image in images]

										lowercase    :      Dict       = {"""pixel_values""": images}
										return BatchFeature(data=__lowerCAmelCase			, tensor_type=__lowerCAmelCase				)








'''simple docstring'''

import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


UpperCamelCase      					="\nHugging 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.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn 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]\n"




class      A     (   unittest.TestCase, SCREAMING_SNAKE_CASE__    ):






 """simple docstring"""





 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Optional[Any]            =				load_tool("""text-question-answering"""			)
       self.tool.setup()
       UpperCamelCase_					: List[str]            =				load_tool("""text-question-answering"""      ,  remote=__lowerCAmelCase			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Union[str, Any]            =				self.tool(__lowerCAmelCase      ,  """What did Hugging Face do in April 2021?"""			)
       self.assertEqual(__lowerCAmelCase      ,  """launched the BigScience Research Workshop"""			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Optional[Any]            =				self.remote_tool(__lowerCAmelCase      ,  """What did Hugging Face do in April 2021?"""			)
       self.assertEqual(__lowerCAmelCase      ,  """launched the BigScience Research Workshop"""			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: List[Any]            =				self.tool(text=__lowerCAmelCase      ,  question="""What did Hugging Face do in April 2021?"""			)
       self.assertEqual(__lowerCAmelCase      ,  """launched the BigScience Research Workshop"""			)





 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Dict            =				self.remote_tool(text=__lowerCAmelCase      ,  question="""What did Hugging Face do in April 2021?"""			)
       self.assertEqual(__lowerCAmelCase      ,  """launched the BigScience Research Workshop"""			)






