Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import pandas as pd
|
|
2 |
import plotly.express as px
|
3 |
import streamlit as st
|
4 |
from transformers import pipeline
|
|
|
5 |
|
6 |
# Function to add custom background image from a URL
|
7 |
def add_bg_from_url(image_url):
|
@@ -19,6 +20,10 @@ def add_bg_from_url(image_url):
|
|
19 |
unsafe_allow_html=True
|
20 |
)
|
21 |
|
|
|
|
|
|
|
|
|
22 |
# File upload
|
23 |
uploaded_file = st.file_uploader("Upload your expense CSV file", type=["csv"])
|
24 |
if uploaded_file:
|
@@ -27,18 +32,18 @@ if uploaded_file:
|
|
27 |
# Display Dataframe
|
28 |
st.write(df.head())
|
29 |
|
30 |
-
# Initialize Hugging Face model for zero-shot classification
|
31 |
-
classifier = pipeline('zero-shot-classification', model='
|
32 |
categories = ["Groceries", "Rent", "Utilities", "Entertainment", "Dining", "Transportation"]
|
33 |
|
34 |
-
# Function to categorize
|
35 |
def categorize_expense(description):
|
36 |
result = classifier(description, candidate_labels=categories)
|
37 |
return result['labels'][0] # Most probable category
|
38 |
|
39 |
# Apply categorization
|
40 |
df['Category'] = df['Description'].apply(categorize_expense)
|
41 |
-
|
42 |
# Display categorized data
|
43 |
st.write("Categorized Data", df)
|
44 |
|
@@ -89,9 +94,9 @@ if uploaded_file:
|
|
89 |
'Budget': [sum(budgets.values())] * len(monthly_expenses) # Same budget for simplicity
|
90 |
})
|
91 |
|
92 |
-
|
|
|
|
|
|
|
|
|
93 |
st.pyplot(fig3)
|
94 |
-
|
95 |
-
# Add the background image using the provided URL
|
96 |
-
background_image_url = 'https://huggingface.co/spaces/engralimalik/Smart-Expense-Tracker/resolve/main/colorful-abstract-textured-background-design.jpg'
|
97 |
-
add_bg_from_url(background_image_url)
|
|
|
2 |
import plotly.express as px
|
3 |
import streamlit as st
|
4 |
from transformers import pipeline
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
|
7 |
# Function to add custom background image from a URL
|
8 |
def add_bg_from_url(image_url):
|
|
|
20 |
unsafe_allow_html=True
|
21 |
)
|
22 |
|
23 |
+
# Add the background image using the provided URL
|
24 |
+
background_image_url = 'https://huggingface.co/spaces/engralimalik/Smart-Expense-Tracker/resolve/main/colorful-abstract-textured-background-design.jpg'
|
25 |
+
add_bg_from_url(background_image_url)
|
26 |
+
|
27 |
# File upload
|
28 |
uploaded_file = st.file_uploader("Upload your expense CSV file", type=["csv"])
|
29 |
if uploaded_file:
|
|
|
32 |
# Display Dataframe
|
33 |
st.write(df.head())
|
34 |
|
35 |
+
# Initialize Hugging Face model for zero-shot classification (using a better model like roberta-large-mnli)
|
36 |
+
classifier = pipeline('zero-shot-classification', model='roberta-large-mnli')
|
37 |
categories = ["Groceries", "Rent", "Utilities", "Entertainment", "Dining", "Transportation"]
|
38 |
|
39 |
+
# Function to categorize expenses based on the description
|
40 |
def categorize_expense(description):
|
41 |
result = classifier(description, candidate_labels=categories)
|
42 |
return result['labels'][0] # Most probable category
|
43 |
|
44 |
# Apply categorization
|
45 |
df['Category'] = df['Description'].apply(categorize_expense)
|
46 |
+
|
47 |
# Display categorized data
|
48 |
st.write("Categorized Data", df)
|
49 |
|
|
|
94 |
'Budget': [sum(budgets.values())] * len(monthly_expenses) # Same budget for simplicity
|
95 |
})
|
96 |
|
97 |
+
# Create a matplotlib figure for the bar chart
|
98 |
+
fig3, ax = plt.subplots(figsize=(10, 6))
|
99 |
+
monthly_expenses_df.plot(kind='bar', ax=ax)
|
100 |
+
ax.set_title('Monthly Spending vs Budget')
|
101 |
+
ax.set_ylabel('Amount ($)')
|
102 |
st.pyplot(fig3)
|
|
|
|
|
|
|
|