Gillie2004 commited on
Commit
4b1347e
·
1 Parent(s): ef64593

added files

Browse files
Files changed (2) hide show
  1. app.py +62 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+
4
+ # Set the title of the app
5
+ st.title("Simple Finance Tracker")
6
+
7
+ # Sidebar for data input
8
+ st.sidebar.header("Enter Your Income and Expenses")
9
+
10
+ # Input for total income
11
+ income = st.sidebar.number_input("Enter your total income for the month ($)", min_value=0.0, value=0.0, step=50.0)
12
+
13
+ # Input for custom expense categories
14
+ st.sidebar.header("Add Expense Categories")
15
+
16
+ # Use a form to input dynamic expenses
17
+ with st.sidebar.form(key='expense_form'):
18
+ # Allow user to input a category and its corresponding expense
19
+ expense_category = st.text_input("Expense Category (e.g., Rent, Groceries, etc.)", "")
20
+ expense_amount = st.number_input("Expense Amount ($)", min_value=0.0, value=0.0, step=10.0)
21
+
22
+ # Add expense to the list
23
+ submit_button = st.form_submit_button(label="Add Expense")
24
+
25
+ # Initialize session state for tracking expenses
26
+ if 'expenses' not in st.session_state:
27
+ st.session_state['expenses'] = {}
28
+
29
+ # When submit button is pressed, add the expense
30
+ if submit_button and expense_category:
31
+ st.session_state.expenses[expense_category] = expense_amount
32
+ st.success(f"Added {expense_category}: ${expense_amount:.2f}")
33
+
34
+ # Display current list of expenses
35
+ if st.session_state.expenses:
36
+ st.write("### Current Expenses")
37
+ expense_df = pd.DataFrame(list(st.session_state.expenses.items()), columns=["Category", "Amount"])
38
+ st.write(expense_df)
39
+ else:
40
+ st.write("No expenses added yet.")
41
+
42
+ # Calculate total expenses and balance
43
+ total_expenses = sum(st.session_state.expenses.values())
44
+ balance = income - total_expenses
45
+
46
+ # Show income, expenses summary, and balance
47
+ st.write("### Income and Expenses Summary")
48
+ st.write(f"**Total Income:** ${income:,.2f}")
49
+ st.write(f"**Total Expenses:** ${total_expenses:,.2f}")
50
+ st.write(f"**Balance:** ${balance:,.2f}")
51
+
52
+ # Display expense distribution in a bar chart
53
+ if st.session_state.expenses:
54
+ st.write("#### Expense Distribution (Bar Chart):")
55
+ st.bar_chart(expense_df.set_index('Category')['Amount'])
56
+
57
+ # Show balance and savings
58
+ st.write("### Your Balance")
59
+ if balance >= 0:
60
+ st.success(f"You're doing great! You have a balance of **${balance:,.2f}** left.")
61
+ else:
62
+ st.error(f"You're in deficit! You owe **${-balance:,.2f}**.")
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ streamlit