




import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


__SCREAMING_SNAKE_CASE 						=False






class  __magic_name__						(  unittest.TestCase):
				'''simple docstring'''







				pass






@nightly
@require_torch_gpu
class  __magic_name__						(  unittest.TestCase):
				'''simple docstring'''







				def     _A							(							self:   Tuple		):
											# clean up the VRAM after each test
											super().tearDown()
											gc.collect()
											torch.cuda.empty_cache()


				def     _A							(							self:   List[Any]		):
											SCREAMING_SNAKE_CASE_   	=    VersatileDiffusionTextToImagePipeline.from_pretrained('''shi-labs/versatile-diffusion'''		)
											# remove text_unet
											pipe.remove_unused_weights()
											pipe.to(_lowerCamelCase		)
											pipe.set_progress_bar_config(disable=_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    '''A painting of a squirrel eating a burger '''
											SCREAMING_SNAKE_CASE_   	=    torch.manual_seed(0		)
											SCREAMING_SNAKE_CASE_   	=    pipe(
											    prompt=_lowerCamelCase		,					generator=_lowerCamelCase		,					guidance_scale=7.5		,					num_inference_steps=2		,					output_type='''numpy'''		).images

											with tempfile.TemporaryDirectory() as tmpdirname:
																		pipe.save_pretrained(_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    VersatileDiffusionTextToImagePipeline.from_pretrained(_lowerCamelCase		)
											pipe.to(_lowerCamelCase		)
											pipe.set_progress_bar_config(disable=_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    generator.manual_seed(0		)
											SCREAMING_SNAKE_CASE_   	=    pipe(
											    prompt=_lowerCamelCase		,					generator=_lowerCamelCase		,					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:   str		):
											SCREAMING_SNAKE_CASE_   	=    VersatileDiffusionTextToImagePipeline.from_pretrained(
											    '''shi-labs/versatile-diffusion'''		,					torch_dtype=torch.floataa		)
											pipe.to(_lowerCamelCase		)
											pipe.set_progress_bar_config(disable=_lowerCamelCase		)

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

											SCREAMING_SNAKE_CASE_   	=    image[0, 2_53:2_56, 2_53:2_56, -1]

											assert image.shape == (1, 5_12, 5_12, 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-2








import requests

def 			a   (_lowerCAmelCase  ,    _lowerCAmelCase     ):
							SCREAMING_SNAKE_CASE_   	=    {'''Content-Type''': '''application/json'''}
							SCREAMING_SNAKE_CASE_   	=    requests.post(_lowerCAmelCase  ,    json={'''text''': message_body}  ,    headers=_lowerCAmelCase     )
							if response.status_code != 2_0_0:
														SCREAMING_SNAKE_CASE_   	=    (
														    '''Request to slack returned an error '''
														    F"{response.status_code}, the response is:\n{response.text}"
														)
														raise ValueError(_lowerCAmelCase     )


if __name__ == "__main__":
			# Set the slack url to the one provided by Slack when you create the webhook at
			# https://my.slack.com/services/new/incoming-webhook/
			send_slack_message("""<YOUR MESSAGE BODY>""", """<SLACK CHANNEL URL>""")


