|
import pandas as pd |
|
import plotly.express as px |
|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload your expense CSV file", type=["csv"]) |
|
if uploaded_file: |
|
df = pd.read_csv(uploaded_file) |
|
|
|
|
|
st.write(df.head()) |
|
|
|
|
|
classifier = pipeline('zero-shot-classification', model='distilbert-base-uncased') |
|
categories = ["Groceries", "Rent", "Utilities", "Entertainment", "Dining", "Transportation"] |
|
|
|
|
|
def categorize_expense(description): |
|
|
|
result = classifier(description, candidate_labels=categories) |
|
st.write(f"Raw classification result for '{description}': {result}") |
|
return result['labels'][0] |
|
|
|
|
|
df['Category'] = df['Description'].apply(categorize_expense) |
|
|
|
|
|
st.write("Categorized Data", df) |
|
|
|
|
|
st.sidebar.header("Set Your Monthly Budget") |
|
groceries_budget = st.sidebar.slider("Groceries Budget", 0, 1000, 300) |
|
rent_budget = st.sidebar.slider("Rent Budget", 0, 5000, 1000) |
|
utilities_budget = st.sidebar.slider("Utilities Budget", 0, 500, 150) |
|
entertainment_budget = st.sidebar.slider("Entertainment Budget", 0, 1000, 100) |
|
dining_budget = st.sidebar.slider("Dining Budget", 0, 1000, 150) |
|
transportation_budget = st.sidebar.slider("Transportation Budget", 0, 500, 120) |
|
|
|
|
|
budgets = { |
|
"Groceries": groceries_budget, |
|
"Rent": rent_budget, |
|
"Utilities": utilities_budget, |
|
"Entertainment": entertainment_budget, |
|
"Dining": dining_budget, |
|
"Transportation": transportation_budget |
|
} |
|
|
|
|
|
df['Budget_Exceeded'] = df.apply(lambda row: row['Amount'] > budgets.get(row['Category'], 0), axis=1) |
|
|
|
|
|
exceeded_budget = df[df['Budget_Exceeded'] == True] |
|
st.write("Categories that exceeded the budget:", exceeded_budget[['Date', 'Category', 'Amount']]) |
|
|
|
|
|
|
|
|
|
category_expenses = df.groupby('Category')['Amount'].sum() |
|
fig1 = px.pie(category_expenses, values=category_expenses.values, names=category_expenses.index, title="Expense Distribution by Category") |
|
st.plotly_chart(fig1) |
|
|
|
|
|
df['Date'] = pd.to_datetime(df['Date']) |
|
df['Month'] = df['Date'].dt.to_period('M').astype(str) |
|
monthly_expenses = df.groupby('Month')['Amount'].sum() |
|
|
|
fig2 = px.line(monthly_expenses, x=monthly_expenses.index, y=monthly_expenses.values, title="Monthly Expenses", labels={"x": "Month", "y": "Amount ($)"}) |
|
st.plotly_chart(fig2) |
|
|
|
|
|
monthly_expenses_df = pd.DataFrame({ |
|
'Actual': monthly_expenses, |
|
'Budget': [sum(budgets.values())] * len(monthly_expenses) |
|
}) |
|
|
|
fig3 = px.bar(monthly_expenses_df, x=monthly_expenses_df.index, y=["Actual", "Budget"], title="Monthly Spending vs Budget", labels={"x": "Month", "y": "Amount ($)"}) |
|
st.plotly_chart(fig3) |
|
|