Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
|
4 |
-
# Function to fetch
|
5 |
def get_exchange_rates_to_pkr():
|
6 |
try:
|
7 |
url = "https://api.exchangerate-api.com/v4/latest/PKR"
|
@@ -14,32 +14,63 @@ def get_exchange_rates_to_pkr():
|
|
14 |
return {}
|
15 |
|
16 |
def main():
|
17 |
-
|
18 |
-
st.
|
19 |
-
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
else:
|
39 |
-
st.warning(f"Exchange rate for {
|
40 |
-
|
41 |
-
|
42 |
-
st.error("Failed to fetch exchange rates. Please try again later.")
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
|
4 |
+
# Function to fetch exchange rates for multiple currencies to PKR
|
5 |
def get_exchange_rates_to_pkr():
|
6 |
try:
|
7 |
url = "https://api.exchangerate-api.com/v4/latest/PKR"
|
|
|
14 |
return {}
|
15 |
|
16 |
def main():
|
17 |
+
# App title and icon
|
18 |
+
st.set_page_config(page_title="Currency to PKR Converter", page_icon="💰")
|
19 |
+
|
20 |
+
# Background styling
|
21 |
+
st.markdown(
|
22 |
+
"""
|
23 |
+
<style>
|
24 |
+
body {
|
25 |
+
background-color: #f5f5f5;
|
26 |
+
font-family: Arial, sans-serif;
|
27 |
+
}
|
28 |
+
.stApp {
|
29 |
+
background-color: #e0f7fa;
|
30 |
+
border-radius: 10px;
|
31 |
+
padding: 20px;
|
32 |
+
}
|
33 |
+
</style>
|
34 |
+
""",
|
35 |
+
unsafe_allow_html=True,
|
36 |
+
)
|
37 |
+
|
38 |
+
st.title("💰 Currency to PKR Converter")
|
39 |
+
st.write("Convert amounts from multiple currencies to Pakistani Rupees (PKR).")
|
40 |
+
|
41 |
+
# Currencies with country names
|
42 |
+
currencies = {
|
43 |
+
"USD": "United States Dollar",
|
44 |
+
"EUR": "Euro (European Union)",
|
45 |
+
"GBP": "British Pound Sterling",
|
46 |
+
"AED": "United Arab Emirates Dirham",
|
47 |
+
"SAR": "Saudi Riyal",
|
48 |
+
"KWD": "Kuwaiti Dinar",
|
49 |
+
"TRY": "Turkish Lira",
|
50 |
+
"JPY": "Japanese Yen",
|
51 |
+
"AUD": "Australian Dollar",
|
52 |
+
"CAD": "Canadian Dollar",
|
53 |
+
"CNY": "Chinese Yuan",
|
54 |
+
"INR": "Indian Rupee",
|
55 |
+
"CHF": "Swiss Franc",
|
56 |
+
"SEK": "Swedish Krona",
|
57 |
+
}
|
58 |
+
|
59 |
+
# Fetch exchange rates
|
60 |
+
rates = get_exchange_rates_to_pkr()
|
61 |
+
|
62 |
+
if rates:
|
63 |
+
# Input fields for each currency
|
64 |
+
for code, name in currencies.items():
|
65 |
+
amount = st.number_input(f"Enter the amount in {name} ({code}):", min_value=0.0, format="%.2f")
|
66 |
+
if amount > 0:
|
67 |
+
if code in rates:
|
68 |
+
converted = amount / rates[code]
|
69 |
+
st.success(f"{amount:.2f} {code} ({name}) = {converted:.2f} PKR")
|
70 |
else:
|
71 |
+
st.warning(f"Exchange rate for {code} ({name}) is not available.")
|
72 |
+
else:
|
73 |
+
st.error("Failed to load exchange rates. Please refresh or try again later.")
|
|
|
74 |
|
75 |
if __name__ == "__main__":
|
76 |
main()
|