

'''simple docstring'''







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

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


__lowerCamelCase		       =    '''CompVis/stable-diffusion-v1-1'''
__lowerCamelCase		       =    '''CompVis/stable-diffusion-v1-2'''
__lowerCamelCase		       =    '''CompVis/stable-diffusion-v1-3'''
__lowerCamelCase		       =    '''CompVis/stable-diffusion-v1-4'''


class 					A__      (      _snake_case			):



    def __init__(					self		,				UpperCamelCase__		,				UpperCamelCase__		,				UpperCamelCase__		,				UpperCamelCase__		,				UpperCamelCase__		,				UpperCamelCase__		,				UpperCamelCase__		,				UpperCamelCase__ = True		,				)						->      Optional[Any]:





           '''simple docstring'''
           super()._init_()

           A_						=      StableDiffusionPipeline.from_pretrained(UpperCamelCase__       )
           A_						=      StableDiffusionPipeline.from_pretrained(UpperCamelCase__       )
           A_						=      StableDiffusionPipeline.from_pretrained(UpperCamelCase__       )
           A_						=      StableDiffusionPipeline(
               vae=UpperCamelCase__		,				text_encoder=UpperCamelCase__		,				tokenizer=UpperCamelCase__		,				unet=UpperCamelCase__		,				scheduler=UpperCamelCase__		,				safety_checker=UpperCamelCase__		,				feature_extractor=UpperCamelCase__		,				requires_safety_checker=UpperCamelCase__		,				)

           self.register_modules(pipelinea=self.pipea		,				pipelinea=self.pipea		,				pipelinea=self.pipea		,				pipelinea=self.pipea       )



    @property
    def 					snake_case_			(					self       )						->      Dict[str, Any]:





           '''simple docstring'''
           return {k: getattr(self		,				UpperCamelCase__       ) for k in self.config.keys() if not k.startswith("""_"""       )}



    def 					snake_case_			(					self		,				UpperCamelCase__ = "auto"       )						->      Any:





           '''simple docstring'''
           if slice_size == "auto":
                  # half the attention head size is usually a good trade-off between
                  # speed and memory
                  A_						=      self.unet.config.attention_head_dim // 2
           self.unet.set_attention_slice(UpperCamelCase__       )



    def 					snake_case_			(					self       )						->      int:





           '''simple docstring'''
           self.enable_attention_slicing(UpperCamelCase__       )



    @torch.no_grad()
    def 					snake_case_			(					self		,				UpperCamelCase__		,				UpperCamelCase__ = 512		,				UpperCamelCase__ = 512		,				UpperCamelCase__ = 50		,				UpperCamelCase__ = 7.5		,				UpperCamelCase__ = None		,				UpperCamelCase__ = 1		,				UpperCamelCase__ = 0.0		,				UpperCamelCase__ = None		,				UpperCamelCase__ = None		,				UpperCamelCase__ = "pil"		,				UpperCamelCase__ = True		,				UpperCamelCase__ = None		,				UpperCamelCase__ = 1		,				**UpperCamelCase__		,				)						->      List[str]:





           '''simple docstring'''
           return self.pipea(
               prompt=UpperCamelCase__		,				height=UpperCamelCase__		,				width=UpperCamelCase__		,				num_inference_steps=UpperCamelCase__		,				guidance_scale=UpperCamelCase__		,				negative_prompt=UpperCamelCase__		,				num_images_per_prompt=UpperCamelCase__		,				eta=UpperCamelCase__		,				generator=UpperCamelCase__		,				latents=UpperCamelCase__		,				output_type=UpperCamelCase__		,				return_dict=UpperCamelCase__		,				callback=UpperCamelCase__		,				callback_steps=UpperCamelCase__		,				**UpperCamelCase__		,				)



    @torch.no_grad()
    def 					snake_case_			(					self		,				UpperCamelCase__		,				UpperCamelCase__ = 512		,				UpperCamelCase__ = 512		,				UpperCamelCase__ = 50		,				UpperCamelCase__ = 7.5		,				UpperCamelCase__ = None		,				UpperCamelCase__ = 1		,				UpperCamelCase__ = 0.0		,				UpperCamelCase__ = None		,				UpperCamelCase__ = None		,				UpperCamelCase__ = "pil"		,				UpperCamelCase__ = True		,				UpperCamelCase__ = None		,				UpperCamelCase__ = 1		,				**UpperCamelCase__		,				)						->      int:





           '''simple docstring'''
           return self.pipea(
               prompt=UpperCamelCase__		,				height=UpperCamelCase__		,				width=UpperCamelCase__		,				num_inference_steps=UpperCamelCase__		,				guidance_scale=UpperCamelCase__		,				negative_prompt=UpperCamelCase__		,				num_images_per_prompt=UpperCamelCase__		,				eta=UpperCamelCase__		,				generator=UpperCamelCase__		,				latents=UpperCamelCase__		,				output_type=UpperCamelCase__		,				return_dict=UpperCamelCase__		,				callback=UpperCamelCase__		,				callback_steps=UpperCamelCase__		,				**UpperCamelCase__		,				)



    @torch.no_grad()
    def 					snake_case_			(					self		,				UpperCamelCase__		,				UpperCamelCase__ = 512		,				UpperCamelCase__ = 512		,				UpperCamelCase__ = 50		,				UpperCamelCase__ = 7.5		,				UpperCamelCase__ = None		,				UpperCamelCase__ = 1		,				UpperCamelCase__ = 0.0		,				UpperCamelCase__ = None		,				UpperCamelCase__ = None		,				UpperCamelCase__ = "pil"		,				UpperCamelCase__ = True		,				UpperCamelCase__ = None		,				UpperCamelCase__ = 1		,				**UpperCamelCase__		,				)						->      str:





           '''simple docstring'''
           return self.pipea(
               prompt=UpperCamelCase__		,				height=UpperCamelCase__		,				width=UpperCamelCase__		,				num_inference_steps=UpperCamelCase__		,				guidance_scale=UpperCamelCase__		,				negative_prompt=UpperCamelCase__		,				num_images_per_prompt=UpperCamelCase__		,				eta=UpperCamelCase__		,				generator=UpperCamelCase__		,				latents=UpperCamelCase__		,				output_type=UpperCamelCase__		,				return_dict=UpperCamelCase__		,				callback=UpperCamelCase__		,				callback_steps=UpperCamelCase__		,				**UpperCamelCase__		,				)



    @torch.no_grad()
    def 					snake_case_			(					self		,				UpperCamelCase__		,				UpperCamelCase__ = 512		,				UpperCamelCase__ = 512		,				UpperCamelCase__ = 50		,				UpperCamelCase__ = 7.5		,				UpperCamelCase__ = None		,				UpperCamelCase__ = 1		,				UpperCamelCase__ = 0.0		,				UpperCamelCase__ = None		,				UpperCamelCase__ = None		,				UpperCamelCase__ = "pil"		,				UpperCamelCase__ = True		,				UpperCamelCase__ = None		,				UpperCamelCase__ = 1		,				**UpperCamelCase__		,				)						->      int:





           '''simple docstring'''
           return self.pipea(
               prompt=UpperCamelCase__		,				height=UpperCamelCase__		,				width=UpperCamelCase__		,				num_inference_steps=UpperCamelCase__		,				guidance_scale=UpperCamelCase__		,				negative_prompt=UpperCamelCase__		,				num_images_per_prompt=UpperCamelCase__		,				eta=UpperCamelCase__		,				generator=UpperCamelCase__		,				latents=UpperCamelCase__		,				output_type=UpperCamelCase__		,				return_dict=UpperCamelCase__		,				callback=UpperCamelCase__		,				callback_steps=UpperCamelCase__		,				**UpperCamelCase__		,				)







    @torch.no_grad()
    def 					snake_case_			(					self		,				UpperCamelCase__		,				UpperCamelCase__ = 512		,				UpperCamelCase__ = 512		,				UpperCamelCase__ = 50		,				UpperCamelCase__ = 7.5		,				UpperCamelCase__ = None		,				UpperCamelCase__ = 1		,				UpperCamelCase__ = 0.0		,				UpperCamelCase__ = None		,				UpperCamelCase__ = None		,				UpperCamelCase__ = "pil"		,				UpperCamelCase__ = True		,				UpperCamelCase__ = None		,				UpperCamelCase__ = 1		,				**UpperCamelCase__		,				)						->      int:





           '''simple docstring'''
           A_						=      """cuda""" if torch.cuda.is_available() else """cpu"""
           self.to(UpperCamelCase__       )

           # Checks if the height and width are divisible by 8 or not
           if height % 8 != 0 or width % 8 != 0:
                  raise ValueError(f'''`height` and `width` must be divisible by 8 but are {height} and {width}.'''       )

           # Get first result from Stable Diffusion Checkpoint v1.1
           A_						=      self.textaimg_sda_a(
               prompt=UpperCamelCase__		,				height=UpperCamelCase__		,				width=UpperCamelCase__		,				num_inference_steps=UpperCamelCase__		,				guidance_scale=UpperCamelCase__		,				negative_prompt=UpperCamelCase__		,				num_images_per_prompt=UpperCamelCase__		,				eta=UpperCamelCase__		,				generator=UpperCamelCase__		,				latents=UpperCamelCase__		,				output_type=UpperCamelCase__		,				return_dict=UpperCamelCase__		,				callback=UpperCamelCase__		,				callback_steps=UpperCamelCase__		,				**UpperCamelCase__		,				)

           # Get first result from Stable Diffusion Checkpoint v1.2
           A_						=      self.textaimg_sda_a(
               prompt=UpperCamelCase__		,				height=UpperCamelCase__		,				width=UpperCamelCase__		,				num_inference_steps=UpperCamelCase__		,				guidance_scale=UpperCamelCase__		,				negative_prompt=UpperCamelCase__		,				num_images_per_prompt=UpperCamelCase__		,				eta=UpperCamelCase__		,				generator=UpperCamelCase__		,				latents=UpperCamelCase__		,				output_type=UpperCamelCase__		,				return_dict=UpperCamelCase__		,				callback=UpperCamelCase__		,				callback_steps=UpperCamelCase__		,				**UpperCamelCase__		,				)

           # Get first result from Stable Diffusion Checkpoint v1.3
           A_						=      self.textaimg_sda_a(
               prompt=UpperCamelCase__		,				height=UpperCamelCase__		,				width=UpperCamelCase__		,				num_inference_steps=UpperCamelCase__		,				guidance_scale=UpperCamelCase__		,				negative_prompt=UpperCamelCase__		,				num_images_per_prompt=UpperCamelCase__		,				eta=UpperCamelCase__		,				generator=UpperCamelCase__		,				latents=UpperCamelCase__		,				output_type=UpperCamelCase__		,				return_dict=UpperCamelCase__		,				callback=UpperCamelCase__		,				callback_steps=UpperCamelCase__		,				**UpperCamelCase__		,				)

           # Get first result from Stable Diffusion Checkpoint v1.4
           A_						=      self.textaimg_sda_a(
               prompt=UpperCamelCase__		,				height=UpperCamelCase__		,				width=UpperCamelCase__		,				num_inference_steps=UpperCamelCase__		,				guidance_scale=UpperCamelCase__		,				negative_prompt=UpperCamelCase__		,				num_images_per_prompt=UpperCamelCase__		,				eta=UpperCamelCase__		,				generator=UpperCamelCase__		,				latents=UpperCamelCase__		,				output_type=UpperCamelCase__		,				return_dict=UpperCamelCase__		,				callback=UpperCamelCase__		,				callback_steps=UpperCamelCase__		,				**UpperCamelCase__		,				)

           # Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
           return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]]       )



'''simple docstring'''







def       UpperCAmelCase__    (      UpperCAmelCase__,       UpperCAmelCase__,       UpperCAmelCase__ = 0,       UpperCAmelCase__ = 0				)			->			int:
       A_						=      right or len(UpperCAmelCase__				) - 1
       if left > right:
              return -1
       elif list_data[left] == key:
              return left
       elif list_data[right] == key:
              return right
       else:
              return search(UpperCAmelCase__,       UpperCAmelCase__,       left + 1,       right - 1				)


if __name__ == "__main__":
      import doctest

      doctest.testmod()
