

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     __snake_case    (				snake_case__  ):
       """simple docstring"""







       def __init__(		self      , _UpperCamelCase      , _UpperCamelCase      , _UpperCamelCase      , _UpperCamelCase      , _UpperCamelCase      , _UpperCamelCase      , _UpperCamelCase      , _UpperCamelCase = True      , )      ->							int:






              """simple docstring"""


              super()._init_()

              __snake_case       	=							StableDiffusionPipeline.from_pretrained(_UpperCamelCase   )
              __snake_case       	=							StableDiffusionPipeline.from_pretrained(_UpperCamelCase   )
              __snake_case       	=							StableDiffusionPipeline.from_pretrained(_UpperCamelCase   )
              __snake_case       	=							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 			a		(		self   )      ->							Dict[str, Any]:






              """simple docstring"""


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


       def 			a		(		self      , _UpperCamelCase = "auto"   )      ->							Tuple:






              """simple docstring"""


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


       def 			a		(		self   )      ->							Any:






              """simple docstring"""


              self.enable_attention_slicing(_UpperCamelCase   )


       @torch.no_grad()
       def 			a		(		self      , _UpperCamelCase      , _UpperCamelCase = 5_12      , _UpperCamelCase = 5_12      , _UpperCamelCase = 50      , _UpperCamelCase = 7.5      , _UpperCamelCase = None      , _UpperCamelCase = 1      , _UpperCamelCase = 0.0      , _UpperCamelCase = None      , _UpperCamelCase = None      , _UpperCamelCase = "pil"      , _UpperCamelCase = True      , _UpperCamelCase = None      , _UpperCamelCase = 1      , **_UpperCamelCase      , )      ->							List[Any]:






              """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 			a		(		self      , _UpperCamelCase      , _UpperCamelCase = 5_12      , _UpperCamelCase = 5_12      , _UpperCamelCase = 50      , _UpperCamelCase = 7.5      , _UpperCamelCase = None      , _UpperCamelCase = 1      , _UpperCamelCase = 0.0      , _UpperCamelCase = None      , _UpperCamelCase = None      , _UpperCamelCase = "pil"      , _UpperCamelCase = True      , _UpperCamelCase = None      , _UpperCamelCase = 1      , **_UpperCamelCase      , )      ->							Dict:






              """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 			a		(		self      , _UpperCamelCase      , _UpperCamelCase = 5_12      , _UpperCamelCase = 5_12      , _UpperCamelCase = 50      , _UpperCamelCase = 7.5      , _UpperCamelCase = None      , _UpperCamelCase = 1      , _UpperCamelCase = 0.0      , _UpperCamelCase = None      , _UpperCamelCase = None      , _UpperCamelCase = "pil"      , _UpperCamelCase = True      , _UpperCamelCase = None      , _UpperCamelCase = 1      , **_UpperCamelCase      , )      ->							int:






              """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 			a		(		self      , _UpperCamelCase      , _UpperCamelCase = 5_12      , _UpperCamelCase = 5_12      , _UpperCamelCase = 50      , _UpperCamelCase = 7.5      , _UpperCamelCase = None      , _UpperCamelCase = 1      , _UpperCamelCase = 0.0      , _UpperCamelCase = None      , _UpperCamelCase = None      , _UpperCamelCase = "pil"      , _UpperCamelCase = True      , _UpperCamelCase = None      , _UpperCamelCase = 1      , **_UpperCamelCase      , )      ->							Any:






              """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 			a		(		self      , _UpperCamelCase      , _UpperCamelCase = 5_12      , _UpperCamelCase = 5_12      , _UpperCamelCase = 50      , _UpperCamelCase = 7.5      , _UpperCamelCase = None      , _UpperCamelCase = 1      , _UpperCamelCase = 0.0      , _UpperCamelCase = None      , _UpperCamelCase = None      , _UpperCamelCase = "pil"      , _UpperCamelCase = True      , _UpperCamelCase = None      , _UpperCamelCase = 1      , **_UpperCamelCase      , )      ->							str:






              """simple docstring"""


              __snake_case       	=							"""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
              __snake_case       	=							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
              __snake_case       	=							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
              __snake_case       	=							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
              __snake_case       	=							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]]   )




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


UpperCamelCase__		 =     {
    '''configuration_convnext''': ['''CONVNEXT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ConvNextConfig''', '''ConvNextOnnxConfig''']
}

try:
    if not is_vision_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    UpperCamelCase__		 =     ['''ConvNextFeatureExtractor''']
    UpperCamelCase__		 =     ['''ConvNextImageProcessor''']

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    UpperCamelCase__		 =     [
        '''CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST''',
        '''ConvNextForImageClassification''',
        '''ConvNextModel''',
        '''ConvNextPreTrainedModel''',
        '''ConvNextBackbone''',
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    UpperCamelCase__		 =     [
        '''TFConvNextForImageClassification''',
        '''TFConvNextModel''',
        '''TFConvNextPreTrainedModel''',
    ]

if TYPE_CHECKING:
    from .configuration_convnext import CONVNEXT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvNextConfig, ConvNextOnnxConfig

    try:
        if not is_vision_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .feature_extraction_convnext import ConvNextFeatureExtractor
        from .image_processing_convnext import ConvNextImageProcessor

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_convnext import (
            CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
            ConvNextBackbone,
            ConvNextForImageClassification,
            ConvNextModel,
            ConvNextPreTrainedModel,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_convnext import TFConvNextForImageClassification, TFConvNextModel, TFConvNextPreTrainedModel


else:
    import sys

    UpperCamelCase__		 =     _LazyModule(__name__, globals()['''__file__'''], _import_structure)

