
"""simple docstring"""







import gc
import random
import unittest

import numpy as np
import torch
from PIL import Image

from diffusers import (
    DDIMScheduler,
    KandinskyVaaImgaImgPipeline,
    KandinskyVaaPriorPipeline,
    UNetaDConditionModel,
    VQModel,
)
from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference


enable_full_determinism()




class 			A__	(     _lowerCamelCase	,					unittest.TestCase):
		A_						:	int           =     KandinskyVaaImgaImgPipeline
		A_						:	Union[str, Any]           =     ["""image_embeds""", """negative_image_embeds""", """image"""]
		A_						:	Dict           =     [
		    """image_embeds""",
		    """negative_image_embeds""",
		    """image""",
		]
		A_						:	Tuple           =     [
		    """generator""",
		    """height""",
		    """width""",
		    """strength""",
		    """guidance_scale""",
		    """num_inference_steps""",
		    """return_dict""",
		    """guidance_scale""",
		    """num_images_per_prompt""",
		    """output_type""",
		    """return_dict""",
		]
		A_						:	int           =     False

		@property
		def 							__lowerCamelCase							(				self			):
			return 32

		@property
		def 							__lowerCamelCase							(				self			):
			return 32

		@property
		def 							__lowerCamelCase							(				self			):
			return self.time_input_dim

		@property
		def 							__lowerCamelCase							(				self			):
			return self.time_input_dim * 4

		@property
		def 							__lowerCamelCase							(				self			):
			return 1_00

		@property
		def 							__lowerCamelCase							(				self			):
			torch.manual_seed(0			)

			__lowerCAmelCase      :						Dict						      =				{
			    'in_channels': 4,
			    # Out channels is double in channels because predicts mean and variance
			    'out_channels': 8,
			    'addition_embed_type': 'image',
			    'down_block_types': ('ResnetDownsampleBlock2D', 'SimpleCrossAttnDownBlock2D'),
			    'up_block_types': ('SimpleCrossAttnUpBlock2D', 'ResnetUpsampleBlock2D'),
			    'mid_block_type': 'UNetMidBlock2DSimpleCrossAttn',
			    'block_out_channels': (self.block_out_channels_a, self.block_out_channels_a * 2),
			    'layers_per_block': 1,
			    'encoder_hid_dim': self.text_embedder_hidden_size,
			    'encoder_hid_dim_type': 'image_proj',
			    'cross_attention_dim': self.cross_attention_dim,
			    'attention_head_dim': 4,
			    'resnet_time_scale_shift': 'scale_shift',
			    'class_embed_type': None,
			}

			__lowerCAmelCase      :						Optional[int]						      =				UNetaDConditionModel(**_lowercase			)
			return model

		@property
		def 							__lowerCamelCase							(				self			):
			return {
			    "block_out_channels": [32, 64],
			    "down_block_types": ["DownEncoderBlock2D", "AttnDownEncoderBlock2D"],
			    "in_channels": 3,
			    "latent_channels": 4,
			    "layers_per_block": 1,
			    "norm_num_groups": 8,
			    "norm_type": "spatial",
			    "num_vq_embeddings": 12,
			    "out_channels": 3,
			    "up_block_types": [
			        "AttnUpDecoderBlock2D",
			        "UpDecoderBlock2D",
			    ],
			    "vq_embed_dim": 4,
			}

		@property
		def 							__lowerCamelCase							(				self			):
			torch.manual_seed(0			)
			__lowerCAmelCase      :						Union[str, Any]						      =				VQModel(**self.dummy_movq_kwargs			)
			return model

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Tuple						      =				self.dummy_unet
			__lowerCAmelCase      :						Optional[int]						      =				self.dummy_movq

			__lowerCAmelCase      :						Optional[int]						      =				{
			    'num_train_timesteps': 10_00,
			    'beta_schedule': 'linear',
			    'beta_start': 0.0_0085,
			    'beta_end': 0.012,
			    'clip_sample': False,
			    'set_alpha_to_one': False,
			    'steps_offset': 0,
			    'prediction_type': 'epsilon',
			    'thresholding': False,
			}

			__lowerCAmelCase      :						List[str]						      =				DDIMScheduler(**_lowercase			)

			__lowerCAmelCase      :						Any						      =				{
			    'unet': unet,
			    'scheduler': scheduler,
			    'movq': movq,
			}

			return components

		def 							__lowerCamelCase							(				self	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE=0			):
			__lowerCAmelCase      :						Any						      =				floats_tensor((1, self.text_embedder_hidden_size)	,		rng=random.Random(_lowercase			)			).to(_lowercase			)
			__lowerCAmelCase      :						Any						      =				floats_tensor((1, self.text_embedder_hidden_size)	,		rng=random.Random(seed + 1			)			).to(
			    _lowercase			)
			# create init_image
			__lowerCAmelCase      :						List[Any]						      =				floats_tensor((1, 3, 64, 64)	,		rng=random.Random(_lowercase			)			).to(_lowercase			)
			__lowerCAmelCase      :						str						      =				image.cpu().permute(0	,		2	,		3	,		1			)[0]
			__lowerCAmelCase      :						str						      =				Image.fromarray(np.uinta(_lowercase			)			).convert('RGB'			).resize((2_56, 2_56)			)

			if str(_lowercase			).startswith('mps'			):
				__lowerCAmelCase      :						Union[str, Any]						      =				torch.manual_seed(_lowercase			)
			else:
				__lowerCAmelCase      :						int						      =				torch.Generator(device=_lowercase			).manual_seed(_lowercase			)
			__lowerCAmelCase      :						Optional[int]						      =				{
			    'image': init_image,
			    'image_embeds': image_embeds,
			    'negative_image_embeds': negative_image_embeds,
			    'generator': generator,
			    'height': 64,
			    'width': 64,
			    'num_inference_steps': 10,
			    'guidance_scale': 7.0,
			    'strength': 0.2,
			    'output_type': 'np',
			}
			return inputs







		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						str						      =				'cpu'

			__lowerCAmelCase      :						List[Any]						      =				self.get_dummy_components()

			__lowerCAmelCase      :						List[str]						      =				self.pipeline_class(**_lowercase			)
			__lowerCAmelCase      :						Optional[Any]						      =				pipe.to(_lowercase			)

			pipe.set_progress_bar_config(disable=_lowercase			)

			__lowerCAmelCase      :						Any						      =				pipe(**self.get_dummy_inputs(_lowercase			)			)
			__lowerCAmelCase      :						str						      =				output.images

			__lowerCAmelCase      :						List[Any]						      =				pipe(
			    **self.get_dummy_inputs(_lowercase			)	,		return_dict=_lowercase	,		)[0]

			__lowerCAmelCase      :						Dict						      =				image[0, -3:, -3:, -1]
			__lowerCAmelCase      :						List[str]						      =				image_from_tuple[0, -3:, -3:, -1]

			assert image.shape == (1, 64, 64, 3)

			__lowerCAmelCase      :						List[str]						      =				np.array(
			    [0.619_9778, 0.6398_4406, 0.4614_5785, 0.6294_4984, 0.562_2215, 0.4730_6132, 0.4744_1456, 0.460_7606, 0.4871_9263]			)
			assert (
			    np.abs(image_slice.flatten() - expected_slice			).max() < 1E-2
			), f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
			assert (
			    np.abs(image_from_tuple_slice.flatten() - expected_slice			).max() < 1E-2
			), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"




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

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







		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Any						      =				load_numpy(
			    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
			    '/kandinskyv22/kandinskyv22_img2img_frog.npy'			)

			__lowerCAmelCase      :						Tuple						      =				load_image(
			    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main' '/kandinsky/cat.png'			)
			__lowerCAmelCase      :						Dict						      =				'A red cartoon frog, 4k'

			__lowerCAmelCase      :						Union[str, Any]						      =				KandinskyVaaPriorPipeline.from_pretrained(
			    'kandinsky-community/kandinsky-2-2-prior'	,		torch_dtype=torch.floataa			)
			pipe_prior.to(_lowercase			)

			__lowerCAmelCase      :						str						      =				KandinskyVaaImgaImgPipeline.from_pretrained(
			    'kandinsky-community/kandinsky-2-2-decoder'	,		torch_dtype=torch.floataa			)
			__lowerCAmelCase      :						List[str]						      =				pipeline.to(_lowercase			)

			pipeline.set_progress_bar_config(disable=_lowercase			)

			__lowerCAmelCase      :						Union[str, Any]						      =				torch.Generator(device='cpu'			).manual_seed(0			)
			__lowerCAmelCase      ,       __lowerCAmelCase      :						int						      =				pipe_prior(
			    _lowercase	,		generator=_lowercase	,		num_inference_steps=5	,		negative_prompt=''	,		).to_tuple()

			__lowerCAmelCase      :						Any						      =				pipeline(
			    image=_lowercase	,		image_embeds=_lowercase	,		negative_image_embeds=_lowercase	,		generator=_lowercase	,		num_inference_steps=1_00	,		height=7_68	,		width=7_68	,		strength=0.2	,		output_type='np'	,		)

			__lowerCAmelCase      :						Tuple						      =				output.images[0]

			assert image.shape == (7_68, 7_68, 3)

			assert_mean_pixel_difference(_lowercase	,		_lowercase			)

"""simple docstring"""







import argparse
import datetime
def    __lowerCAmelCase    (_UpperCamelCase		):
	__lowerCAmelCase      :						Optional[Any]						      =				{
	    '0': 'Sunday',
	    '1': 'Monday',
	    '2': 'Tuesday',
	    '3': 'Wednesday',
	    '4': 'Thursday',
	    '5': 'Friday',
	    '6': 'Saturday',
	}

	__lowerCAmelCase      :						Optional[Any]						      =				{0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 0}

	# Validate
	if not 0 < len(_UpperCamelCase		) < 11:
		raise ValueError('Must be 10 characters long'		)

	# Get month
	__lowerCAmelCase      :						int						      =				int(date_input[0] + date_input[1]		)
	# Validate
	if not 0 < m < 13:
		raise ValueError('Month must be between 1 - 12'		)

	__lowerCAmelCase      :						str						      =				date_input[2]
	# Validate
	if sep_a not in ["-", "/"]:
		raise ValueError('Date separator must be \'-\' or \'/\''		)

	# Get day
	__lowerCAmelCase      :						int						      =				int(date_input[3] + date_input[4]		)
	# Validate
	if not 0 < d < 32:
		raise ValueError('Date must be between 1 - 31'		)

	# Get second separator
	__lowerCAmelCase      :						str						      =				date_input[5]
	# Validate
	if sep_a not in ["-", "/"]:
		raise ValueError('Date separator must be \'-\' or \'/\''		)

	# Get year
	__lowerCAmelCase      :						int						      =				int(date_input[6] + date_input[7] + date_input[8] + date_input[9]		)
	# Arbitrary year range
	if not 45 < y < 8500:
		raise ValueError(
		    'Year out of range. There has to be some sort of limit...right?'		)

	# Get datetime obj for validation
	__lowerCAmelCase      :						Tuple						      =				datetime.date(int(_UpperCamelCase		)	,  int(_UpperCamelCase		)	,  int(_UpperCamelCase		)		)

	# Start math
	if m <= 2:
		__lowerCAmelCase      :						int						      =				y - 1
		__lowerCAmelCase      :						Tuple						      =				m + 12
	# maths var
	__lowerCAmelCase      :						int						      =				int(str(_UpperCamelCase		)[:2]		)
	__lowerCAmelCase      :						int						      =				int(str(_UpperCamelCase		)[2:]		)
	__lowerCAmelCase      :						int						      =				int(2.6 * m - 5.39		)
	__lowerCAmelCase      :						int						      =				int(c / 4		)
	__lowerCAmelCase      :						int						      =				int(k / 4		)
	__lowerCAmelCase      :						int						      =				int(d + k		)
	__lowerCAmelCase      :						int						      =				int(t + u + v + x		)
	__lowerCAmelCase      :						int						      =				int(z - (2 * c)		)
	__lowerCAmelCase      :						int						      =				round(w % 7		)
	# End math

	# Validate math
	if f != convert_datetime_days[dt_ck.weekday()]:
		raise AssertionError('The date was evaluated incorrectly. Contact developer.'		)

	# Response
	__lowerCAmelCase      :						str						      =				F"Your date {date_input}, is a {days[str(_UpperCamelCase		)]}!"
	return response


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							lowerCamelCase__        =		argparse.ArgumentParser(
							    description=(
							        """Find out what day of the week nearly any date is or was. Enter """
							        """date as a string in the mm-dd-yyyy or mm/dd/yyyy format"""
							    )
							)
							parser.add_argument(
							    """date_input""", type=str, help="""Date as a string (mm-dd-yyyy or mm/dd/yyyy)"""
							)
							lowerCamelCase__        =		parser.parse_args()
							zeller(args.date_input)