rizwanaidris2 commited on
Commit
22b60f5
·
verified ·
1 Parent(s): fe8793f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from forex_python.converter import CurrencyRates, CurrencyCodes, RatesNotAvailableError
3
+
4
+ # Set up the title and sidebar for user inputs
5
+ st.title("Currency Converter")
6
+
7
+ st.sidebar.header("Conversion Settings")
8
+ amount = st.sidebar.number_input("Amount", min_value=0.0, value=1.0, step=1.0)
9
+ currency_list = ["USD", "EUR", "GBP", "JPY", "AUD", "CAD", "CHF", "CNY", "SEK", "NZD"]
10
+ from_currency = st.sidebar.selectbox("From Currency", currency_list)
11
+ to_currency = st.sidebar.selectbox("To Currency", currency_list)
12
+
13
+ # Conversion result section
14
+ st.header("Conversion Result")
15
+
16
+ if st.button("Convert"):
17
+ c = CurrencyRates()
18
+ try:
19
+ converted_amount = c.convert(from_currency, to_currency, amount)
20
+ st.write(f"{amount} {from_currency} is equal to {converted_amount:.2f} {to_currency}")
21
+
22
+ code = CurrencyCodes()
23
+ from_symbol = code.get_symbol(from_currency)
24
+ to_symbol = code.get_symbol(to_currency)
25
+ st.write(f"Symbols: {from_symbol} to {to_symbol}")
26
+ except RatesNotAvailableError as e:
27
+ st.error(f"Error: The conversion rate for {from_currency} to {to_currency} is not available.")
28
+ except Exception as e:
29
+ st.error(f"Error: {e}")
30
+
31
+ st.sidebar.header("API used")
32
+ st.sidebar.write("Forex Python API")