


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_				:			int   =	'CompVis/stable-diffusion-v1-1'
UpperCAmelCase_				:			Optional[Any]   =	'CompVis/stable-diffusion-v1-2'
UpperCAmelCase_				:			Tuple   =	'CompVis/stable-diffusion-v1-3'
UpperCAmelCase_				:			Union[str, Any]   =	'CompVis/stable-diffusion-v1-4'
class 			SCREAMING_SNAKE_CASE__  (    lowercase__      ):
      def __init__(	self    :	Dict					,							SCREAMING_SNAKE_CASE__    :	AutoencoderKL					,							SCREAMING_SNAKE_CASE__    :	CLIPTextModel					,							SCREAMING_SNAKE_CASE__    :	CLIPTokenizer					,							SCREAMING_SNAKE_CASE__    :	UNetaDConditionModel					,							SCREAMING_SNAKE_CASE__    :	Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]					,							SCREAMING_SNAKE_CASE__    :	StableDiffusionSafetyChecker					,							SCREAMING_SNAKE_CASE__    :	CLIPImageProcessor					,							SCREAMING_SNAKE_CASE__    :	bool = True					,							)		->      Union[str, Any]:
             super()._init_()

             a_ :		Optional[int]							=  StableDiffusionPipeline.from_pretrained(SCREAMING_SNAKE_CASE__					)
             a_ :		List[str]							=  StableDiffusionPipeline.from_pretrained(SCREAMING_SNAKE_CASE__					)
             a_ :		Optional[Any]							=  StableDiffusionPipeline.from_pretrained(SCREAMING_SNAKE_CASE__					)
             a_ :		str							=  StableDiffusionPipeline(
                 vae=SCREAMING_SNAKE_CASE__					,							text_encoder=SCREAMING_SNAKE_CASE__					,							tokenizer=SCREAMING_SNAKE_CASE__					,							unet=SCREAMING_SNAKE_CASE__					,							scheduler=SCREAMING_SNAKE_CASE__					,							safety_checker=SCREAMING_SNAKE_CASE__					,							feature_extractor=SCREAMING_SNAKE_CASE__					,							requires_safety_checker=SCREAMING_SNAKE_CASE__					,							)

             self.register_modules(pipelinea=self.pipea					,							pipelinea=self.pipea					,							pipelinea=self.pipea					,							pipelinea=self.pipea					)
      @property
      def 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					)		->      Dict[str, Any]:
             return {k: getattr(self					,							SCREAMING_SNAKE_CASE__					) for k in self.config.keys() if not k.startswith('_'					)}
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Optional[Union[str, int]] = "auto"					)		->      Optional[int]:
             if slice_size == "auto":
                    # half the attention head size is usually a good trade-off between
                    # speed and memory
                    a_ :		Dict							=  self.unet.config.attention_head_dim // 2
             self.unet.set_attention_slice(SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					)		->      Optional[Any]:
             self.enable_attention_slicing(SCREAMING_SNAKE_CASE__					)
      @torch.no_grad()
      def 	SCREAMING_SNAKE_CASE							(	self    :	Dict					,							SCREAMING_SNAKE_CASE__    :	Union[str, List[str]]					,							SCREAMING_SNAKE_CASE__    :	int = 5_1_2					,							SCREAMING_SNAKE_CASE__    :	int = 5_1_2					,							SCREAMING_SNAKE_CASE__    :	int = 5_0					,							SCREAMING_SNAKE_CASE__    :	float = 7.5					,							SCREAMING_SNAKE_CASE__    :	Optional[Union[str, List[str]]] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[int] = 1					,							SCREAMING_SNAKE_CASE__    :	float = 0.0					,							SCREAMING_SNAKE_CASE__    :	Optional[torch.Generator] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[torch.FloatTensor] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[str] = "pil"					,							SCREAMING_SNAKE_CASE__    :	bool = True					,							SCREAMING_SNAKE_CASE__    :	Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,							SCREAMING_SNAKE_CASE__    :	int = 1					,							**SCREAMING_SNAKE_CASE__    :	Any					,							)		->      Any:
             return self.pipea(
                 prompt=SCREAMING_SNAKE_CASE__					,							height=SCREAMING_SNAKE_CASE__					,							width=SCREAMING_SNAKE_CASE__					,							num_inference_steps=SCREAMING_SNAKE_CASE__					,							guidance_scale=SCREAMING_SNAKE_CASE__					,							negative_prompt=SCREAMING_SNAKE_CASE__					,							num_images_per_prompt=SCREAMING_SNAKE_CASE__					,							eta=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							latents=SCREAMING_SNAKE_CASE__					,							output_type=SCREAMING_SNAKE_CASE__					,							return_dict=SCREAMING_SNAKE_CASE__					,							callback=SCREAMING_SNAKE_CASE__					,							callback_steps=SCREAMING_SNAKE_CASE__					,							**SCREAMING_SNAKE_CASE__					,							)
      @torch.no_grad()
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	Union[str, List[str]]					,							SCREAMING_SNAKE_CASE__    :	int = 5_1_2					,							SCREAMING_SNAKE_CASE__    :	int = 5_1_2					,							SCREAMING_SNAKE_CASE__    :	int = 5_0					,							SCREAMING_SNAKE_CASE__    :	float = 7.5					,							SCREAMING_SNAKE_CASE__    :	Optional[Union[str, List[str]]] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[int] = 1					,							SCREAMING_SNAKE_CASE__    :	float = 0.0					,							SCREAMING_SNAKE_CASE__    :	Optional[torch.Generator] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[torch.FloatTensor] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[str] = "pil"					,							SCREAMING_SNAKE_CASE__    :	bool = True					,							SCREAMING_SNAKE_CASE__    :	Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,							SCREAMING_SNAKE_CASE__    :	int = 1					,							**SCREAMING_SNAKE_CASE__    :	Optional[Any]					,							)		->      List[str]:
             return self.pipea(
                 prompt=SCREAMING_SNAKE_CASE__					,							height=SCREAMING_SNAKE_CASE__					,							width=SCREAMING_SNAKE_CASE__					,							num_inference_steps=SCREAMING_SNAKE_CASE__					,							guidance_scale=SCREAMING_SNAKE_CASE__					,							negative_prompt=SCREAMING_SNAKE_CASE__					,							num_images_per_prompt=SCREAMING_SNAKE_CASE__					,							eta=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							latents=SCREAMING_SNAKE_CASE__					,							output_type=SCREAMING_SNAKE_CASE__					,							return_dict=SCREAMING_SNAKE_CASE__					,							callback=SCREAMING_SNAKE_CASE__					,							callback_steps=SCREAMING_SNAKE_CASE__					,							**SCREAMING_SNAKE_CASE__					,							)
      @torch.no_grad()
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					,							SCREAMING_SNAKE_CASE__    :	Union[str, List[str]]					,							SCREAMING_SNAKE_CASE__    :	int = 5_1_2					,							SCREAMING_SNAKE_CASE__    :	int = 5_1_2					,							SCREAMING_SNAKE_CASE__    :	int = 5_0					,							SCREAMING_SNAKE_CASE__    :	float = 7.5					,							SCREAMING_SNAKE_CASE__    :	Optional[Union[str, List[str]]] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[int] = 1					,							SCREAMING_SNAKE_CASE__    :	float = 0.0					,							SCREAMING_SNAKE_CASE__    :	Optional[torch.Generator] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[torch.FloatTensor] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[str] = "pil"					,							SCREAMING_SNAKE_CASE__    :	bool = True					,							SCREAMING_SNAKE_CASE__    :	Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,							SCREAMING_SNAKE_CASE__    :	int = 1					,							**SCREAMING_SNAKE_CASE__    :	Union[str, Any]					,							)		->      Optional[Any]:
             return self.pipea(
                 prompt=SCREAMING_SNAKE_CASE__					,							height=SCREAMING_SNAKE_CASE__					,							width=SCREAMING_SNAKE_CASE__					,							num_inference_steps=SCREAMING_SNAKE_CASE__					,							guidance_scale=SCREAMING_SNAKE_CASE__					,							negative_prompt=SCREAMING_SNAKE_CASE__					,							num_images_per_prompt=SCREAMING_SNAKE_CASE__					,							eta=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							latents=SCREAMING_SNAKE_CASE__					,							output_type=SCREAMING_SNAKE_CASE__					,							return_dict=SCREAMING_SNAKE_CASE__					,							callback=SCREAMING_SNAKE_CASE__					,							callback_steps=SCREAMING_SNAKE_CASE__					,							**SCREAMING_SNAKE_CASE__					,							)
      @torch.no_grad()
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					,							SCREAMING_SNAKE_CASE__    :	Union[str, List[str]]					,							SCREAMING_SNAKE_CASE__    :	int = 5_1_2					,							SCREAMING_SNAKE_CASE__    :	int = 5_1_2					,							SCREAMING_SNAKE_CASE__    :	int = 5_0					,							SCREAMING_SNAKE_CASE__    :	float = 7.5					,							SCREAMING_SNAKE_CASE__    :	Optional[Union[str, List[str]]] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[int] = 1					,							SCREAMING_SNAKE_CASE__    :	float = 0.0					,							SCREAMING_SNAKE_CASE__    :	Optional[torch.Generator] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[torch.FloatTensor] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[str] = "pil"					,							SCREAMING_SNAKE_CASE__    :	bool = True					,							SCREAMING_SNAKE_CASE__    :	Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,							SCREAMING_SNAKE_CASE__    :	int = 1					,							**SCREAMING_SNAKE_CASE__    :	Union[str, Any]					,							)		->      str:
             return self.pipea(
                 prompt=SCREAMING_SNAKE_CASE__					,							height=SCREAMING_SNAKE_CASE__					,							width=SCREAMING_SNAKE_CASE__					,							num_inference_steps=SCREAMING_SNAKE_CASE__					,							guidance_scale=SCREAMING_SNAKE_CASE__					,							negative_prompt=SCREAMING_SNAKE_CASE__					,							num_images_per_prompt=SCREAMING_SNAKE_CASE__					,							eta=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							latents=SCREAMING_SNAKE_CASE__					,							output_type=SCREAMING_SNAKE_CASE__					,							return_dict=SCREAMING_SNAKE_CASE__					,							callback=SCREAMING_SNAKE_CASE__					,							callback_steps=SCREAMING_SNAKE_CASE__					,							**SCREAMING_SNAKE_CASE__					,							)

      @torch.no_grad()
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	Union[str, List[str]]					,							SCREAMING_SNAKE_CASE__    :	int = 5_1_2					,							SCREAMING_SNAKE_CASE__    :	int = 5_1_2					,							SCREAMING_SNAKE_CASE__    :	int = 5_0					,							SCREAMING_SNAKE_CASE__    :	float = 7.5					,							SCREAMING_SNAKE_CASE__    :	Optional[Union[str, List[str]]] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[int] = 1					,							SCREAMING_SNAKE_CASE__    :	float = 0.0					,							SCREAMING_SNAKE_CASE__    :	Optional[torch.Generator] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[torch.FloatTensor] = None					,							SCREAMING_SNAKE_CASE__    :	Optional[str] = "pil"					,							SCREAMING_SNAKE_CASE__    :	bool = True					,							SCREAMING_SNAKE_CASE__    :	Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,							SCREAMING_SNAKE_CASE__    :	int = 1					,							**SCREAMING_SNAKE_CASE__    :	Union[str, Any]					,							)		->      Dict:
             a_ :		str							=  'cuda' if torch.cuda.is_available() else 'cpu'
             self.to(SCREAMING_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
             a_ :		int							=  self.textaimg_sda_a(
                 prompt=SCREAMING_SNAKE_CASE__					,							height=SCREAMING_SNAKE_CASE__					,							width=SCREAMING_SNAKE_CASE__					,							num_inference_steps=SCREAMING_SNAKE_CASE__					,							guidance_scale=SCREAMING_SNAKE_CASE__					,							negative_prompt=SCREAMING_SNAKE_CASE__					,							num_images_per_prompt=SCREAMING_SNAKE_CASE__					,							eta=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							latents=SCREAMING_SNAKE_CASE__					,							output_type=SCREAMING_SNAKE_CASE__					,							return_dict=SCREAMING_SNAKE_CASE__					,							callback=SCREAMING_SNAKE_CASE__					,							callback_steps=SCREAMING_SNAKE_CASE__					,							**SCREAMING_SNAKE_CASE__					,							)

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

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

             # Get first result from Stable Diffusion Checkpoint v1.4
             a_ :		List[str]							=  self.textaimg_sda_a(
                 prompt=SCREAMING_SNAKE_CASE__					,							height=SCREAMING_SNAKE_CASE__					,							width=SCREAMING_SNAKE_CASE__					,							num_inference_steps=SCREAMING_SNAKE_CASE__					,							guidance_scale=SCREAMING_SNAKE_CASE__					,							negative_prompt=SCREAMING_SNAKE_CASE__					,							num_images_per_prompt=SCREAMING_SNAKE_CASE__					,							eta=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							latents=SCREAMING_SNAKE_CASE__					,							output_type=SCREAMING_SNAKE_CASE__					,							return_dict=SCREAMING_SNAKE_CASE__					,							callback=SCREAMING_SNAKE_CASE__					,							callback_steps=SCREAMING_SNAKE_CASE__					,							**SCREAMING_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 __future__ import annotations

from math import pi

# Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of
# Pi and the function
UpperCAmelCase_				:			str   =	1.054571817e-34  # unit of ℏ : J * s

UpperCAmelCase_				:			Dict   =	3e8  # unit of c : m * s^-1







def 	SCREAMING_SNAKE_CASE_						(      __A			:      float  ,   __A			:      float  ,   __A			:      float    )     ->		dict[str, float]:

       """simple docstring"""

       if (force, area, distance).count(0    ) != 1:
              raise ValueError('One and only one argument must be 0'    )
       if force < 0:
              raise ValueError('Magnitude of force can not be negative'    )
       if distance < 0:
              raise ValueError('Distance can not be negative'    )
       if area < 0:
              raise ValueError('Area can not be negative'    )
       if force == 0:
              a_ :		Optional[Any]							=  (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2 * area) / (
                  2_40 * (distance) ** 4
              )
              return {"force": force}
       elif area == 0:
              a_ :		List[str]							=  (2_40 * force * (distance) ** 4) / (
                  REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2
              )
              return {"area": area}
       elif distance == 0:
              a_ :		Tuple							=  (
                  (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2 * area) / (2_40 * force)
              ) ** (1 / 4)
              return {"distance": distance}
       raise ValueError('One and only one argument must be 0'    )


# Run doctest
if __name__ == "__main__":
   import doctest

   doctest.testmod()


