Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,45 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from forex_python.converter import CurrencyRates, CurrencyCodes
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
except Exception as e:
|
| 24 |
-
st.error(f"Error: {e}")
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
+
# Set up the app's layout
|
| 4 |
+
st.set_page_config(page_title="Currency Exchange Calculator", layout="wide")
|
| 5 |
+
st.title("🌍💱 Currency Exchange Calculator")
|
| 6 |
|
| 7 |
+
# Sidebar
|
| 8 |
+
st.sidebar.title("About the App")
|
| 9 |
+
st.sidebar.info("This simple currency converter allows you to exchange between commonly used currencies using predefined exchange rates.")
|
| 10 |
|
| 11 |
+
# Latest hardcoded exchange rates (example rates, replace with the latest you know)
|
| 12 |
+
exchange_rates = {
|
| 13 |
+
"USD": 1.0, # Base currency
|
| 14 |
+
"EUR": 0.91,
|
| 15 |
+
"GBP": 0.78,
|
| 16 |
+
"PKR": 277.5,
|
| 17 |
+
"INR": 83.2,
|
| 18 |
+
"JPY": 141.8,
|
| 19 |
+
"RMB": 7.2,
|
| 20 |
+
}
|
| 21 |
|
| 22 |
+
# Main layout with two columns
|
| 23 |
+
col1, col2 = st.columns(2)
|
| 24 |
|
| 25 |
+
with col1:
|
| 26 |
+
# User inputs for currency conversion
|
| 27 |
+
st.subheader("Input")
|
| 28 |
+
from_currency = st.selectbox("From Currency", options=exchange_rates.keys(), index=0)
|
| 29 |
+
to_currency = st.selectbox("To Currency", options=exchange_rates.keys(), index=1)
|
| 30 |
+
amount = st.number_input("Amount to Convert", min_value=0.0, value=1.0, step=0.01)
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
with col2:
|
| 33 |
+
# Perform conversion
|
| 34 |
+
st.subheader("Result")
|
| 35 |
+
if st.button("Convert"):
|
| 36 |
+
try:
|
| 37 |
+
# Conversion logic
|
| 38 |
+
converted_amount = amount * (exchange_rates[to_currency] / exchange_rates[from_currency])
|
| 39 |
+
st.success(f"{amount} {from_currency} = {converted_amount:,.2f} {to_currency}")
|
| 40 |
+
except Exception as e:
|
| 41 |
+
st.error(f"An error occurred: {e}")
|
| 42 |
+
|
| 43 |
+
# Footer
|
| 44 |
+
st.sidebar.markdown("---")
|
| 45 |
+
st.sidebar.markdown("**Exchange rates are static and need to be updated manually.**")
|