




'''simple docstring'''






from __future__ import annotations

from collections import deque
from enum import Enum
from math import atana, degrees
from sys import maxsize



class  A		(			SCREAMING_SNAKE_CASE__		):




				'''simple docstring'''





				A				     =    1
				A				     =    2
				A				     =    3
				def __repr__(self      )     ->	Union[str, Any]:
							return f"{self.__class__.__name__}.{self.name}"







def       __lowerCAmelCase (   snake_case__ ,				snake_case__ ,				snake_case__						):
			__UpperCamelCase		, __UpperCamelCase				:      Dict									=       point
			return degrees(atana(y - miny ,				x - minx						)						)

def       __lowerCAmelCase (   snake_case__ ,				snake_case__ ,				snake_case__						):
			__UpperCamelCase		, __UpperCamelCase				:      Dict									=       starting
			__UpperCamelCase		, __UpperCamelCase				:      List[str]									=       via
			__UpperCamelCase		, __UpperCamelCase				:      Dict									=       target
			__UpperCamelCase				:      List[Any]									=       degrees(atana(ya - ya ,				xa - xa						)						)
			via_angle %= 360
			__UpperCamelCase				:      Optional[Any]									=       degrees(atana(ya - ya ,				xa - xa						)						)
			target_angle %= 360
			# t-
			#  \ \
			#   \ v
			#    \|
			#     s
			# via_angle is always lower than target_angle, if direction is left.
			# If they are same, it means they are on a same line of convex hull.
			if target_angle > via_angle:
						return Direction.left
			elif target_angle == via_angle:
						return Direction.straight
			else:
						return Direction.right




def       __lowerCAmelCase (   snake_case__						):

			if len(snake_case__						) <= 2:
						# There is no convex hull
						raise ValueError("graham_scan: argument must contain more than 3 points."						)
			if len(snake_case__						) == 3:
						return points
			# find the lowest and the most left point
			__UpperCamelCase				:      Any									=       0
			__UpperCamelCase		, __UpperCamelCase				:      Optional[Any]									=       maxsize, maxsize
			for i, point in enumerate(snake_case__						):
						__UpperCamelCase				:      Union[str, Any]									=       point[0]
						__UpperCamelCase				:      Optional[Any]									=       point[1]
						if y < miny:
									__UpperCamelCase				:      List[Any]									=       y
									__UpperCamelCase				:      List[str]									=       x
									__UpperCamelCase				:      Optional[int]									=       i
						if y == miny and x < minx:
									__UpperCamelCase				:      List[Any]									=       x
									__UpperCamelCase				:      Any									=       i

    # remove the lowest and the most left point from points for preparing for sort
			points.pop(snake_case__						)

			__UpperCamelCase				:      Any									=       sorted(snake_case__ ,				key=lambda snake_case__						: angle_comparer(snake_case__ ,				snake_case__ ,				snake_case__						)						)
			# This insert actually costs complexity,
			# and you should instead add (minx, miny) into stack later.
			# I'm using insert just for easy understanding.
			sorted_points.insert(0 ,				(minx, miny)						)

			__UpperCamelCase				:      deque[tuple[int, int]]									=       deque()
			stack.append(sorted_points[0]						)
			stack.append(sorted_points[1]						)
			stack.append(sorted_points[2]						)
			# In any ways, the first 3 points line are towards left.
			# Because we sort them the angle from minx, miny.
			__UpperCamelCase				:      Tuple									=       Direction.left

			for i in range(3 ,				len(snake_case__						)						):
						while True:
									__UpperCamelCase				:      Dict									=       stack[-2]
									__UpperCamelCase				:      Union[str, Any]									=       stack[-1]
									__UpperCamelCase				:      int									=       sorted_points[i]
									__UpperCamelCase				:      Tuple									=       check_direction(snake_case__ ,				snake_case__ ,				snake_case__						)

									if next_direction == Direction.left:
												__UpperCamelCase				:      Dict									=       Direction.left
												break
									if next_direction == Direction.straight:
												if current_direction == Direction.left:
															# We keep current_direction as left.
															# Because if the straight line keeps as straight,
															# we want to know if this straight line is towards left.
															break
												elif current_direction == Direction.right:
															# If the straight line is towards right,
															# every previous points on those straigh line is not convex hull.
															stack.pop()
									if next_direction == Direction.right:
												stack.pop()
						stack.append(sorted_points[i]						)
			return list(snake_case__						)









'''simple docstring'''






from typing import Any, Callable, Dict, List, Optional, Union

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


_lowerCAmelCase				     = logging.get_logger(__name__)  # pylint: disable=invalid-name



class  A		(			SCREAMING_SNAKE_CASE__		):




				'''simple docstring'''





				A				     =    ["safety_checker", "feature_extractor"]
				def __init__(self			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase = True			,  )     ->	List[str]:
							super().__init__()
							if hasattr(scheduler.config			,  "steps_offset"      ) and scheduler.config.steps_offset != 1:
										__UpperCamelCase				:      List[str]									=       (
										    f"The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`"
										    f" should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure "
										    "to update the config accordingly as leaving `steps_offset` might led to incorrect results"
										    " in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,"
										    " it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`"
										    " file"
										)
										deprecate("steps_offset!=1"			,  "1.0.0"			,  _UpperCAmelCase			,  standard_warn=_UpperCAmelCase      )
										__UpperCamelCase				:      str									=       dict(scheduler.config      )
										__UpperCamelCase				:      Optional[Any]									=       1
										__UpperCamelCase				:      Dict									=       FrozenDict(_UpperCAmelCase      )

							self.register_modules(
							    vae=_UpperCAmelCase			,  text_encoder=_UpperCAmelCase			,  tokenizer=_UpperCAmelCase			,  unet=_UpperCAmelCase			,  scheduler=_UpperCAmelCase			,  safety_checker=_UpperCAmelCase			,  feature_extractor=_UpperCAmelCase			,  )
							self.register_to_config(requires_safety_checker=_UpperCAmelCase      )
				@property
				def 	a_	(self      )     ->	Dict[str, Any]:
							return {k: getattr(self			,  _UpperCAmelCase      ) for k in self.config.keys() if not k.startswith("_"      )}
				def 	a_	(self			,  _UpperCAmelCase = "auto"      )     ->	List[str]:
							if slice_size == "auto":
										# half the attention head size is usually a good trade-off between
										# speed and memory
										__UpperCamelCase				:      Dict									=       self.unet.config.attention_head_dim // 2
							self.unet.set_attention_slice(_UpperCAmelCase      )
				def 	a_	(self      )     ->	Dict:
							self.enable_attention_slicing(_UpperCAmelCase      )
				@torch.no_grad()
				def 	a_	(self			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase = 0.8			,  _UpperCAmelCase = 5_0			,  _UpperCAmelCase = 7.5			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  _UpperCAmelCase = 0.0			,  _UpperCAmelCase = None			,  _UpperCAmelCase = "pil"			,  _UpperCAmelCase = True			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  )     ->	List[str]:
							# For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
							return StableDiffusionInpaintPipelineLegacy(**self.components      )(
							    prompt=_UpperCAmelCase			,  image=_UpperCAmelCase			,  mask_image=_UpperCAmelCase			,  strength=_UpperCAmelCase			,  num_inference_steps=_UpperCAmelCase			,  guidance_scale=_UpperCAmelCase			,  negative_prompt=_UpperCAmelCase			,  num_images_per_prompt=_UpperCAmelCase			,  eta=_UpperCAmelCase			,  generator=_UpperCAmelCase			,  output_type=_UpperCAmelCase			,  return_dict=_UpperCAmelCase			,  callback=_UpperCAmelCase			,  )
				@torch.no_grad()
				def 	a_	(self			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase = 0.8			,  _UpperCAmelCase = 5_0			,  _UpperCAmelCase = 7.5			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  _UpperCAmelCase = 0.0			,  _UpperCAmelCase = None			,  _UpperCAmelCase = "pil"			,  _UpperCAmelCase = True			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  **_UpperCAmelCase			,  )     ->	Optional[Any]:
							# For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
							return StableDiffusionImgaImgPipeline(**self.components      )(
							    prompt=_UpperCAmelCase			,  image=_UpperCAmelCase			,  strength=_UpperCAmelCase			,  num_inference_steps=_UpperCAmelCase			,  guidance_scale=_UpperCAmelCase			,  negative_prompt=_UpperCAmelCase			,  num_images_per_prompt=_UpperCAmelCase			,  eta=_UpperCAmelCase			,  generator=_UpperCAmelCase			,  output_type=_UpperCAmelCase			,  return_dict=_UpperCAmelCase			,  callback=_UpperCAmelCase			,  callback_steps=_UpperCAmelCase			,  )





				@torch.no_grad()
				def 	a_	(self			,  _UpperCAmelCase			,  _UpperCAmelCase = 5_1_2			,  _UpperCAmelCase = 5_1_2			,  _UpperCAmelCase = 5_0			,  _UpperCAmelCase = 7.5			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  _UpperCAmelCase = 0.0			,  _UpperCAmelCase = None			,  _UpperCAmelCase = None			,  _UpperCAmelCase = "pil"			,  _UpperCAmelCase = True			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  )     ->	Union[str, Any]:
							# For more information on how this function https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline
							return StableDiffusionPipeline(**self.components      )(
							    prompt=_UpperCAmelCase			,  height=_UpperCAmelCase			,  width=_UpperCAmelCase			,  num_inference_steps=_UpperCAmelCase			,  guidance_scale=_UpperCAmelCase			,  negative_prompt=_UpperCAmelCase			,  num_images_per_prompt=_UpperCAmelCase			,  eta=_UpperCAmelCase			,  generator=_UpperCAmelCase			,  latents=_UpperCAmelCase			,  output_type=_UpperCAmelCase			,  return_dict=_UpperCAmelCase			,  callback=_UpperCAmelCase			,  callback_steps=_UpperCAmelCase			,  )



