Smart-Round-Up / app.py
alekhya1707's picture
Upload 2 files
7068b71 verified
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?")