code: 
  
  
  
  import copy
  import fnmatch
  import json
  import os
  import pickle as pkl
  import shutil
  import sys
  import tarfile
  import tempfile
  from collections import OrderedDict
  from contextlib import contextmanager
  from functools import partial
  from hashlib import shaaaa
  from io import BytesIO
  from pathlib import Path
  from urllib.parse import urlparse
  from zipfile import ZipFile, is_zipfile
  
  import cva
  import numpy as np
  import requests
  import wget
  from filelock import FileLock
  from PIL import Image
  from tqdm.auto import tqdm
  from yaml import Loader, dump, load
  
  
  try:
  	import torch
  
  	__A       					=		True
  except ImportError:
  	__A       					=		False
  
  
  try:
  	from torch.hub import _get_torch_home
  
  	__A       					=		_get_torch_home()
  except ImportError:
  	__A       					=		os.path.expanduser(
  	    os.getenv('''TORCH_HOME''', os.path.join(os.getenv('''XDG_CACHE_HOME''', '''~/.cache'''), '''torch'''))
  	)
  
  __A       					=		os.path.join(torch_cache_home, '''transformers''')
  
  __A       					=		'''https://cdn.huggingface.co'''
  __A       					=		'''https://s3.amazonaws.com/models.huggingface.co/bert'''
  __A       					=		'''/'''.join(str(Path(__file__).resolve()).split('''/''')[:-1])
  __A       					=		os.path.join(PATH, '''config.yaml''')
  __A       					=		os.path.join(PATH, '''attributes.txt''')
  __A       					=		os.path.join(PATH, '''objects.txt''')
  __A       					=		os.getenv('''PYTORCH_PRETRAINED_BERT_CACHE''', default_cache_path)
  __A       					=		os.getenv('''PYTORCH_TRANSFORMERS_CACHE''', PYTORCH_PRETRAINED_BERT_CACHE)
  __A       					=		os.getenv('''TRANSFORMERS_CACHE''', PYTORCH_TRANSFORMERS_CACHE)
  __A       					=		'''pytorch_model.bin'''
  __A       					=		'''config.yaml'''
  
  
  
  def  __a  (					lowerCAmelCase_     :      List[Any]=OBJECTS    ,lowerCAmelCase_     :      List[str]=ATTRIBUTES       )   ->				str:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     []
  						with open(lowerCAmelCase_       ) as f:
  												for object in f.readlines():
  																		vg_classes.append(object.split(""","""       )[0].lower().strip()       )
  
  						UpperCAmelCase_=     []
  						with open(lowerCAmelCase_       ) as f:
  												for object in f.readlines():
  																		vg_attrs.append(object.split(""","""       )[0].lower().strip()       )
  						return vg_classes, vg_attrs
  
  
  
  def  __a  (					lowerCAmelCase_     :      Dict       )   ->				Optional[int]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     OrderedDict()
  						with open(lowerCAmelCase_    ,"""rb"""       ) as f:
  												UpperCAmelCase_=     pkl.load(lowerCAmelCase_       )["""model"""]
  						for k in copy.deepcopy(list(ckp.keys()       )       ):
  												UpperCAmelCase_=     ckp.pop(lowerCAmelCase_       )
  												if isinstance(lowerCAmelCase_    ,np.ndarray       ):
  																		UpperCAmelCase_=     torch.tensor(lowerCAmelCase_       )
  												else:
  																		assert isinstance(lowerCAmelCase_    ,torch.tensor       ), type(lowerCAmelCase_       )
  												UpperCAmelCase_=     v
  						return r
  
  
  
  
  
  
  class 	lowercase		:
  
  
  
  
  
  
  	"""simple docstring"""
  
  
  	a__   :      str	     =							{}
  
  
  
  
  	def __init__(			self			:		Tuple		,						__UpperCAmelCase			:		dict		,						__UpperCAmelCase			:		str = "root"		,						__UpperCAmelCase			:		str=0  )    ->				Tuple:
  							UpperCAmelCase_=     name
  							UpperCAmelCase_=     level
  							UpperCAmelCase_=     {}
  							for k, v in dictionary.items():
  													if v is None:
  																			raise ValueError()
  													UpperCAmelCase_=     copy.deepcopy(__UpperCAmelCase  )
  													UpperCAmelCase_=     copy.deepcopy(__UpperCAmelCase  )
  													if isinstance(__UpperCAmelCase		,						__UpperCAmelCase  ):
  																			UpperCAmelCase_=     Config(__UpperCAmelCase		,						name=__UpperCAmelCase		,						level=level + 1  )
  													UpperCAmelCase_=     v
  													setattr(self		,						__UpperCAmelCase		,						__UpperCAmelCase  )
  
  							UpperCAmelCase_=     d
  
  
  
  
  	def __repr__(			self			:		str  )    ->				Any:
  							return str(list((self._pointer.keys())  )  )
  
  
  
  
  	def __setattr__(			self			:		Union[str, Any]		,						__UpperCAmelCase			:		Tuple		,						__UpperCAmelCase			:		Dict  )    ->				Optional[int]:
  							UpperCAmelCase_=     val
  							UpperCAmelCase_=     val
  							UpperCAmelCase_=     key.split("""."""  )
  							UpperCAmelCase_=     len(__UpperCAmelCase  ) - 1
  							UpperCAmelCase_=     self._pointer
  							if len(__UpperCAmelCase  ) > 1:
  													for i, l in enumerate(__UpperCAmelCase  ):
  																			if hasattr(self		,						__UpperCAmelCase  ) and isinstance(getattr(self		,						__UpperCAmelCase  )		,						__UpperCAmelCase  ):
  																									setattr(getattr(self		,						__UpperCAmelCase  )		,						""".""".join(levels[i:]  )		,						__UpperCAmelCase  )
  																			if l == last_level:
  																									UpperCAmelCase_=     val
  																			else:
  																									UpperCAmelCase_=     pointer[l]
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		Tuple  )    ->				Tuple:
  							return self._pointer
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		Dict		,						__UpperCAmelCase			:		Dict		,						__UpperCAmelCase			:		Dict  )    ->				Dict:
  							with open(F"""{file_name}"""		,						"""w"""  ) as stream:
  													dump(__UpperCAmelCase		,						__UpperCAmelCase  )
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		Any		,						__UpperCAmelCase			:		Any		,						__UpperCAmelCase			:		List[Any]  )    ->				Union[str, Any]:
  							with open(F"""{file_name}"""		,						"""w"""  ) as stream:
  													json.dump(__UpperCAmelCase		,						__UpperCAmelCase  )
  
  
  
  
  	@staticmethod
  	def 						_SCREAMING_SNAKE_CASE	(			__UpperCAmelCase			:		int  )    ->				Union[str, Any]:
  							with open(__UpperCAmelCase  ) as stream:
  													UpperCAmelCase_=     load(__UpperCAmelCase		,						Loader=__UpperCAmelCase  )
  							return data
  
  
  
  
  	def __str__(			self			:		Union[str, Any]  )    ->				Any:
  							UpperCAmelCase_=     """    """
  							if self._name != "root":
  													UpperCAmelCase_=     F"""{t * (self._level-1)}{self._name}:\n"""
  							else:
  													UpperCAmelCase_=     """"""
  							UpperCAmelCase_=     self._level
  							for i, (k, v) in enumerate(self._pointer.items()  ):
  													if isinstance(__UpperCAmelCase		,						__UpperCAmelCase  ):
  																			r += F"""{t * (self._level)}{v}\n"""
  																			self._level += 1
  													else:
  																			r += F"""{t * (self._level)}{k}: {v} ({type(__UpperCAmelCase  ).__name__})\n"""
  													UpperCAmelCase_=     level
  							return r[:-1]
  
  
  
  
  	@classmethod
  	def 						_SCREAMING_SNAKE_CASE	(			cls			:		int		,						__UpperCAmelCase			:		str		,						**__UpperCAmelCase			:		Union[str, Any]  )    ->				List[str]:
  							UpperCAmelCase_,     UpperCAmelCase_=     cls.get_config_dict(__UpperCAmelCase		,						**__UpperCAmelCase  )
  							return cls(__UpperCAmelCase  )
  
  
  
  
  	@classmethod
  	def 						_SCREAMING_SNAKE_CASE	(			cls			:		Optional[Any]		,						__UpperCAmelCase			:		str		,						**__UpperCAmelCase			:		List[str]  )    ->				str:
  							UpperCAmelCase_=     kwargs.pop("""cache_dir"""		,						__UpperCAmelCase  )
  							UpperCAmelCase_=     kwargs.pop("""force_download"""		,						__UpperCAmelCase  )
  							UpperCAmelCase_=     kwargs.pop("""resume_download"""		,						__UpperCAmelCase  )
  							UpperCAmelCase_=     kwargs.pop("""proxies"""		,						__UpperCAmelCase  )
  							UpperCAmelCase_=     kwargs.pop("""local_files_only"""		,						__UpperCAmelCase  )
  
  							if os.path.isdir(__UpperCAmelCase  ):
  													UpperCAmelCase_=     os.path.join(__UpperCAmelCase		,						__UpperCAmelCase  )
  							elif os.path.isfile(__UpperCAmelCase  ) or is_remote_url(__UpperCAmelCase  ):
  													UpperCAmelCase_=     pretrained_model_name_or_path
  							else:
  													UpperCAmelCase_=     hf_bucket_url(__UpperCAmelCase		,						filename=__UpperCAmelCase		,						use_cdn=__UpperCAmelCase  )
  
  							try:
  													# Load from URL or cache if already cached
  													UpperCAmelCase_=     cached_path(
  													    __UpperCAmelCase		,						cache_dir=__UpperCAmelCase		,						force_download=__UpperCAmelCase		,						proxies=__UpperCAmelCase		,						resume_download=__UpperCAmelCase		,						local_files_only=__UpperCAmelCase		,						)
  													# Load config dict
  													if resolved_config_file is None:
  																			raise EnvironmentError
  
  													UpperCAmelCase_=     Config.load_yaml(__UpperCAmelCase  )
  
  							except EnvironmentError:
  													UpperCAmelCase_=     """Can't load config for"""
  													raise EnvironmentError(__UpperCAmelCase  )
  
  							if resolved_config_file == config_file:
  													print("""loading configuration file from path"""  )
  							else:
  													print("""loading configuration file cache"""  )
  
  							return Config.load_yaml(__UpperCAmelCase  ), kwargs
  
  
  
  def  __a  (					lowerCAmelCase_     :      Any       )   ->				int:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     torch.load("""dump.pt"""    ,map_location=in_tensor.device       )
  						UpperCAmelCase_=     in_tensor.numpy()
  						UpperCAmelCase_=     out_tensor.numpy()[0]
  						print(na.shape    ,na[0, 0, :5]       )
  						print(na.shape    ,na[0, 0, :5]       )
  						assert np.allclose(lowerCAmelCase_    ,lowerCAmelCase_    ,rtol=0.01    ,atol=0.1       ), (
  						    F"""{sum([1 for x in np.isclose(lowerCAmelCase_    ,lowerCAmelCase_    ,rtol=0.01    ,atol=0.1       ).flatten() if x is False]       )/len(na.flatten()       )*1_00:.4f} %"""
  						    " element-wise mismatch"
  						)
  						raise Exception("""tensors are all good"""       )
  
  						# Hugging face functions below
  
  
  
  def  __a  (					lowerCAmelCase_     :      Dict       )   ->				List[Any]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     urlparse(lowerCAmelCase_       )
  						return parsed.scheme in ("http", "https")
  
  
  
  def  __a  (					lowerCAmelCase_     :      str    ,lowerCAmelCase_     :      str    ,lowerCAmelCase_     :      List[str]=True       )   ->				str:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     CLOUDFRONT_DISTRIB_PREFIX if use_cdn else S3_BUCKET_PREFIX
  						UpperCAmelCase_=     """/""" not in model_id
  						if legacy_format:
  												return F"""{endpoint}/{model_id}-{filename}"""
  						else:
  												return F"""{endpoint}/{model_id}/{filename}"""
  
  
  
  def  __a  (					lowerCAmelCase_     :      Any    ,lowerCAmelCase_     :      Tuple    ,lowerCAmelCase_     :      int=None    ,lowerCAmelCase_     :      Optional[int]=0    ,lowerCAmelCase_     :      Optional[int]=None    ,)   ->				Tuple:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     """python/{}""".format(sys.version.split()[0]       )
  						if _torch_available:
  												ua += "; torch/{}".format(torch.__version__       )
  						if isinstance(lowerCAmelCase_    ,lowerCAmelCase_       ):
  												ua += "; " + "; ".join("""{}/{}""".format(lowerCAmelCase_    ,lowerCAmelCase_       ) for k, v in user_agent.items()       )
  						elif isinstance(lowerCAmelCase_    ,lowerCAmelCase_       ):
  												ua += "; " + user_agent
  						UpperCAmelCase_=     {"""user-agent""": ua}
  						if resume_size > 0:
  												UpperCAmelCase_=     """bytes=%d-""" % (resume_size,)
  						UpperCAmelCase_=     requests.get(lowerCAmelCase_    ,stream=lowerCAmelCase_    ,proxies=lowerCAmelCase_    ,headers=lowerCAmelCase_       )
  						if response.status_code == 4_16:  # Range not satisfiable
  												return
  						UpperCAmelCase_=     response.headers.get("""Content-Length"""       )
  						UpperCAmelCase_=     resume_size + int(lowerCAmelCase_       ) if content_length is not None else None
  						UpperCAmelCase_=     tqdm(
  						    unit="""B"""    ,unit_scale=lowerCAmelCase_    ,total=lowerCAmelCase_    ,initial=lowerCAmelCase_    ,desc="""Downloading"""    ,)
  						for chunk in response.iter_content(chunk_size=10_24       ):
  												if chunk:  # filter out keep-alive new chunks
  																		progress.update(len(lowerCAmelCase_       )       )
  																		temp_file.write(lowerCAmelCase_       )
  						progress.close()
  
  
  
  def  __a  (					lowerCAmelCase_     :      Optional[int]    ,lowerCAmelCase_     :      Optional[int]=None    ,lowerCAmelCase_     :      List[str]=False    ,lowerCAmelCase_     :      Union[str, Any]=None    ,lowerCAmelCase_     :      Union[str, Any]=10    ,lowerCAmelCase_     :      List[Any]=False    ,lowerCAmelCase_     :      Union[str, Any]=None    ,lowerCAmelCase_     :      Optional[int]=False    ,)   ->				Optional[int]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						if cache_dir is None:
  												UpperCAmelCase_=     TRANSFORMERS_CACHE
  						if isinstance(lowerCAmelCase_    ,lowerCAmelCase_       ):
  												UpperCAmelCase_=     str(lowerCAmelCase_       )
  
  						os.makedirs(lowerCAmelCase_    ,exist_ok=lowerCAmelCase_       )
  
  						UpperCAmelCase_=     None
  						if not local_files_only:
  												try:
  																		UpperCAmelCase_=     requests.head(lowerCAmelCase_    ,allow_redirects=lowerCAmelCase_    ,proxies=lowerCAmelCase_    ,timeout=lowerCAmelCase_       )
  																		if response.status_code == 2_00:
  																								UpperCAmelCase_=     response.headers.get("""ETag"""       )
  												except (EnvironmentError, requests.exceptions.Timeout):
  																		# etag is already None
  																		pass
  
  						UpperCAmelCase_=     url_to_filename(lowerCAmelCase_    ,lowerCAmelCase_       )
  
  						# get cache path to put the file
  						UpperCAmelCase_=     os.path.join(lowerCAmelCase_    ,lowerCAmelCase_       )
  
  						# etag is None = we don't have a connection, or url doesn't exist, or is otherwise inaccessible.
  						# try to get the last downloaded one
  						if etag is None:
  												if os.path.exists(lowerCAmelCase_       ):
  																		return cache_path
  												else:
  																		UpperCAmelCase_=     [
  																		    file
  																		    for file in fnmatch.filter(os.listdir(lowerCAmelCase_       )    ,filename + """.*"""       )
  																		    if not file.endswith(""".json"""       ) and not file.endswith(""".lock"""       )
  																		]
  																		if len(lowerCAmelCase_       ) > 0:
  																								return os.path.join(lowerCAmelCase_    ,matching_files[-1]       )
  																		else:
  																								# If files cannot be found and local_files_only=True,
  																								# the models might've been found if local_files_only=False
  																								# Notify the user about that
  																								if local_files_only:
  																														raise ValueError(
  																														    """Cannot find the requested files in the cached path and outgoing traffic has been"""
  																														    """ disabled. To enable model look-ups and downloads online, set 'local_files_only'"""
  																														    """ to False."""       )
  																								return None
  
      # From now on, etag is not None.
  						if os.path.exists(lowerCAmelCase_       ) and not force_download:
  												return cache_path
  
  						# Prevent parallel downloads of the same file with a lock.
  						UpperCAmelCase_=     cache_path + """.lock"""
  						with FileLock(lowerCAmelCase_       ):
  												# If the download just completed while the lock was activated.
  												if os.path.exists(lowerCAmelCase_       ) and not force_download:
  																		# Even if returning early like here, the lock will be released.
  																		return cache_path
  
  												if resume_download:
  																		UpperCAmelCase_=     cache_path + """.incomplete"""
  
  																		@contextmanager
  																		def _resumable_file_manager():
  																								with open(lowerCAmelCase_    ,"""a+b"""       ) as f:
  																														yield f
  
  																		UpperCAmelCase_=     _resumable_file_manager
  																		if os.path.exists(lowerCAmelCase_       ):
  																								UpperCAmelCase_=     os.stat(lowerCAmelCase_       ).st_size
  																		else:
  																								UpperCAmelCase_=     0
  												else:
  																		UpperCAmelCase_=     partial(tempfile.NamedTemporaryFile    ,dir=lowerCAmelCase_    ,delete=lowerCAmelCase_       )
  																		UpperCAmelCase_=     0
  
  												# Download to temporary file, then copy to cache dir once finished.
  												# Otherwise you get corrupt cache entries if the download gets interrupted.
  												with temp_file_manager() as temp_file:
  																		print(
  																		    """%s not found in cache or force_download set to True, downloading to %s"""    ,lowerCAmelCase_    ,temp_file.name    ,)
  
  																		http_get(
  																		    lowerCAmelCase_    ,lowerCAmelCase_    ,proxies=lowerCAmelCase_    ,resume_size=lowerCAmelCase_    ,user_agent=lowerCAmelCase_    ,)
  
  												os.replace(temp_file.name    ,lowerCAmelCase_       )
  
  												UpperCAmelCase_=     {"""url""": url, """etag""": etag}
  												UpperCAmelCase_=     cache_path + """.json"""
  												with open(lowerCAmelCase_    ,"""w"""       ) as meta_file:
  																		json.dump(lowerCAmelCase_    ,lowerCAmelCase_       )
  
  						return cache_path
  
  
  
  def  __a  (					lowerCAmelCase_     :      List[str]    ,lowerCAmelCase_     :      Optional[int]=None       )   ->				Tuple:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     url.encode("""utf-8"""       )
  						UpperCAmelCase_=     shaaaa(lowerCAmelCase_       )
  						UpperCAmelCase_=     url_hash.hexdigest()
  
  						if etag:
  												UpperCAmelCase_=     etag.encode("""utf-8"""       )
  												UpperCAmelCase_=     shaaaa(lowerCAmelCase_       )
  												filename += "." + etag_hash.hexdigest()
  
  						if url.endswith(""".h5"""       ):
  												filename += ".h5"
  
  						return filename
  
  
  
  def  __a  (					lowerCAmelCase_     :      Optional[int]    ,lowerCAmelCase_     :      Any=None    ,lowerCAmelCase_     :      List[str]=False    ,lowerCAmelCase_     :      Tuple=None    ,lowerCAmelCase_     :      Optional[int]=False    ,lowerCAmelCase_     :      Dict=None    ,lowerCAmelCase_     :      str=False    ,lowerCAmelCase_     :      List[str]=False    ,lowerCAmelCase_     :      Optional[Any]=False    ,)   ->				Optional[int]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						if cache_dir is None:
  												UpperCAmelCase_=     TRANSFORMERS_CACHE
  						if isinstance(lowerCAmelCase_    ,lowerCAmelCase_       ):
  												UpperCAmelCase_=     str(lowerCAmelCase_       )
  						if isinstance(lowerCAmelCase_    ,lowerCAmelCase_       ):
  												UpperCAmelCase_=     str(lowerCAmelCase_       )
  
  						if is_remote_url(lowerCAmelCase_       ):
  												# URL, so get it from the cache (downloading if necessary)
  												UpperCAmelCase_=     get_from_cache(
  												    lowerCAmelCase_    ,cache_dir=lowerCAmelCase_    ,force_download=lowerCAmelCase_    ,proxies=lowerCAmelCase_    ,resume_download=lowerCAmelCase_    ,user_agent=lowerCAmelCase_    ,local_files_only=lowerCAmelCase_    ,)
  						elif os.path.exists(lowerCAmelCase_       ):
  												# File, and it exists.
  												UpperCAmelCase_=     url_or_filename
  						elif urlparse(lowerCAmelCase_       ).scheme == "":
  												# File, but it doesn't exist.
  												raise EnvironmentError("""file {} not found""".format(lowerCAmelCase_       )       )
  						else:
  												# Something unknown
  												raise ValueError("""unable to parse {} as a URL or as a local path""".format(lowerCAmelCase_       )       )
  
  						if extract_compressed_file:
  												if not is_zipfile(lowerCAmelCase_       ) and not tarfile.is_tarfile(lowerCAmelCase_       ):
  																		return output_path
  
  												# Path where we extract compressed archives
  												# We avoid '.' in dir name and add "-extracted" at the end: "./model.zip" => "./model-zip-extracted/"
  												UpperCAmelCase_,     UpperCAmelCase_=     os.path.split(lowerCAmelCase_       )
  												UpperCAmelCase_=     output_file.replace("""."""    ,"""-"""       ) + """-extracted"""
  												UpperCAmelCase_=     os.path.join(lowerCAmelCase_    ,lowerCAmelCase_       )
  
  												if os.path.isdir(lowerCAmelCase_       ) and os.listdir(lowerCAmelCase_       ) and not force_extract:
  																		return output_path_extracted
  
  												# Prevent parallel extractions
  												UpperCAmelCase_=     output_path + """.lock"""
  												with FileLock(lowerCAmelCase_       ):
  																		shutil.rmtree(lowerCAmelCase_    ,ignore_errors=lowerCAmelCase_       )
  																		os.makedirs(lowerCAmelCase_       )
  																		if is_zipfile(lowerCAmelCase_       ):
  																								with ZipFile(lowerCAmelCase_    ,"""r"""       ) as zip_file:
  																														zip_file.extractall(lowerCAmelCase_       )
  																														zip_file.close()
  																		elif tarfile.is_tarfile(lowerCAmelCase_       ):
  																								UpperCAmelCase_=     tarfile.open(lowerCAmelCase_       )
  																								tar_file.extractall(lowerCAmelCase_       )
  																								tar_file.close()
  																		else:
  																								raise EnvironmentError("""Archive format of {} could not be identified""".format(lowerCAmelCase_       )       )
  
  												return output_path_extracted
  
  						return output_path
  
  
  
  def  __a  (					lowerCAmelCase_     :      Dict    ,lowerCAmelCase_     :      str=","       )   ->				Any:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						assert isinstance(lowerCAmelCase_    ,lowerCAmelCase_       )
  						if os.path.isfile(lowerCAmelCase_       ):
  												with open(lowerCAmelCase_       ) as f:
  																		UpperCAmelCase_=     eval(f.read()       )
  						else:
  												UpperCAmelCase_=     requests.get(lowerCAmelCase_       )
  												try:
  																		UpperCAmelCase_=     requests.json()
  												except Exception:
  																		UpperCAmelCase_=     req.content.decode()
  																		assert data is not None, "could not connect"
  																		try:
  																								UpperCAmelCase_=     eval(lowerCAmelCase_       )
  																		except Exception:
  																								UpperCAmelCase_=     data.split("""\n"""       )
  												req.close()
  						return data
  
  
  
  def  __a  (					lowerCAmelCase_     :      List[Any]       )   ->				Tuple:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     requests.get(lowerCAmelCase_       )
  						UpperCAmelCase_=     np.array(Image.open(BytesIO(response.content       )       )       )
  						return img
  
  
  
  def  __a  (					lowerCAmelCase_     :      Optional[int]       )   ->				Optional[Any]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     url.split("""/"""       )[-1]
  						if fn not in os.listdir(os.getcwd()       ):
  												wget.download(lowerCAmelCase_       )
  						with open(lowerCAmelCase_    ,"""rb"""       ) as stream:
  												UpperCAmelCase_=     pkl.load(lowerCAmelCase_       )
  						UpperCAmelCase_=     weights.pop("""model"""       )
  						UpperCAmelCase_=     {}
  						for k, v in model.items():
  												UpperCAmelCase_=     torch.from_numpy(lowerCAmelCase_       )
  												if "running_var" in k:
  																		UpperCAmelCase_=     torch.tensor([0]       )
  																		UpperCAmelCase_=     k.replace("""running_var"""    ,"""num_batches_tracked"""       )
  																		UpperCAmelCase_=     zero
  						return new
  
  
  
  def  __a  (					)   ->				int:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						print(F"""{os.path.abspath(os.path.join(lowerCAmelCase_    ,os.pardir       )       )}/demo.ipynb"""       )
  
  
  
  def  __a  (					lowerCAmelCase_     :      str    ,lowerCAmelCase_     :      int="RGB"       )   ->				Optional[Any]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						assert isinstance(lowerCAmelCase_    ,lowerCAmelCase_       )
  						if os.path.isfile(lowerCAmelCase_       ):
  												UpperCAmelCase_=     cva.imread(lowerCAmelCase_       )
  						else:
  												UpperCAmelCase_=     get_image_from_url(lowerCAmelCase_       )
  												assert img is not None, F"""could not connect to: {im}"""
  						UpperCAmelCase_=     cva.cvtColor(lowerCAmelCase_    ,cva.COLOR_BGR2RGB       )
  						if input_format == "RGB":
  												UpperCAmelCase_=     img[:, :, ::-1]
  						return img
  
  
  
  def  __a  (					lowerCAmelCase_     :      Dict    ,lowerCAmelCase_     :      Optional[int]=1       )   ->				List[Any]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						return (images[i : i + batch] for i in range(0    ,len(lowerCAmelCase_       )    ,lowerCAmelCase_       ))
  
  
  
  
  
style_context: 
  
  
  
  from math import radians as angle_to_radians
  from math import sin
  
  # Acceleration Constant on Earth (unit m/s^2)
  __A       					=		9.8_0_6_6_5
  
  
  
  def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				None:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						if not isinstance(lowerCAmelCase_    ,(int, float)       ):
  												raise TypeError("""Invalid velocity. Should be a positive number."""       )
  
  						if not isinstance(lowerCAmelCase_    ,(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  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				float:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						check_args(lowerCAmelCase_    ,lowerCAmelCase_       )
  						UpperCAmelCase_=     angle_to_radians(2 * angle       )
  						return round(init_velocity**2 * sin(lowerCAmelCase_       ) / g    ,2       )
  
  
  
  def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				float:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						check_args(lowerCAmelCase_    ,lowerCAmelCase_       )
  						UpperCAmelCase_=     angle_to_radians(lowerCAmelCase_       )
  						return round(init_velocity**2 * sin(lowerCAmelCase_       ) ** 2 / (2 * g)    ,2       )
  
  
  
  def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				float:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						check_args(lowerCAmelCase_    ,lowerCAmelCase_       )
  						UpperCAmelCase_=     angle_to_radians(lowerCAmelCase_       )
  						return round(2 * init_velocity * sin(lowerCAmelCase_       ) / g    ,2       )
  
  
  
  def  __a  (					)   ->				None:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_,     UpperCAmelCase_=     25, 20
  						assert horizontal_distance(lowerCAmelCase_    ,lowerCAmelCase_       ) == 40.97
  						assert max_height(lowerCAmelCase_    ,lowerCAmelCase_       ) == 3.73
  						assert total_time(lowerCAmelCase_    ,lowerCAmelCase_       ) == 1.74
  
  
  if __name__ == "__main__":
  	from doctest import testmod
  
  	testmod()
  
  	# Get input from user
  	__A       					=		float(input('''Initial Velocity: ''').strip())
  
  	# Get input from user
  	__A       					=		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]')
  
  
  
  
  