Spaces:
Build error
Build error
Download app.py from HFUsman/Currency_Convertor: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/HFUsman/Currency_Convertor/resolve/main/app.py
- Command line
-
hf download hf://spaces/HFUsman/Currency_Convertor/app.py
-
curl -L -o app.py https://huggingface.co/spaces/HFUsman/Currency_Convertor/resolve/main/app.py
1.54 kB
| import streamlit as st | |
| # Set up the app's layout | |
| st.set_page_config(page_title="Currency Exchange Calculator", layout="wide") | |
| st.title("🌍💱 Currency Exchange Calculator") | |
| # Sidebar | |
| st.sidebar.title("About the App") | |
| st.sidebar.info("This simple currency converter allows you to exchange between commonly used currencies using predefined exchange rates.") | |
| # Latest hardcoded exchange rates (example rates, replace with the latest you know) | |
| exchange_rates = { | |
| "USD": 1.0, # Base currency | |
| "EUR": 0.91, | |
| "GBP": 0.78, | |
| "PKR": 277.5, | |
| "INR": 83.2, | |
| "JPY": 141.8, | |
| "RMB": 7.2, | |
| } | |
| # Main layout with two columns | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| # User inputs for currency conversion | |
| st.subheader("Input") | |
| from_currency = st.selectbox("From Currency", options=exchange_rates.keys(), index=0) | |
| to_currency = st.selectbox("To Currency", options=exchange_rates.keys(), index=1) | |
| amount = st.number_input("Amount to Convert", min_value=0.0, value=1.0, step=0.01) | |
| with col2: | |
| # Perform conversion | |
| st.subheader("Result") | |
| if st.button("Convert"): | |
| try: | |
| # Conversion logic | |
| converted_amount = amount * (exchange_rates[to_currency] / exchange_rates[from_currency]) | |
| st.success(f"{amount} {from_currency} = {converted_amount:,.2f} {to_currency}") | |
| except Exception as e: | |
| st.error(f"An error occurred: {e}") | |
| # Footer | |
| st.sidebar.markdown("---") | |
| st.sidebar.markdown("**Exchange rates are static and need to be updated manually.**") |