



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


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import VivitImageProcessor




class 							lowerCAmelCase__  (	unittest.TestCase						):







					def __init__(       self      :     int			,		_A      :     List[str]			,		_A      :     List[Any]=7			,		_A      :     List[Any]=3			,		_A      :     Union[str, Any]=10			,		_A      :     Optional[Any]=18			,		_A      :     List[Any]=30			,		_A      :     Union[str, Any]=400			,		_A      :     Optional[Any]=True			,		_A      :     List[Any]=None			,		_A      :     Any=True			,		_A      :     int=[0.5, 0.5, 0.5]			,		_A      :     List[str]=[0.5, 0.5, 0.5]			,		_A      :     int=None			,		):
											A__	:							Tuple						    = size if size is not None else {"shortest_edge": 18}
											A__	:							Any						    = crop_size if crop_size is not None else {"height": 18, "width": 18}

											A__	:							Optional[int]						    = parent
											A__	:							Tuple						    = batch_size
											A__	:							Dict						    = num_channels
											A__	:							Optional[Any]						    = num_frames
											A__	:							Optional[int]						    = image_size
											A__	:							List[Any]						    = min_resolution
											A__	:							Union[str, Any]						    = max_resolution
											A__	:							Optional[Any]						    = do_resize
											A__	:							Optional[int]						    = size
											A__	:							str						    = do_normalize
											A__	:							Optional[Any]						    = image_mean
											A__	:							str						    = image_std
											A__	:							Optional[Any]						    = crop_size







					def  _lowercase			(       self      :     int):
											return {
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											    "do_normalize": self.do_normalize,
											    "do_resize": self.do_resize,
											    "size": self.size,
											    "crop_size": self.crop_size,
											}




@require_torch
@require_vision
class 							lowerCAmelCase__  (	UpperCamelCase					,							unittest.TestCase						):
					__A     :    Tuple           =						VivitImageProcessor if is_vision_available() else None







					def  _lowercase			(       self      :     Any):
											A__	:							List[Any]						    = VivitImageProcessingTester(self)







					@property
					def  _lowercase			(       self      :     List[Any]):
											return self.image_processor_tester.prepare_image_processor_dict()







					def  _lowercase			(       self      :     Tuple):
											A__	:							Tuple						    = self.image_processing_class(**self.image_processor_dict)
											self.assertTrue(hasattr(_A			,		"image_mean"))
											self.assertTrue(hasattr(_A			,		"image_std"))
											self.assertTrue(hasattr(_A			,		"do_normalize"))
											self.assertTrue(hasattr(_A			,		"do_resize"))
											self.assertTrue(hasattr(_A			,		"do_center_crop"))
											self.assertTrue(hasattr(_A			,		"size"))







					def  _lowercase			(       self      :     str):
											A__	:							Any						    = self.image_processing_class.from_dict(self.image_processor_dict)
											self.assertEqual(image_processor.size			,		{"shortest_edge": 18})
											self.assertEqual(image_processor.crop_size			,		{"height": 18, "width": 18})

											A__	:							int						    = 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  _lowercase			(       self      :     Tuple):
											# Initialize image_processing
											A__	:							List[str]						    = self.image_processing_class(**self.image_processor_dict)
											# create random PIL videos
											A__	:							Dict						    = prepare_video_inputs(self.image_processor_tester			,		equal_resolution=_A)
											for video in video_inputs:
																	self.assertIsInstance(_A			,		_A)
																	self.assertIsInstance(video[0]			,		Image.Image)

											# Test not batched input
											A__	:							int						    = image_processing(video_inputs[0]			,		return_tensors="pt").pixel_values
											self.assertEqual(
											    encoded_videos.shape			,		(
											        1,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )			,		)

											# Test batched
											A__	:							int						    = image_processing(_A			,		return_tensors="pt").pixel_values
											self.assertEqual(
											    encoded_videos.shape			,		(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )			,		)







					def  _lowercase			(       self      :     Optional[Any]):
											# Initialize image_processing
											A__	:							Any						    = self.image_processing_class(**self.image_processor_dict)
											# create random numpy tensors
											A__	:							Optional[Any]						    = prepare_video_inputs(self.image_processor_tester			,		equal_resolution=_A			,		numpify=_A)
											for video in video_inputs:
																	self.assertIsInstance(_A			,		_A)
																	self.assertIsInstance(video[0]			,		np.ndarray)

											# Test not batched input
											A__	:							Tuple						    = image_processing(video_inputs[0]			,		return_tensors="pt").pixel_values
											self.assertEqual(
											    encoded_videos.shape			,		(
											        1,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )			,		)

											# Test batched
											A__	:							List[Any]						    = image_processing(_A			,		return_tensors="pt").pixel_values
											self.assertEqual(
											    encoded_videos.shape			,		(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )			,		)







					def  _lowercase			(       self      :     List[Any]):
											# Initialize image_processing
											A__	:							Dict						    = self.image_processing_class(**self.image_processor_dict)
											# create random PyTorch tensors
											A__	:							str						    = prepare_video_inputs(self.image_processor_tester			,		equal_resolution=_A			,		torchify=_A)
											for video in video_inputs:
																	self.assertIsInstance(_A			,		_A)
																	self.assertIsInstance(video[0]			,		torch.Tensor)

											# Test not batched input
											A__	:							List[str]						    = image_processing(video_inputs[0]			,		return_tensors="pt").pixel_values
											self.assertEqual(
											    encoded_videos.shape			,		(
											        1,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )			,		)

											# Test batched
											A__	:							Any						    = image_processing(_A			,		return_tensors="pt").pixel_values
											self.assertEqual(
											    encoded_videos.shape			,		(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )			,		)




import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin




class 							lowerCAmelCase__  (	unittest.TestCase					,							UpperCamelCase						):







					def  _lowercase			(       self      :     List[Any]):
											A__	:							Optional[Any]						    = load_tool("text-classification")
											self.tool.setup()
											A__	:							Any						    = load_tool("text-classification"			,		remote=_A)







					def  _lowercase			(       self      :     List[Any]):
											A__	:							Optional[Any]						    = self.tool("That's quite cool"			,		["positive", "negative"])
											self.assertEqual(_A			,		"positive")







					def  _lowercase			(       self      :     List[str]):
											A__	:							Any						    = self.remote_tool("That's quite cool"			,		["positive", "negative"])
											self.assertEqual(_A			,		"positive")







					def  _lowercase			(       self      :     Optional[Any]):
											A__	:							List[str]						    = self.tool(text="That's quite cool"			,		labels=["positive", "negative"])
											self.assertEqual(_A			,		"positive")







					def  _lowercase			(       self      :     Tuple):
											A__	:							Union[str, Any]						    = self.remote_tool(text="That's quite cool"			,		labels=["positive", "negative"])
											self.assertEqual(_A			,		"positive")