Spaces:
Sleeping
Sleeping
# 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 | |
) | |