Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from forex_python.converter import CurrencyRates, CurrencyCodes, RatesNotAvailableError | |
| # Set up the title and sidebar for user inputs | |
| st.title("Currency Converter") | |
| st.sidebar.header("Conversion Settings") | |
| amount = st.sidebar.number_input("Amount", min_value=0.0, value=1.0, step=1.0) | |
| currency_list = ["USD", "EUR", "GBP", "JPY", "AUD", "CAD", "CHF", "CNY", "SEK", "NZD"] | |
| from_currency = st.sidebar.selectbox("From Currency", currency_list) | |
| to_currency = st.sidebar.selectbox("To Currency", currency_list) | |
| # Conversion result section | |
| st.header("Conversion Result") | |
| if st.button("Convert"): | |
| c = CurrencyRates() | |
| try: | |
| converted_amount = c.convert(from_currency, to_currency, amount) | |
| st.write(f"{amount} {from_currency} is equal to {converted_amount:.2f} {to_currency}") | |
| code = CurrencyCodes() | |
| from_symbol = code.get_symbol(from_currency) | |
| to_symbol = code.get_symbol(to_currency) | |
| st.write(f"Symbols: {from_symbol} to {to_symbol}") | |
| except RatesNotAvailableError as e: | |
| st.error(f"Error: The conversion rate for {from_currency} to {to_currency} is not available.") | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |
| st.sidebar.header("API used") | |
| st.sidebar.write("Forex Python API") | |