from typing import Any, Callable, Dict, List, Optional, Union

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


UpperCAmelCase							   =      logging.get_logger(__name__)  # pylint: disable=invalid-name






class 							_SCREAMING_SNAKE_CASE(   snake_case__	):
   UpperCamelCase_				:						Union[str, Any] 			=   ['safety_checker', 'feature_extractor']
   def __init__(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_ = True							,     )	->Any:
        super().__init__()
        if hasattr(scheduler.config							,     '''steps_offset'''    ) and scheduler.config.steps_offset != 1:
             a  :    Optional[Any]				=						(
                 F"""The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`"""
                 F""" should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure """
                 '''to update the config accordingly as leaving `steps_offset` might led to incorrect results'''
                 ''' in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,'''
                 ''' it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`'''
                 ''' file'''
             )
             deprecate('''steps_offset!=1'''							,     '''1.0.0'''							,     lowerCAmelCase_							,     standard_warn=lowerCAmelCase_    )
             a  :    Optional[Any]				=						dict(scheduler.config    )
             a  :    Any				=						1
             a  :    Optional[Any]				=						FrozenDict(lowerCAmelCase_    )

        self.register_modules(
            vae=lowerCAmelCase_							,     text_encoder=lowerCAmelCase_							,     tokenizer=lowerCAmelCase_							,     unet=lowerCAmelCase_							,     scheduler=lowerCAmelCase_							,     safety_checker=lowerCAmelCase_							,     feature_extractor=lowerCAmelCase_							,     )
        self.register_to_config(requires_safety_checker=lowerCAmelCase_    )
   @property
   def _lowercase(    self    )	->Dict[str, Any]:
        return {k: getattr(self							,     lowerCAmelCase_    ) for k in self.config.keys() if not k.startswith('''_'''    )}
   def _lowercase(    self							,     lowerCAmelCase_ = "auto"    )	->Tuple:
        if slice_size == "auto":
             # half the attention head size is usually a good trade-off between
             # speed and memory
             a  :    int				=						self.unet.config.attention_head_dim // 2
        self.unet.set_attention_slice(lowerCAmelCase_    )
   def _lowercase(    self    )	->Optional[Any]:
        self.enable_attention_slicing(lowerCAmelCase_    )
   @torch.no_grad()
   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_ = 0.8							,     lowerCAmelCase_ = 50							,     lowerCAmelCase_ = 7.5							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = 1							,     lowerCAmelCase_ = 0.0							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = "pil"							,     lowerCAmelCase_ = True							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = 1							,     )	->Optional[Any]:
        # For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
        return StableDiffusionInpaintPipelineLegacy(**self.components    )(
            prompt=lowerCAmelCase_							,     image=lowerCAmelCase_							,     mask_image=lowerCAmelCase_							,     strength=lowerCAmelCase_							,     num_inference_steps=lowerCAmelCase_							,     guidance_scale=lowerCAmelCase_							,     negative_prompt=lowerCAmelCase_							,     num_images_per_prompt=lowerCAmelCase_							,     eta=lowerCAmelCase_							,     generator=lowerCAmelCase_							,     output_type=lowerCAmelCase_							,     return_dict=lowerCAmelCase_							,     callback=lowerCAmelCase_							,     )
   @torch.no_grad()
   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_ = 0.8							,     lowerCAmelCase_ = 50							,     lowerCAmelCase_ = 7.5							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = 1							,     lowerCAmelCase_ = 0.0							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = "pil"							,     lowerCAmelCase_ = True							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = 1							,     **lowerCAmelCase_							,     )	->Optional[Any]:
        # For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
        return StableDiffusionImgaImgPipeline(**self.components    )(
            prompt=lowerCAmelCase_							,     image=lowerCAmelCase_							,     strength=lowerCAmelCase_							,     num_inference_steps=lowerCAmelCase_							,     guidance_scale=lowerCAmelCase_							,     negative_prompt=lowerCAmelCase_							,     num_images_per_prompt=lowerCAmelCase_							,     eta=lowerCAmelCase_							,     generator=lowerCAmelCase_							,     output_type=lowerCAmelCase_							,     return_dict=lowerCAmelCase_							,     callback=lowerCAmelCase_							,     callback_steps=lowerCAmelCase_							,     )


   @torch.no_grad()
   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_ = 5_12							,     lowerCAmelCase_ = 5_12							,     lowerCAmelCase_ = 50							,     lowerCAmelCase_ = 7.5							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = 1							,     lowerCAmelCase_ = 0.0							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = "pil"							,     lowerCAmelCase_ = True							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = 1							,     )	->int:
        # For more information on how this function https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline
        return StableDiffusionPipeline(**self.components    )(
            prompt=lowerCAmelCase_							,     height=lowerCAmelCase_							,     width=lowerCAmelCase_							,     num_inference_steps=lowerCAmelCase_							,     guidance_scale=lowerCAmelCase_							,     negative_prompt=lowerCAmelCase_							,     num_images_per_prompt=lowerCAmelCase_							,     eta=lowerCAmelCase_							,     generator=lowerCAmelCase_							,     latents=lowerCAmelCase_							,     output_type=lowerCAmelCase_							,     return_dict=lowerCAmelCase_							,     callback=lowerCAmelCase_							,     callback_steps=lowerCAmelCase_							,     )
def 	UpperCAmelCase       (		lowerCAmelCase_       )	->	int:
     return 1 if input_a == 0 else 0







def 	UpperCAmelCase       (		)	->	None:
     assert not_gate(0       ) == 1
     assert not_gate(1       ) == 0


if __name__ == "__main__":
  print(not_gate(0))
  print(not_gate(1))