



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      :							List[str]							       ="""CompVis/stable-diffusion-v1-1"""
UpperCAmelCase      :							Optional[int]							       ="""CompVis/stable-diffusion-v1-2"""
UpperCAmelCase      :							Optional[Any]							       ="""CompVis/stable-diffusion-v1-3"""
UpperCAmelCase      :							Dict							       ="""CompVis/stable-diffusion-v1-4"""


class 					_lowercase      (a_					):
				'''simple docstring'''







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

									'''simple docstring'''


									super()._init_()

									UpperCamelCase_						     =      StableDiffusionPipeline.from_pretrained(__UpperCAmelCase			)
									UpperCamelCase_						     =      StableDiffusionPipeline.from_pretrained(__UpperCAmelCase			)
									UpperCamelCase_						     =      StableDiffusionPipeline.from_pretrained(__UpperCAmelCase			)
									UpperCamelCase_						     =      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 					_lowerCamelCase    (       self			):

									'''simple docstring'''


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

				def 					_lowerCamelCase    (       self   ,       snake_case__ = "auto"			):

									'''simple docstring'''


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

				def 					_lowerCamelCase    (       self			):

									'''simple docstring'''


									self.enable_attention_slicing(__UpperCAmelCase			)

				@torch.no_grad()
				def 					_lowerCamelCase    (       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__   ,       ):

									'''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 					_lowerCamelCase    (       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__   ,       ):

									'''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 					_lowerCamelCase    (       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__   ,       ):

									'''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 					_lowerCamelCase    (       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__   ,       ):

									'''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 					_lowerCamelCase    (       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__   ,       ):

									'''simple docstring'''


									UpperCamelCase_						     =      '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
									UpperCamelCase_						     =      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
									UpperCamelCase_						     =      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
									UpperCamelCase_						     =      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
									UpperCamelCase_						     =      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"""





from typing import TYPE_CHECKING

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


__A											=		{
    """configuration_data2vec_audio""": ["""DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP""", """Data2VecAudioConfig"""],
    """configuration_data2vec_text""": [
        """DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """Data2VecTextConfig""",
        """Data2VecTextOnnxConfig""",
    ],
    """configuration_data2vec_vision""": [
        """DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """Data2VecVisionConfig""",
        """Data2VecVisionOnnxConfig""",
    ],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __A											=		[
      """DATA2VEC_AUDIO_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """Data2VecAudioForAudioFrameClassification""",
      """Data2VecAudioForCTC""",
      """Data2VecAudioForSequenceClassification""",
      """Data2VecAudioForXVector""",
      """Data2VecAudioModel""",
      """Data2VecAudioPreTrainedModel""",
  ]
  __A											=		[
      """DATA2VEC_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """Data2VecTextForCausalLM""",
      """Data2VecTextForMaskedLM""",
      """Data2VecTextForMultipleChoice""",
      """Data2VecTextForQuestionAnswering""",
      """Data2VecTextForSequenceClassification""",
      """Data2VecTextForTokenClassification""",
      """Data2VecTextModel""",
      """Data2VecTextPreTrainedModel""",
  ]
  __A											=		[
      """DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """Data2VecVisionForImageClassification""",
      """Data2VecVisionForMaskedImageModeling""",
      """Data2VecVisionForSemanticSegmentation""",
      """Data2VecVisionModel""",
      """Data2VecVisionPreTrainedModel""",
  ]

if is_tf_available():
  __A											=		[
      """TFData2VecVisionForImageClassification""",
      """TFData2VecVisionForSemanticSegmentation""",
      """TFData2VecVisionModel""",
      """TFData2VecVisionPreTrainedModel""",
  ]

if TYPE_CHECKING:
  from .configuration_dataavec_audio import DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP, DataaVecAudioConfig
  from .configuration_dataavec_text import (
      DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP,
      DataaVecTextConfig,
      DataaVecTextOnnxConfig,
  )
  from .configuration_dataavec_vision import (
      DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP,
      DataaVecVisionConfig,
      DataaVecVisionOnnxConfig,
  )

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_dataavec_audio import (
        DATA2VEC_AUDIO_PRETRAINED_MODEL_ARCHIVE_LIST,
        DataaVecAudioForAudioFrameClassification,
        DataaVecAudioForCTC,
        DataaVecAudioForSequenceClassification,
        DataaVecAudioForXVector,
        DataaVecAudioModel,
        DataaVecAudioPreTrainedModel,
    )
    from .modeling_dataavec_text import (
        DATA2VEC_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
        DataaVecTextForCausalLM,
        DataaVecTextForMaskedLM,
        DataaVecTextForMultipleChoice,
        DataaVecTextForQuestionAnswering,
        DataaVecTextForSequenceClassification,
        DataaVecTextForTokenClassification,
        DataaVecTextModel,
        DataaVecTextPreTrainedModel,
    )
    from .modeling_dataavec_vision import (
        DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST,
        DataaVecVisionForImageClassification,
        DataaVecVisionForMaskedImageModeling,
        DataaVecVisionForSemanticSegmentation,
        DataaVecVisionModel,
        DataaVecVisionPreTrainedModel,
    )
  if is_tf_available():
    from .modeling_tf_dataavec_vision import (
        TFDataaVecVisionForImageClassification,
        TFDataaVecVisionForSemanticSegmentation,
        TFDataaVecVisionModel,
        TFDataaVecVisionPreTrainedModel,
    )

else:
  import sys

  __A											=		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
