
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


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





class 						lowercase       (  __UpperCamelCase					):
					__a					=    ["""safety_checker""", """feature_extractor"""]
					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 ,	):
								"""simple docstring"""







								super().__init__()
								if hasattr(scheduler.config ,	'''steps_offset'''    ) and scheduler.config.steps_offset != 1:
											lowerCAmelCase__ :    int				      =			(
											    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''' ,	SCREAMING_SNAKE_CASE__ ,	standard_warn=SCREAMING_SNAKE_CASE__    )
											lowerCAmelCase__ :    str				      =			dict(scheduler.config    )
											lowerCAmelCase__ :    Any				      =			1
											lowerCAmelCase__ :    Any				      =			FrozenDict(SCREAMING_SNAKE_CASE__    )

								self.register_modules(
								    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__ ,	)
								self.register_to_config(requires_safety_checker=SCREAMING_SNAKE_CASE__    )
					@property
					def lowercase_			(		self    ):
								"""simple docstring"""







								return {k: getattr(self ,	SCREAMING_SNAKE_CASE__    ) for k in self.config.keys() if not k.startswith('''_'''    )}
					def lowercase_			(		self ,	SCREAMING_SNAKE_CASE__ = "auto"    ):
								"""simple docstring"""







								if slice_size == "auto":
											# half the attention head size is usually a good trade-off between
											# speed and memory
											lowerCAmelCase__ :    str				      =			self.unet.config.attention_head_dim // 2
								self.unet.set_attention_slice(SCREAMING_SNAKE_CASE__    )
					def lowercase_			(		self    ):
								"""simple docstring"""







								self.enable_attention_slicing(SCREAMING_SNAKE_CASE__    )
					@torch.no_grad()
					def lowercase_			(		self ,	SCREAMING_SNAKE_CASE__ ,	SCREAMING_SNAKE_CASE__ ,	SCREAMING_SNAKE_CASE__ ,	SCREAMING_SNAKE_CASE__ = 0.8 ,	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__ = "pil" ,	SCREAMING_SNAKE_CASE__ = True ,	SCREAMING_SNAKE_CASE__ = None ,	SCREAMING_SNAKE_CASE__ = 1 ,	):
								"""simple docstring"""







								return StableDiffusionInpaintPipelineLegacy(**self.components    )(
								    prompt=SCREAMING_SNAKE_CASE__ ,	image=SCREAMING_SNAKE_CASE__ ,	mask_image=SCREAMING_SNAKE_CASE__ ,	strength=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__ ,	output_type=SCREAMING_SNAKE_CASE__ ,	return_dict=SCREAMING_SNAKE_CASE__ ,	callback=SCREAMING_SNAKE_CASE__ ,	)
					@torch.no_grad()
					def lowercase_			(		self ,	SCREAMING_SNAKE_CASE__ ,	SCREAMING_SNAKE_CASE__ ,	SCREAMING_SNAKE_CASE__ = 0.8 ,	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__ = "pil" ,	SCREAMING_SNAKE_CASE__ = True ,	SCREAMING_SNAKE_CASE__ = None ,	SCREAMING_SNAKE_CASE__ = 1 ,	**SCREAMING_SNAKE_CASE__ ,	):
								"""simple docstring"""







								return StableDiffusionImgaImgPipeline(**self.components    )(
								    prompt=SCREAMING_SNAKE_CASE__ ,	image=SCREAMING_SNAKE_CASE__ ,	strength=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__ ,	output_type=SCREAMING_SNAKE_CASE__ ,	return_dict=SCREAMING_SNAKE_CASE__ ,	callback=SCREAMING_SNAKE_CASE__ ,	callback_steps=SCREAMING_SNAKE_CASE__ ,	)
					@torch.no_grad()
					def lowercase_			(		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 ,	):
								"""simple docstring"""







								return StableDiffusionPipeline(**self.components    )(
								    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__ ,	)





from math import radians as angle_to_radians
from math import sin

# Acceleration Constant on Earth (unit m/s^2)
A__       :   str   						=					9.8_0665



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):

			# Ensure valid instance
			if not isinstance(__UpperCamelCase	,(int, float)    ):
						raise TypeError('''Invalid velocity. Should be a positive number.'''    )

			if not isinstance(__UpperCamelCase	,(int, float)    ):
						raise TypeError('''Invalid angle. Range is 1-90 degrees.'''    )

			# Ensure valid angle
			if angle > 90 or angle < 1:
						raise ValueError('''Invalid angle. Range is 1-90 degrees.'''    )

			# Ensure valid velocity
			if init_velocity < 0:
						raise ValueError('''Invalid velocity. Should be a positive number.'''    )



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):
			check_args(__UpperCamelCase	,__UpperCamelCase    )
			lowerCAmelCase__ :    Union[str, Any]				      =			angle_to_radians(2 * angle    )
			return round(init_velocity**2 * sin(__UpperCamelCase    ) / g	,2    )



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):
			check_args(__UpperCamelCase	,__UpperCamelCase    )
			lowerCAmelCase__ :    List[str]				      =			angle_to_radians(__UpperCamelCase    )
			return round(init_velocity**2 * sin(__UpperCamelCase    ) ** 2 / (2 * g)	,2    )



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):
			check_args(__UpperCamelCase	,__UpperCamelCase    )
			lowerCAmelCase__ :    Dict				      =			angle_to_radians(__UpperCamelCase    )
			return round(2 * init_velocity * sin(__UpperCamelCase    ) / g	,2    )



def      _a     (   ):
			lowerCAmelCase__      ,				lowerCAmelCase__ :    List[Any]				      =			25, 20
			assert horizontal_distance(__UpperCamelCase	,__UpperCamelCase    ) == 40.97
			assert max_height(__UpperCamelCase	,__UpperCamelCase    ) == 3.73
			assert total_time(__UpperCamelCase	,__UpperCamelCase    ) == 1.74


if __name__ == "__main__":
							from doctest import testmod

							testmod()

							# Get input from user
							A__       :   List[Any]   						=					float(input("""Initial Velocity: """).strip())

							# Get input from user
							A__       :   Optional[Any]   						=					float(input("""angle: """).strip())

							# Print results
							print()
							print("""Results: """)
							print(f"""Horizontal Distance: {horizontal_distance(init_vel, angle)!s} [m]""")
							print(f"""Maximum Height: {max_height(init_vel, angle)!s} [m]""")
							print(f"""Total Time: {total_time(init_vel, angle)!s} [s]""")



