RathodHarish commited on
Commit
6a3054b
·
verified ·
1 Parent(s): 71903f7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ API_KEY = "your_api_key"
5
+ BASE_URL = f"https://v6.exchangerate-api.com/v6/{API_KEY}/pair"
6
+
7
+ def convert_currency(amount, from_currency, to_currency):
8
+ url = f"{BASE_URL}/{from_currency}/{to_currency}"
9
+ response = requests.get(url).json()
10
+ rate = response.get("conversion_rate", 1)
11
+ return round(amount * rate, 2)
12
+
13
+ iface = gr.Interface(
14
+ fn=convert_currency,
15
+ inputs=[
16
+ gr.Number(label="Amount"),
17
+ gr.Textbox(label="From Currency (e.g., USD)"),
18
+ gr.Textbox(label="To Currency (e.g., EUR)")
19
+ ],
20
+ outputs="number",
21
+ title="Currency Converter"
22
+ )
23
+
24
+ iface.launch()