|
import gradio as gr |
|
import pandas as pd |
|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
from transformers import pipeline |
|
import plotly.express as px |
|
|
|
|
|
expense_classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli") |
|
|
|
|
|
def categorize_transaction_batch(descriptions): |
|
candidate_labels = ["Groceries", "Entertainment", "Rent", "Utilities", "Dining", "Transportation", "Shopping", "Others"] |
|
return [expense_classifier(description, candidate_labels)["labels"][0] for description in descriptions] |
|
|
|
|
|
def process_expenses(file): |
|
|
|
df = pd.read_csv(file.name) |
|
|
|
|
|
if 'Date' not in df.columns or 'Description' not in df.columns or 'Amount' not in df.columns: |
|
return "CSV file should contain 'Date', 'Description', and 'Amount' columns." |
|
|
|
|
|
df['Category'] = categorize_transaction_batch(df['Description'].tolist()) |
|
|
|
|
|
|
|
|