HFUsman commited on
Commit
6584f8d
·
verified ·
1 Parent(s): 6cc1716

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -24
app.py CHANGED
@@ -1,31 +1,45 @@
1
  import streamlit as st
2
- from forex_python.converter import CurrencyRates, CurrencyCodes
3
 
4
- # Initialize currency converter
5
- c = CurrencyRates()
6
- cc = CurrencyCodes()
7
 
8
- st.title("Currency Exchange Calculator 🌎💱")
 
 
9
 
10
- # User input: Select currencies
11
- from_currency = st.selectbox("From Currency", options=list(c.get_rates("").keys()), index=0)
12
- to_currency = st.selectbox("To Currency", options=list(c.get_rates("").keys()), index=1)
 
 
 
 
 
 
 
13
 
14
- # User input: Enter amount
15
- amount = st.number_input("Enter amount to convert", min_value=0.0, value=1.0, step=0.01)
16
 
17
- # Calculate exchange rate
18
- if st.button("Convert"):
19
- try:
20
- converted_amount = c.convert(from_currency, to_currency, amount)
21
- symbol = cc.get_symbol(to_currency)
22
- st.success(f"{amount} {from_currency} = {symbol}{converted_amount:,.2f} {to_currency}")
23
- except Exception as e:
24
- st.error(f"Error: {e}")
25
 
26
- # Display additional rates
27
- st.sidebar.title("Additional Features")
28
- if st.sidebar.checkbox("View Current Rates"):
29
- rates = c.get_rates(from_currency)
30
- st.sidebar.write(f"Exchange rates for {from_currency}:")
31
- st.sidebar.table(rates)
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
 
2
 
3
+ # Set up the app's layout
4
+ st.set_page_config(page_title="Currency Exchange Calculator", layout="wide")
5
+ st.title("🌍💱 Currency Exchange Calculator")
6
 
7
+ # Sidebar
8
+ st.sidebar.title("About the App")
9
+ st.sidebar.info("This simple currency converter allows you to exchange between commonly used currencies using predefined exchange rates.")
10
 
11
+ # Latest hardcoded exchange rates (example rates, replace with the latest you know)
12
+ exchange_rates = {
13
+ "USD": 1.0, # Base currency
14
+ "EUR": 0.91,
15
+ "GBP": 0.78,
16
+ "PKR": 277.5,
17
+ "INR": 83.2,
18
+ "JPY": 141.8,
19
+ "RMB": 7.2,
20
+ }
21
 
22
+ # Main layout with two columns
23
+ col1, col2 = st.columns(2)
24
 
25
+ with col1:
26
+ # User inputs for currency conversion
27
+ st.subheader("Input")
28
+ from_currency = st.selectbox("From Currency", options=exchange_rates.keys(), index=0)
29
+ to_currency = st.selectbox("To Currency", options=exchange_rates.keys(), index=1)
30
+ amount = st.number_input("Amount to Convert", min_value=0.0, value=1.0, step=0.01)
 
 
31
 
32
+ with col2:
33
+ # Perform conversion
34
+ st.subheader("Result")
35
+ if st.button("Convert"):
36
+ try:
37
+ # Conversion logic
38
+ converted_amount = amount * (exchange_rates[to_currency] / exchange_rates[from_currency])
39
+ st.success(f"{amount} {from_currency} = {converted_amount:,.2f} {to_currency}")
40
+ except Exception as e:
41
+ st.error(f"An error occurred: {e}")
42
+
43
+ # Footer
44
+ st.sidebar.markdown("---")
45
+ st.sidebar.markdown("**Exchange rates are static and need to be updated manually.**")