




"""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


A_      			=       '''CompVis/stable-diffusion-v1-1'''
A_      			=       '''CompVis/stable-diffusion-v1-2'''
A_      			=       '''CompVis/stable-diffusion-v1-3'''
A_      			=       '''CompVis/stable-diffusion-v1-4'''






class       lowercase(  __a				):







 '''simple docstring'''





 def __init__(       self:	Union[str, Any],   a_:	AutoencoderKL,   a_:	CLIPTextModel,   a_:	CLIPTokenizer,   a_:	UNetaDConditionModel,   a_:	Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler],   a_:	StableDiffusionSafetyChecker,   a_:	CLIPImageProcessor,   a_:	bool = True,   ):




   '''simple docstring'''



   super()._init_()

   _snake_case							:	Tuple			=						StableDiffusionPipeline.from_pretrained(a_	)
   _snake_case							:	int			=						StableDiffusionPipeline.from_pretrained(a_	)
   _snake_case							:	Any			=						StableDiffusionPipeline.from_pretrained(a_	)
   _snake_case							:	Any			=						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:	Optional[int]	):




   '''simple docstring'''



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


 def 				UpperCamelCase_     (       self:	str,   a_:	Optional[Union[str, int]] = "auto"	):




   '''simple docstring'''



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


 def 				UpperCamelCase_     (       self:	Union[str, Any]	):




   '''simple docstring'''



   self.enable_attention_slicing(a_	)


 @torch.no_grad()
 def 				UpperCamelCase_     (       self:	Union[str, Any],   a_:	Union[str, List[str]],   a_:	int = 512,   a_:	int = 512,   a_:	int = 50,   a_:	float = 7.5,   a_:	Optional[Union[str, List[str]]] = None,   a_:	Optional[int] = 1,   a_:	float = 0.0,   a_:	Optional[torch.Generator] = None,   a_:	Optional[torch.FloatTensor] = None,   a_:	Optional[str] = "pil",   a_:	bool = True,   a_:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None,   a_:	int = 1,   **a_:	List[str],   ):




   '''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:	List[Any],   a_:	Union[str, List[str]],   a_:	int = 512,   a_:	int = 512,   a_:	int = 50,   a_:	float = 7.5,   a_:	Optional[Union[str, List[str]]] = None,   a_:	Optional[int] = 1,   a_:	float = 0.0,   a_:	Optional[torch.Generator] = None,   a_:	Optional[torch.FloatTensor] = None,   a_:	Optional[str] = "pil",   a_:	bool = True,   a_:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None,   a_:	int = 1,   **a_:	Any,   ):




   '''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:	Dict,   a_:	Union[str, List[str]],   a_:	int = 512,   a_:	int = 512,   a_:	int = 50,   a_:	float = 7.5,   a_:	Optional[Union[str, List[str]]] = None,   a_:	Optional[int] = 1,   a_:	float = 0.0,   a_:	Optional[torch.Generator] = None,   a_:	Optional[torch.FloatTensor] = None,   a_:	Optional[str] = "pil",   a_:	bool = True,   a_:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None,   a_:	int = 1,   **a_:	Optional[int],   ):




   '''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:	Any,   a_:	Union[str, List[str]],   a_:	int = 512,   a_:	int = 512,   a_:	int = 50,   a_:	float = 7.5,   a_:	Optional[Union[str, List[str]]] = None,   a_:	Optional[int] = 1,   a_:	float = 0.0,   a_:	Optional[torch.Generator] = None,   a_:	Optional[torch.FloatTensor] = None,   a_:	Optional[str] = "pil",   a_:	bool = True,   a_:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None,   a_:	int = 1,   **a_:	Union[str, Any],   ):




   '''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:	str,   a_:	Union[str, List[str]],   a_:	int = 512,   a_:	int = 512,   a_:	int = 50,   a_:	float = 7.5,   a_:	Optional[Union[str, List[str]]] = None,   a_:	Optional[int] = 1,   a_:	float = 0.0,   a_:	Optional[torch.Generator] = None,   a_:	Optional[torch.FloatTensor] = None,   a_:	Optional[str] = "pil",   a_:	bool = True,   a_:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None,   a_:	int = 1,   **a_:	int,   ):




   '''simple docstring'''



   _snake_case							:	int			=						"""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
   _snake_case							:	Dict			=						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
   _snake_case							:	str			=						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
   _snake_case							:	Optional[int]			=						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
   _snake_case							:	Optional[int]			=						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 TYPE_CHECKING

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


A_      			=       {
    '''configuration_owlvit''': [
        '''OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''OwlViTConfig''',
        '''OwlViTOnnxConfig''',
        '''OwlViTTextConfig''',
        '''OwlViTVisionConfig''',
    ],
    '''processing_owlvit''': ['''OwlViTProcessor'''],
}


try:
     if not is_vision_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     A_      			=       ['''OwlViTFeatureExtractor''']
     A_      			=       ['''OwlViTImageProcessor''']

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     A_      			=       [
         '''OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''OwlViTModel''',
         '''OwlViTPreTrainedModel''',
         '''OwlViTTextModel''',
         '''OwlViTVisionModel''',
         '''OwlViTForObjectDetection''',
     ]

if TYPE_CHECKING:
     from .configuration_owlvit import (
         OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP,
         OwlViTConfig,
         OwlViTOnnxConfig,
         OwlViTTextConfig,
         OwlViTVisionConfig,
     )
     from .processing_owlvit import OwlViTProcessor

     try:
          if not is_vision_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .feature_extraction_owlvit import OwlViTFeatureExtractor
          from .image_processing_owlvit import OwlViTImageProcessor

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_owlvit import (
              OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
              OwlViTForObjectDetection,
              OwlViTModel,
              OwlViTPreTrainedModel,
              OwlViTTextModel,
              OwlViTVisionModel,
          )

else:
     import sys

     A_      			=       _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


