bhagwandas commited on
Commit
6ad158b
·
verified ·
1 Parent(s): c8ad5b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -32
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;'>💸 اردو کرنسی کنورٹر</h1>
16
- <p style='text-align: center; color: #555;'>دنیا کی کسی بھی کرنسی کو آسانی سے تبدیل کریں</p>
17
  """,
18
  unsafe_allow_html=True
19
  )
20
 
21
- # API Key (Replace with your actual key from exchangerate-api.com)
22
- API_KEY = "your_api_key_here"
23
- BASE_URL = f"https://v6.exchangerate-api.com/v6/{API_KEY}/latest/"
 
 
 
 
24
 
25
  # Currency Selection
26
  col1, col2 = st.columns(2)
27
  with col1:
28
- from_currency = st.text_input('🔄 اصل کرنسی منتخب کریں (USD, EUR, PKR):', 'USD').upper()
29
  with col2:
30
- to_currency = st.text_input('🔄 مطلوبہ کرنسی منتخب کریں (USD, EUR, PKR):', 'PKR').upper()
31
 
32
  # Amount Input
33
- amount = st.number_input('💰 رقم درج کریں:', min_value=0.0, format='%.2f')
34
 
35
  # Convert Button
36
- if st.button('🔄 تبدیل کریں'):
37
- try:
38
- response = requests.get(BASE_URL + from_currency)
39
-
40
- if response.status_code != 200:
41
- st.error(f"❌ API خرابی: {response.status_code} - {response.text}")
42
- else:
43
- try:
44
- data = response.json()
45
- rate = data['conversion_rates'].get(to_currency)
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>ڈیزائن کردہ از ChatGPT</b></p>
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
  )