


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_ :str  							=			"CompVis/stable-diffusion-v1-1"
a_ :Union[str, Any]  							=			"CompVis/stable-diffusion-v1-2"
a_ :Dict  							=			"CompVis/stable-diffusion-v1-3"
a_ :List[str]  							=			"CompVis/stable-diffusion-v1-4"

class 							lowercase  (						_SCREAMING_SNAKE_CASE			):







     def __init__(						self :						Tuple   ,   _lowercase :						AutoencoderKL   ,   _lowercase :						CLIPTextModel   ,   _lowercase :						CLIPTokenizer   ,   _lowercase :						UNetaDConditionModel   ,   _lowercase :						Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]   ,   _lowercase :						StableDiffusionSafetyChecker   ,   _lowercase :						CLIPImageProcessor   ,   _lowercase :						bool = True   ,   ):
           super()._init_()

           SCREAMING_SNAKE_CASE__       :  Any						     =		StableDiffusionPipeline.from_pretrained(_lowercase      )
           SCREAMING_SNAKE_CASE__       :  Any						     =		StableDiffusionPipeline.from_pretrained(_lowercase      )
           SCREAMING_SNAKE_CASE__       :  Dict						     =		StableDiffusionPipeline.from_pretrained(_lowercase      )
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		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 :						List[Any]      ):
           return {k: getattr(self   ,   _lowercase      ) for k in self.config.keys() if not k.startswith('''_'''      )}







     def 							lowercase__       (						self :						Tuple   ,   _lowercase :						Optional[Union[str, int]] = "auto"      ):
           if slice_size == "auto":
                 # half the attention head size is usually a good trade-off between
                 # speed and memory
                 SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		self.unet.config.attention_head_dim // 2
           self.unet.set_attention_slice(_lowercase      )







     def 							lowercase__       (						self :						List[str]      ):
           self.enable_attention_slicing(_lowercase      )







     @torch.no_grad()
     def 							lowercase__       (						self :						Any   ,   _lowercase :						Union[str, List[str]]   ,   _lowercase :						int = 5_12   ,   _lowercase :						int = 5_12   ,   _lowercase :						int = 50   ,   _lowercase :						float = 7.5   ,   _lowercase :						Optional[Union[str, List[str]]] = None   ,   _lowercase :						Optional[int] = 1   ,   _lowercase :						float = 0.0   ,   _lowercase :						Optional[torch.Generator] = None   ,   _lowercase :						Optional[torch.FloatTensor] = None   ,   _lowercase :						Optional[str] = "pil"   ,   _lowercase :						bool = True   ,   _lowercase :						Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,   _lowercase :						int = 1   ,   **_lowercase :						List[Any]   ,   ):
           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 :						List[str]   ,   _lowercase :						Union[str, List[str]]   ,   _lowercase :						int = 5_12   ,   _lowercase :						int = 5_12   ,   _lowercase :						int = 50   ,   _lowercase :						float = 7.5   ,   _lowercase :						Optional[Union[str, List[str]]] = None   ,   _lowercase :						Optional[int] = 1   ,   _lowercase :						float = 0.0   ,   _lowercase :						Optional[torch.Generator] = None   ,   _lowercase :						Optional[torch.FloatTensor] = None   ,   _lowercase :						Optional[str] = "pil"   ,   _lowercase :						bool = True   ,   _lowercase :						Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,   _lowercase :						int = 1   ,   **_lowercase :						Union[str, Any]   ,   ):
           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 :						int   ,   _lowercase :						Union[str, List[str]]   ,   _lowercase :						int = 5_12   ,   _lowercase :						int = 5_12   ,   _lowercase :						int = 50   ,   _lowercase :						float = 7.5   ,   _lowercase :						Optional[Union[str, List[str]]] = None   ,   _lowercase :						Optional[int] = 1   ,   _lowercase :						float = 0.0   ,   _lowercase :						Optional[torch.Generator] = None   ,   _lowercase :						Optional[torch.FloatTensor] = None   ,   _lowercase :						Optional[str] = "pil"   ,   _lowercase :						bool = True   ,   _lowercase :						Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,   _lowercase :						int = 1   ,   **_lowercase :						Tuple   ,   ):
           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 :						Optional[Any]   ,   _lowercase :						Union[str, List[str]]   ,   _lowercase :						int = 5_12   ,   _lowercase :						int = 5_12   ,   _lowercase :						int = 50   ,   _lowercase :						float = 7.5   ,   _lowercase :						Optional[Union[str, List[str]]] = None   ,   _lowercase :						Optional[int] = 1   ,   _lowercase :						float = 0.0   ,   _lowercase :						Optional[torch.Generator] = None   ,   _lowercase :						Optional[torch.FloatTensor] = None   ,   _lowercase :						Optional[str] = "pil"   ,   _lowercase :						bool = True   ,   _lowercase :						Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,   _lowercase :						int = 1   ,   **_lowercase :						Union[str, Any]   ,   ):
           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 :						List[Any]   ,   _lowercase :						Union[str, List[str]]   ,   _lowercase :						int = 5_12   ,   _lowercase :						int = 5_12   ,   _lowercase :						int = 50   ,   _lowercase :						float = 7.5   ,   _lowercase :						Optional[Union[str, List[str]]] = None   ,   _lowercase :						Optional[int] = 1   ,   _lowercase :						float = 0.0   ,   _lowercase :						Optional[torch.Generator] = None   ,   _lowercase :						Optional[torch.FloatTensor] = None   ,   _lowercase :						Optional[str] = "pil"   ,   _lowercase :						bool = True   ,   _lowercase :						Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,   _lowercase :						int = 1   ,   **_lowercase :						Tuple   ,   ):
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		"""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
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		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
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		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
           SCREAMING_SNAKE_CASE__       :  Dict						     =		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
           SCREAMING_SNAKE_CASE__       :  int						     =		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 __future__ import annotations

# This is the precision for this function which can be altered.
# It is recommended for users to keep this number greater than or equal to 10.
__A   :    Tuple											= 10







def 							UpperCamelCase_     (       A__   :  int				,       A__   :  int				,       A__   :  list[int]				,       A__   :  int   ):
  '''simple docstring'''





  for i in range(A__				,       A__   ):
    if array[i] == target:
      return i
  return -1







def 							UpperCamelCase_     (       A__   :  list[int]				,       A__   :  int   ):
  '''simple docstring'''





  lowerCAmelCase_     : Optional[int]     =  0
  lowerCAmelCase_     : Union[str, Any]     =  len(A__   )
  while left <= right:
    if right - left < precision:
      return lin_search(A__				,       A__				,       A__				,       A__   )

    lowerCAmelCase_     : Dict     =  (left + right) // 3 + 1
    lowerCAmelCase_     : List[Any]     =  2 * (left + right) // 3 + 1

    if array[one_third] == target:
      return one_third
    elif array[two_third] == target:
      return two_third

    elif target < array[one_third]:
      lowerCAmelCase_     : List[str]     =  one_third - 1
    elif array[two_third] < target:
      lowerCAmelCase_     : Tuple     =  two_third + 1

    else:
      lowerCAmelCase_     : Tuple     =  one_third + 1
      lowerCAmelCase_     : Any     =  two_third - 1
  else:
    return -1







def 							UpperCamelCase_     (       A__   :  int				,       A__   :  int				,       A__   :  list[int]				,       A__   :  int   ):
  '''simple docstring'''





  if left < right:
    if right - left < precision:
      return lin_search(A__				,       A__				,       A__				,       A__   )
    lowerCAmelCase_     : Dict     =  (left + right) // 3 + 1
    lowerCAmelCase_     : Dict     =  2 * (left + right) // 3 + 1

    if array[one_third] == target:
      return one_third
    elif array[two_third] == target:
      return two_third

    elif target < array[one_third]:
      return rec_ternary_search(A__				,       one_third - 1				,       A__				,       A__   )
    elif array[two_third] < target:
      return rec_ternary_search(two_third + 1				,       A__				,       A__				,       A__   )
    else:
      return rec_ternary_search(one_third + 1				,       two_third - 1				,       A__				,       A__   )
  else:
    return -1


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  __A   :    List[Any]											= input("Enter numbers separated by comma:\n").strip()
  __A   :    Union[str, Any]											= [int(item.strip()) for item in user_input.split(",")]
  assert collection == sorted(collection), F"List must be ordered.\n{collection}."
  __A   :    List[Any]											= int(input("Enter the number to be found in the list:\n").strip())
  __A   :    str											= ite_ternary_search(collection, target)
  __A   :    Dict											= rec_ternary_search(0, len(collection) - 1, collection, target)
  if resulta != -1:
    print(F'''Iterative search: {target} found at positions: {resulta}''')
    print(F'''Recursive search: {target} found at positions: {resulta}''')
  else:
    print("Not found")



