
"""simple docstring"""

import gc
import unittest

import numpy as np
import torch

from diffusers import (
    AudioDiffusionPipeline,
    AutoencoderKL,
    DDIMScheduler,
    DDPMScheduler,
    DiffusionPipeline,
    Mel,
    UNetaDConditionModel,
    UNetaDModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()






class 	_lowercase       (    unittest.TestCase		):




	def       _UpperCamelCase   (			self )		->							Union[str, Any]:
			# clean up the VRAM after each test
			super().tearDown()
			gc.collect()
			torch.cuda.empty_cache()




	@property
	def       _UpperCamelCase   (			self )		->							List[Any]:
			torch.manual_seed(0 )
			lowerCamelCase					:      List[Any]          =   UNetaDModel(
			    sample_size=(32, 64)		,			in_channels=1		,			out_channels=1		,			layers_per_block=2		,			block_out_channels=(128, 128)		,			down_block_types=('AttnDownBlock2D', 'DownBlock2D')		,			up_block_types=('UpBlock2D', 'AttnUpBlock2D')		,			)
			return model




	@property
	def       _UpperCamelCase   (			self )		->							Union[str, Any]:
			torch.manual_seed(0 )
			lowerCamelCase					:      Tuple          =   UNetaDConditionModel(
			    sample_size=(64, 32)		,			in_channels=1		,			out_channels=1		,			layers_per_block=2		,			block_out_channels=(128, 128)		,			down_block_types=('CrossAttnDownBlock2D', 'DownBlock2D')		,			up_block_types=('UpBlock2D', 'CrossAttnUpBlock2D')		,			cross_attention_dim=10		,			)
			return model




	@property
	def       _UpperCamelCase   (			self )		->							List[str]:
			torch.manual_seed(0 )
			lowerCamelCase					:      Optional[Any]          =   AutoencoderKL(
			    sample_size=(128, 64)		,			in_channels=1		,			out_channels=1		,			latent_channels=1		,			layers_per_block=2		,			block_out_channels=(128, 128)		,			down_block_types=('DownEncoderBlock2D', 'DownEncoderBlock2D')		,			up_block_types=('UpDecoderBlock2D', 'UpDecoderBlock2D')		,			)
			lowerCamelCase					:      List[str]          =   UNetaDModel(
			    sample_size=(64, 32)		,			in_channels=1		,			out_channels=1		,			layers_per_block=2		,			block_out_channels=(128, 128)		,			down_block_types=('AttnDownBlock2D', 'DownBlock2D')		,			up_block_types=('UpBlock2D', 'AttnUpBlock2D')		,			)
			return vqvae, unet




	@slow
	def       _UpperCamelCase   (			self )		->							Tuple:
			lowerCamelCase					:      List[str]          =   'cpu'  # ensure determinism for the device-dependent torch.Generator
			lowerCamelCase					:      Optional[Any]          =   Mel(
			    x_res=self.dummy_unet.config.sample_size[1]		,			y_res=self.dummy_unet.config.sample_size[0]		,			)

			lowerCamelCase					:      Optional[Any]          =   DDPMScheduler()
			lowerCamelCase					:      Union[str, Any]          =   AudioDiffusionPipeline(vqvae=UpperCAmelCase_		,			unet=self.dummy_unet		,			mel=UpperCAmelCase_		,			scheduler=UpperCAmelCase_ )
			lowerCamelCase					:      Any          =   pipe.to(UpperCAmelCase_ )
			pipe.set_progress_bar_config(disable=UpperCAmelCase_ )

			lowerCamelCase					:      List[Any]          =   torch.Generator(device=UpperCAmelCase_ ).manual_seed(42 )
			lowerCamelCase					:      List[str]          =   pipe(generator=UpperCAmelCase_		,			steps=4 )
			lowerCamelCase					:      Optional[int]          =   output.audios[0]
			lowerCamelCase					:      Union[str, Any]          =   output.images[0]

			lowerCamelCase					:      Optional[Any]          =   torch.Generator(device=UpperCAmelCase_ ).manual_seed(42 )
			lowerCamelCase					:      List[Any]          =   pipe(generator=UpperCAmelCase_		,			steps=4		,			return_dict=UpperCAmelCase_ )
			lowerCamelCase					:      Union[str, Any]          =   output[0][0]

			assert audio.shape == (1, (self.dummy_unet.config.sample_size[1] - 1) * mel.hop_length)
			assert (
			    image.height == self.dummy_unet.config.sample_size[0]
			    and image.width == self.dummy_unet.config.sample_size[1]
			)
			lowerCamelCase					:      Dict          =   np.frombuffer(image.tobytes()		,			dtype='uint8' )[:10]
			lowerCamelCase					:      Optional[int]          =   np.frombuffer(image_from_tuple.tobytes()		,			dtype='uint8' )[:10]
			lowerCamelCase					:      Optional[Any]          =   np.array([69, 255, 255, 255, 0, 0, 77, 181, 12, 127] )

			assert np.abs(image_slice.flatten() - expected_slice ).max() == 0
			assert np.abs(image_from_tuple_slice.flatten() - expected_slice ).max() == 0

			lowerCamelCase					:      Union[str, Any]          =   Mel(
			    x_res=self.dummy_vqvae_and_unet[0].config.sample_size[1]		,			y_res=self.dummy_vqvae_and_unet[0].config.sample_size[0]		,			)

			lowerCamelCase					:      Union[str, Any]          =   DDIMScheduler()
			lowerCamelCase					:      int          =   self.dummy_vqvae_and_unet
			lowerCamelCase					:      Optional[Any]          =   AudioDiffusionPipeline(
			    vqvae=self.dummy_vqvae_and_unet[0]		,			unet=dummy_vqvae_and_unet[1]		,			mel=UpperCAmelCase_		,			scheduler=UpperCAmelCase_ )
			lowerCamelCase					:      List[Any]          =   pipe.to(UpperCAmelCase_ )
			pipe.set_progress_bar_config(disable=UpperCAmelCase_ )

			np.random.seed(0 )
			lowerCamelCase					:      List[Any]          =   np.random.uniform(-1		,			1		,			((dummy_vqvae_and_unet[0].config.sample_size[1] - 1) * mel.hop_length,) )
			lowerCamelCase					:      str          =   torch.Generator(device=UpperCAmelCase_ ).manual_seed(42 )
			lowerCamelCase					:      Optional[int]          =   pipe(raw_audio=UpperCAmelCase_		,			generator=UpperCAmelCase_		,			start_step=5		,			steps=10 )
			lowerCamelCase					:      Optional[int]          =   output.images[0]

			assert (
			    image.height == self.dummy_vqvae_and_unet[0].config.sample_size[0]
			    and image.width == self.dummy_vqvae_and_unet[0].config.sample_size[1]
			)
			lowerCamelCase					:      Union[str, Any]          =   np.frombuffer(image.tobytes()		,			dtype='uint8' )[:10]
			lowerCamelCase					:      Any          =   np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121] )

			assert np.abs(image_slice.flatten() - expected_slice ).max() == 0

			lowerCamelCase					:      Optional[int]          =   self.dummy_unet_condition
			lowerCamelCase					:      Union[str, Any]          =   AudioDiffusionPipeline(
			    vqvae=self.dummy_vqvae_and_unet[0]		,			unet=UpperCAmelCase_		,			mel=UpperCAmelCase_		,			scheduler=UpperCAmelCase_ )
			lowerCamelCase					:      Optional[int]          =   pipe.to(UpperCAmelCase_ )
			pipe.set_progress_bar_config(disable=UpperCAmelCase_ )

			np.random.seed(0 )
			lowerCamelCase					:      List[Any]          =   torch.rand((1, 1, 10) )
			lowerCamelCase					:      Optional[Any]          =   pipe(generator=UpperCAmelCase_		,			encoding=UpperCAmelCase_ )
			lowerCamelCase					:      Any          =   output.images[0]
			lowerCamelCase					:      int          =   np.frombuffer(image.tobytes()		,			dtype='uint8' )[:10]
			lowerCamelCase					:      Tuple          =   np.array([107, 103, 120, 127, 142, 122, 113, 122, 97, 111] )

			assert np.abs(image_slice.flatten() - expected_slice ).max() == 0






@slow
@require_torch_gpu
class 	_lowercase       (    unittest.TestCase		):




	def       _UpperCamelCase   (			self )		->							List[str]:
			# clean up the VRAM after each test
			super().tearDown()
			gc.collect()
			torch.cuda.empty_cache()




	def       _UpperCamelCase   (			self )		->							List[Any]:
			lowerCamelCase					:      Union[str, Any]          =   torch_device

			lowerCamelCase					:      Optional[int]          =   DiffusionPipeline.from_pretrained('teticio/audio-diffusion-ddim-256' )
			lowerCamelCase					:      Tuple          =   pipe.to(UpperCAmelCase_ )
			pipe.set_progress_bar_config(disable=UpperCAmelCase_ )

			lowerCamelCase					:      str          =   torch.Generator(device=UpperCAmelCase_ ).manual_seed(42 )
			lowerCamelCase					:      str          =   pipe(generator=UpperCAmelCase_ )
			lowerCamelCase					:      Optional[int]          =   output.audios[0]
			lowerCamelCase					:      Dict          =   output.images[0]

			assert audio.shape == (1, (pipe.unet.config.sample_size[1] - 1) * pipe.mel.hop_length)
			assert image.height == pipe.unet.config.sample_size[0] and image.width == pipe.unet.config.sample_size[1]
			lowerCamelCase					:      Union[str, Any]          =   np.frombuffer(image.tobytes()		,			dtype='uint8' )[:10]
			lowerCamelCase					:      List[str]          =   np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26] )

			assert np.abs(image_slice.flatten() - expected_slice ).max() == 0








"""simple docstring"""

def 		UpperCAmelCase (		a_      ):





		'''simple docstring'''


		lowerCamelCase					:      List[Any]          =   1
		for i in range(1,						num + 1      ):
				fact *= i
		return fact
def 		UpperCAmelCase (		a_      ):





		'''simple docstring'''


		lowerCamelCase					:      Optional[Any]          =   0
		while number > 0:
				lowerCamelCase					:      str          =   number % 10
				sum_of_digits += last_digit
				lowerCamelCase					:      Tuple          =   number // 10  # Removing the last_digit from the given number
		return sum_of_digits
def 		UpperCAmelCase (		a_ = 100      ):





		'''simple docstring'''


		lowerCamelCase					:      Optional[Any]          =   factorial(a_      )
		lowerCamelCase					:      int          =   split_and_add(a_      )
		return result


if __name__ == "__main__":
					print(solution(int(input('Enter the Number: ').strip())))






