Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Title of the app
|
4 |
+
st.title("🌍 Currency Converter App")
|
5 |
+
|
6 |
+
# Static exchange rates (base currency: USD)
|
7 |
+
# Note: These rates are for demonstration purposes only and may not reflect real-world values.
|
8 |
+
exchange_rates = {
|
9 |
+
"PKR": 279.50, # Pakistani Rupee
|
10 |
+
"USD": 1.0, # US Dollar
|
11 |
+
"CNY": 7.20, # Chinese Yuan
|
12 |
+
"INR": 83.00, # Indian Rupee
|
13 |
+
"RUB": 92.00, # Russian Ruble
|
14 |
+
"JPY": 149.00, # Japanese Yen
|
15 |
+
"EUR": 0.93, # Euro (Germany, France, Italy, etc.)
|
16 |
+
"GBP": 0.80, # British Pound
|
17 |
+
"BRL": 5.00, # Brazilian Real
|
18 |
+
"CAD": 1.35, # Canadian Dollar
|
19 |
+
"AUD": 1.55, # Australian Dollar
|
20 |
+
"KRW": 1300.00, # South Korean Won
|
21 |
+
"MXN": 18.00, # Mexican Peso
|
22 |
+
"IDR": 15500.00,# Indonesian Rupiah
|
23 |
+
"TRY": 30.00, # Turkish Lira
|
24 |
+
"SAR": 3.75, # Saudi Riyal
|
25 |
+
"CHF": 0.90, # Swiss Franc
|
26 |
+
"ARS": 800.00, # Argentine Peso
|
27 |
+
"ZAR": 19.00, # South African Rand
|
28 |
+
"EGP": 30.00, # Egyptian Pound
|
29 |
+
"THB": 36.00, # Thai Baht
|
30 |
+
"SEK": 10.50, # Swedish Krona
|
31 |
+
"NOK": 10.00, # Norwegian Krone
|
32 |
+
"PLN": 4.20, # Polish Złoty
|
33 |
+
"MYR": 4.70, # Malaysian Ringgit
|
34 |
+
"SGD": 1.35, # Singapore Dollar
|
35 |
+
"PHP": 56.00, # Philippine Peso
|
36 |
+
"VND": 24000.00,# Vietnamese Dong
|
37 |
+
"DKK": 6.90, # Danish Krone
|
38 |
+
"IRR": 42000.00,# Iranian Rial
|
39 |
+
"IQD": 1300.00, # Iraqi Dinar
|
40 |
+
"ILS": 3.90, # Israeli Shekel
|
41 |
+
"AED": 3.67, # UAE Dirham
|
42 |
+
"NGN": 900.00, # Nigerian Naira
|
43 |
+
"KES": 150.00, # Kenyan Shilling
|
44 |
+
"COP": 4000.00, # Colombian Peso
|
45 |
+
"CLP": 900.00, # Chilean Peso
|
46 |
+
"PEN": 3.80, # Peruvian Sol
|
47 |
+
"NZD": 1.65, # New Zealand Dollar
|
48 |
+
"BDT": 110.00, # Bangladeshi Taka
|
49 |
+
"LKR": 320.00, # Sri Lankan Rupee
|
50 |
+
"NPR": 130.00, # Nepalese Rupee
|
51 |
+
"AFN": 85.00, # Afghan Afghani
|
52 |
+
"QAR": 3.64, # Qatari Riyal
|
53 |
+
}
|
54 |
+
|
55 |
+
# List of countries and their currency codes
|
56 |
+
country_currencies = {
|
57 |
+
"Pakistan": "PKR",
|
58 |
+
"United States": "USD",
|
59 |
+
"China": "CNY",
|
60 |
+
"India": "INR",
|
61 |
+
"Russia": "RUB",
|
62 |
+
"Japan": "JPY",
|
63 |
+
"Germany": "EUR",
|
64 |
+
"United Kingdom": "GBP",
|
65 |
+
"France": "EUR",
|
66 |
+
"Brazil": "BRL",
|
67 |
+
"Canada": "CAD",
|
68 |
+
"Australia": "AUD",
|
69 |
+
"Italy": "EUR",
|
70 |
+
"South Korea": "KRW",
|
71 |
+
"Spain": "EUR",
|
72 |
+
"Mexico": "MXN",
|
73 |
+
"Indonesia": "IDR",
|
74 |
+
"Turkey": "TRY",
|
75 |
+
"Saudi Arabia": "SAR",
|
76 |
+
"Switzerland": "CHF",
|
77 |
+
"Netherlands": "EUR",
|
78 |
+
"Argentina": "ARS",
|
79 |
+
"South Africa": "ZAR",
|
80 |
+
"Egypt": "EGP",
|
81 |
+
"Thailand": "THB",
|
82 |
+
"Sweden": "SEK",
|
83 |
+
"Norway": "NOK",
|
84 |
+
"Poland": "PLN",
|
85 |
+
"Malaysia": "MYR",
|
86 |
+
"Singapore": "SGD",
|
87 |
+
"Philippines": "PHP",
|
88 |
+
"Vietnam": "VND",
|
89 |
+
"Greece": "EUR",
|
90 |
+
"Portugal": "EUR",
|
91 |
+
"Denmark": "DKK",
|
92 |
+
"Iran": "IRR",
|
93 |
+
"Iraq": "IQD",
|
94 |
+
"Israel": "ILS",
|
95 |
+
"UAE (United Arab Emirates)": "AED",
|
96 |
+
"Nigeria": "NGN",
|
97 |
+
"Kenya": "KES",
|
98 |
+
"Colombia": "COP",
|
99 |
+
"Chile": "CLP",
|
100 |
+
"Peru": "PEN",
|
101 |
+
"New Zealand": "NZD",
|
102 |
+
"Bangladesh": "BDT",
|
103 |
+
"Sri Lanka": "LKR",
|
104 |
+
"Nepal": "NPR",
|
105 |
+
"Afghanistan": "AFN",
|
106 |
+
"Qatar": "QAR",
|
107 |
+
}
|
108 |
+
|
109 |
+
# Function to convert currency
|
110 |
+
def convert_currency(amount, from_currency, to_currency):
|
111 |
+
if from_currency == to_currency:
|
112 |
+
return amount
|
113 |
+
# Convert to USD first, then to the target currency
|
114 |
+
amount_in_usd = amount / exchange_rates[from_currency]
|
115 |
+
converted_amount = amount_in_usd * exchange_rates[to_currency]
|
116 |
+
return converted_amount
|
117 |
+
|
118 |
+
# Streamlit UI
|
119 |
+
st.write("### Select Currencies and Amount")
|
120 |
+
|
121 |
+
# Dropdown for selecting source and target currencies
|
122 |
+
from_currency = st.selectbox("From Currency", list(country_currencies.values()), key="from_currency")
|
123 |
+
to_currency = st.selectbox("To Currency", list(country_currencies.values()), key="to_currency")
|
124 |
+
|
125 |
+
# Input for amount
|
126 |
+
amount = st.number_input("Amount", min_value=0.01, value=1.00, step=0.01)
|
127 |
+
|
128 |
+
# Convert button
|
129 |
+
if st.button("Convert"):
|
130 |
+
converted_amount = convert_currency(amount, from_currency, to_currency)
|
131 |
+
st.success(f"**{amount} {from_currency} = {converted_amount:.2f} {to_currency}**")
|
132 |
+
|
133 |
+
# Footer
|
134 |
+
st.write("---")
|
135 |
+
st.write("**Note:** Exchange rates are static and for demonstration purposes only.")
|