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


_lowercase    =		"""CompVis/stable-diffusion-v1-1"""
_lowercase    =		"""CompVis/stable-diffusion-v1-2"""
_lowercase    =		"""CompVis/stable-diffusion-v1-3"""
_lowercase    =		"""CompVis/stable-diffusion-v1-4"""




class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






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

												"""simple docstring"""



												super()._init_()

												_lowerCAmelCase  						=			StableDiffusionPipeline.from_pretrained(_lowercase				)
												_lowerCAmelCase  						=			StableDiffusionPipeline.from_pretrained(_lowercase				)
												_lowerCAmelCase  						=			StableDiffusionPipeline.from_pretrained(_lowercase				)
												_lowerCAmelCase  						=			StableDiffusionPipeline(
												    vae=_lowercase   ,       text_encoder=_lowercase   ,       tokenizer=_lowercase   ,       unet=_lowercase   ,       scheduler=_lowercase   ,       safety_checker=_lowercase   ,       feature_extractor=_lowercase   ,       requires_safety_checker=_lowercase   ,       )

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




						@property
						def  _lowercase     ( self				):

												"""simple docstring"""



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




						def  _lowercase     ( self   ,       _lowercase = "auto"				):

												"""simple docstring"""



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




						def  _lowercase     ( self				):

												"""simple docstring"""



												self.enable_attention_slicing(_lowercase				)




						@torch.no_grad()
						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase = 512   ,       _lowercase = 512   ,       _lowercase = 50   ,       _lowercase = 7.5   ,       _lowercase = None   ,       _lowercase = 1   ,       _lowercase = 0.0   ,       _lowercase = None   ,       _lowercase = None   ,       _lowercase = "pil"   ,       _lowercase = True   ,       _lowercase = None   ,       _lowercase = 1   ,       **_lowercase   ,       ):

												"""simple docstring"""



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




						@torch.no_grad()
						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase = 512   ,       _lowercase = 512   ,       _lowercase = 50   ,       _lowercase = 7.5   ,       _lowercase = None   ,       _lowercase = 1   ,       _lowercase = 0.0   ,       _lowercase = None   ,       _lowercase = None   ,       _lowercase = "pil"   ,       _lowercase = True   ,       _lowercase = None   ,       _lowercase = 1   ,       **_lowercase   ,       ):

												"""simple docstring"""



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




						@torch.no_grad()
						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase = 512   ,       _lowercase = 512   ,       _lowercase = 50   ,       _lowercase = 7.5   ,       _lowercase = None   ,       _lowercase = 1   ,       _lowercase = 0.0   ,       _lowercase = None   ,       _lowercase = None   ,       _lowercase = "pil"   ,       _lowercase = True   ,       _lowercase = None   ,       _lowercase = 1   ,       **_lowercase   ,       ):

												"""simple docstring"""



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




						@torch.no_grad()
						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase = 512   ,       _lowercase = 512   ,       _lowercase = 50   ,       _lowercase = 7.5   ,       _lowercase = None   ,       _lowercase = 1   ,       _lowercase = 0.0   ,       _lowercase = None   ,       _lowercase = None   ,       _lowercase = "pil"   ,       _lowercase = True   ,       _lowercase = None   ,       _lowercase = 1   ,       **_lowercase   ,       ):

												"""simple docstring"""



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




						@torch.no_grad()
						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase = 512   ,       _lowercase = 512   ,       _lowercase = 50   ,       _lowercase = 7.5   ,       _lowercase = None   ,       _lowercase = 1   ,       _lowercase = 0.0   ,       _lowercase = None   ,       _lowercase = None   ,       _lowercase = "pil"   ,       _lowercase = True   ,       _lowercase = None   ,       _lowercase = 1   ,       **_lowercase   ,       ):

												"""simple docstring"""



												_lowerCAmelCase  						=			"""cuda""" if torch.cuda.is_available() else """cpu"""
												self.to(_lowercase				)

												# 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
												_lowerCAmelCase  						=			self.textaimg_sda_a(
												    prompt=_lowercase   ,       height=_lowercase   ,       width=_lowercase   ,       num_inference_steps=_lowercase   ,       guidance_scale=_lowercase   ,       negative_prompt=_lowercase   ,       num_images_per_prompt=_lowercase   ,       eta=_lowercase   ,       generator=_lowercase   ,       latents=_lowercase   ,       output_type=_lowercase   ,       return_dict=_lowercase   ,       callback=_lowercase   ,       callback_steps=_lowercase   ,       **_lowercase   ,       )

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

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

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

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


_lowercase    =		{
    """configuration_table_transformer""": [
        """TABLE_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """TableTransformerConfig""",
        """TableTransformerOnnxConfig""",
    ]
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_lowercase    =		[
						    """TABLE_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
						    """TableTransformerForObjectDetection""",
						    """TableTransformerModel""",
						    """TableTransformerPreTrainedModel""",
						]


if TYPE_CHECKING:
						from .configuration_table_transformer import (
						    TABLE_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    TableTransformerConfig,
						    TableTransformerOnnxConfig,
						)

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_table_transformer import (
												    TABLE_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    TableTransformerForObjectDetection,
												    TableTransformerModel,
												    TableTransformerPreTrainedModel,
												)

else:
						import sys

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