Download app.py from ZETAIB/test: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/spaces/ZETAIB/test/resolve/main/app.py
- Command line
-
hf download hf://spaces/ZETAIB/test/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ZETAIB/test/resolve/main/app.py
1.87 kB
| import gradio as gr | |
| import requests | |
| # Function to make the API call | |
| def get_exchange_rate(source, target, amount=1): | |
| headers = { | |
| 'accept': '*/*', | |
| 'accept-language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7', | |
| 'authorization': 'Basic OGNhN2FlMjUtOTNjNS00MmFlLThhYjQtMzlkZTFlOTQzZDEwOjliN2UzNmZkLWRjYjgtNDEwZS1hYzc3LTQ5NGRmYmEyZGJjZA==', | |
| 'content-type': 'application/json', | |
| 'origin': 'https://wise.com', | |
| 'priority': 'u=1, i', | |
| 'referer': 'https://wise.com/', | |
| 'sec-ch-ua': '"Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"', | |
| 'sec-ch-ua-mobile': '?0', | |
| 'sec-ch-ua-platform': '"Linux"', | |
| 'sec-fetch-dest': 'empty', | |
| 'sec-fetch-mode': 'cors', | |
| 'sec-fetch-site': 'same-site', | |
| 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36', | |
| } | |
| params = { | |
| 'source': source.upper(), # Convert to uppercase | |
| 'target': target.upper(), # Convert to uppercase | |
| } | |
| response = requests.get('https://api.wise.com/v1/rates', params=params, headers=headers) | |
| if response.status_code == 200: | |
| data = response.json() | |
| if data: | |
| d= data[0] | |
| d['amount'] = amount | |
| d['amount converted'] = d['amount'] * d['rate'] | |
| return d | |
| else: | |
| return {'error': 'No data found'} | |
| else: | |
| return {'error': 'Failed to fetch data'} | |
| # Gradio interface | |
| iface = gr.Interface( | |
| fn=get_exchange_rate, | |
| inputs=[gr.Textbox(label="Source Currency", value="EUR"), | |
| gr.Textbox(label="Target Currency", value="MAD"), | |
| gr.Number(label="Amount", value=1)], | |
| outputs="json", | |
| title="Currency Exchange Rate", | |
| description="Get the exchange rate using the Wise API." | |
| ) | |
| iface.launch() |