import streamlit as st from forex_python.converter import CurrencyRates, RatesNotAvailableError # Title of the app st.title("Currency Converter") # Initialize the currency converter currency_rates = CurrencyRates() # Input fields st.header("Currency Conversion") base_currency = st.text_input("Enter the base currency (e.g., USD):", "USD").upper() target_currency = st.text_input("Enter the target currency (e.g., EUR):", "EUR").upper() amount = st.number_input("Enter the amount to convert:", min_value=0.0, step=1.0) # Perform conversion when the user clicks the button if st.button("Convert"): try: converted_amount = currency_rates.convert(base_currency, target_currency, amount) st.success(f"{amount} {base_currency} = {converted_amount:.2f} {target_currency}") except RatesNotAvailableError: st.error("Currency rates not available. Please check the currency codes.") except Exception as e: st.error(f"An error occurred: {str(e)}")