Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,21 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import requests
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
data = response.json()
|
| 12 |
-
return data["rates"][to_currency]
|
| 13 |
else:
|
| 14 |
-
|
| 15 |
|
| 16 |
-
st.title("
|
| 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=
|
| 28 |
-
to_currency = st.selectbox("To Currency:", options=
|
| 29 |
|
| 30 |
# Button to trigger conversion
|
| 31 |
if st.button("Convert"):
|
| 32 |
-
|
| 33 |
-
|
| 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
|
| 40 |
st.markdown("---")
|
| 41 |
-
st.write("**Note:**
|
| 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.")
|
|
|