
import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


lowercase  :					List[Any]													=       False




class  lowerCamelCase__							(				unittest.TestCase):




	'''simple docstring'''




	pass




@nightly
@require_torch_gpu
class  lowerCamelCase__							(				unittest.TestCase):




	'''simple docstring'''




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







	def    _lowerCamelCase				(					self		:Optional[int]						)		-> Optional[int]:
								__UpperCamelCase	:   str			   =					VersatileDiffusionPipeline.from_pretrained("shi-labs/versatile-diffusion"     ,   torch_dtype=torch.floataa						)
								pipe.to(a						)
								pipe.set_progress_bar_config(disable=a						)

								__UpperCamelCase	:   List[Any]			   =					load_image(
								    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"						)

								__UpperCamelCase	:   Union[str, Any]			   =					torch.manual_seed(0						)
								__UpperCamelCase	:   Any			   =					pipe.dual_guided(
								    prompt="first prompt"     ,   image=a     ,   text_to_image_strength=0.75     ,   generator=a     ,   guidance_scale=7.5     ,   num_inference_steps=2     ,   output_type="numpy"     ,   ).images

								with tempfile.TemporaryDirectory() as tmpdirname:
															pipe.save_pretrained(a						)
															__UpperCamelCase	:   Any			   =					VersatileDiffusionPipeline.from_pretrained(a     ,   torch_dtype=torch.floataa						)
								pipe.to(a						)
								pipe.set_progress_bar_config(disable=a						)

								__UpperCamelCase	:   Tuple			   =					generator.manual_seed(0						)
								__UpperCamelCase	:   List[str]			   =					pipe.dual_guided(
								    prompt="first prompt"     ,   image=a     ,   text_to_image_strength=0.75     ,   generator=a     ,   guidance_scale=7.5     ,   num_inference_steps=2     ,   output_type="numpy"     ,   ).images

								assert np.abs(image - new_image						).sum() < 1E-5, "Models don't have the same forward pass"







	def    _lowerCamelCase				(					self		:List[str]						)		-> List[str]:
								__UpperCamelCase	:   int			   =					VersatileDiffusionPipeline.from_pretrained("shi-labs/versatile-diffusion"     ,   torch_dtype=torch.floataa						)
								pipe.to(a						)
								pipe.set_progress_bar_config(disable=a						)

								__UpperCamelCase	:   Tuple			   =					"cyberpunk 2077"
								__UpperCamelCase	:   str			   =					load_image(
								    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"						)
								__UpperCamelCase	:   Optional[Any]			   =					torch.manual_seed(0						)
								__UpperCamelCase	:   Union[str, Any]			   =					pipe.dual_guided(
								    prompt=a     ,   image=a     ,   text_to_image_strength=0.75     ,   generator=a     ,   guidance_scale=7.5     ,   num_inference_steps=5_0     ,   output_type="numpy"     ,   ).images

								__UpperCamelCase	:   int			   =					image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

								assert image.shape == (1, 5_1_2, 5_1_2, 3)
								__UpperCamelCase	:   List[Any]			   =					np.array([0.1448, 0.1619, 0.1741, 0.1086, 0.1147, 0.1128, 0.1199, 0.1165, 0.1001]						)

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

								__UpperCamelCase	:   Any			   =					"A painting of a squirrel eating a burger "
								__UpperCamelCase	:   Any			   =					torch.manual_seed(0						)
								__UpperCamelCase	:   Tuple			   =					pipe.text_to_image(
								    prompt=a     ,   generator=a     ,   guidance_scale=7.5     ,   num_inference_steps=5_0     ,   output_type="numpy"						).images

								__UpperCamelCase	:   Tuple			   =					image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

								assert image.shape == (1, 5_1_2, 5_1_2, 3)
								__UpperCamelCase	:   str			   =					np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]						)

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

								__UpperCamelCase	:   List[Any]			   =					pipe.image_variation(a     ,   generator=a     ,   output_type="numpy"						).images

								__UpperCamelCase	:   Optional[int]			   =					image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

								assert image.shape == (1, 5_1_2, 5_1_2, 3)
								__UpperCamelCase	:   Optional[int]			   =					np.array([0.3076, 0.3123, 0.3284, 0.3782, 0.3770, 0.3894, 0.4297, 0.4331, 0.4456]						)

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

def 	_SCREAMING_SNAKE_CASE					(		_lowerCamelCase :			int						,  _lowerCamelCase :			int)					->    float:






							'''simple docstring'''





							return base * power(_lowerCamelCase						,  (exponent - 1)) if exponent else 1


if __name__ == "__main__":
		print('Raise base to the power of exponent using recursion...')
		lowercase  :					Optional[int]													=       int(input('Enter the base: ').strip())
		lowercase  :					Tuple													=       int(input('Enter the exponent: ').strip())
		lowercase  :					str													=       power(base, abs(exponent))
		if exponent < 0:  # power() does not properly deal w/ negative exponents
				lowercase  :					Tuple													=       1 / result
		print(f"{base} to the power of {exponent} is {result}")