




"""simple docstring"""




import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
					import torch

if is_vision_available():
					from PIL import Image

					from transformers import ChineseCLIPImageProcessor






class        __magic_name__				(			unittest.TestCase							):






				'''simple docstring'''





				def __init__(			self						,					_a						,					_a=7						,					_a=3						,					_a=18						,					_a=30						,					_a=400						,					_a=True						,					_a=None						,					_a=True						,					_a=None						,					_a=True						,					_a=[0.48_145_466, 0.4_578_275, 0.40_821_073]						,					_a=[0.26_862_954, 0.26_130_258, 0.27_577_711]						,					_a=True						,					):





							"""simple docstring"""
							lowerCamelCase      =   size if size is not None else {"""height""": 224, """width""": 224}
							lowerCamelCase      =   crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
							lowerCamelCase      =   parent
							lowerCamelCase      =   batch_size
							lowerCamelCase      =   num_channels
							lowerCamelCase      =   image_size
							lowerCamelCase      =   min_resolution
							lowerCamelCase      =   max_resolution
							lowerCamelCase      =   do_resize
							lowerCamelCase      =   size
							lowerCamelCase      =   do_center_crop
							lowerCamelCase      =   crop_size
							lowerCamelCase      =   do_normalize
							lowerCamelCase      =   image_mean
							lowerCamelCase      =   image_std
							lowerCamelCase      =   do_convert_rgb





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							return {
							    "do_resize": self.do_resize,
							    "size": self.size,
							    "do_center_crop": self.do_center_crop,
							    "crop_size": self.crop_size,
							    "do_normalize": self.do_normalize,
							    "image_mean": self.image_mean,
							    "image_std": self.image_std,
							    "do_convert_rgb": self.do_convert_rgb,
							}





				def   _lowerCAmelCase							(			self						,					_a=False						,					_a=False						,					_a=False					):





							"""simple docstring"""
							assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

							if equal_resolution:
										lowerCamelCase      =   []
										for i in range(self.batch_size					):
													image_inputs.append(
													    np.random.randint(
													        255						,					size=(self.num_channels, self.max_resolution, self.max_resolution)						,					dtype=np.uinta					)					)
							else:
										lowerCamelCase      =   []
										for i in range(self.batch_size					):
													lowerCamelCase ,  lowerCamelCase      =   np.random.choice(np.arange(self.min_resolution						,					self.max_resolution					)						,					2					)
													image_inputs.append(np.random.randint(255						,					size=(self.num_channels, width, height)						,					dtype=np.uinta					)					)

							if not numpify and not torchify:
										# PIL expects the channel dimension as last dimension
										lowerCamelCase      =   [Image.fromarray(np.moveaxis(_a						,					0						,					-1					)					) for x in image_inputs]

							if torchify:
										lowerCamelCase      =   [torch.from_numpy(_a					) for x in image_inputs]

							return image_inputs






@require_torch
@require_vision
class        __magic_name__				(			UpperCAmelCase__		,   unittest.TestCase							):






				'''simple docstring'''
				__UpperCamelCase         =		ChineseCLIPImageProcessor if is_vision_available() else None





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   ChineseCLIPImageProcessingTester(self						,					do_center_crop=_a					)





				@property
				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							return self.image_processor_tester.prepare_image_processor_dict()





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   self.image_processing_class(**self.image_processor_dict					)
							self.assertTrue(hasattr(_a						,					"""do_resize"""					)					)
							self.assertTrue(hasattr(_a						,					"""size"""					)					)
							self.assertTrue(hasattr(_a						,					"""do_center_crop"""					)					)
							self.assertTrue(hasattr(_a						,					"""center_crop"""					)					)
							self.assertTrue(hasattr(_a						,					"""do_normalize"""					)					)
							self.assertTrue(hasattr(_a						,					"""image_mean"""					)					)
							self.assertTrue(hasattr(_a						,					"""image_std"""					)					)
							self.assertTrue(hasattr(_a						,					"""do_convert_rgb"""					)					)





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   self.image_processing_class.from_dict(self.image_processor_dict					)
							self.assertEqual(image_processor.size						,					{"""height""": 224, """width""": 224}					)
							self.assertEqual(image_processor.crop_size						,					{"""height""": 18, """width""": 18}					)

							lowerCamelCase      =   self.image_processing_class.from_dict(self.image_processor_dict						,					size=42						,					crop_size=84					)
							self.assertEqual(image_processor.size						,					{"""shortest_edge""": 42}					)
							self.assertEqual(image_processor.crop_size						,					{"""height""": 84, """width""": 84}					)





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							pass





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							# Initialize image_processing
							lowerCamelCase      =   self.image_processing_class(**self.image_processor_dict					)
							# create random PIL images
							lowerCamelCase      =   self.image_processor_tester.prepare_inputs(equal_resolution=_a					)
							for image in image_inputs:
										self.assertIsInstance(_a						,					Image.Image					)

							# Test not batched input
							lowerCamelCase      =   image_processing(image_inputs[0]						,					return_tensors="""pt"""					).pixel_values
							self.assertEqual(
							    encoded_images.shape						,					(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )						,					)

							# Test batched
							lowerCamelCase      =   image_processing(_a						,					return_tensors="""pt"""					).pixel_values
							self.assertEqual(
							    encoded_images.shape						,					(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )						,					)





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							# Initialize image_processing
							lowerCamelCase      =   self.image_processing_class(**self.image_processor_dict					)
							# create random numpy tensors
							lowerCamelCase      =   self.image_processor_tester.prepare_inputs(equal_resolution=_a						,					numpify=_a					)
							for image in image_inputs:
										self.assertIsInstance(_a						,					np.ndarray					)

							# Test not batched input
							lowerCamelCase      =   image_processing(image_inputs[0]						,					return_tensors="""pt"""					).pixel_values
							self.assertEqual(
							    encoded_images.shape						,					(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )						,					)

							# Test batched
							lowerCamelCase      =   image_processing(_a						,					return_tensors="""pt"""					).pixel_values
							self.assertEqual(
							    encoded_images.shape						,					(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )						,					)





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							# Initialize image_processing
							lowerCamelCase      =   self.image_processing_class(**self.image_processor_dict					)
							# create random PyTorch tensors
							lowerCamelCase      =   self.image_processor_tester.prepare_inputs(equal_resolution=_a						,					torchify=_a					)
							for image in image_inputs:
										self.assertIsInstance(_a						,					torch.Tensor					)

							# Test not batched input
							lowerCamelCase      =   image_processing(image_inputs[0]						,					return_tensors="""pt"""					).pixel_values
							self.assertEqual(
							    encoded_images.shape						,					(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )						,					)

							# Test batched
							lowerCamelCase      =   image_processing(_a						,					return_tensors="""pt"""					).pixel_values
							self.assertEqual(
							    encoded_images.shape						,					(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )						,					)






@require_torch
@require_vision
class        __magic_name__				(			UpperCAmelCase__		,   unittest.TestCase							):






				'''simple docstring'''
				__UpperCamelCase         =		ChineseCLIPImageProcessor if is_vision_available() else None





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   ChineseCLIPImageProcessingTester(self						,					num_channels=4						,					do_center_crop=_a					)
							lowerCamelCase      =   3





				@property
				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							return self.image_processor_tester.prepare_image_processor_dict()





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   self.image_processing_class(**self.image_processor_dict					)
							self.assertTrue(hasattr(_a						,					"""do_resize"""					)					)
							self.assertTrue(hasattr(_a						,					"""size"""					)					)
							self.assertTrue(hasattr(_a						,					"""do_center_crop"""					)					)
							self.assertTrue(hasattr(_a						,					"""center_crop"""					)					)
							self.assertTrue(hasattr(_a						,					"""do_normalize"""					)					)
							self.assertTrue(hasattr(_a						,					"""image_mean"""					)					)
							self.assertTrue(hasattr(_a						,					"""image_std"""					)					)
							self.assertTrue(hasattr(_a						,					"""do_convert_rgb"""					)					)





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							pass





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							# Initialize image_processing
							lowerCamelCase      =   self.image_processing_class(**self.image_processor_dict					)
							# create random PIL images
							lowerCamelCase      =   self.image_processor_tester.prepare_inputs(equal_resolution=_a					)
							for image in image_inputs:
										self.assertIsInstance(_a						,					Image.Image					)

							# Test not batched input
							lowerCamelCase      =   image_processing(image_inputs[0]						,					return_tensors="""pt"""					).pixel_values
							self.assertEqual(
							    encoded_images.shape						,					(
							        1,
							        self.expected_encoded_image_num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )						,					)

							# Test batched
							lowerCamelCase      =   image_processing(_a						,					return_tensors="""pt"""					).pixel_values
							self.assertEqual(
							    encoded_images.shape						,					(
							        self.image_processor_tester.batch_size,
							        self.expected_encoded_image_num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )						,					)









"""simple docstring"""




import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin






class        __magic_name__				(			unittest.TestCase		,   UpperCAmelCase__							):






				'''simple docstring'''





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   load_tool("""text-classification"""					)
							self.tool.setup()
							lowerCamelCase      =   load_tool("""text-classification"""						,					remote=_a					)





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   self.tool("""That's quite cool"""						,					["""positive""", """negative"""]					)
							self.assertEqual(_a						,					"""positive"""					)





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   self.remote_tool("""That's quite cool"""						,					["""positive""", """negative"""]					)
							self.assertEqual(_a						,					"""positive"""					)





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   self.tool(text="""That's quite cool"""						,					labels=["""positive""", """negative"""]					)
							self.assertEqual(_a						,					"""positive"""					)





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   self.remote_tool(text="""That's quite cool"""						,					labels=["""positive""", """negative"""]					)
							self.assertEqual(_a						,					"""positive"""					)



