

"""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, prepare_image_inputs


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import DeiTImageProcessor

class        _UpperCamelCase	(						unittest.TestCase	):


  """simple docstring"""





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


         '''simple docstring'''





         __magic_name__			:		Dict        =     size if size is not None else {'''height''': 20, '''width''': 20}
         __magic_name__			:		Optional[Any]        =     crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

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




  def 							_UpperCAmelCase      ( 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        _UpperCamelCase	(						_UpperCAmelCase   ,				unittest.TestCase	):


  """simple docstring"""





  snake_case_        =    DeiTImageProcessor if is_vision_available() else None
  snake_case_        =    True



  def 							_UpperCAmelCase      ( self					: Union[str, Any]      )	->			Any:


         '''simple docstring'''





         __magic_name__			:		Dict        =     DeiTImageProcessingTester(self      )



  @property
  def 							_UpperCAmelCase      ( self					: Union[str, Any]      )	->			Optional[int]:


         '''simple docstring'''





         return self.image_processor_tester.prepare_image_processor_dict()



  def 							_UpperCAmelCase      ( self					: Dict      )	->			Union[str, Any]:


         '''simple docstring'''





         __magic_name__			:		Any        =     self.image_processing_class(**self.image_processor_dict      )
         self.assertTrue(hasattr(snake_case       ,       '''do_resize'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''size'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''do_center_crop'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''center_crop'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''do_normalize'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''image_mean'''      )      )
         self.assertTrue(hasattr(snake_case       ,       '''image_std'''      )      )



  def 							_UpperCAmelCase      ( self					: str      )	->			Optional[int]:


         '''simple docstring'''





         __magic_name__			:		List[str]        =     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}      )

         __magic_name__			:		Optional[Any]        =     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 							_UpperCAmelCase      ( self					: List[str]      )	->			Any:


         '''simple docstring'''





         pass



  def 							_UpperCAmelCase      ( self					: Dict      )	->			str:


         '''simple docstring'''





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

         # Test not batched input
         __magic_name__			:		List[Any]        =     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
         __magic_name__			:		List[Any]        =     image_processing(snake_case       ,       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 							_UpperCAmelCase      ( self					: Tuple      )	->			Optional[Any]:


         '''simple docstring'''





         __magic_name__			:		List[Any]        =     self.image_processing_class(**self.image_processor_dict      )
         # create random numpy tensors
         __magic_name__			:		List[Any]        =     prepare_image_inputs(self.image_processor_tester       ,       equal_resolution=snake_case       ,       numpify=snake_case      )
         for image in image_inputs:
                self.assertIsInstance(snake_case       ,       np.ndarray      )

         # Test not batched input
         __magic_name__			:		Tuple        =     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
         __magic_name__			:		Optional[Any]        =     image_processing(snake_case       ,       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 							_UpperCAmelCase      ( self					: Union[str, Any]      )	->			int:


         '''simple docstring'''





         __magic_name__			:		Union[str, Any]        =     self.image_processing_class(**self.image_processor_dict      )
         # create random PyTorch tensors
         __magic_name__			:		Tuple        =     prepare_image_inputs(self.image_processor_tester       ,       equal_resolution=snake_case       ,       torchify=snake_case      )
         for image in image_inputs:
                self.assertIsInstance(snake_case       ,       torch.Tensor      )

         # Test not batched input
         __magic_name__			:		Optional[int]        =     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
         __magic_name__			:		Union[str, Any]        =     image_processing(snake_case       ,       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__)





