Spaces:
Sleeping
Sleeping
Commit
·
09ec673
1
Parent(s):
1829dce
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
class SalaryTracker:
|
6 |
+
def __init__(self, initial_salary):
|
7 |
+
self.salary = initial_salary
|
8 |
+
self.expenses = []
|
9 |
+
self.data = pd.DataFrame({'Month': [], 'Salary': []})
|
10 |
+
|
11 |
+
def add_expense(self, amount):
|
12 |
+
self.expenses.append(amount)
|
13 |
+
self.salary -= amount
|
14 |
+
|
15 |
+
def deduct_expense(self, amount):
|
16 |
+
self.expenses.append(-amount)
|
17 |
+
self.salary += amount
|
18 |
+
|
19 |
+
def update_data(self, month):
|
20 |
+
self.data = self.data.append({'Month': month, 'Salary': self.salary}, ignore_index=True)
|
21 |
+
|
22 |
+
def generate_report(self):
|
23 |
+
return self.data
|
24 |
+
|
25 |
+
# Streamlit UI
|
26 |
+
st.title("Monthly Salary Tracker")
|
27 |
+
initial_salary = st.number_input("Enter your initial monthly salary:", min_value=0.0, value=0.0, key="initial_salary")
|
28 |
+
|
29 |
+
salary_tracker = SalaryTracker(initial_salary)
|
30 |
+
|
31 |
+
# Add or Deduct Expenses
|
32 |
+
col1, col2 = st.beta_columns(2)
|
33 |
+
add_expense = col1.number_input("Add Expense", min_value=0.0, key="add_expense")
|
34 |
+
deduct_expense = col2.number_input("Deduct Expense", min_value=0.0, key="deduct_expense")
|
35 |
+
|
36 |
+
if st.button("Add Expense"):
|
37 |
+
if add_expense > 0:
|
38 |
+
salary_tracker.add_expense(add_expense)
|
39 |
+
month = st.text_input("Enter the month and year (e.g., 'Oct 2023'):", key="month")
|
40 |
+
salary_tracker.update_data(month)
|
41 |
+
|
42 |
+
if st.button("Deduct Expense"):
|
43 |
+
if deduct_expense > 0:
|
44 |
+
salary_tracker.deduct_expense(deduct_expense)
|
45 |
+
month = st.text_input("Enter the month and year (e.g., 'Oct 2023'):", key="month")
|
46 |
+
salary_tracker.update_data(month)
|
47 |
+
|
48 |
+
# Display Salary Data
|
49 |
+
st.subheader("Salary History")
|
50 |
+
if not salary_tracker.data.empty:
|
51 |
+
st.dataframe(salary_tracker.data)
|
52 |
+
|
53 |
+
# Generate and Display Graph
|
54 |
+
if not salary_tracker.data.empty:
|
55 |
+
plt.figure(figsize=(10, 5))
|
56 |
+
plt.plot(salary_tracker.data['Month'], salary_tracker.data['Salary'], marker='o')
|
57 |
+
plt.title("Salary History Over Time")
|
58 |
+
plt.xlabel("Month and Year")
|
59 |
+
plt.ylabel("Salary")
|
60 |
+
st.pyplot(plt)
|
61 |
+
|