engralimalik's picture
Update app.py
c7d0bb8 verified
raw
history blame
1.22 kB
import pandas as pd
import matplotlib.pyplot as plt
import plotly.express as px
import streamlit as st
from transformers import pipeline
# Upload CSV file containing transaction data
uploaded_file = st.file_uploader("Upload Expense CSV", type="csv")
if uploaded_file is not None:
# Load the file into a DataFrame
df = pd.read_csv(uploaded_file)
# Display the first few rows of the dataset
st.write("First few rows of the dataset:", df.head())
# Initialize Hugging Face's zero-shot text classification model
model_name = 'distilbert-base-uncased'
classifier = pipeline('zero-shot-classification', model=model_name)
# List of possible expense categories
categories = ["Groceries", "Rent", "Utilities", "Entertainment", "Dining", "Transportation", "Salary"]
# Function to classify transaction descriptions into categories
def categorize_expense(description):
result = classifier(description, candidate_labels=categories)
return result['labels'][0] # Choose the most probable category
# Apply the categorization function to the 'Description' column in the dataset
df['Category'] = df['Description'].apply(categorize_expense)
# Show the ca