






"""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


_UpperCamelCase		:  Dict						=		'CompVis/stable-diffusion-v1-1'
_UpperCamelCase		:  List[str]						=		'CompVis/stable-diffusion-v1-2'
_UpperCamelCase		:  Optional[int]						=		'CompVis/stable-diffusion-v1-3'
_UpperCamelCase		:  str						=		'CompVis/stable-diffusion-v1-4'

class        a     (   a_	):







    def __init__(			self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase = True							,		):
      super()._init_()

      lowercase							    =       StableDiffusionPipeline.from_pretrained(_lowerCamelCase       )
      lowercase							    =       StableDiffusionPipeline.from_pretrained(_lowerCamelCase       )
      lowercase							    =       StableDiffusionPipeline.from_pretrained(_lowerCamelCase       )
      lowercase							    =       StableDiffusionPipeline(
          vae=_lowerCamelCase							,		text_encoder=_lowerCamelCase							,		tokenizer=_lowerCamelCase							,		unet=_lowerCamelCase							,		scheduler=_lowerCamelCase							,		safety_checker=_lowerCamelCase							,		feature_extractor=_lowerCamelCase							,		requires_safety_checker=_lowerCamelCase							,		)

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







    @property
    def 			UpperCamelCase_      (			self       ):
      return {k: getattr(self							,		_lowerCamelCase       ) for k in self.config.keys() if not k.startswith('_'       )}







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase = "auto"       ):
      if slice_size == "auto":
        # half the attention head size is usually a good trade-off between
        # speed and memory
        lowercase							    =       self.unet.config.attention_head_dim // 2
      self.unet.set_attention_slice(_lowerCamelCase       )







    def 			UpperCamelCase_      (			self       ):
      self.enable_attention_slicing(_lowerCamelCase       )







    @torch.no_grad()
    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase = 5_1_2							,		_lowerCamelCase = 5_1_2							,		_lowerCamelCase = 5_0							,		_lowerCamelCase = 7.5							,		_lowerCamelCase = None							,		_lowerCamelCase = 1							,		_lowerCamelCase = 0.0							,		_lowerCamelCase = None							,		_lowerCamelCase = None							,		_lowerCamelCase = "pil"							,		_lowerCamelCase = True							,		_lowerCamelCase = None							,		_lowerCamelCase = 1							,		**_lowerCamelCase							,		):
      return self.pipea(
          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							,		**_lowerCamelCase							,		)







    @torch.no_grad()
    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase = 5_1_2							,		_lowerCamelCase = 5_1_2							,		_lowerCamelCase = 5_0							,		_lowerCamelCase = 7.5							,		_lowerCamelCase = None							,		_lowerCamelCase = 1							,		_lowerCamelCase = 0.0							,		_lowerCamelCase = None							,		_lowerCamelCase = None							,		_lowerCamelCase = "pil"							,		_lowerCamelCase = True							,		_lowerCamelCase = None							,		_lowerCamelCase = 1							,		**_lowerCamelCase							,		):
      return self.pipea(
          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							,		**_lowerCamelCase							,		)







    @torch.no_grad()
    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase = 5_1_2							,		_lowerCamelCase = 5_1_2							,		_lowerCamelCase = 5_0							,		_lowerCamelCase = 7.5							,		_lowerCamelCase = None							,		_lowerCamelCase = 1							,		_lowerCamelCase = 0.0							,		_lowerCamelCase = None							,		_lowerCamelCase = None							,		_lowerCamelCase = "pil"							,		_lowerCamelCase = True							,		_lowerCamelCase = None							,		_lowerCamelCase = 1							,		**_lowerCamelCase							,		):
      return self.pipea(
          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							,		**_lowerCamelCase							,		)







    @torch.no_grad()
    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase = 5_1_2							,		_lowerCamelCase = 5_1_2							,		_lowerCamelCase = 5_0							,		_lowerCamelCase = 7.5							,		_lowerCamelCase = None							,		_lowerCamelCase = 1							,		_lowerCamelCase = 0.0							,		_lowerCamelCase = None							,		_lowerCamelCase = None							,		_lowerCamelCase = "pil"							,		_lowerCamelCase = True							,		_lowerCamelCase = None							,		_lowerCamelCase = 1							,		**_lowerCamelCase							,		):
      return self.pipea(
          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							,		**_lowerCamelCase							,		)







    @torch.no_grad()
    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase = 5_1_2							,		_lowerCamelCase = 5_1_2							,		_lowerCamelCase = 5_0							,		_lowerCamelCase = 7.5							,		_lowerCamelCase = None							,		_lowerCamelCase = 1							,		_lowerCamelCase = 0.0							,		_lowerCamelCase = None							,		_lowerCamelCase = None							,		_lowerCamelCase = "pil"							,		_lowerCamelCase = True							,		_lowerCamelCase = None							,		_lowerCamelCase = 1							,		**_lowerCamelCase							,		):
      lowercase							    =       'cuda' if torch.cuda.is_available() else 'cpu'
      self.to(_lowerCamelCase       )

      # 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
      lowercase							    =       self.textaimg_sda_a(
          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							,		**_lowerCamelCase							,		)

      # Get first result from Stable Diffusion Checkpoint v1.2
      lowercase							    =       self.textaimg_sda_a(
          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							,		**_lowerCamelCase							,		)

      # Get first result from Stable Diffusion Checkpoint v1.3
      lowercase							    =       self.textaimg_sda_a(
          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							,		**_lowerCamelCase							,		)

      # Get first result from Stable Diffusion Checkpoint v1.4
      lowercase							    =       self.textaimg_sda_a(
          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							,		**_lowerCamelCase							,		)

      # 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"""



from argparse import ArgumentParser

from .env import EnvironmentCommand
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  lowercase							    =       ArgumentParser('Diffusers CLI tool'		,					usage='diffusers-cli <command> [<args>]'    )
  lowercase							    =       parser.add_subparsers(help='diffusers-cli command helpers'    )

  # Register commands
  EnvironmentCommand.register_subcommand(__snake_case    )

  # Let's go
  lowercase							    =       parser.parse_args()

  if not hasattr(__snake_case		,					'func'    ):
    parser.print_help()
    exit(1    )

  # Run
  lowercase							    =       args.func(__snake_case    )
  service.run()


if __name__ == "__main__":
    main()


