






"""simple docstring"""



import unittest

import numpy as np
import PIL
import torch

from diffusers.image_processor import VaeImageProcessor






class 				__SCREAMING_SNAKE_CASE    (					unittest.TestCase		):


							@property
							def     _UpperCamelCase							(      self   :    int				):
													'''simple docstring'''





													A__    :	Dict			=	1
													A__    :	Dict			=	3
													A__    :	Dict			=	8
													A__    :	Optional[int]			=	8

													A__    :	Any			=	torch.rand((batch_size, num_channels, height, width)				)

													return sample


							def     _UpperCamelCase							(      self   :    Any      ,     snake_case   :    int				):
													'''simple docstring'''





													if isinstance(image[0]      ,     PIL.Image.Image				):
																			return np.stack([np.array(snake_case				) for i in image]      ,     axis=0				)
													elif isinstance(snake_case      ,     torch.Tensor				):
																			return image.cpu().numpy().transpose(0      ,     2      ,     3      ,     1				)
													return image


							def     _UpperCamelCase							(      self   :    Tuple				):
													'''simple docstring'''





													A__    :	int			=	VaeImageProcessor(do_resize=snake_case      ,     do_normalize=snake_case				)

													A__    :	int			=	self.dummy_sample
													A__    :	Optional[Any]			=	self.to_np(snake_case				)

													for output_type in ["pt", "np", "pil"]:
																			A__    :	Dict			=	image_processor.postprocess(
																			    image_processor.preprocess(snake_case				)      ,     output_type=snake_case      ,     )
																			A__    :	List[str]			=	self.to_np(snake_case				)
																			A__    :	Any			=	(input_np * 255).round() if output_type == """pil""" else input_np
																			assert (
																			    np.abs(in_np - out_np				).max() < 1e-6
																			), F'decoded output does not match input for output_type {output_type}'


							def     _UpperCamelCase							(      self   :    Any				):
													'''simple docstring'''





													A__    :	Any			=	VaeImageProcessor(do_resize=snake_case      ,     do_normalize=snake_case				)
													A__    :	Optional[int]			=	self.dummy_sample.cpu().numpy().transpose(0      ,     2      ,     3      ,     1				)

													for output_type in ["pt", "np", "pil"]:
																			A__    :	Any			=	image_processor.postprocess(image_processor.preprocess(snake_case				)      ,     output_type=snake_case				)

																			A__    :	Optional[Any]			=	self.to_np(snake_case				)
																			A__    :	Tuple			=	(input_np * 255).round() if output_type == """pil""" else input_np
																			assert (
																			    np.abs(in_np - out_np				).max() < 1e-6
																			), F'decoded output does not match input for output_type {output_type}'


							def     _UpperCamelCase							(      self   :    List[Any]				):
													'''simple docstring'''





													A__    :	Union[str, Any]			=	VaeImageProcessor(do_resize=snake_case      ,     do_normalize=snake_case				)

													A__    :	Union[str, Any]			=	self.dummy_sample.cpu().numpy().transpose(0      ,     2      ,     3      ,     1				)
													A__    :	Union[str, Any]			=	image_processor.numpy_to_pil(snake_case				)

													for output_type in ["pt", "np", "pil"]:
																			A__    :	List[str]			=	image_processor.postprocess(image_processor.preprocess(snake_case				)      ,     output_type=snake_case				)
																			for i, o in zip(snake_case      ,     snake_case				):
																									A__    :	Tuple			=	np.array(snake_case				)
																									A__    :	Dict			=	self.to_np(snake_case				) if output_type == """pil""" else (self.to_np(snake_case				) * 255).round()
																									assert (
																									    np.abs(in_np - out_np				).max() < 1e-6
																									), F'decoded output does not match input for output_type {output_type}'


							def     _UpperCamelCase							(      self   :    Tuple				):
													'''simple docstring'''





													A__    :	Any			=	VaeImageProcessor(do_resize=snake_case      ,     do_normalize=snake_case				)

													A__    :	str			=	self.dummy_sample
													A__    :	Optional[int]			=	input_pt_ad.squeeze(0				)

													A__    :	Dict			=	image_processor.postprocess(
													    image_processor.preprocess(snake_case				)      ,     output_type="""np"""      ,     )
													A__    :	List[Any]			=	image_processor.postprocess(
													    image_processor.preprocess(snake_case				)      ,     output_type="""np"""      ,     )

													A__    :	Optional[Any]			=	self.to_np(self.dummy_sample				)
													A__    :	int			=	input_np_ad.squeeze(0				)

													A__    :	Optional[int]			=	image_processor.postprocess(
													    image_processor.preprocess(snake_case				)      ,     output_type="""np"""      ,     )
													A__    :	Dict			=	image_processor.postprocess(
													    image_processor.preprocess(snake_case				)      ,     output_type="""np"""      ,     )

													assert np.abs(out_pt_ad - out_pt_ad				).max() < 1e-6
													assert np.abs(out_np_ad - out_np_ad				).max() < 1e-6


							def     _UpperCamelCase							(      self   :    int				):
													'''simple docstring'''





													A__    :	Dict			=	VaeImageProcessor(do_resize=snake_case      ,     do_normalize=snake_case				)

													A__    :	Optional[int]			=	self.dummy_sample
													A__    :	Optional[Any]			=	list(snake_case				)

													A__    :	Optional[int]			=	image_processor.postprocess(
													    image_processor.preprocess(snake_case				)      ,     output_type="""np"""      ,     )

													A__    :	List[Any]			=	image_processor.postprocess(
													    image_processor.preprocess(snake_case				)      ,     output_type="""np"""      ,     )

													A__    :	Dict			=	self.to_np(self.dummy_sample				)
													list(snake_case				)

													A__    :	Optional[Any]			=	image_processor.postprocess(
													    image_processor.preprocess(snake_case				)      ,     output_type="""np"""      ,     )

													A__    :	Dict			=	image_processor.postprocess(
													    image_processor.preprocess(snake_case				)      ,     output_type="""np"""      ,     )

													assert np.abs(out_pt_ad - out_pt_list				).max() < 1e-6
													assert np.abs(out_np_ad - out_np_list				).max() < 1e-6














"""simple docstring"""



import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


A_     =				'''
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 				__SCREAMING_SNAKE_CASE    (					unittest.TestCase							,		UpperCamelCase		):


							def     _UpperCamelCase							(      self   :    int				):
													'''simple docstring'''





													A__    :	Any			=	load_tool("""summarization"""				)
													self.tool.setup()
													A__    :	List[Any]			=	load_tool("""summarization"""      ,     remote=snake_case				)


							def     _UpperCamelCase							(      self   :    Any				):
													'''simple docstring'''





													A__    :	List[Any]			=	self.tool(snake_case				)
													self.assertEqual(
													    snake_case      ,     """Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. 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. In 2022, the workshop concluded with the announcement of BLOOM."""      ,     )


							def     _UpperCamelCase							(      self   :    Optional[int]				):
													'''simple docstring'''





													A__    :	List[str]			=	self.remote_tool(snake_case				)
													self.assertEqual(
													    snake_case      ,     """Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. 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. In 2022, the workshop concluded with the announcement of BLOOM."""      ,     )


							def     _UpperCamelCase							(      self   :    Dict				):
													'''simple docstring'''





													A__    :	List[Any]			=	self.tool(text=snake_case				)
													self.assertEqual(
													    snake_case      ,     """Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. 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. In 2022, the workshop concluded with the announcement of BLOOM."""      ,     )


							def     _UpperCamelCase							(      self   :    Union[str, Any]				):
													'''simple docstring'''





													A__    :	Optional[int]			=	self.remote_tool(text=snake_case				)
													self.assertEqual(
													    snake_case      ,     """Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. 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. In 2022, the workshop concluded with the announcement of BLOOM."""      ,     )






