File size: 1,866 Bytes
d41f1b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232e364
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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()