


from ...processing_utils import ProcessorMixin
class 	UpperCAmelCase_					(					lowercase__    ):

   '''simple docstring'''




   __A :      int     		=		['''image_processor''', '''feature_extractor''']
   __A :      Optional[int]     		=		'''TvltImageProcessor'''
   __A :      Optional[int]     		=		'''TvltFeatureExtractor'''






   def __init__(		self						,				__A						,				__A ):






     """simple docstring"""





     super().__init__(image_processor=_a						,				feature_extractor=_a )

     lowerCamelCase :					List[str]    =				image_processor
     lowerCamelCase :					Optional[int]    =				feature_extractor






   def __call__(		self						,				__A=None						,				__A=None						,				__A=None						,				__A=None						,				__A=False						,				__A=False						,				*__A						,				**__A						,				):






     """simple docstring"""





     if images is None and audio is None:
       raise ValueError("You need to specify either an `images` or `audio` input to process." )

     lowerCamelCase :					Optional[Any]    =				None
     if images is not None:
       lowerCamelCase :					Optional[Any]    =				self.image_processor(_a						,				mask_pixel=_a						,				*_a						,				**_a )
     if images_mixed is not None:
       lowerCamelCase :					str    =				self.image_processor(_a						,				is_mixed=_a						,				*_a						,				**_a )
     if audio is not None:
       lowerCamelCase :					str    =				self.feature_extractor(
           _a						,				*_a						,				sampling_rate=_a						,				mask_audio=_a						,				**_a )

     lowerCamelCase :					List[str]    =				{}
     if audio is not None:
       output_dict.update(_a )
     if images is not None:
       output_dict.update(_a )
     if images_mixed_dict is not None:
       output_dict.update(_a )
     return output_dict






   @property
   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					List[str]    =				self.image_processor.model_input_names
     lowerCamelCase :					List[str]    =				self.feature_extractor.model_input_names
     return list(dict.fromkeys(image_processor_input_names + feature_extractor_input_names ) )





'''simple docstring'''







import unittest

import numpy as np
import torch

from diffusers import PNDMPipeline, PNDMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()







class UpperCAmelCase__	( unittest.TestCase	):





  """simple docstring"""

  @property
  def   __lowercase		(		self      :     List[str]       ):


     '''simple docstring'''






     torch.manual_seed(0       )
     _a				:	int			=   UNetaDModel(
         block_out_channels=(32, 64)							,layers_per_block=2							,sample_size=32							,in_channels=3							,out_channels=3							,down_block_types=('DownBlock2D', 'AttnDownBlock2D')							,up_block_types=('AttnUpBlock2D', 'UpBlock2D')							,)
     return model


  def   __lowercase		(		self      :     Optional[Any]       ):


     '''simple docstring'''






     _a				:	str			=   self.dummy_uncond_unet
     _a				:	int			=   PNDMScheduler()

     _a				:	str			=   PNDMPipeline(unet=_a							,scheduler=_a       )
     pndm.to(_a       )
     pndm.set_progress_bar_config(disable=_a       )

     _a				:	Optional[int]			=   torch.manual_seed(0       )
     _a				:	Optional[Any]			=   pndm(generator=_a							,num_inference_steps=20							,output_type='numpy'       ).images

     _a				:	List[str]			=   torch.manual_seed(0       )
     _a				:	Any			=   pndm(generator=_a							,num_inference_steps=20							,output_type='numpy'							,return_dict=_a       )[0]

     _a				:	List[Any]			=   image[0, -3:, -3:, -1]
     _a				:	Any			=   image_from_tuple[0, -3:, -3:, -1]

     assert image.shape == (1, 32, 32, 3)
     _a				:	List[Any]			=   np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]       )

     assert np.abs(image_slice.flatten() - expected_slice       ).max() < 1E-2
     assert np.abs(image_from_tuple_slice.flatten() - expected_slice       ).max() < 1E-2







@slow
@require_torch
class UpperCAmelCase__	( unittest.TestCase	):





  """simple docstring"""

  def   __lowercase		(		self      :     Tuple       ):


     '''simple docstring'''






     _a				:	List[str]			=   'google/ddpm-cifar10-32'

     _a				:	str			=   UNetaDModel.from_pretrained(_a       )
     _a				:	Union[str, Any]			=   PNDMScheduler()

     _a				:	Tuple			=   PNDMPipeline(unet=_a							,scheduler=_a       )
     pndm.to(_a       )
     pndm.set_progress_bar_config(disable=_a       )
     _a				:	str			=   torch.manual_seed(0       )
     _a				:	Optional[Any]			=   pndm(generator=_a							,output_type='numpy'       ).images

     _a				:	Dict			=   image[0, -3:, -3:, -1]

     assert image.shape == (1, 32, 32, 3)
     _a				:	Tuple			=   np.array([0.1564, 0.1_4645, 0.1406, 0.1_4715, 0.1_2425, 0.1_4045, 0.1_3115, 0.1_2175, 0.125]       )

     assert np.abs(image_slice.flatten() - expected_slice       ).max() < 1E-2



