"""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 MobileNetVaImageProcessor


class       _lowercase		( unittest.TestCase	):

				def __init__(  self							:     Dict							,     _lowercase							:     int							,     _lowercase							:     Dict=7							,     _lowercase							:     List[str]=3							,     _lowercase							:     Dict=1_8							,     _lowercase							:     List[str]=3_0							,     _lowercase							:     List[Any]=4_0_0							,     _lowercase							:     str=True							,     _lowercase							:     str=None							,     _lowercase							:     Union[str, Any]=True							,     _lowercase							:     Optional[int]=None							,     ):


										'''simple docstring'''
										UpperCAmelCase__       						=		size if size is not None else {"""shortest_edge""": 2_0}
										UpperCAmelCase__       						=		crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}
										UpperCAmelCase__       						=		parent
										UpperCAmelCase__       						=		batch_size
										UpperCAmelCase__       						=		num_channels
										UpperCAmelCase__       						=		image_size
										UpperCAmelCase__       						=		min_resolution
										UpperCAmelCase__       						=		max_resolution
										UpperCAmelCase__       						=		do_resize
										UpperCAmelCase__       						=		size
										UpperCAmelCase__       						=		do_center_crop
										UpperCAmelCase__       						=		crop_size

				def 							A			(  self							:     List[Any]  ):


										'''simple docstring'''
										return {
										    "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       _lowercase		( __lowerCamelCase   ,   unittest.TestCase	):
				lowerCamelCase__							=							MobileNetVaImageProcessor if is_vision_available() else None

				def 							A			(  self							:     Dict  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		MobileNetVaImageProcessingTester(self  )

				@property
				def 							A			(  self							:     Dict  ):


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

				def 							A			(  self							:     Any  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		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"""  )  )

				def 							A			(  self							:     Tuple  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		self.image_processing_class.from_dict(self.image_processor_dict  )
										self.assertEqual(image_processor.size							,     {"""shortest_edge""": 2_0}  )
										self.assertEqual(image_processor.crop_size							,     {"""height""": 1_8, """width""": 1_8}  )

										UpperCAmelCase__       						=		self.image_processing_class.from_dict(self.image_processor_dict							,     size=4_2							,     crop_size=8_4  )
										self.assertEqual(image_processor.size							,     {"""shortest_edge""": 4_2}  )
										self.assertEqual(image_processor.crop_size							,     {"""height""": 8_4, """width""": 8_4}  )

				def 							A			(  self							:     str  ):


										'''simple docstring'''
										pass

				def 							A			(  self							:     List[Any]  ):


										'''simple docstring'''
										# Initialize image_processing
										UpperCAmelCase__       						=		self.image_processing_class(**self.image_processor_dict  )
										# create random PIL images
										UpperCAmelCase__       						=		prepare_image_inputs(self.image_processor_tester							,     equal_resolution=_lowercase  )
										for image in image_inputs:
																self.assertIsInstance(_lowercase							,     Image.Image  )

										# Test not batched input
										UpperCAmelCase__       						=		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
										UpperCAmelCase__       						=		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 							A			(  self							:     Optional[int]  ):


										'''simple docstring'''
										# Initialize image_processing
										UpperCAmelCase__       						=		self.image_processing_class(**self.image_processor_dict  )
										# create random numpy tensors
										UpperCAmelCase__       						=		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
										UpperCAmelCase__       						=		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
										UpperCAmelCase__       						=		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 							A			(  self							:     Any  ):


										'''simple docstring'''
										# Initialize image_processing
										UpperCAmelCase__       						=		self.image_processing_class(**self.image_processor_dict  )
										# create random PyTorch tensors
										UpperCAmelCase__       						=		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
										UpperCAmelCase__       						=		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
										UpperCAmelCase__       						=		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"""],
										    )							,     )


"""simple docstring"""







from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
						if not (is_transformers_available() and is_torch_available() and is_transformers_version(""">=""", """4.27.0""")):
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ...utils.dummy_torch_and_transformers_objects import (
						    AudioLDMPipeline,
						)
else:
						from .pipeline_audioldm import AudioLDMPipeline

