
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 TvltImageProcessor




def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: int       ,				SCREAMING_SNAKE_CASE			: Tuple=10       ,				SCREAMING_SNAKE_CASE			: Union[str, Any]=10       ,				SCREAMING_SNAKE_CASE			: Optional[Any]=False       ,				SCREAMING_SNAKE_CASE			: Optional[int]=False     )	->		Union[str, Any]:
				__lowercase								=   []
				for i in range(image_processor_tester.num_frames     ):
								video.append(np.random.randint(255       ,				size=(image_processor_tester.num_channels, width, height)       ,				dtype=np.uinta     )     )

				if not numpify and not torchify:
								# PIL expects the channel dimension as last dimension
								__lowercase								=   [Image.fromarray(np.moveaxis(SCREAMING_SNAKE_CASE       ,				0       ,				-1     )     ) for frame in video]

				if torchify:
								__lowercase								=   [torch.from_numpy(SCREAMING_SNAKE_CASE     ) for frame in video]

				return video




def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: Optional[Any]       ,				SCREAMING_SNAKE_CASE			: Optional[Any]=False       ,				SCREAMING_SNAKE_CASE			: Dict=False       ,				SCREAMING_SNAKE_CASE			: List[Any]=False     )	->		Dict:
				assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

				__lowercase								=   []
				for i in range(image_processor_tester.batch_size     ):
								if equal_resolution:
												__lowercase								=   __lowercase								=   image_processor_tester.max_resolution
								else:
												__lowercase						,   __lowercase								=   np.random.choice(
												    np.arange(image_processor_tester.min_resolution       ,				image_processor_tester.max_resolution     )       ,				2     )
												__lowercase								=   prepare_video(
												    image_processor_tester=SCREAMING_SNAKE_CASE       ,				width=SCREAMING_SNAKE_CASE       ,				height=SCREAMING_SNAKE_CASE       ,				numpify=SCREAMING_SNAKE_CASE       ,				torchify=SCREAMING_SNAKE_CASE       ,				)
								video_inputs.append(SCREAMING_SNAKE_CASE     )

				return video_inputs
class       A__  (		unittest.TestCase							):





							def __init__(					self    :  Optional[Any]	,					_UpperCAmelCase    :  List[str]	,					_UpperCAmelCase    :  Tuple=7	,					_UpperCAmelCase    :  Optional[int]=3	,					_UpperCAmelCase    :  Tuple=4	,					_UpperCAmelCase    :  List[Any]=18	,					_UpperCAmelCase    :  Dict=30	,					_UpperCAmelCase    :  Dict=4_00	,					_UpperCAmelCase    :  int=True	,					_UpperCAmelCase    :  Optional[Any]=None	,					_UpperCAmelCase    :  List[Any]=True	,					_UpperCAmelCase    :  Dict=[0.5, 0.5, 0.5]	,					_UpperCAmelCase    :  Tuple=[0.5, 0.5, 0.5]	,					_UpperCAmelCase    :  Dict=True	,					_UpperCAmelCase    :  List[str]=None	,					)		->						List[Any]:



											"""simple docstring"""


											__lowercase								=   size if size is not None else {'shortest_edge': 18}
											__lowercase								=   crop_size if crop_size is not None else {'height': 18, 'width': 18}

											__lowercase								=   parent
											__lowercase								=   batch_size
											__lowercase								=   num_channels
											__lowercase								=   num_frames
											__lowercase								=   image_size
											__lowercase								=   min_resolution
											__lowercase								=   max_resolution
											__lowercase								=   do_resize
											__lowercase								=   size
											__lowercase								=   do_normalize
											__lowercase								=   image_mean
											__lowercase								=   image_std
											__lowercase								=   do_center_crop
											__lowercase								=   crop_size





							def      a__					(					self    :  List[str]							)		->						str:



											"""simple docstring"""


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






@require_torch
@require_vision
class       A__  (		lowerCAmelCase__       ,		unittest.TestCase							):
							lowerCAmelCase__						:		List[Any]            =				TvltImageProcessor if is_vision_available() else None





							def      a__					(					self    :  str							)		->						int:



											"""simple docstring"""


											__lowercase								=   TvltImageProcessorTester(self							)





							@property
							def      a__					(					self    :  List[str]							)		->						List[str]:



											"""simple docstring"""


											return self.image_processor_tester.prepare_image_processor_dict()





							def      a__					(					self    :  int							)		->						str:



											"""simple docstring"""


											__lowercase								=   self.image_processing_class(**self.image_processor_dict							)
											self.assertTrue(hasattr(_UpperCAmelCase	,					'image_mean'							)							)
											self.assertTrue(hasattr(_UpperCAmelCase	,					'image_std'							)							)
											self.assertTrue(hasattr(_UpperCAmelCase	,					'do_normalize'							)							)
											self.assertTrue(hasattr(_UpperCAmelCase	,					'do_resize'							)							)
											self.assertTrue(hasattr(_UpperCAmelCase	,					'do_center_crop'							)							)
											self.assertTrue(hasattr(_UpperCAmelCase	,					'size'							)							)





							def      a__					(					self    :  int							)		->						Any:



											"""simple docstring"""


											__lowercase								=   self.image_processing_class(**self.image_processor_dict							)
											# create random PIL videos
											__lowercase								=   prepare_video_inputs(self.image_processor_tester	,					equal_resolution=_UpperCAmelCase							)
											for video in video_inputs:
															self.assertIsInstance(_UpperCAmelCase	,					_UpperCAmelCase							)
															self.assertIsInstance(video[0]	,					Image.Image							)

											# Test not batched input
											__lowercase								=   image_processor(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
											__lowercase								=   image_processor(_UpperCAmelCase	,					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      a__					(					self    :  List[str]							)		->						List[str]:



											"""simple docstring"""


											__lowercase								=   self.image_processing_class(**self.image_processor_dict							)
											# create random numpy tensors
											__lowercase								=   prepare_video_inputs(self.image_processor_tester	,					equal_resolution=_UpperCAmelCase	,					numpify=_UpperCAmelCase							)
											for video in video_inputs:
															self.assertIsInstance(_UpperCAmelCase	,					_UpperCAmelCase							)
															self.assertIsInstance(video[0]	,					np.ndarray							)

											# Test not batched input
											__lowercase								=   image_processor(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
											__lowercase								=   image_processor(_UpperCAmelCase	,					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      a__					(					self    :  Tuple							)		->						Tuple:



											"""simple docstring"""


											__lowercase								=   self.image_processing_class(**self.image_processor_dict							)
											# create random PyTorch tensors
											__lowercase								=   prepare_video_inputs(self.image_processor_tester	,					equal_resolution=_UpperCAmelCase	,					torchify=_UpperCAmelCase							)
											for video in video_inputs:
															self.assertIsInstance(_UpperCAmelCase	,					_UpperCAmelCase							)
															self.assertIsInstance(video[0]	,					torch.Tensor							)

											# Test not batched input
											__lowercase								=   image_processor(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
											__lowercase								=   image_processor(_UpperCAmelCase	,					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'],
											    )	,					)







# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ..utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


SCREAMING_SNAKE_CASE__				=							{
    """agents""": ["""Agent""", """AzureOpenAiAgent""", """HfAgent""", """LocalAgent""", """OpenAiAgent"""],
    """base""": ["""PipelineTool""", """RemoteTool""", """Tool""", """launch_gradio_demo""", """load_tool"""],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__				=							["""DocumentQuestionAnsweringTool"""]
							SCREAMING_SNAKE_CASE__				=							["""ImageCaptioningTool"""]
							SCREAMING_SNAKE_CASE__				=							["""ImageQuestionAnsweringTool"""]
							SCREAMING_SNAKE_CASE__				=							["""ImageSegmentationTool"""]
							SCREAMING_SNAKE_CASE__				=							["""SpeechToTextTool"""]
							SCREAMING_SNAKE_CASE__				=							["""TextClassificationTool"""]
							SCREAMING_SNAKE_CASE__				=							["""TextQuestionAnsweringTool"""]
							SCREAMING_SNAKE_CASE__				=							["""TextSummarizationTool"""]
							SCREAMING_SNAKE_CASE__				=							["""TextToSpeechTool"""]
							SCREAMING_SNAKE_CASE__				=							["""TranslationTool"""]

if TYPE_CHECKING:
							from .agents import Agent, AzureOpenAiAgent, HfAgent, LocalAgent, OpenAiAgent
							from .base import PipelineTool, RemoteTool, Tool, launch_gradio_demo, load_tool

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .document_question_answering import DocumentQuestionAnsweringTool
														from .image_captioning import ImageCaptioningTool
														from .image_question_answering import ImageQuestionAnsweringTool
														from .image_segmentation import ImageSegmentationTool
														from .speech_to_text import SpeechToTextTool
														from .text_classification import TextClassificationTool
														from .text_question_answering import TextQuestionAnsweringTool
														from .text_summarization import TextSummarizationTool
														from .text_to_speech import TextToSpeechTool
														from .translation import TranslationTool
else:
							import sys

							SCREAMING_SNAKE_CASE__				=							_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





