KubraBashir commited on
Commit
aa663df
·
verified ·
1 Parent(s): 4fe526b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -26
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import streamlit as st
2
  import requests
3
 
4
- # Function to fetch the exchange rate 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,32 +14,63 @@ def get_exchange_rates_to_pkr():
14
  return {}
15
 
16
  def main():
17
- st.title("Currency to PKR Converter")
18
- st.write("Convert amounts in multiple currencies to Pakistani Rupees (PKR).")
19
-
20
- # Input Section
21
- available_currencies = ["USD", "EUR", "GBP", "AED", "SAR", "KWD", "TRY"]
22
- selected_currencies = st.multiselect("Select the currencies:", available_currencies)
23
- amounts = {}
24
-
25
- for currency in selected_currencies:
26
- amounts[currency] = st.number_input(f"Enter the amount in {currency}:", min_value=0.0, format="%.2f")
27
-
28
- # Convert Button
29
- if st.button("Convert to PKR"):
30
- rates = get_exchange_rates_to_pkr()
31
- if rates:
32
- total_pkr = 0
33
- for currency, amount in amounts.items():
34
- if currency in rates:
35
- converted = amount / rates[currency]
36
- total_pkr += converted
37
- st.success(f"{amount:.2f} {currency} = {converted:.2f} PKR")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  else:
39
- st.warning(f"Exchange rate for {currency} is not available.")
40
- st.write(f"### Total in PKR: {total_pkr:.2f}")
41
- else:
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()