bhagwandas's picture
Update app.py
6ad158b verified
# app.py
import streamlit as st
# Set page configuration
st.set_page_config(
page_title='πŸ’΅ Currency Converter',
page_icon='πŸ’±',
layout='centered'
)
# App Header
st.markdown(
"""
<h1 style='text-align: center; color: #4CAF50;'>πŸ’΅ Currency Converter</h1>
<p style='text-align: center; color: #555;'>Easily convert currencies offline with predefined rates</p>
""",
unsafe_allow_html=True
)
# Predefined Exchange Rates (Static Data)
EXCHANGE_RATES = {
"USD": {"EUR": 0.85, "GBP": 0.75, "PKR": 280.0},
"EUR": {"USD": 1.18, "GBP": 0.88, "PKR": 330.0},
"GBP": {"USD": 1.33, "EUR": 1.14, "PKR": 380.0},
"PKR": {"USD": 0.0036, "EUR": 0.0030, "GBP": 0.0026}
}
# Currency Selection
col1, col2 = st.columns(2)
with col1:
from_currency = st.selectbox('πŸ”„ Select Base Currency:', list(EXCHANGE_RATES.keys()))
with col2:
to_currency = st.selectbox('πŸ”„ Select Target Currency:', list(EXCHANGE_RATES.keys()))
# Amount Input
amount = st.number_input('πŸ’° Enter Amount:', min_value=0.0, format='%.2f')
# Convert Button
if st.button('πŸ”„ Convert'):
if from_currency == to_currency:
st.warning("⚠️ Base and target currencies are the same. Please select different currencies.")
else:
try:
rate = EXCHANGE_RATES[from_currency][to_currency]
result = amount * rate
st.success(f'βœ… {amount} {from_currency} = {result:.2f} {to_currency}')
except KeyError:
st.error("❌ Conversion rate not available for selected currencies.")
# Footer
st.markdown(
"""
<hr>
<p style='text-align: center;'>πŸ’» <b>Developed by ChatGPT</b></p>
""",
unsafe_allow_html=True
)