


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   _lowerCamelCase (					UpperCAmelCase__			):




       """simple docstring"""



       def __init__(      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE = True				,       )->List[Any]:




         '''simple docstring'''





         super()._init_()

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

         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				,       SCREAMING_SNAKE_CASE__		) for k in self.config.keys() if not k.startswith('''_'''		)}



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE = "auto"		)->Optional[int]:




         '''simple docstring'''





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



       def        _snake_case       (      self		)->Optional[int]:




         '''simple docstring'''





         self.enable_attention_slicing(SCREAMING_SNAKE_CASE__		)



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




         '''simple docstring'''





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



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




         '''simple docstring'''





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



       @torch.no_grad()
       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE = 512				,       _SCREAMING_SNAKE_CASE = 512				,       _SCREAMING_SNAKE_CASE = 50				,       _SCREAMING_SNAKE_CASE = 7.5				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = 1				,       _SCREAMING_SNAKE_CASE = 0.0				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = "pil"				,       _SCREAMING_SNAKE_CASE = True				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = 1				,       **_SCREAMING_SNAKE_CASE				,       )->Union[str, Any]:




         '''simple docstring'''





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



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




         '''simple docstring'''





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







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




         '''simple docstring'''





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

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

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

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

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

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

import warnings

from ...utils import logging
from .image_processing_segformer import SegformerImageProcessor


_A			:      Optional[int]					      =				logging.get_logger(__name__)







class 				_lowercase     (				UpperCAmelCase__			):


 '''simple docstring'''






 def __init__(      self   :	Dict      ,       *SCREAMING_SNAKE_CASE__   :	Optional[int]      ,       **SCREAMING_SNAKE_CASE__   :	List[str]							)  ->    None:
  warnings.warn(
      """The class SegformerFeatureExtractor is deprecated and will be removed in version 5 of Transformers."""
      """ Please use SegformerImageProcessor instead."""      ,       SCREAMING_SNAKE_CASE__      ,       )
  super().__init__(*SCREAMING_SNAKE_CASE__      ,       **SCREAMING_SNAKE_CASE__							)






