




'''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_    	=				"CompVis/stable-diffusion-v1-1"
UpperCamelCase_    	=				"CompVis/stable-diffusion-v1-2"
UpperCamelCase_    	=				"CompVis/stable-diffusion-v1-3"
UpperCamelCase_    	=				"CompVis/stable-diffusion-v1-4"






class 							_a				(			SCREAMING_SNAKE_CASE ):





       '''simple docstring'''






       def __init__(      self,							A,							A,							A,							A,							A,							A,							A,							A = True,							):







             '''simple docstring'''







             super()._init_()

             SCREAMING_SNAKE_CASE   :      Optional[int]    					=						StableDiffusionPipeline.from_pretrained(A  )
             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						StableDiffusionPipeline.from_pretrained(A  )
             SCREAMING_SNAKE_CASE   :      int    					=						StableDiffusionPipeline.from_pretrained(A  )
             SCREAMING_SNAKE_CASE   :      Tuple    					=						StableDiffusionPipeline(
                 vae=A,							text_encoder=A,							tokenizer=A,							unet=A,							scheduler=A,							safety_checker=A,							feature_extractor=A,							requires_safety_checker=A,							)

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







       @property
       def        UpperCamelCase_							(      self  ):







             '''simple docstring'''







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







       def        UpperCamelCase_							(      self,							A = "auto"  ):







             '''simple docstring'''







             if slice_size == "auto":
                   # half the attention head size is usually a good trade-off between
                   # speed and memory
                   SCREAMING_SNAKE_CASE   :      List[str]    					=						self.unet.config.attention_head_dim // 2
             self.unet.set_attention_slice(A  )







       def        UpperCamelCase_							(      self  ):







             '''simple docstring'''







             self.enable_attention_slicing(A  )







       @torch.no_grad()
       def        UpperCamelCase_							(      self,							A,							A = 512,							A = 512,							A = 50,							A = 7.5,							A = None,							A = 1,							A = 0.0,							A = None,							A = None,							A = "pil",							A = True,							A = None,							A = 1,							**A,							):







             '''simple docstring'''







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







       @torch.no_grad()
       def        UpperCamelCase_							(      self,							A,							A = 512,							A = 512,							A = 50,							A = 7.5,							A = None,							A = 1,							A = 0.0,							A = None,							A = None,							A = "pil",							A = True,							A = None,							A = 1,							**A,							):







             '''simple docstring'''







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







       @torch.no_grad()
       def        UpperCamelCase_							(      self,							A,							A = 512,							A = 512,							A = 50,							A = 7.5,							A = None,							A = 1,							A = 0.0,							A = None,							A = None,							A = "pil",							A = True,							A = None,							A = 1,							**A,							):







             '''simple docstring'''







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







       @torch.no_grad()
       def        UpperCamelCase_							(      self,							A,							A = 512,							A = 512,							A = 50,							A = 7.5,							A = None,							A = 1,							A = 0.0,							A = None,							A = None,							A = "pil",							A = True,							A = None,							A = 1,							**A,							):







             '''simple docstring'''







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







       @torch.no_grad()
       def        UpperCamelCase_							(      self,							A,							A = 512,							A = 512,							A = 50,							A = 7.5,							A = None,							A = 1,							A = 0.0,							A = None,							A = None,							A = "pil",							A = True,							A = None,							A = 1,							**A,							):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      Union[str, Any]    					=						'cuda' if torch.cuda.is_available() else 'cpu'
             self.to(A  )

             # 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
             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						self.textaimg_sda_a(
                 prompt=A,							height=A,							width=A,							num_inference_steps=A,							guidance_scale=A,							negative_prompt=A,							num_images_per_prompt=A,							eta=A,							generator=A,							latents=A,							output_type=A,							return_dict=A,							callback=A,							callback_steps=A,							**A,							)

             # Get first result from Stable Diffusion Checkpoint v1.2
             SCREAMING_SNAKE_CASE   :      List[Any]    					=						self.textaimg_sda_a(
                 prompt=A,							height=A,							width=A,							num_inference_steps=A,							guidance_scale=A,							negative_prompt=A,							num_images_per_prompt=A,							eta=A,							generator=A,							latents=A,							output_type=A,							return_dict=A,							callback=A,							callback_steps=A,							**A,							)

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

             # Get first result from Stable Diffusion Checkpoint v1.4
             SCREAMING_SNAKE_CASE   :      Union[str, Any]    					=						self.textaimg_sda_a(
                 prompt=A,							height=A,							width=A,							num_inference_steps=A,							guidance_scale=A,							negative_prompt=A,							num_images_per_prompt=A,							eta=A,							generator=A,							latents=A,							output_type=A,							return_dict=A,							callback=A,							callback_steps=A,							**A,							)

             # 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 typing import Dict

from .base import GenericTensor, Pipeline






class 							_a				(			SCREAMING_SNAKE_CASE ):





       '''simple docstring'''






       def        UpperCamelCase_							(      self,							A=None,							A=None,							A=None,							**A  ):







             '''simple docstring'''







             if tokenize_kwargs is None:
                   SCREAMING_SNAKE_CASE   :      Optional[int]    					=						{}

             if truncation is not None:
                   if "truncation" in tokenize_kwargs:
                         raise ValueError(
                             'truncation parameter defined twice (given as keyword argument as well as in tokenize_kwargs)'  )
                   SCREAMING_SNAKE_CASE   :      Tuple    					=						truncation

             SCREAMING_SNAKE_CASE   :      int    					=						tokenize_kwargs

             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						{}
             if return_tensors is not None:
                   SCREAMING_SNAKE_CASE   :      Optional[int]    					=						return_tensors

             return preprocess_params, {}, postprocess_params







       def        UpperCamelCase_							(      self,							A,							**A  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      Tuple    					=						self.framework
             SCREAMING_SNAKE_CASE   :      Tuple    					=						self.tokenizer(A,							return_tensors=A,							**A  )
             return model_inputs







       def        UpperCamelCase_							(      self,							A  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      Any    					=						self.model(**A  )
             return model_outputs







       def        UpperCamelCase_							(      self,							A,							A=False  ):







             '''simple docstring'''







             if return_tensors:
                   return model_outputs[0]
             if self.framework == "pt":
                   return model_outputs[0].tolist()
             elif self.framework == "tf":
                   return model_outputs[0].numpy().tolist()







       def __call__(      self,							*A,							**A  ):







             '''simple docstring'''







             return super().__call__(*A,							**A  )


