Spaces:
Sleeping
Sleeping
import streamlit as st | |
import sympy as sp | |
from forex_python.converter import CurrencyRates, RatesNotAvailableError | |
# Scientific Calculator Function | |
def scientific_calculator(): | |
st.header("Advanced Scientific Calculator") | |
expression = st.text_input("Enter the mathematical expression:", value="sin(pi/2) + log(10)") | |
if st.button("Calculate"): | |
try: | |
result = sp.sympify(expression).evalf() | |
st.success(f"Result: {result}") | |
except Exception as e: | |
st.error(f"Invalid Expression! Error: {e}") | |
# Currency Converter Function | |
def currency_converter(): | |
st.header("Currency Converter") | |
c = CurrencyRates() | |
try: | |
# Fetch available currencies | |
currencies = list(c.get_rates("").keys()) | |
except Exception: | |
st.error("Unable to fetch currency rates. Using a fallback list.") | |
currencies = ["USD", "EUR", "GBP", "INR", "AUD", "CAD"] | |
from_currency = st.selectbox("From Currency:", currencies) | |
to_currency = st.selectbox("To Currency:", currencies) | |
amount = st.number_input("Amount to Convert:", min_value=0.0, value=1.0, step=0.01) | |
if st.button("Convert"): | |
try: | |
converted_amount = c.convert(from_currency, to_currency, amount) | |
st.success(f"{amount} {from_currency} = {converted_amount:.2f} {to_currency}") | |
except RatesNotAvailableError: | |
st.error("Currency rates are currently unavailable.") | |
except Exception as e: | |
st.error(f"Error in conversion: {e}") | |
# Main Function to Manage App | |
def main(): | |
st.title("Scientific Calculator and Currency Converter") | |
st.sidebar.title("Navigation") | |
option = st.sidebar.radio("Choose a Tool:", ["Scientific Calculator", "Currency Converter"]) | |
if option == "Scientific Calculator": | |
scientific_calculator() | |
elif option == "Currency Converter": | |
currency_converter() | |
if __name__ == "__main__": | |
main() | |