Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import datetime | |
| # Initialize session state | |
| if "balance" not in st.session_state: | |
| st.session_state.balance = 0 | |
| if "transactions" not in st.session_state: | |
| st.session_state.transactions = [] | |
| if "multiple" not in st.session_state: | |
| st.session_state.multiple = 5 # default multiple | |
| # Function to calculate round-up | |
| def round_up(transaction, multiple): | |
| rounded = ((transaction + multiple - 1) // multiple) * multiple | |
| savings = rounded - transaction | |
| return rounded, savings | |
| # App title | |
| st.title("π° Smart Round-Up Savings (User Controlled)") | |
| st.markdown("*Choose your round-up multiple:*") | |
| multiple = st.selectbox("Round to nearest:", [5, 10, 20, 50], index=[5,10,20,50].index(st.session_state.multiple)) | |
| st.session_state.multiple = multiple | |
| # Transaction input | |
| transaction = st.number_input("Enter transaction amount (βΉ):", min_value=1, step=1) | |
| if st.button("Add Transaction"): | |
| rounded, savings = round_up(transaction, st.session_state.multiple) | |
| st.session_state.balance += savings | |
| st.session_state.transactions.append( | |
| {"amount": transaction, "rounded": rounded, "savings": savings, "date": datetime.date.today()} | |
| ) | |
| st.success(f"Spent βΉ{transaction} β Rounded to βΉ{rounded} β Saved βΉ{savings}") | |
| # Show Smart Pot Balance | |
| st.metric("π° Smart Pot Balance", f"βΉ{st.session_state.balance}") | |
| # Show transaction history | |
| st.subheader("π Transaction History") | |
| if st.session_state.transactions: | |
| for t in reversed(st.session_state.transactions[-5:]): | |
| st.write(f"π’ βΉ{t['amount']} β βΉ{t['rounded']} (Saved βΉ{t['savings']}) on {t['date']}") | |
| else: | |
| st.write("No transactions yet.") | |
| # Monthly reminder simulation | |
| if st.button("π New Month"): | |
| st.info(f"Last month you saved βΉ{st.session_state.balance} with multiples of βΉ{st.session_state.multiple}.") | |
| st.info("π Do you want to keep it the same, lower for less pressure, or increase for faster savings?") | |