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?")