



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_image_inputs


if is_torch_available():
			import torch

if is_vision_available():
			from PIL import Image

			from transformers import DeiTImageProcessor
class       _lowerCAmelCase (			unittest.TestCase      ):






			"""simple docstring"""





			def __init__(					self						:							Optional[Any]      ,  lowercase						:							Dict      ,  lowercase						:							List[str]=7      ,  lowercase						:							List[Any]=3      ,  lowercase						:							Any=18      ,  lowercase						:							str=30      ,  lowercase						:							Tuple=400      ,  lowercase						:							List[Any]=True      ,  lowercase						:							Union[str, Any]=None      ,  lowercase						:							List[Any]=True      ,  lowercase						:							Dict=None      ,  lowercase						:							Tuple=True      ,  lowercase						:							Any=[0.5, 0.5, 0.5]      ,  lowercase						:							Optional[int]=[0.5, 0.5, 0.5]      ,  )    ->       List[str]:
									"""simple docstring"""







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

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







			def 		snake_case__      (					self						:							Optional[Any] )    ->       Any:
									"""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,
									}





@require_torch
@require_vision
class       _lowerCAmelCase (			_UpperCAmelCase     ,       unittest.TestCase      ):






			"""simple docstring"""





			lowercase__   :	List[str]  			=      DeiTImageProcessor if is_vision_available() else None
			lowercase__   :	Optional[Any]  			=      True





			def 		snake_case__      (					self						:							Union[str, Any] )    ->       Any:
									"""simple docstring"""







									__lowercase											=					DeiTImageProcessingTester(self )





			@property
			def 		snake_case__      (					self						:							Union[str, Any] )    ->       Optional[int]:
									"""simple docstring"""







									return self.image_processor_tester.prepare_image_processor_dict()





			def 		snake_case__      (					self						:							Dict )    ->       Union[str, Any]:
									"""simple docstring"""







									__lowercase											=					self.image_processing_class(**self.image_processor_dict )
									self.assertTrue(hasattr(lowercase      ,  """do_resize""" ) )
									self.assertTrue(hasattr(lowercase      ,  """size""" ) )
									self.assertTrue(hasattr(lowercase      ,  """do_center_crop""" ) )
									self.assertTrue(hasattr(lowercase      ,  """center_crop""" ) )
									self.assertTrue(hasattr(lowercase      ,  """do_normalize""" ) )
									self.assertTrue(hasattr(lowercase      ,  """image_mean""" ) )
									self.assertTrue(hasattr(lowercase      ,  """image_std""" ) )





			def 		snake_case__      (					self						:							str )    ->       Optional[int]:
									"""simple docstring"""







									__lowercase											=					self.image_processing_class.from_dict(self.image_processor_dict )
									self.assertEqual(image_processor.size      ,  {"""height""": 20, """width""": 20} )
									self.assertEqual(image_processor.crop_size      ,  {"""height""": 18, """width""": 18} )

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





			def 		snake_case__      (					self						:							List[str] )    ->       Any:
									"""simple docstring"""







									pass





			def 		snake_case__      (					self						:							Dict )    ->       str:
									"""simple docstring"""







									__lowercase											=					self.image_processing_class(**self.image_processor_dict )
									# create random PIL images
									__lowercase											=					prepare_image_inputs(self.image_processor_tester      ,  equal_resolution=lowercase )
									for image in image_inputs:
															self.assertIsInstance(lowercase      ,  Image.Image )

									# Test not batched input
									__lowercase											=					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
									__lowercase											=					image_processing(lowercase      ,  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 		snake_case__      (					self						:							Tuple )    ->       Optional[Any]:
									"""simple docstring"""







									__lowercase											=					self.image_processing_class(**self.image_processor_dict )
									# create random numpy tensors
									__lowercase											=					prepare_image_inputs(self.image_processor_tester      ,  equal_resolution=lowercase      ,  numpify=lowercase )
									for image in image_inputs:
															self.assertIsInstance(lowercase      ,  np.ndarray )

									# Test not batched input
									__lowercase											=					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
									__lowercase											=					image_processing(lowercase      ,  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 		snake_case__      (					self						:							Union[str, Any] )    ->       int:
									"""simple docstring"""







									__lowercase											=					self.image_processing_class(**self.image_processor_dict )
									# create random PyTorch tensors
									__lowercase											=					prepare_image_inputs(self.image_processor_tester      ,  equal_resolution=lowercase      ,  torchify=lowercase )
									for image in image_inputs:
															self.assertIsInstance(lowercase      ,  torch.Tensor )

									# Test not batched input
									__lowercase											=					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
									__lowercase											=					image_processing(lowercase      ,  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"""],
									    )      ,  )










# 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,
)


UpperCamelCase__			=    {
    "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:
			UpperCamelCase__			=    ["DocumentQuestionAnsweringTool"]
			UpperCamelCase__			=    ["ImageCaptioningTool"]
			UpperCamelCase__			=    ["ImageQuestionAnsweringTool"]
			UpperCamelCase__			=    ["ImageSegmentationTool"]
			UpperCamelCase__			=    ["SpeechToTextTool"]
			UpperCamelCase__			=    ["TextClassificationTool"]
			UpperCamelCase__			=    ["TextQuestionAnsweringTool"]
			UpperCamelCase__			=    ["TextSummarizationTool"]
			UpperCamelCase__			=    ["TextToSpeechTool"]
			UpperCamelCase__			=    ["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

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





