"""simple docstring"""





# Imports
import numpy as np
class  _snake_case     :






						def __init__(       self      :			Dict							,					UpperCAmelCase      :			Tuple=None							,					UpperCAmelCase      :			Tuple=None							,					UpperCAmelCase      :			int=None							,					UpperCAmelCase      :			Optional[Any]=None							,					UpperCAmelCase      :			List[str]=None    ):
													self.set_matricies(red=UpperCAmelCase							,					green=UpperCAmelCase							,					blue=UpperCAmelCase							,					red_edge=UpperCAmelCase							,					nir=UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			List[Any]							,					UpperCAmelCase      :			Optional[Any]=None							,					UpperCAmelCase      :			List[Any]=None							,					UpperCAmelCase      :			Any=None							,					UpperCAmelCase      :			Optional[int]=None							,					UpperCAmelCase      :			str=None    ):
													if red is not None:
																				__lowerCamelCase					:		int		   =     red
													if green is not None:
																				__lowerCamelCase					:		int		   =     green
													if blue is not None:
																				__lowerCamelCase					:		Optional[int]		   =     blue
													if red_edge is not None:
																				__lowerCamelCase					:		Optional[Any]		   =     red_edge
													if nir is not None:
																				__lowerCamelCase					:		Optional[int]		   =     nir
													return True






						def       lowerCamelCase__     (       self      :			int							,					UpperCAmelCase      :			Optional[Any]=""							,					UpperCAmelCase      :			Tuple=None							,					UpperCAmelCase      :			Any=None							,					UpperCAmelCase      :			List[Any]=None							,					UpperCAmelCase      :			Optional[Any]=None							,					UpperCAmelCase      :			Dict=None    ):
													self.set_matricies(red=UpperCAmelCase							,					green=UpperCAmelCase							,					blue=UpperCAmelCase							,					red_edge=UpperCAmelCase							,					nir=UpperCAmelCase    )
													__lowerCamelCase					:		Tuple		   =     {
													    "ARVI2": self.arvaa,
													    "CCCI": self.ccci,
													    "CVI": self.cvi,
													    "GLI": self.gli,
													    "NDVI": self.ndvi,
													    "BNDVI": self.bndvi,
													    "redEdgeNDVI": self.red_edge_ndvi,
													    "GNDVI": self.gndvi,
													    "GBNDVI": self.gbndvi,
													    "GRNDVI": self.grndvi,
													    "RBNDVI": self.rbndvi,
													    "PNDVI": self.pndvi,
													    "ATSAVI": self.atsavi,
													    "BWDRVI": self.bwdrvi,
													    "CIgreen": self.ci_green,
													    "CIrededge": self.ci_rededge,
													    "CI": self.ci,
													    "CTVI": self.ctvi,
													    "GDVI": self.gdvi,
													    "EVI": self.evi,
													    "GEMI": self.gemi,
													    "GOSAVI": self.gosavi,
													    "GSAVI": self.gsavi,
													    "Hue": self.hue,
													    "IVI": self.ivi,
													    "IPVI": self.ipvi,
													    "I": self.i,
													    "RVI": self.rvi,
													    "MRVI": self.mrvi,
													    "MSAVI": self.m_savi,
													    "NormG": self.norm_g,
													    "NormNIR": self.norm_nir,
													    "NormR": self.norm_r,
													    "NGRDI": self.ngrdi,
													    "RI": self.ri,
													    "S": self.s,
													    "IF": self._if,
													    "DVI": self.dvi,
													    "TVI": self.tvi,
													    "NDRE": self.ndre,
													}

													try:
																				return funcs[index]()
													except KeyError:
																				print("Index not in the list!"    )
																				return False






						def       lowerCamelCase__     (       self      :			str    ):
													return -0.1_8 + (1.1_7 * ((self.nir - self.red) / (self.nir + self.red)))






						def       lowerCamelCase__     (       self      :			Optional[int]    ):
													return ((self.nir - self.redEdge) / (self.nir + self.redEdge)) / (
													    (self.nir - self.red) / (self.nir + self.red)
													)






						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													return self.nir * (self.red / (self.green**2))






						def       lowerCamelCase__     (       self      :			Tuple    ):
													return (2 * self.green - self.red - self.blue) / (
													    2 * self.green + self.red + self.blue
													)






						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													return (self.nir - self.red) / (self.nir + self.red)






						def       lowerCamelCase__     (       self      :			List[str]    ):
													return (self.nir - self.blue) / (self.nir + self.blue)






						def       lowerCamelCase__     (       self      :			str    ):
													return (self.redEdge - self.red) / (self.redEdge + self.red)






						def       lowerCamelCase__     (       self      :			Tuple    ):
													return (self.nir - self.green) / (self.nir + self.green)






						def       lowerCamelCase__     (       self      :			Dict    ):
													return (self.nir - (self.green + self.blue)) / (
													    self.nir + (self.green + self.blue)
													)






						def       lowerCamelCase__     (       self      :			Any    ):
													return (self.nir - (self.green + self.red)) / (
													    self.nir + (self.green + self.red)
													)






						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													return (self.nir - (self.blue + self.red)) / (self.nir + (self.blue + self.red))






						def       lowerCamelCase__     (       self      :			List[str]    ):
													return (self.nir - (self.green + self.red + self.blue)) / (
													    self.nir + (self.green + self.red + self.blue)
													)






						def       lowerCamelCase__     (       self      :			List[str]							,					UpperCAmelCase      :			Dict=0.0_8							,					UpperCAmelCase      :			Tuple=1.2_2							,					UpperCAmelCase      :			Optional[int]=0.0_3    ):
													return a * (
													    (self.nir - a * self.red - b)
													    / (a * self.nir + self.red - a * b + x * (1 + a**2))
													)






						def       lowerCamelCase__     (       self      :			Any    ):
													return (0.1 * self.nir - self.blue) / (0.1 * self.nir + self.blue)






						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													return (self.nir / self.green) - 1






						def       lowerCamelCase__     (       self      :			List[Any]    ):
													return (self.nir / self.redEdge) - 1






						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													return (self.red - self.blue) / self.red






						def       lowerCamelCase__     (       self      :			Tuple    ):
													__lowerCamelCase					:		Optional[Any]		   =     self.ndvi()
													return ((ndvi + 0.5) / (abs(ndvi + 0.5    ))) * (abs(ndvi + 0.5    ) ** (1 / 2))






						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													return self.nir - self.green






						def       lowerCamelCase__     (       self      :			Tuple    ):
													return 2.5 * (
													    (self.nir - self.red) / (self.nir + 6 * self.red - 7.5 * self.blue + 1)
													)






						def       lowerCamelCase__     (       self      :			str    ):
													__lowerCamelCase					:		Optional[Any]		   =     (2 * (self.nir**2 - self.red**2) + 1.5 * self.nir + 0.5 * self.red) / (
													    self.nir + self.red + 0.5
													)
													return n * (1 - 0.2_5 * n) - (self.red - 0.1_2_5) / (1 - self.red)






						def       lowerCamelCase__     (       self      :			List[str]							,					UpperCAmelCase      :			Optional[int]=0.1_6    ):
													return (self.nir - self.green) / (self.nir + self.green + y)






						def       lowerCamelCase__     (       self      :			List[str]							,					UpperCAmelCase      :			str=0.5    ):
													return ((self.nir - self.green) / (self.nir + self.green + n)) * (1 + n)






						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													return np.arctan(
													    ((2 * self.red - self.green - self.blue) / 3_0.5) * (self.green - self.blue)    )






						def       lowerCamelCase__     (       self      :			Tuple							,					UpperCAmelCase      :			Dict=None							,					UpperCAmelCase      :			Optional[Any]=None    ):
													return (self.nir - b) / (a * self.red)






						def       lowerCamelCase__     (       self      :			Tuple    ):
													return (self.nir / ((self.nir + self.red) / 2)) * (self.ndvi() + 1)






						def       lowerCamelCase__     (       self      :			int    ):
													return (self.red + self.green + self.blue) / 3_0.5






						def       lowerCamelCase__     (       self      :			Any    ):
													return self.nir / self.red






						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													return (self.rvi() - 1) / (self.rvi() + 1)






						def       lowerCamelCase__     (       self      :			List[Any]    ):
													return (
													    (2 * self.nir + 1)
													    - ((2 * self.nir + 1) ** 2 - 8 * (self.nir - self.red)) ** (1 / 2)
													) / 2






						def       lowerCamelCase__     (       self      :			int    ):
													return self.green / (self.nir + self.red + self.green)






						def       lowerCamelCase__     (       self      :			str    ):
													return self.nir / (self.nir + self.red + self.green)






						def       lowerCamelCase__     (       self      :			Any    ):
													return self.red / (self.nir + self.red + self.green)






						def       lowerCamelCase__     (       self      :			Optional[int]    ):
													return (self.green - self.red) / (self.green + self.red)






						def       lowerCamelCase__     (       self      :			int    ):
													return (self.red - self.green) / (self.red + self.green)






						def       lowerCamelCase__     (       self      :			str    ):
													__lowerCamelCase					:		int		   =     np.max([np.max(self.red    ), np.max(self.green    ), np.max(self.blue    )]    )
													__lowerCamelCase					:		str		   =     np.min([np.min(self.red    ), np.min(self.green    ), np.min(self.blue    )]    )
													return (max_value - min_value) / max_value






						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													return (2 * self.red - self.green - self.blue) / (self.green - self.blue)






						def       lowerCamelCase__     (       self      :			Dict    ):
													return self.nir / self.red






						def       lowerCamelCase__     (       self      :			Optional[int]    ):
													return (self.ndvi() + 0.5) ** (1 / 2)







						def       lowerCamelCase__     (       self      :			List[str]    ):
													return (self.nir - self.redEdge) / (self.nir + self.redEdge)
"""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


__A  =				'''CompVis/stable-diffusion-v1-1'''
__A  =				'''CompVis/stable-diffusion-v1-2'''
__A  =				'''CompVis/stable-diffusion-v1-3'''
__A  =				'''CompVis/stable-diffusion-v1-4'''
class  _snake_case     (					a__		):






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

													__lowerCamelCase					:		Optional[int]		   =     StableDiffusionPipeline.from_pretrained(UpperCAmelCase    )
													__lowerCamelCase					:		Optional[int]		   =     StableDiffusionPipeline.from_pretrained(UpperCAmelCase    )
													__lowerCamelCase					:		Tuple		   =     StableDiffusionPipeline.from_pretrained(UpperCAmelCase    )
													__lowerCamelCase					:		List[str]		   =     StableDiffusionPipeline(
													    vae=UpperCAmelCase							,					text_encoder=UpperCAmelCase							,					tokenizer=UpperCAmelCase							,					unet=UpperCAmelCase							,					scheduler=UpperCAmelCase							,					safety_checker=UpperCAmelCase							,					feature_extractor=UpperCAmelCase							,					requires_safety_checker=UpperCAmelCase							,					)

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






						@property
						def       lowerCamelCase__     (       self      :			Dict    ):
													return {k: getattr(self							,					UpperCAmelCase    ) for k in self.config.keys() if not k.startswith("_"    )}






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






						def       lowerCamelCase__     (       self      :			Tuple    ):
													self.enable_attention_slicing(UpperCAmelCase    )






						@torch.no_grad()
						def       lowerCamelCase__     (       self      :			Dict							,					UpperCAmelCase      :			Union[str, List[str]]							,					UpperCAmelCase      :			int = 512							,					UpperCAmelCase      :			int = 512							,					UpperCAmelCase      :			int = 50							,					UpperCAmelCase      :			float = 7.5							,					UpperCAmelCase      :			Optional[Union[str, List[str]]] = None							,					UpperCAmelCase      :			Optional[int] = 1							,					UpperCAmelCase      :			float = 0.0							,					UpperCAmelCase      :			Optional[torch.Generator] = None							,					UpperCAmelCase      :			Optional[torch.FloatTensor] = None							,					UpperCAmelCase      :			Optional[str] = "pil"							,					UpperCAmelCase      :			bool = True							,					UpperCAmelCase      :			Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,					UpperCAmelCase      :			int = 1							,					**UpperCAmelCase      :			Optional[Any]							,					):
													return self.pipea(
													    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							,					**UpperCAmelCase							,					)






						@torch.no_grad()
						def       lowerCamelCase__     (       self      :			Dict							,					UpperCAmelCase      :			Union[str, List[str]]							,					UpperCAmelCase      :			int = 512							,					UpperCAmelCase      :			int = 512							,					UpperCAmelCase      :			int = 50							,					UpperCAmelCase      :			float = 7.5							,					UpperCAmelCase      :			Optional[Union[str, List[str]]] = None							,					UpperCAmelCase      :			Optional[int] = 1							,					UpperCAmelCase      :			float = 0.0							,					UpperCAmelCase      :			Optional[torch.Generator] = None							,					UpperCAmelCase      :			Optional[torch.FloatTensor] = None							,					UpperCAmelCase      :			Optional[str] = "pil"							,					UpperCAmelCase      :			bool = True							,					UpperCAmelCase      :			Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,					UpperCAmelCase      :			int = 1							,					**UpperCAmelCase      :			Union[str, Any]							,					):
													return self.pipea(
													    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							,					**UpperCAmelCase							,					)






						@torch.no_grad()
						def       lowerCamelCase__     (       self      :			Tuple							,					UpperCAmelCase      :			Union[str, List[str]]							,					UpperCAmelCase      :			int = 512							,					UpperCAmelCase      :			int = 512							,					UpperCAmelCase      :			int = 50							,					UpperCAmelCase      :			float = 7.5							,					UpperCAmelCase      :			Optional[Union[str, List[str]]] = None							,					UpperCAmelCase      :			Optional[int] = 1							,					UpperCAmelCase      :			float = 0.0							,					UpperCAmelCase      :			Optional[torch.Generator] = None							,					UpperCAmelCase      :			Optional[torch.FloatTensor] = None							,					UpperCAmelCase      :			Optional[str] = "pil"							,					UpperCAmelCase      :			bool = True							,					UpperCAmelCase      :			Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,					UpperCAmelCase      :			int = 1							,					**UpperCAmelCase      :			Dict							,					):
													return self.pipea(
													    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							,					**UpperCAmelCase							,					)






						@torch.no_grad()
						def       lowerCamelCase__     (       self      :			Optional[Any]							,					UpperCAmelCase      :			Union[str, List[str]]							,					UpperCAmelCase      :			int = 512							,					UpperCAmelCase      :			int = 512							,					UpperCAmelCase      :			int = 50							,					UpperCAmelCase      :			float = 7.5							,					UpperCAmelCase      :			Optional[Union[str, List[str]]] = None							,					UpperCAmelCase      :			Optional[int] = 1							,					UpperCAmelCase      :			float = 0.0							,					UpperCAmelCase      :			Optional[torch.Generator] = None							,					UpperCAmelCase      :			Optional[torch.FloatTensor] = None							,					UpperCAmelCase      :			Optional[str] = "pil"							,					UpperCAmelCase      :			bool = True							,					UpperCAmelCase      :			Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,					UpperCAmelCase      :			int = 1							,					**UpperCAmelCase      :			List[str]							,					):
													return self.pipea(
													    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							,					**UpperCAmelCase							,					)







						@torch.no_grad()
						def       lowerCamelCase__     (       self      :			str							,					UpperCAmelCase      :			Union[str, List[str]]							,					UpperCAmelCase      :			int = 512							,					UpperCAmelCase      :			int = 512							,					UpperCAmelCase      :			int = 50							,					UpperCAmelCase      :			float = 7.5							,					UpperCAmelCase      :			Optional[Union[str, List[str]]] = None							,					UpperCAmelCase      :			Optional[int] = 1							,					UpperCAmelCase      :			float = 0.0							,					UpperCAmelCase      :			Optional[torch.Generator] = None							,					UpperCAmelCase      :			Optional[torch.FloatTensor] = None							,					UpperCAmelCase      :			Optional[str] = "pil"							,					UpperCAmelCase      :			bool = True							,					UpperCAmelCase      :			Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,					UpperCAmelCase      :			int = 1							,					**UpperCAmelCase      :			Tuple							,					):
													__lowerCamelCase					:		Optional[int]		   =     "cuda" if torch.cuda.is_available() else "cpu"
													self.to(UpperCAmelCase    )

													# 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					:		str		   =     self.textaimg_sda_a(
													    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							,					**UpperCAmelCase							,					)

													# Get first result from Stable Diffusion Checkpoint v1.2
													__lowerCamelCase					:		Optional[int]		   =     self.textaimg_sda_a(
													    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							,					**UpperCAmelCase							,					)

													# Get first result from Stable Diffusion Checkpoint v1.3
													__lowerCamelCase					:		Any		   =     self.textaimg_sda_a(
													    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							,					**UpperCAmelCase							,					)

													# Get first result from Stable Diffusion Checkpoint v1.4
													__lowerCamelCase					:		Optional[Any]		   =     self.textaimg_sda_a(
													    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							,					**UpperCAmelCase							,					)

													# 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]]    )