




'''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 convert_to_rgb, 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


if is_vision_available():
				import PIL


_snake_case   :   Optional[Any]     							=	logging.get_logger(__name__)

class     A					(	_a					):
							lowercase_           =       ['pixel_values']







							def __init__(						self :						List[str]							,    lowerCAmelCase_ :						bool = True							,    lowerCAmelCase_ :						Dict[str, int] = None							,    lowerCAmelCase_ :						PILImageResampling = PILImageResampling.BICUBIC							,    lowerCAmelCase_ :						bool = True							,    lowerCAmelCase_ :						Union[int, float] = 1 / 2_55							,    lowerCAmelCase_ :						bool = True							,    lowerCAmelCase_ :						Optional[Union[float, List[float]]] = None							,    lowerCAmelCase_ :						Optional[Union[float, List[float]]] = None							,    lowerCAmelCase_ :						bool = True							,    **lowerCAmelCase_ :						Optional[Any]							,    )    ->							None:


														"""simple docstring"""


														super().__init__(**lowerCAmelCase_      )
														_a			  =       size if size is not None else {'''height''': 3_84, '''width''': 3_84}
														_a			  =       get_size_dict(lowerCAmelCase_							,    default_to_square=lowerCAmelCase_      )

														_a			  =       do_resize
														_a			  =       size
														_a			  =       resample
														_a			  =       do_rescale
														_a			  =       rescale_factor
														_a			  =       do_normalize
														_a			  =       image_mean if image_mean is not None else OPENAI_CLIP_MEAN
														_a			  =       image_std if image_std is not None else OPENAI_CLIP_STD
														_a			  =       do_convert_rgb







							def      __lowerCAmelCase    (						self :						Optional[int]							,    lowerCAmelCase_ :						np.ndarray							,    lowerCAmelCase_ :						Dict[str, int]							,    lowerCAmelCase_ :						PILImageResampling = PILImageResampling.BICUBIC							,    lowerCAmelCase_ :						Optional[Union[str, ChannelDimension]] = None							,    **lowerCAmelCase_ :						str							,    )    ->							np.ndarray:


														"""simple docstring"""


														_a			  =       get_size_dict(lowerCAmelCase_							,    default_to_square=lowerCAmelCase_      )
														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()}'      )
														_a			  =       (size['''height'''], size['''width'''])
														return resize(lowerCAmelCase_							,    size=lowerCAmelCase_							,    resample=lowerCAmelCase_							,    data_format=lowerCAmelCase_							,    **lowerCAmelCase_      )







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


														"""simple docstring"""


														return rescale(lowerCAmelCase_							,    scale=lowerCAmelCase_							,    data_format=lowerCAmelCase_							,    **lowerCAmelCase_      )







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


														"""simple docstring"""


														return normalize(lowerCAmelCase_							,    mean=lowerCAmelCase_							,    std=lowerCAmelCase_							,    data_format=lowerCAmelCase_							,    **lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						int							,    lowerCAmelCase_ :						ImageInput							,    lowerCAmelCase_ :						Optional[bool] = None							,    lowerCAmelCase_ :						Optional[Dict[str, int]] = None							,    lowerCAmelCase_ :						PILImageResampling = None							,    lowerCAmelCase_ :						Optional[bool] = None							,    lowerCAmelCase_ :						Optional[float] = None							,    lowerCAmelCase_ :						Optional[bool] = None							,    lowerCAmelCase_ :						Optional[Union[float, List[float]]] = None							,    lowerCAmelCase_ :						Optional[Union[float, List[float]]] = None							,    lowerCAmelCase_ :						Optional[Union[str, TensorType]] = None							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						ChannelDimension = ChannelDimension.FIRST							,    **lowerCAmelCase_ :						Optional[Any]							,    )    ->							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_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			  =       do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

														_a			  =       size if size is not None else self.size
														_a			  =       get_size_dict(lowerCAmelCase_							,    default_to_square=lowerCAmelCase_      )

														_a			  =       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 or resample is None:
																					raise ValueError('''Size and resample 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.'''      )

														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:
																					_a			  =       [convert_to_rgb(lowerCAmelCase_      ) for image in images]

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

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

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

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

														_a			  =       [to_channel_dimension_format(lowerCAmelCase_							,    lowerCAmelCase_      ) for image in images]

														_a			  =       BatchFeature(data={'''pixel_values''': images}							,    tensor_type=lowerCAmelCase_      )

														return encoded_outputs







'''simple docstring'''


import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


_snake_case   :   str     							=	'\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  ,_a					):







							def      __lowerCAmelCase    (						self :						Any      )    ->							Dict:


														"""simple docstring"""


														_a			  =       load_tool('''text-question-answering'''      )
														self.tool.setup()
														_a			  =       load_tool('''text-question-answering'''							,    remote=lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							Optional[int]:


														"""simple docstring"""


														_a			  =       self.tool(lowerCAmelCase_							,    '''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )







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


														"""simple docstring"""


														_a			  =       self.remote_tool(lowerCAmelCase_							,    '''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )







							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							List[str]:


														"""simple docstring"""


														_a			  =       self.tool(text=lowerCAmelCase_							,    question='''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )







							def      __lowerCAmelCase    (						self :						int      )    ->							List[Any]:


														"""simple docstring"""


														_a			  =       self.remote_tool(text=lowerCAmelCase_							,    question='''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )

