Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
# app.py
|
2 |
import streamlit as st
|
3 |
-
import requests
|
4 |
|
5 |
# Set page configuration
|
6 |
st.set_page_config(
|
7 |
-
page_title='
|
8 |
page_icon='💱',
|
9 |
layout='centered'
|
10 |
)
|
@@ -12,54 +11,47 @@ st.set_page_config(
|
|
12 |
# App Header
|
13 |
st.markdown(
|
14 |
"""
|
15 |
-
<h1 style='text-align: center; color: #4CAF50;'
|
16 |
-
<p style='text-align: center; color: #555;'
|
17 |
""",
|
18 |
unsafe_allow_html=True
|
19 |
)
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
|
25 |
# Currency Selection
|
26 |
col1, col2 = st.columns(2)
|
27 |
with col1:
|
28 |
-
from_currency = st.
|
29 |
with col2:
|
30 |
-
to_currency = st.
|
31 |
|
32 |
# Amount Input
|
33 |
-
amount = st.number_input('💰
|
34 |
|
35 |
# Convert Button
|
36 |
-
if st.button('🔄
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
if not rate:
|
48 |
-
raise Exception('منتخب کردہ کرنسی دستیاب نہیں ہے۔')
|
49 |
-
|
50 |
-
result = amount * rate
|
51 |
-
st.success(f'✅ {amount} {from_currency} = {result:.2f} {to_currency}')
|
52 |
-
except ValueError:
|
53 |
-
st.error("❌ JSON Parsing خرابی: API کا جواب درست نہیں ہے۔")
|
54 |
-
st.write("🔍 API Response:", response.text)
|
55 |
-
except requests.exceptions.RequestException as e:
|
56 |
-
st.error(f"❌ نیٹ ورک خرابی: {e}")
|
57 |
|
58 |
# Footer
|
59 |
st.markdown(
|
60 |
"""
|
61 |
<hr>
|
62 |
-
<p style='text-align: center;'>💻 <b
|
63 |
""",
|
64 |
unsafe_allow_html=True
|
65 |
)
|
|
|
1 |
# app.py
|
2 |
import streamlit as st
|
|
|
3 |
|
4 |
# Set page configuration
|
5 |
st.set_page_config(
|
6 |
+
page_title='💵 Currency Converter',
|
7 |
page_icon='💱',
|
8 |
layout='centered'
|
9 |
)
|
|
|
11 |
# App Header
|
12 |
st.markdown(
|
13 |
"""
|
14 |
+
<h1 style='text-align: center; color: #4CAF50;'>💵 Currency Converter</h1>
|
15 |
+
<p style='text-align: center; color: #555;'>Easily convert currencies offline with predefined rates</p>
|
16 |
""",
|
17 |
unsafe_allow_html=True
|
18 |
)
|
19 |
|
20 |
+
# Predefined Exchange Rates (Static Data)
|
21 |
+
EXCHANGE_RATES = {
|
22 |
+
"USD": {"EUR": 0.85, "GBP": 0.75, "PKR": 280.0},
|
23 |
+
"EUR": {"USD": 1.18, "GBP": 0.88, "PKR": 330.0},
|
24 |
+
"GBP": {"USD": 1.33, "EUR": 1.14, "PKR": 380.0},
|
25 |
+
"PKR": {"USD": 0.0036, "EUR": 0.0030, "GBP": 0.0026}
|
26 |
+
}
|
27 |
|
28 |
# Currency Selection
|
29 |
col1, col2 = st.columns(2)
|
30 |
with col1:
|
31 |
+
from_currency = st.selectbox('🔄 Select Base Currency:', list(EXCHANGE_RATES.keys()))
|
32 |
with col2:
|
33 |
+
to_currency = st.selectbox('🔄 Select Target Currency:', list(EXCHANGE_RATES.keys()))
|
34 |
|
35 |
# Amount Input
|
36 |
+
amount = st.number_input('💰 Enter Amount:', min_value=0.0, format='%.2f')
|
37 |
|
38 |
# Convert Button
|
39 |
+
if st.button('🔄 Convert'):
|
40 |
+
if from_currency == to_currency:
|
41 |
+
st.warning("⚠️ Base and target currencies are the same. Please select different currencies.")
|
42 |
+
else:
|
43 |
+
try:
|
44 |
+
rate = EXCHANGE_RATES[from_currency][to_currency]
|
45 |
+
result = amount * rate
|
46 |
+
st.success(f'✅ {amount} {from_currency} = {result:.2f} {to_currency}')
|
47 |
+
except KeyError:
|
48 |
+
st.error("❌ Conversion rate not available for selected currencies.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
# Footer
|
51 |
st.markdown(
|
52 |
"""
|
53 |
<hr>
|
54 |
+
<p style='text-align: center;'>💻 <b>Developed by ChatGPT</b></p>
|
55 |
""",
|
56 |
unsafe_allow_html=True
|
57 |
)
|