File size: 1,710 Bytes
e279bd0
 
 
 
 
6ad158b
e279bd0
 
 
 
 
 
 
6ad158b
 
e279bd0
 
 
 
6ad158b
 
 
 
 
 
 
e279bd0
 
 
 
6ad158b
e279bd0
6ad158b
e279bd0
 
6ad158b
e279bd0
 
6ad158b
 
 
 
 
 
 
 
 
 
e279bd0
 
 
 
 
6ad158b
e279bd0
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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
)