Engineer786 commited on
Commit
b283839
·
verified ·
1 Parent(s): ebdc8ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -25
app.py CHANGED
@@ -1,22 +1,21 @@
1
  import streamlit as st
2
- import requests
3
 
4
- # Replace 'YOUR_API_KEY' with your actual API key
5
- API_KEY = 'YOUR_API_KEY'
6
- API_URL = f"https://api.exchangerate.host/latest?access_key={API_KEY}"
 
 
 
 
 
7
 
8
- def get_conversion_rate(from_currency, to_currency):
9
- response = requests.get(API_URL, params={"base": from_currency, "symbols": to_currency})
10
- if response.status_code == 200:
11
- data = response.json()
12
- return data["rates"][to_currency]
13
  else:
14
- raise ValueError(f"API request failed with status code: {response.status_code}")
15
 
16
- st.title("Real-time Currency Converter")
17
-
18
- # Supported currencies, including PKR
19
- supported_currencies = ["USD", "EUR", "GBP", "JPY", "PKR"]
20
 
21
  # User input for amount and currencies
22
  with st.container():
@@ -24,19 +23,14 @@ with st.container():
24
  with col1:
25
  amount = st.number_input("Enter amount:", min_value=0.01, step=0.01)
26
  with col2:
27
- from_currency = st.selectbox("From Currency:", options=supported_currencies)
28
- to_currency = st.selectbox("To Currency:", options=supported_currencies)
29
 
30
  # Button to trigger conversion
31
  if st.button("Convert"):
32
- try:
33
- conversion_rate = get_conversion_rate(from_currency, to_currency)
34
- converted_amount = amount * conversion_rate
35
- st.success(f"{amount} {from_currency} is equal to {converted_amount:.2f} {to_currency}")
36
- except ValueError as e:
37
- st.error(f"Error: {e}")
38
 
39
- # Add some visual appeal
40
  st.markdown("---")
41
- st.write("**Note:** Currency conversion rates are updated in real-time.")
42
- st.write("**Disclaimer:** While we strive to provide accurate and up-to-date exchange rates, please note that exchange rates can fluctuate rapidly. It's always advisable to verify the exact rates with your financial institution or a reliable currency exchange service.")
 
1
  import streamlit as st
 
2
 
3
+ # Static exchange rates (approximate)
4
+ exchange_rates = {
5
+ "USD": 1,
6
+ "EUR": 0.9,
7
+ "GBP": 0.8,
8
+ "JPY": 140,
9
+ "PKR": 300
10
+ }
11
 
12
+ def convert_currency(amount, from_currency, to_currency):
13
+ if from_currency == to_currency:
14
+ return amount
 
 
15
  else:
16
+ return amount * (exchange_rates[to_currency] / exchange_rates[from_currency])
17
 
18
+ st.title("Currency Converter")
 
 
 
19
 
20
  # User input for amount and currencies
21
  with st.container():
 
23
  with col1:
24
  amount = st.number_input("Enter amount:", min_value=0.01, step=0.01)
25
  with col2:
26
+ from_currency = st.selectbox("From Currency:", options=exchange_rates.keys())
27
+ to_currency = st.selectbox("To Currency:", options=exchange_rates.keys())
28
 
29
  # Button to trigger conversion
30
  if st.button("Convert"):
31
+ converted_amount = convert_currency(amount, from_currency, to_currency)
32
+ st.success(f"{amount} {from_currency} is equal to {converted_amount:.2f} {to_currency}")
 
 
 
 
33
 
34
+ # Add a disclaimer about the limitations of static exchange rates
35
  st.markdown("---")
36
+ st.write("**Note:** This converter uses static exchange rates. For accurate and real-time conversions, please use a service that accesses live exchange rates.")