import streamlit as st import pandas as pd import matplotlib.pyplot as plt class SalaryTracker: def __init__(self, initial_salary): self.salary = initial_salary self.expenses = [] self.data = pd.DataFrame({'Transaction': [], 'Salary': []}) self.transaction_count = 0 def add_expense(self, amount): self.expenses.append(amount) self.salary -= amount self.transaction_count += 1 def deduct_expense(self, amount): self.expenses.append(-amount) self.salary += amount self.transaction_count += 1 def update_data(self, transaction): new_data = pd.DataFrame({'Transaction': [f"Transaction {self.transaction_count} - {transaction}"], 'Salary': [self.salary]}) self.data = pd.concat([self.data, new_data], ignore_index=True) def generate_report(self): return self.data # Streamlit UI st.title("Monthly Salary Tracker") initial_salary = st.number_input("Enter your initial monthly salary:", min_value=0.0, value=0.0, key="initial_salary") salary_tracker = SalaryTracker(initial_salary) # Add or Deduct Expenses col1, col2 = st.columns(2) add_expense = col1.number_input("Add Expense", min_value=0.0, key="add_expense") deduct_expense = col2.number_input("Deduct Expense", min_value=0.0, key="deduct_expense") if st.button("Add Expense"): if add_expense > 0: salary_tracker.add_expense(add_expense) salary_tracker.update_data("Credit") if st.button("Deduct Expense"): if deduct_expense > 0: salary_tracker.deduct_expense(deduct_expense) salary_tracker.update_data("Debit") # Display Salary Data st.subheader("Salary History") if not salary_tracker.data.empty: st.dataframe(salary_tracker.data) # Generate and Display Graph if not salary_tracker.data.empty: plt.figure(figsize=(10, 5)) plt.plot(salary_tracker.data['Transaction'], salary_tracker.data['Salary'], marker='o') plt.title("Salary History Over Transactions") plt.xlabel("Transactions") plt.ylabel("Salary") st.pyplot(plt)