
"""simple docstring"""

import os

import requests

_A				=					'https://www.amdoren.com/api/currency.php'


# Currency and their description
_A				=					'\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 						UpperCAmelCase   (						a_ = "USD",		a_ = "INR",		a_ = 1.0,		a_ = ""     ):





		'''simple docstring'''


		lowerCamelCase	:     List[str]            =       locals()
		# from is a reserved keyword
		lowerCamelCase	:     str            =       params.pop('from_'     )
		lowerCamelCase	:     Tuple            =       requests.get(a_,		params=a_     ).json()
		return str(res['amount']     ) if res["error"] == 0 else res["error_message"]


if __name__ == "__main__":
					_A				=					os.getenv('CI', '')
					_A				=					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,
					    )
					)








"""simple docstring"""

import collections
import types

import numpy as np

from ..utils import (
    add_end_docstrings,
    is_tensorflow_probability_available,
    is_tf_available,
    is_torch_available,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, ArgumentHandler, Dataset, Pipeline, PipelineException


if is_torch_available():
					import torch

					from ..models.auto.modeling_auto import (
					    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
					    MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
					)

if is_tf_available() and is_tensorflow_probability_available():
					import tensorflow as tf
					import tensorflow_probability as tfp

					from ..models.auto.modeling_tf_auto import (
					    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
					    TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
					)






class 			_lowercase  (							__UpperCAmelCase						):




	def __call__(					self						,					UpperCAmelCase_=None						,					UpperCAmelCase_=None						,					**UpperCAmelCase_   )						->				Dict:
			# Returns tqa_pipeline_inputs of shape:
			# [
			#   {"table": pd.DataFrame, "query": List[str]},
			#   ...,
			#   {"table": pd.DataFrame, "query" : List[str]}
			# ]
			requires_backends(self						,					'pandas'   )
			import pandas as pd

			if table is None:
					raise ValueError('Keyword argument `table` cannot be None.'   )
			elif query is None:
					if isinstance(UpperCAmelCase_						,					UpperCAmelCase_   ) and table.get('query'   ) is not None and table.get('table'   ) is not None:
							lowerCamelCase	:     Any            =       [table]
					elif isinstance(UpperCAmelCase_						,					UpperCAmelCase_   ) and len(UpperCAmelCase_   ) > 0:
							if not all(isinstance(UpperCAmelCase_						,					UpperCAmelCase_   ) for d in table   ):
									raise ValueError(
									    F"""Keyword argument `table` should be a list of dict, but is {(type(UpperCAmelCase_   ) for d in table)}"""   )

							if table[0].get('query'   ) is not None and table[0].get('table'   ) is not None:
									lowerCamelCase	:     List[Any]            =       table
							else:
									raise ValueError(
									    'If keyword argument `table` is a list of dictionaries, each dictionary should have a `table`'
									    F""" and `query` key, but only dictionary has keys {table[0].keys()} `table` and `query` keys."""   )
					elif Dataset is not None and isinstance(UpperCAmelCase_						,					UpperCAmelCase_   ) or isinstance(UpperCAmelCase_						,					types.GeneratorType   ):
							return table
					else:
							raise ValueError(
							    'Invalid input. Keyword argument `table` should be either of type `dict` or `list`, but '
							    F"""is {type(UpperCAmelCase_   )})"""   )
			else:
					lowerCamelCase	:     List[str]            =       [{'table': table, 'query': query}]

			for tqa_pipeline_input in tqa_pipeline_inputs:
					if not isinstance(tqa_pipeline_input['table']						,					pd.DataFrame   ):
							if tqa_pipeline_input["table"] is None:
									raise ValueError('Table cannot be None.'   )

							lowerCamelCase	:     Optional[int]            =       pd.DataFrame(tqa_pipeline_input['table']   )

			return tqa_pipeline_inputs






@add_end_docstrings(__UpperCAmelCase						)
class 			_lowercase  (							__UpperCAmelCase						):
	lowercase_								=      'table,query'




	def __init__(					self						,					UpperCAmelCase_=TableQuestionAnsweringArgumentHandler()						,					*UpperCAmelCase_						,					**UpperCAmelCase_   )						->				int:
			super().__init__(*UpperCAmelCase_						,					**UpperCAmelCase_   )
			lowerCamelCase	:     List[str]            =       args_parser

			self.check_model_type(
			    dict(
			        TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING.items()
			        + TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()   )
			    if self.framework == 'tf'
			    else dict(
			        MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING.items() + MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()   )   )

			lowerCamelCase	:     Dict            =       bool(getattr(self.model.config						,					'aggregation_labels'						,					UpperCAmelCase_   )   ) and bool(
			    getattr(self.model.config						,					'num_aggregation_labels'						,					UpperCAmelCase_   )   )
			lowerCamelCase	:     str            =       'tapas' if hasattr(self.model.config						,					'aggregation_labels'   ) else None




	def      _UpperCamelCase       (					self						,					**UpperCAmelCase_   )						->				Any:
			return self.model(**UpperCAmelCase_   )




	def      _UpperCamelCase       (					self						,					**UpperCAmelCase_   )						->				Dict:
			if self.framework == "pt":
					lowerCamelCase	:     List[Any]            =       []
					lowerCamelCase	:     Optional[Any]            =       []
					lowerCamelCase	:     List[str]            =       None
					lowerCamelCase	:     List[str]            =       inputs['input_ids'].shape[0]

					lowerCamelCase	:     Any            =       inputs['input_ids'].to(self.device   )
					lowerCamelCase	:     Optional[Any]            =       inputs['attention_mask'].to(self.device   )
					lowerCamelCase	:     Optional[int]            =       inputs['token_type_ids'].to(self.device   )
					lowerCamelCase	:     str            =       None

					for index in range(UpperCAmelCase_   ):
							# If sequences have already been processed, the token type IDs will be created according to the previous
							# answer.
							if prev_answers is not None:
									lowerCamelCase	:     List[str]            =       token_type_ids_example[:, 3]  # shape (seq_len,)
									lowerCamelCase	:     Dict            =       np.zeros_like(prev_labels_example.cpu().numpy()   )  # shape (seq_len,)

									lowerCamelCase	:     Optional[Any]            =       token_type_ids[index]  # shape (seq_len, 7)
									for i in range(model_labels.shape[0]   ):
											lowerCamelCase	:     str            =       token_type_ids_example[:, 0].tolist()[i]
											lowerCamelCase	:     str            =       token_type_ids_example[:, 1].tolist()[i] - 1
											lowerCamelCase	:     str            =       token_type_ids_example[:, 2].tolist()[i] - 1

											if row_id >= 0 and col_id >= 0 and segment_id == 1:
													lowerCamelCase	:     List[str]            =       int(prev_answers[(col_id, row_id)]   )

									lowerCamelCase	:     Optional[int]            =       torch.from_numpy(UpperCAmelCase_   ).type(torch.long   ).to(self.device   )

							lowerCamelCase	:     List[Any]            =       input_ids[index]
							lowerCamelCase	:     Optional[int]            =       attention_mask[index]  # shape (seq_len,)
							lowerCamelCase	:     List[str]            =       token_type_ids[index]  # shape (seq_len, 7)
							lowerCamelCase	:     Tuple            =       self.model(
							    input_ids=input_ids_example.unsqueeze(0   )						,					attention_mask=attention_mask_example.unsqueeze(0   )						,					token_type_ids=token_type_ids_example.unsqueeze(0   )						,					)
							lowerCamelCase	:     str            =       outputs.logits

							if self.aggregate:
									all_aggregations.append(outputs.logits_aggregation   )

							all_logits.append(UpperCAmelCase_   )

							lowerCamelCase	:     Dict            =       torch.distributions.Bernoulli(logits=UpperCAmelCase_   )
							lowerCamelCase	:     Tuple            =       dist_per_token.probs * attention_mask_example.type(torch.floataa   ).to(
							    dist_per_token.probs.device   )

							lowerCamelCase	:     str            =       collections.defaultdict(UpperCAmelCase_   )
							for i, p in enumerate(probabilities.squeeze().tolist()   ):
									lowerCamelCase	:     Tuple            =       token_type_ids_example[:, 0].tolist()[i]
									lowerCamelCase	:     Dict            =       token_type_ids_example[:, 1].tolist()[i] - 1
									lowerCamelCase	:     List[Any]            =       token_type_ids_example[:, 2].tolist()[i] - 1
									if col >= 0 and row >= 0 and segment_id == 1:
											coords_to_probs[(col, row)].append(UpperCAmelCase_   )

							lowerCamelCase	:     List[str]            =       {key: np.array(coords_to_probs[key]   ).mean() > 0.5 for key in coords_to_probs}

					lowerCamelCase	:     int            =       torch.cat(tuple(UpperCAmelCase_   )						,					0   )

					return (logits_batch,) if not self.aggregate else (logits_batch, torch.cat(tuple(UpperCAmelCase_   )						,					0   ))
			else:
					lowerCamelCase	:     Union[str, Any]            =       []
					lowerCamelCase	:     Union[str, Any]            =       []
					lowerCamelCase	:     Union[str, Any]            =       None
					lowerCamelCase	:     str            =       inputs['input_ids'].shape[0]

					lowerCamelCase	:     List[Any]            =       inputs['input_ids']
					lowerCamelCase	:     str            =       inputs['attention_mask']
					lowerCamelCase	:     Optional[Any]            =       inputs['token_type_ids'].numpy()
					lowerCamelCase	:     Optional[Any]            =       None

					for index in range(UpperCAmelCase_   ):
							# If sequences have already been processed, the token type IDs will be created according to the previous
							# answer.
							if prev_answers is not None:
									lowerCamelCase	:     Union[str, Any]            =       token_type_ids_example[:, 3]  # shape (seq_len,)
									lowerCamelCase	:     List[Any]            =       np.zeros_like(UpperCAmelCase_						,					dtype=np.intaa   )  # shape (seq_len,)

									lowerCamelCase	:     str            =       token_type_ids[index]  # shape (seq_len, 7)
									for i in range(model_labels.shape[0]   ):
											lowerCamelCase	:     int            =       token_type_ids_example[:, 0].tolist()[i]
											lowerCamelCase	:     Optional[int]            =       token_type_ids_example[:, 1].tolist()[i] - 1
											lowerCamelCase	:     Tuple            =       token_type_ids_example[:, 2].tolist()[i] - 1

											if row_id >= 0 and col_id >= 0 and segment_id == 1:
													lowerCamelCase	:     Optional[int]            =       int(prev_answers[(col_id, row_id)]   )

									lowerCamelCase	:     Optional[int]            =       model_labels

							lowerCamelCase	:     str            =       input_ids[index]
							lowerCamelCase	:     Tuple            =       attention_mask[index]  # shape (seq_len,)
							lowerCamelCase	:     Tuple            =       token_type_ids[index]  # shape (seq_len, 7)
							lowerCamelCase	:     Union[str, Any]            =       self.model(
							    input_ids=np.expand_dims(UpperCAmelCase_						,					axis=0   )						,					attention_mask=np.expand_dims(UpperCAmelCase_						,					axis=0   )						,					token_type_ids=np.expand_dims(UpperCAmelCase_						,					axis=0   )						,					)
							lowerCamelCase	:     int            =       outputs.logits

							if self.aggregate:
									all_aggregations.append(outputs.logits_aggregation   )

							all_logits.append(UpperCAmelCase_   )

							lowerCamelCase	:     int            =       tfp.distributions.Bernoulli(logits=UpperCAmelCase_   )
							lowerCamelCase	:     Dict            =       dist_per_token.probs_parameter() * tf.cast(UpperCAmelCase_						,					tf.floataa   )

							lowerCamelCase	:     Union[str, Any]            =       collections.defaultdict(UpperCAmelCase_   )
							lowerCamelCase	:     List[str]            =       token_type_ids_example
							for i, p in enumerate(tf.squeeze(UpperCAmelCase_   ).numpy().tolist()   ):
									lowerCamelCase	:     List[str]            =       token_type_ids_example[:, 0].tolist()[i]
									lowerCamelCase	:     Optional[int]            =       token_type_ids_example[:, 1].tolist()[i] - 1
									lowerCamelCase	:     int            =       token_type_ids_example[:, 2].tolist()[i] - 1
									if col >= 0 and row >= 0 and segment_id == 1:
											coords_to_probs[(col, row)].append(UpperCAmelCase_   )

							lowerCamelCase	:     Any            =       {key: np.array(coords_to_probs[key]   ).mean() > 0.5 for key in coords_to_probs}

					lowerCamelCase	:     Union[str, Any]            =       tf.concat(tuple(UpperCAmelCase_   )						,					0   )

					return (logits_batch,) if not self.aggregate else (logits_batch, tf.concat(tuple(UpperCAmelCase_   )						,					0   ))




	def __call__(					self						,					*UpperCAmelCase_						,					**UpperCAmelCase_   )						->				Optional[int]:
			lowerCamelCase	:     Optional[Any]            =       self._args_parser(*UpperCAmelCase_						,					**UpperCAmelCase_   )

			lowerCamelCase	:     Union[str, Any]            =       super().__call__(UpperCAmelCase_						,					**UpperCAmelCase_   )
			if len(UpperCAmelCase_   ) == 1:
					return results[0]
			return results




	def      _UpperCamelCase       (					self						,					UpperCAmelCase_=None						,					UpperCAmelCase_=None						,					UpperCAmelCase_=None						,					**UpperCAmelCase_   )						->				Union[str, Any]:
			lowerCamelCase	:     List[Any]            =       {}
			if padding is not None:
					lowerCamelCase	:     Union[str, Any]            =       padding
			if truncation is not None:
					lowerCamelCase	:     Dict            =       truncation

			lowerCamelCase	:     Optional[Any]            =       {}
			if sequential is not None:
					lowerCamelCase	:     Any            =       sequential
			return preprocess_params, forward_params, {}




	def      _UpperCamelCase       (					self						,					UpperCAmelCase_						,					UpperCAmelCase_=None						,					UpperCAmelCase_=True						,					UpperCAmelCase_=None   )						->				str:
			if truncation is None:
					if self.type == "tapas":
							lowerCamelCase	:     Any            =       'drop_rows_to_fit'
					else:
							lowerCamelCase	:     str            =       'do_not_truncate'

			lowerCamelCase      ,       lowerCamelCase	:     List[str]            =       pipeline_input['table'], pipeline_input['query']
			if table.empty:
					raise ValueError('table is empty'   )
			if query is None or query == "":
					raise ValueError('query is empty'   )
			lowerCamelCase	:     Union[str, Any]            =       self.tokenizer(UpperCAmelCase_						,					UpperCAmelCase_						,					return_tensors=self.framework						,					truncation=UpperCAmelCase_						,					padding=UpperCAmelCase_   )
			lowerCamelCase	:     int            =       table
			return inputs




	def      _UpperCamelCase       (					self						,					UpperCAmelCase_						,					UpperCAmelCase_=False   )						->				Optional[Any]:
			lowerCamelCase	:     Optional[Any]            =       model_inputs.pop('table'   )

			if self.type == "tapas":
					if sequential:
							lowerCamelCase	:     List[Any]            =       self.sequential_inference(**UpperCAmelCase_   )
					else:
							lowerCamelCase	:     int            =       self.batch_inference(**UpperCAmelCase_   )
			else:
					lowerCamelCase	:     Tuple            =       self.model.generate(**UpperCAmelCase_   )
			lowerCamelCase	:     Union[str, Any]            =       {'model_inputs': model_inputs, 'table': table, 'outputs': outputs}
			return model_outputs




	def      _UpperCamelCase       (					self						,					UpperCAmelCase_   )						->				str:
			lowerCamelCase	:     str            =       model_outputs['model_inputs']
			lowerCamelCase	:     int            =       model_outputs['table']
			lowerCamelCase	:     Optional[Any]            =       model_outputs['outputs']
			if self.type == "tapas":
					if self.aggregate:
							lowerCamelCase      ,       lowerCamelCase	:     Optional[int]            =       outputs[:2]
							lowerCamelCase	:     List[str]            =       self.tokenizer.convert_logits_to_predictions(UpperCAmelCase_						,					UpperCAmelCase_						,					UpperCAmelCase_   )
							lowerCamelCase      ,       lowerCamelCase	:     Union[str, Any]            =       predictions
							lowerCamelCase	:     Dict            =       {i: self.model.config.aggregation_labels[pred] for i, pred in enumerate(UpperCAmelCase_   )}

							lowerCamelCase	:     Union[str, Any]            =       self.model.config.no_aggregation_label_index
							lowerCamelCase	:     int            =       {
							    i: aggregators[i] + ' > ' for i, pred in enumerate(UpperCAmelCase_   ) if pred != no_agg_label_index
							}
					else:
							lowerCamelCase	:     int            =       outputs[0]
							lowerCamelCase	:     Any            =       self.tokenizer.convert_logits_to_predictions(UpperCAmelCase_						,					UpperCAmelCase_   )
							lowerCamelCase	:     List[str]            =       predictions[0]
							lowerCamelCase	:     Optional[int]            =       {}
							lowerCamelCase	:     List[str]            =       {}
					lowerCamelCase	:     Any            =       []
					for index, coordinates in enumerate(UpperCAmelCase_   ):
							lowerCamelCase	:     Optional[int]            =       [table.iat[coordinate] for coordinate in coordinates]
							lowerCamelCase	:     Dict            =       aggregators.get(UpperCAmelCase_						,					''   )
							lowerCamelCase	:     Optional[Any]            =       aggregators_prefix.get(UpperCAmelCase_						,					''   )
							lowerCamelCase	:     int            =       {
							    'answer': aggregator_prefix + ', '.join(UpperCAmelCase_   ),
							    'coordinates': coordinates,
							    'cells': [table.iat[coordinate] for coordinate in coordinates],
							}
							if aggregator:
									lowerCamelCase	:     Optional[Any]            =       aggregator

							answers.append(UpperCAmelCase_   )
					if len(UpperCAmelCase_   ) == 0:
							raise PipelineException('Empty answer'   )
			else:
					lowerCamelCase	:     List[Any]            =       [{'answer': answer} for answer in self.tokenizer.batch_decode(UpperCAmelCase_						,					skip_special_tokens=UpperCAmelCase_   )]

			return answers if len(UpperCAmelCase_   ) > 1 else answers[0]






