




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__ :   str						=							'''CompVis/stable-diffusion-v1-1'''
UpperCamelCase__ :   Optional[Any]						=							'''CompVis/stable-diffusion-v1-2'''
UpperCamelCase__ :   Optional[int]						=							'''CompVis/stable-diffusion-v1-3'''
UpperCamelCase__ :   Union[str, Any]						=							'''CompVis/stable-diffusion-v1-4'''







class 				lowerCAmelCase_       (					lowerCamelCase_							):






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

							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      StableDiffusionPipeline.from_pretrained(snake_case__ )
							SCREAMING_SNAKE_CASE_   : str					  =      StableDiffusionPipeline.from_pretrained(snake_case__ )
							SCREAMING_SNAKE_CASE_   : Dict					  =      StableDiffusionPipeline.from_pretrained(snake_case__ )
							SCREAMING_SNAKE_CASE_   : Tuple					  =      StableDiffusionPipeline(
							    vae=snake_case__      ,text_encoder=snake_case__      ,tokenizer=snake_case__      ,unet=snake_case__      ,scheduler=snake_case__      ,safety_checker=snake_case__      ,feature_extractor=snake_case__      ,requires_safety_checker=snake_case__      ,)

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






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






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






				def 		snake_case	(			self ):
							self.enable_attention_slicing(snake_case__ )






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      'cuda' if torch.cuda.is_available() else 'cpu'
							self.to(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
							SCREAMING_SNAKE_CASE_   : Any					  =      self.textaimg_sda_a(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**snake_case__      ,)

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

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

							# Get first result from Stable Diffusion Checkpoint v1.4
							SCREAMING_SNAKE_CASE_   : str					  =      self.textaimg_sda_a(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**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]] )










from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


UpperCAmelCase_							=				{
    """configuration_maskformer""": ["""MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MaskFormerConfig"""],
    """configuration_maskformer_swin""": ["""MaskFormerSwinConfig"""],
}

try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase_							=				["""MaskFormerFeatureExtractor"""]
							UpperCAmelCase_							=				["""MaskFormerImageProcessor"""]


try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase_							=				[
							    """MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """MaskFormerForInstanceSegmentation""",
							    """MaskFormerModel""",
							    """MaskFormerPreTrainedModel""",
							]
							UpperCAmelCase_							=				[
							    """MaskFormerSwinBackbone""",
							    """MaskFormerSwinModel""",
							    """MaskFormerSwinPreTrainedModel""",
							]

if TYPE_CHECKING:
							from .configuration_maskformer import MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, MaskFormerConfig
							from .configuration_maskformer_swin import MaskFormerSwinConfig

							try:
														if not is_vision_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .feature_extraction_maskformer import MaskFormerFeatureExtractor
														from .image_processing_maskformer import MaskFormerImageProcessor
							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_maskformer import (
														    MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
														    MaskFormerForInstanceSegmentation,
														    MaskFormerModel,
														    MaskFormerPreTrainedModel,
														)
														from .modeling_maskformer_swin import (
														    MaskFormerSwinBackbone,
														    MaskFormerSwinModel,
														    MaskFormerSwinPreTrainedModel,
														)


else:
							import sys

							UpperCAmelCase_							=				_LazyModule(__name__, globals()["""__file__"""], _import_structure)