'''simple docstring'''

import gc
import tempfile
import unittest

import numpy as np
import torch

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


__snake_case       :   Any  		=    False
@nightly
@require_torch_gpu
class 							lowercase_    (     unittest.TestCase						):







    def   lowerCamelCase_    (	self				)				->       Optional[int]:





     """simple docstring"""

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







    def   lowerCamelCase_    (	self				)				->       Dict:





     """simple docstring"""

     UpperCAmelCase_				       =					VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"				)
     # remove text_unet
     pipe.remove_unused_weights()
     pipe.to(_A				)
     pipe.set_progress_bar_config(disable=_A				)

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

     UpperCAmelCase_				       =					torch.manual_seed(0				)
     UpperCAmelCase_				       =					pipe(
         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_				       =					VersatileDiffusionDualGuidedPipeline.from_pretrained(_A				)

     pipe.to(_A				)
     pipe.set_progress_bar_config(disable=_A				)

     UpperCAmelCase_				       =					generator.manual_seed(0				)
     UpperCAmelCase_				       =					pipe(
         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				)				->       Union[str, Any]:





     """simple docstring"""

     UpperCAmelCase_				       =					VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"				)
     pipe.remove_unused_weights()
     pipe.to(_A				)
     pipe.set_progress_bar_config(disable=_A				)

     UpperCAmelCase_				       =					'cyberpunk 2077'
     UpperCAmelCase_				       =					load_image(
         "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"				)
     UpperCAmelCase_				       =					torch.manual_seed(0				)
     UpperCAmelCase_				       =					pipe(
         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_				       =					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_				       =					np.array([0.0787, 0.0849, 0.0826, 0.0812, 0.0807, 0.0795, 0.0818, 0.0798, 0.0779]				)

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

'''simple docstring'''

from ..utils import DummyObject, requires_backends
class 							lowercase_    (     metaclass=_A						):
    a_             =   ["""torch""", """librosa"""]







    def __init__(	self       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       int:





     """simple docstring"""

     requires_backends(self       ,     ["torch", "librosa"]				)







    @classmethod
    def   lowerCamelCase_    (	cls       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       Union[str, Any]:





     """simple docstring"""

     requires_backends(cls       ,     ["torch", "librosa"]				)







    @classmethod
    def   lowerCamelCase_    (	cls       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       Dict:





     """simple docstring"""

     requires_backends(cls       ,     ["torch", "librosa"]				)


class 							lowercase_    (     metaclass=_A						):
    a_             =   ["""torch""", """librosa"""]







    def __init__(	self       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       str:





     """simple docstring"""

     requires_backends(self       ,     ["torch", "librosa"]				)







    @classmethod
    def   lowerCamelCase_    (	cls       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       Union[str, Any]:





     """simple docstring"""

     requires_backends(cls       ,     ["torch", "librosa"]				)







    @classmethod
    def   lowerCamelCase_    (	cls       ,     *UpperCamelCase__       ,     **UpperCamelCase__				)				->       int:





     """simple docstring"""

     requires_backends(cls       ,     ["torch", "librosa"]				)
