

'''simple docstring'''




import json
import os
from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import yaml

from ...utils import ComputeEnvironment, DistributedType, SageMakerDistributedType
from ...utils.constants import SAGEMAKER_PYTHON_VERSION, SAGEMAKER_PYTORCH_VERSION, SAGEMAKER_TRANSFORMERS_VERSION


_a      :      Dict       				=      os.path.expanduser(
    os.getenv("HF_HOME", os.path.join(os.getenv("XDG_CACHE_HOME", "~/.cache"), "huggingface"))
)
_a      :      Any       				=      os.path.join(hf_cache_home, "accelerate")
_a      :      List[Any]       				=      os.path.join(cache_dir, "default_config.yaml")
_a      :      Any       				=      os.path.join(cache_dir, "default_config.yaml")

# For backward compatibility: the default config is the json one if it's the only existing file.
if os.path.isfile(default_yaml_config_file) or not os.path.isfile(default_json_config_file):
       _a      :      str       				=      default_yaml_config_file
else:
       _a      :      Any       				=      default_json_config_file





def      _a		(lowercase__ :      List[str]	) -> Dict:






     """simple docstring"""
     if config_file is not None:
          if not os.path.isfile(lowercase__	):
               raise FileNotFoundError(
                   f'The passed configuration file `{config_file}` does not exist. '
                   'Please pass an existing file to `accelerate launch`, or use the the default one '
                   'created through `accelerate config` and run `accelerate launch` '
                   'without the `--config_file` argument.'	)
     else:
          __snake_case    			=	default_config_file
     with open(lowercase__       ,      'r'       ,      encoding='utf-8'	) as f:
          if config_file.endswith('.json'	):
               if (
                   json.load(lowercase__	).get('compute_environment'       ,      ComputeEnvironment.LOCAL_MACHINE	)
                   == ComputeEnvironment.LOCAL_MACHINE
               ):
                    __snake_case    			=	ClusterConfig
               else:
                    __snake_case    			=	SageMakerConfig
               return config_class.from_json_file(json_file=lowercase__	)
          else:
               if (
                   yaml.safe_load(lowercase__	).get('compute_environment'       ,      ComputeEnvironment.LOCAL_MACHINE	)
                   == ComputeEnvironment.LOCAL_MACHINE
               ):
                    __snake_case    			=	ClusterConfig
               else:
                    __snake_case    			=	SageMakerConfig
               return config_class.from_yaml_file(yaml_file=lowercase__	)




@dataclass
class  _lowercase   :
   _SCREAMING_SNAKE_CASE     :     Optional[int]									=  4_2
   _SCREAMING_SNAKE_CASE     :     Optional[Any]									=  4_2
   _SCREAMING_SNAKE_CASE     :     List[str]									=  4_2
   _SCREAMING_SNAKE_CASE     :     Optional[int]									=  4_2
   def a     (	self					:			Union[str, Any]			)   ->       List[Any]:
        __snake_case    			=	self.__dict__
        # For serialization, it's best to convert Enums to strings (or their underlying value type).
        for key, value in result.items():
             if isinstance(__A					,      __A			):
                  __snake_case    			=	value.value
             if isinstance(__A					,      __A			) and not bool(__A			):
                  __snake_case    			=	None
        __snake_case    			=	{k: v for k, v in result.items() if v is not None}
        return result
   @classmethod
   def a     (	cls					:			Any					,      SCREAMING_SNAKE_CASE_					:			List[Any]=None			)   ->       List[Any]:
        __snake_case    			=	default_json_config_file if json_file is None else json_file
        with open(__A					,      'r'					,      encoding='utf-8'			) as f:
             __snake_case    			=	json.load(__A			)
        if "compute_environment" not in config_dict:
             __snake_case    			=	ComputeEnvironment.LOCAL_MACHINE
        if "mixed_precision" not in config_dict:
             __snake_case    			=	'fp16' if ('fp16' in config_dict and config_dict['fp16']) else None
        if "fp16" in config_dict:  # Convert the config to the new format.
             del config_dict["fp16"]
        if "dynamo_backend" in config_dict:  # Convert the config to the new format.
             __snake_case    			=	config_dict.pop('dynamo_backend'			)
             __snake_case    			=	{} if dynamo_backend == 'NO' else {'dynamo_backend': dynamo_backend}
        if "use_cpu" not in config_dict:
             __snake_case    			=	False
        return cls(**__A			)
   def a     (	self					:			int					,      SCREAMING_SNAKE_CASE_					:			Dict			)   ->       int:
        with open(__A					,      'w'					,      encoding='utf-8'			) as f:
             __snake_case    			=	json.dumps(self.to_dict()					,      indent=2					,      sort_keys=__A			) + '\n'
             f.write(__A			)
   @classmethod
   def a     (	cls					:			Optional[int]					,      SCREAMING_SNAKE_CASE_					:			Optional[int]=None			)   ->       List[str]:
        __snake_case    			=	default_yaml_config_file if yaml_file is None else yaml_file
        with open(__A					,      'r'					,      encoding='utf-8'			) as f:
             __snake_case    			=	yaml.safe_load(__A			)
        if "compute_environment" not in config_dict:
             __snake_case    			=	ComputeEnvironment.LOCAL_MACHINE

        if "mixed_precision" not in config_dict:
             __snake_case    			=	'fp16' if ('fp16' in config_dict and config_dict['fp16']) else None
        if isinstance(config_dict['mixed_precision']					,      __A			) and not config_dict["mixed_precision"]:
             __snake_case    			=	'no'
        if "fp16" in config_dict:  # Convert the config to the new format.
             del config_dict["fp16"]
        if "dynamo_backend" in config_dict:  # Convert the config to the new format.
             __snake_case    			=	config_dict.pop('dynamo_backend'			)
             __snake_case    			=	{} if dynamo_backend == 'NO' else {'dynamo_backend': dynamo_backend}
        if "use_cpu" not in config_dict:
             __snake_case    			=	False
        return cls(**__A			)
   def a     (	self					:			List[str]					,      SCREAMING_SNAKE_CASE_					:			Dict			)   ->       Optional[Any]:
        with open(__A					,      'w'					,      encoding='utf-8'			) as f:
             yaml.safe_dump(self.to_dict()					,      __A			)





   def a     (	self					:			List[str]			)   ->       Dict:
        if isinstance(self.compute_environment					,      __A			):
             __snake_case    			=	ComputeEnvironment(self.compute_environment			)
        if isinstance(self.distributed_type					,      __A			):
             if self.compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
                  __snake_case    			=	SageMakerDistributedType(self.distributed_type			)
             else:
                  __snake_case    			=	DistributedType(self.distributed_type			)
        if self.dynamo_config is None:
             __snake_case    			=	{}




@dataclass
class  _lowercase   (  _SCREAMING_SNAKE_CASE       ):
   _SCREAMING_SNAKE_CASE     :     Optional[Any]									=  4_2
   _SCREAMING_SNAKE_CASE     :     List[str]									=  0
   _SCREAMING_SNAKE_CASE     :     Optional[int]									=  1
   _SCREAMING_SNAKE_CASE     :     Any									=  None
   _SCREAMING_SNAKE_CASE     :     int									=  None
   _SCREAMING_SNAKE_CASE     :     Tuple									=  None
   _SCREAMING_SNAKE_CASE     :     List[Any]									=  "static"
   _SCREAMING_SNAKE_CASE     :     Union[str, Any]									=  False
   _SCREAMING_SNAKE_CASE     :     Union[str, Any]									=  "main"

   # args for deepspeed_plugin
   _SCREAMING_SNAKE_CASE     :     Union[str, Any]									=  None
   # args for fsdp
   _SCREAMING_SNAKE_CASE     :     Any									=  None
   # args for megatron_lm
   _SCREAMING_SNAKE_CASE     :     int									=  None
   # args for ipex
   _SCREAMING_SNAKE_CASE     :     Tuple									=  None
   # args for TPU
   _SCREAMING_SNAKE_CASE     :     List[str]									=  False

   # args for TPU pods
   _SCREAMING_SNAKE_CASE     :     Tuple									=  None
   _SCREAMING_SNAKE_CASE     :     int									=  None
   _SCREAMING_SNAKE_CASE     :     List[str]									=  False
   _SCREAMING_SNAKE_CASE     :     List[Any]									=  False
   _SCREAMING_SNAKE_CASE     :     Any									=  None
   _SCREAMING_SNAKE_CASE     :     Union[str, Any]									=  None
   _SCREAMING_SNAKE_CASE     :     Any									=  None
   _SCREAMING_SNAKE_CASE     :     Union[str, Any]									=  None

   # args for dynamo
   _SCREAMING_SNAKE_CASE     :     Optional[Any]									=  None
   def a     (	self					:			Tuple			)   ->       Optional[Any]:
        if self.deepspeed_config is None:
             __snake_case    			=	{}
        if self.fsdp_config is None:
             __snake_case    			=	{}
        if self.megatron_lm_config is None:
             __snake_case    			=	{}
        if self.ipex_config is None:
             __snake_case    			=	{}
        return super().__post_init__()




@dataclass
class  _lowercase   (  _SCREAMING_SNAKE_CASE       ):
   _SCREAMING_SNAKE_CASE     :     Any									=  4_2
   _SCREAMING_SNAKE_CASE     :     List[Any]									=  4_2
   _SCREAMING_SNAKE_CASE     :     str									=  None
   _SCREAMING_SNAKE_CASE     :     List[str]									=  None
   _SCREAMING_SNAKE_CASE     :     Any									=  "us-east-1"
   _SCREAMING_SNAKE_CASE     :     Any									=  1
   _SCREAMING_SNAKE_CASE     :     Optional[Any]									=  "all"
   _SCREAMING_SNAKE_CASE     :     str									=  F'accelerate-sagemaker-{num_machines}'
   _SCREAMING_SNAKE_CASE     :     Union[str, Any]									=  SAGEMAKER_PYTORCH_VERSION
   _SCREAMING_SNAKE_CASE     :     int									=  SAGEMAKER_TRANSFORMERS_VERSION
   _SCREAMING_SNAKE_CASE     :     Tuple									=  SAGEMAKER_PYTHON_VERSION
   _SCREAMING_SNAKE_CASE     :     Union[str, Any]									=  None
   _SCREAMING_SNAKE_CASE     :     int									=  None
   _SCREAMING_SNAKE_CASE     :     Any									=  None
   _SCREAMING_SNAKE_CASE     :     Tuple									=  None








'''simple docstring'''




import os

import requests

_a      :      List[str]       				=      "https://www.amdoren.com/api/currency.php"


# Currency and their description
_a      :      Tuple       				=      "\nAED	United Arab Emirates Dirham\nAFN	Afghan Afghani\nALL	Albanian Lek\nAMD	Armenian Dram\nANG	Netherlands Antillean Guilder\nAOA	Angolan Kwanza\nARS	Argentine Peso\nAUD	Australian Dollar\nAWG	Aruban Florin\nAZN	Azerbaijani Manat\nBAM	Bosnia & Herzegovina Convertible Mark\nBBD	Barbadian Dollar\nBDT	Bangladeshi Taka\nBGN	Bulgarian Lev\nBHD	Bahraini Dinar\nBIF	Burundian Franc\nBMD	Bermudian Dollar\nBND	Brunei Dollar\nBOB	Bolivian Boliviano\nBRL	Brazilian Real\nBSD	Bahamian Dollar\nBTN	Bhutanese Ngultrum\nBWP	Botswana Pula\nBYN	Belarus Ruble\nBZD	Belize Dollar\nCAD	Canadian Dollar\nCDF	Congolese Franc\nCHF	Swiss Franc\nCLP	Chilean Peso\nCNY	Chinese Yuan\nCOP	Colombian Peso\nCRC	Costa Rican Colon\nCUC	Cuban Convertible Peso\nCVE	Cape Verdean Escudo\nCZK	Czech Republic Koruna\nDJF	Djiboutian Franc\nDKK	Danish Krone\nDOP	Dominican Peso\nDZD	Algerian Dinar\nEGP	Egyptian Pound\nERN	Eritrean Nakfa\nETB	Ethiopian Birr\nEUR	Euro\nFJD	Fiji Dollar\nGBP	British Pound Sterling\nGEL	Georgian Lari\nGHS	Ghanaian Cedi\nGIP	Gibraltar Pound\nGMD	Gambian Dalasi\nGNF	Guinea Franc\nGTQ	Guatemalan Quetzal\nGYD	Guyanaese Dollar\nHKD	Hong Kong Dollar\nHNL	Honduran Lempira\nHRK	Croatian Kuna\nHTG	Haiti Gourde\nHUF	Hungarian Forint\nIDR	Indonesian Rupiah\nILS	Israeli Shekel\nINR	Indian Rupee\nIQD	Iraqi Dinar\nIRR	Iranian Rial\nISK	Icelandic Krona\nJMD	Jamaican Dollar\nJOD	Jordanian Dinar\nJPY	Japanese Yen\nKES	Kenyan Shilling\nKGS	Kyrgystani Som\nKHR	Cambodian Riel\nKMF	Comorian Franc\nKPW	North Korean Won\nKRW	South Korean Won\nKWD	Kuwaiti Dinar\nKYD	Cayman Islands Dollar\nKZT	Kazakhstan Tenge\nLAK	Laotian Kip\nLBP	Lebanese Pound\nLKR	Sri Lankan Rupee\nLRD	Liberian Dollar\nLSL	Lesotho Loti\nLYD	Libyan Dinar\nMAD	Moroccan Dirham\nMDL	Moldovan Leu\nMGA	Malagasy Ariary\nMKD	Macedonian Denar\nMMK	Myanma Kyat\nMNT	Mongolian Tugrik\nMOP	Macau Pataca\nMRO	Mauritanian Ouguiya\nMUR	Mauritian Rupee\nMVR	Maldivian Rufiyaa\nMWK	Malawi Kwacha\nMXN	Mexican Peso\nMYR	Malaysian Ringgit\nMZN	Mozambican Metical\nNAD	Namibian Dollar\nNGN	Nigerian Naira\nNIO	Nicaragua Cordoba\nNOK	Norwegian Krone\nNPR	Nepalese Rupee\nNZD	New Zealand Dollar\nOMR	Omani Rial\nPAB	Panamanian Balboa\nPEN	Peruvian Nuevo Sol\nPGK	Papua New Guinean Kina\nPHP	Philippine Peso\nPKR	Pakistani Rupee\nPLN	Polish Zloty\nPYG	Paraguayan Guarani\nQAR	Qatari Riyal\nRON	Romanian Leu\nRSD	Serbian Dinar\nRUB	Russian Ruble\nRWF	Rwanda Franc\nSAR	Saudi Riyal\nSBD	Solomon Islands Dollar\nSCR	Seychellois Rupee\nSDG	Sudanese Pound\nSEK	Swedish Krona\nSGD	Singapore Dollar\nSHP	Saint Helena Pound\nSLL	Sierra Leonean Leone\nSOS	Somali Shilling\nSRD	Surinamese Dollar\nSSP	South Sudanese Pound\nSTD	Sao Tome and Principe Dobra\nSYP	Syrian Pound\nSZL	Swazi Lilangeni\nTHB	Thai Baht\nTJS	Tajikistan Somoni\nTMT	Turkmenistani Manat\nTND	Tunisian Dinar\nTOP	Tonga Paanga\nTRY	Turkish Lira\nTTD	Trinidad and Tobago Dollar\nTWD	New Taiwan Dollar\nTZS	Tanzanian Shilling\nUAH	Ukrainian Hryvnia\nUGX	Ugandan Shilling\nUSD	United States Dollar\nUYU	Uruguayan Peso\nUZS	Uzbekistan Som\nVEF	Venezuelan Bolivar\nVND	Vietnamese Dong\nVUV	Vanuatu Vatu\nWST	Samoan Tala\nXAF	Central African CFA franc\nXCD	East Caribbean Dollar\nXOF	West African CFA franc\nXPF	CFP Franc\nYER	Yemeni Rial\nZAR	South African Rand\nZMW	Zambian Kwacha\n"





def      _a		(lowercase__ :      str = "USD"       ,      lowercase__ :      str = "INR"       ,      lowercase__ :      float = 1.0       ,      lowercase__ :      str = ""	) -> str:






     """simple docstring"""
     __snake_case    			=	locals()
     # from is a reserved keyword
     __snake_case    			=	params.pop('from_'	)
     __snake_case    			=	requests.get(lowercase__       ,      params=lowercase__	).json()
     return str(res['amount']	) if res["error"] == 0 else res["error_message"]


if __name__ == "__main__":
       _a      :      str       				=      os.getenv("CI", "")
       _a      :      Dict       				=      os.getenv("AMDOREN_API_KEY", "")

       if not API_KEY and not TESTING:
              raise KeyError(
                  "API key must be provided in the 'AMDOREN_API_KEY' environment variable."
              )

       print(
           convert_currency(
               input("Enter from currency: ").strip(),
               input("Enter to currency: ").strip(),
               float(input("Enter the amount: ").strip()),
               API_KEY,
           )
       )




