

'''simple docstring'''
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


lowerCamelCase :      int					 =     False







class 							A__    (       unittest.TestCase  ):
  pass







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





  def 						A  (		self      :	List[Any] )	->    List[Any]:





       '''simple docstring'''






       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()





  def 						A  (		self      :	List[str] )	->    List[Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =VersatileDiffusionPipeline.from_pretrained('shi-labs/versatile-diffusion'							,					torch_dtype=torch.floataa )
       pipe.to(_a )
       pipe.set_progress_bar_config(disable=_a )

       _SCREAMING_SNAKE_CASE							    =load_image(
           'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg' )

       _SCREAMING_SNAKE_CASE							    =torch.manual_seed(0 )
       _SCREAMING_SNAKE_CASE							    =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 )
            _SCREAMING_SNAKE_CASE							    =VersatileDiffusionPipeline.from_pretrained(_a							,					torch_dtype=torch.floataa )
       pipe.to(_a )
       pipe.set_progress_bar_config(disable=_a )

       _SCREAMING_SNAKE_CASE							    =generator.manual_seed(0 )
       _SCREAMING_SNAKE_CASE							    =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 						A  (		self      :	int )	->    List[Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =VersatileDiffusionPipeline.from_pretrained('shi-labs/versatile-diffusion'							,					torch_dtype=torch.floataa )
       pipe.to(_a )
       pipe.set_progress_bar_config(disable=_a )

       _SCREAMING_SNAKE_CASE							    ='cyberpunk 2077'
       _SCREAMING_SNAKE_CASE							    =load_image(
           'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg' )
       _SCREAMING_SNAKE_CASE							    =torch.manual_seed(0 )
       _SCREAMING_SNAKE_CASE							    =pipe.dual_guided(
           prompt=_a							,					image=_a							,					text_to_image_strength=0.75							,					generator=_a							,					guidance_scale=7.5							,					num_inference_steps=50							,					output_type='numpy'							,					).images

       _SCREAMING_SNAKE_CASE							    =image[0, 253:256, 253:256, -1]

       assert image.shape == (1, 512, 512, 3)
       _SCREAMING_SNAKE_CASE							    =np.array([0.14_48, 0.16_19, 0.17_41, 0.10_86, 0.11_47, 0.11_28, 0.11_99, 0.11_65, 0.10_01] )

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

       _SCREAMING_SNAKE_CASE							    ='A painting of a squirrel eating a burger '
       _SCREAMING_SNAKE_CASE							    =torch.manual_seed(0 )
       _SCREAMING_SNAKE_CASE							    =pipe.text_to_image(
           prompt=_a							,					generator=_a							,					guidance_scale=7.5							,					num_inference_steps=50							,					output_type='numpy' ).images

       _SCREAMING_SNAKE_CASE							    =image[0, 253:256, 253:256, -1]

       assert image.shape == (1, 512, 512, 3)
       _SCREAMING_SNAKE_CASE							    =np.array([0.33_67, 0.31_69, 0.26_56, 0.38_70, 0.47_90, 0.37_96, 0.40_09, 0.48_78, 0.47_78] )

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

       _SCREAMING_SNAKE_CASE							    =pipe.image_variation(_a							,					generator=_a							,					output_type='numpy' ).images

       _SCREAMING_SNAKE_CASE							    =image[0, 253:256, 253:256, -1]

       assert image.shape == (1, 512, 512, 3)
       _SCREAMING_SNAKE_CASE							    =np.array([0.30_76, 0.31_23, 0.32_84, 0.37_82, 0.37_70, 0.38_94, 0.42_97, 0.43_31, 0.44_56] )

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



'''simple docstring'''
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionImageVariationPipeline
from diffusers.utils.testing_utils import load_image, require_torch_gpu, slow, torch_device


lowerCamelCase :      Optional[int]					 =     False







class 							A__    (       unittest.TestCase  ):
  pass







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





  def 						A  (		self      :	Tuple )	->    Dict:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =VersatileDiffusionImageVariationPipeline.from_pretrained('shi-labs/versatile-diffusion' )
       pipe.to(_a )
       pipe.set_progress_bar_config(disable=_a )

       _SCREAMING_SNAKE_CASE							    =load_image(
           'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg' )
       _SCREAMING_SNAKE_CASE							    =torch.manual_seed(0 )
       _SCREAMING_SNAKE_CASE							    =pipe(
           image=_a							,					generator=_a							,					guidance_scale=7.5							,					num_inference_steps=50							,					output_type='numpy'							,					).images

       _SCREAMING_SNAKE_CASE							    =image[0, 253:256, 253:256, -1]

       assert image.shape == (1, 512, 512, 3)
       _SCREAMING_SNAKE_CASE							    =np.array([0.04_41, 0.04_69, 0.05_07, 0.05_75, 0.06_32, 0.06_50, 0.08_65, 0.09_09, 0.09_45] )

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