Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# Function to fetch exchange rates
|
5 |
+
def get_exchange_rates():
|
6 |
+
try:
|
7 |
+
response = requests.get('https://api.frankfurter.app/latest')
|
8 |
+
data = response.json()
|
9 |
+
return data['rates']
|
10 |
+
except Exception as e:
|
11 |
+
st.error(f"Error fetching exchange rates: {e}")
|
12 |
+
return None
|
13 |
+
|
14 |
+
# Dictionary of 50 currencies with symbols
|
15 |
+
currencies = {
|
16 |
+
'USD': 'US Dollar ($)', 'EUR': 'Euro (€)', 'GBP': 'British Pound (£)', 'JPY': 'Japanese Yen (¥)',
|
17 |
+
'AUD': 'Australian Dollar (A$)', 'CAD': 'Canadian Dollar (C$)', 'CHF': 'Swiss Franc (CHF)',
|
18 |
+
'CNY': 'Chinese Yuan (¥)', 'SEK': 'Swedish Krona (kr)', 'NZD': 'New Zealand Dollar (NZ$)',
|
19 |
+
'MXN': 'Mexican Peso (Mex$)', 'SGD': 'Singapore Dollar (S$)', 'HKD': 'Hong Kong Dollar (HK$)',
|
20 |
+
'NOK': 'Norwegian Krone (kr)', 'KRW': 'South Korean Won (₩)', 'TRY': 'Turkish Lira (₺)',
|
21 |
+
'INR': 'Indian Rupee (₹)', 'RUB': 'Russian Ruble (₽)', 'BRL': 'Brazilian Real (R$)',
|
22 |
+
'ZAR': 'South African Rand (R)', 'PLN': 'Polish Złoty (zł)', 'PHP': 'Philippine Peso (₱)',
|
23 |
+
'IDR': 'Indonesian Rupiah (Rp)', 'MYR': 'Malaysian Ringgit (RM)', 'THB': 'Thai Baht (฿)',
|
24 |
+
'HUF': 'Hungarian Forint (Ft)', 'CZK': 'Czech Koruna (Kč)', 'ILS': 'Israeli Shekel (₪)',
|
25 |
+
'PKR': 'Pakistani Rupee (Rs)', 'AED': 'UAE Dirham (د.إ)', 'SAR': 'Saudi Riyal (﷼)',
|
26 |
+
'EGP': 'Egyptian Pound (E£)', 'BDT': 'Bangladeshi Taka (৳)', 'LKR': 'Sri Lankan Rupee (Rs)',
|
27 |
+
'VND': 'Vietnamese Dong (₫)', 'COP': 'Colombian Peso (Col$)', 'ARS': 'Argentine Peso (AR$)',
|
28 |
+
'NGN': 'Nigerian Naira (₦)', 'KES': 'Kenyan Shilling (KSh)', 'GHS': 'Ghanaian Cedi (GH₵)',
|
29 |
+
'RON': 'Romanian Leu (lei)', 'DZD': 'Algerian Dinar (دج)', 'QAR': 'Qatari Riyal (ر.ق)',
|
30 |
+
'BHD': 'Bahraini Dinar (BD)', 'OMR': 'Omani Rial (ر.ع.)', 'KWD': 'Kuwaiti Dinar (KD)',
|
31 |
+
'JOD': 'Jordanian Dinar (JD)', 'MAD': 'Moroccan Dirham (د.م.)', 'TWD': 'New Taiwan Dollar (NT$)'
|
32 |
+
}
|
33 |
+
|
34 |
+
st.title("🌍 Currency Converter 💰")
|
35 |
+
|
36 |
+
# Get exchange rates
|
37 |
+
exchange_rates = get_exchange_rates()
|
38 |
+
|
39 |
+
if exchange_rates:
|
40 |
+
# Sidebar
|
41 |
+
st.sidebar.header("Currency Conversion Settings")
|
42 |
+
|
43 |
+
# Amount input
|
44 |
+
amount = st.sidebar.number_input("Enter amount:", min_value=0.01, value=1.0, format="%.2f")
|
45 |
+
|
46 |
+
# Select currencies
|
47 |
+
from_currency = st.sidebar.selectbox("From Currency:", list(currencies.keys()), format_func=lambda x: f"{x} - {currencies[x]}")
|
48 |
+
to_currency = st.sidebar.selectbox("To Currency:", list(currencies.keys()), format_func=lambda x: f"{x} - {currencies[x]}")
|
49 |
+
|
50 |
+
# Convert currency
|
51 |
+
if from_currency == "EUR":
|
52 |
+
base_amount = amount
|
53 |
+
else:
|
54 |
+
base_amount = amount / exchange_rates[from_currency]
|
55 |
+
|
56 |
+
converted_amount = base_amount * exchange_rates[to_currency]
|
57 |
+
|
58 |
+
# Display result
|
59 |
+
st.success(f"💱 {amount} {currencies[from_currency]} = {converted_amount:.2f} {currencies[to_currency]}")
|
60 |
+
else:
|
61 |
+
st.error("Unable to fetch exchange rates. Please try again later.")
|