






'''simple docstring'''

from __future__ import annotations







def    lowercase__			(				__UpperCamelCase		,						__UpperCamelCase		,						__UpperCamelCase   )->			int | float:
      if len(_A   ) == 0:
            raise ValueError("""find_max() arg is an empty sequence"""   )
      if (
          left >= len(_A   )
          or left < -len(_A   )
          or right >= len(_A   )
          or right < -len(_A   )
      ):
            raise IndexError("""list index out of range"""   )
      if left == right:
            return nums[left]
      UpperCamelCase      = (left + right) >> 1  # the middle
      UpperCamelCase      = find_max(_A		,						_A		,						_A   )  # find max in range[left, mid]
      UpperCamelCase      = find_max(_A		,						mid + 1		,						_A   )  # find max in range[mid + 1, right]

      return left_max if left_max >= right_max else right_max


if __name__ == "__main__":
 import doctest

 doctest.testmod(verbose=True)








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


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






class     a_						(      lowerCamelCase    ):

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



        """simple docstring"""






        super()._init_()

        UpperCamelCase      = StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE				)
        UpperCamelCase      = StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE				)
        UpperCamelCase      = StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE				)
        UpperCamelCase      = 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   A__						(				self				)  ->				Dict[str, Any]:



        """simple docstring"""






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

  def   A__						(				self      ,		_SCREAMING_SNAKE_CASE = "auto"				)  ->				Any:



        """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(_SCREAMING_SNAKE_CASE				)

  def   A__						(				self				)  ->				Optional[int]:



        """simple docstring"""






        self.enable_attention_slicing(_SCREAMING_SNAKE_CASE				)

  @torch.no_grad()
  def   A__						(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 50      ,		_SCREAMING_SNAKE_CASE = 7.5      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		_SCREAMING_SNAKE_CASE = 0.0      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = "pil"      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				List[Any]:



        """simple docstring"""






        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   A__						(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 50      ,		_SCREAMING_SNAKE_CASE = 7.5      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		_SCREAMING_SNAKE_CASE = 0.0      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = "pil"      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				str:



        """simple docstring"""






        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   A__						(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 50      ,		_SCREAMING_SNAKE_CASE = 7.5      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		_SCREAMING_SNAKE_CASE = 0.0      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = "pil"      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				Optional[Any]:



        """simple docstring"""






        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   A__						(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 50      ,		_SCREAMING_SNAKE_CASE = 7.5      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		_SCREAMING_SNAKE_CASE = 0.0      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = "pil"      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				Union[str, Any]:



        """simple docstring"""






        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   A__						(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 50      ,		_SCREAMING_SNAKE_CASE = 7.5      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		_SCREAMING_SNAKE_CASE = 0.0      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = "pil"      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				int:



        """simple docstring"""






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