zetaah commited on
Commit
d41f1b8
·
verified ·
1 Parent(s): c582cb0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # Function to make the API call
5
+ def get_exchange_rate(source, target, amount=1):
6
+ headers = {
7
+ 'accept': '*/*',
8
+ 'accept-language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
9
+ 'authorization': 'Basic OGNhN2FlMjUtOTNjNS00MmFlLThhYjQtMzlkZTFlOTQzZDEwOjliN2UzNmZkLWRjYjgtNDEwZS1hYzc3LTQ5NGRmYmEyZGJjZA==',
10
+ 'content-type': 'application/json',
11
+ 'origin': 'https://wise.com',
12
+ 'priority': 'u=1, i',
13
+ 'referer': 'https://wise.com/',
14
+ 'sec-ch-ua': '"Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
15
+ 'sec-ch-ua-mobile': '?0',
16
+ 'sec-ch-ua-platform': '"Linux"',
17
+ 'sec-fetch-dest': 'empty',
18
+ 'sec-fetch-mode': 'cors',
19
+ 'sec-fetch-site': 'same-site',
20
+ 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
21
+ }
22
+
23
+ params = {
24
+ 'source': source.upper(), # Convert to uppercase
25
+ 'target': target.upper(), # Convert to uppercase
26
+ }
27
+
28
+ response = requests.get('https://api.wise.com/v1/rates', params=params, headers=headers)
29
+
30
+ if response.status_code == 200:
31
+ data = response.json()
32
+ if data:
33
+ d= data[0]
34
+ d['amount'] = amount
35
+ d['amount converted'] = d['amount'] * d['rate']
36
+ return d
37
+ else:
38
+ return {'error': 'No data found'}
39
+ else:
40
+ return {'error': 'Failed to fetch data'}
41
+
42
+ # Gradio interface
43
+ iface = gr.Interface(
44
+ fn=get_exchange_rate,
45
+ inputs=[gr.Textbox(label="Source Currency", value="EUR"),
46
+ gr.Textbox(label="Target Currency", value="MAD"),
47
+ gr.Number(label="Amount", value=1)],
48
+ outputs="json",
49
+ title="Currency Exchange Rate",
50
+ description="Get the exchange rate using the Wise API."
51
+ )
52
+
53
+ iface.launch(share=True)