How to make smart costs tracker with Azgar and LLMS

by SkillAiNest

Imagine that you are sipping a warm latte from the star box on your way to your work. You quickly swipe your card, and the receipt is lost in your bag. At the end of the day, you pay for the Uber ride, order lunch and buy an aerial time. By evening, you know that you have spent money, but you cannot say exactly how much, or where most of them have gone.

This is the challenge with personal finance. There are traditional spending tracking, but mostly you need to manually enter every detail, select categories and run reports. After a while, you stop keeping track because it feels like it is more than the price.

But what if your tracker was smart? Can be:

  • Automatically understand that “Dominos Pizza” should be classified Food and drinks.

  • Summarize your weekly expenses in simple English, such as: “This week, you spent 000 32,000 on transportation, 000, 15,000, and on purchase, 000 8,000.”

  • Even show you a clean pie chart where your money has gone?

In this tutorial, we will produce exactly the same way, using a smart cost tracker and a large language model (LLM). We will start with a simple aggregate tracker, then slowly add it to it:

  1. Data storage system for costs.

  2. Automatic rating using LLMS.

  3. Concepts to make costs more straightforward.

Until the end, you will have an expense tracker that doesn’t just record the data, it really talks back, understands your expenses, and helps you make better financial decisions.

The table of content

  1. How to configure the expense data

  2. How to make a tracker of basic costs

  3. How to make it smart with LLMS (auto category)

  4. How to imagine costs

  5. How to build a simple cost tracker streamlit dashboard

  6. Conclusion

How to configure the expense data

Before you can make the cost tracker, you need real transaction data. Instead of creating a CSV from the beginning, Use Datastate from Caigel: My expenses datA Throne by Prabo.

This dataset has detailed personal expenses with columns such as:

  • History: Time stamp of transaction.

  • Account: Where the payment (bank account, card, and so on.

  • Category / Sub Category: Type of expenses.

  • Note: A brief description such as “Branger” or “Metro”.

  • Money: How much was spent.

  • Earnings/costs: Distinguish between money earned.

  • Some column (like Note.1For, for, for,. Account.1) Looks useless and can be cleaned.

How to load the data in Uzar

Use pandas to read CSV:

import pandas as pd

df = pd.read_csv("Expense_data_1.csv")
print(df.head())

What is happening through the line is here:

  • import pandas as pd: We filled the Pandas Library and gave it a short ache (pd) So we don’t have to type pandas Recurrence

  • pd.read_csv("Expense_data_1.csv"): This CSV file reads your expenses from the data frame to the data frame.

  • df.head(): You show the first 5 rows of datasate, which you can check in columns such as quickly Date, detail, money, category, And so on

Output:

Showing sample costs data with columns history, account, category, note, and money

How to clear the data

Since you do not need all columns, clean the datastas to keep only useful people for tracker.

data = df(("Date", "Category", "Note", "Amount", "Income/Expense"))
print(data.head())

What is happening here:

  • df(...): It tells Pandas that you just want to select a specific column from the full data frame.

  • ("Date", "Category", "Note", "Amount", "Income/Expense"): These are the columns we have chosen to keep:

    • Date : When spent

    • Category: Labels such as food, transport, entertainment

    • Note: Short detail (eg, “shorema”, “Uber riding”)

    • Amount: How much did you spend

    • Income/Expense: Whether this money is going out or money is coming

  • print(data.head())Once again, we look at the first 5 rows to make sure our dataset now looks clean and focused.

Output:

Date of columns, category, notes, money, and sample costs with expenses/income.

Now we have a clean dataset:

  • Date

  • Category

  • Note (Brief detail)

  • Amount

  • Income/Expense

It is enough to start building our basic cost trackers.

How to make a tracker of basic costs

Just imagine it’s weekend:

  • On Friday evening, you catch a shorema after work.

  • On Saturday morning, you pay your Netflix subscription to catch your favorite series.

  • At the end of this day, you order a riding Uber to meet friends.

  • On Sunday afternoon, you join them for outdoor sports at the local sports center.

Wouldn’t it be nice to automatically log them into your tracker and then look at how much you spent just the weekend? Let’s do it.

  1. How to add multiple costs

We will write a function that takes history, category, note, money, and type (income/costs) and adds it to your data frame.

def add_expense(date, category, note, amount, exp_type="Expense"):
    global data
    new_entry = {
        "Date": date,
        "Category": category,
        "Note": note,
        "Amount": amount,
        "Income/Expense": exp_type
    }
    data = data.append(new_entry, ignore_index=True)
    print(f" Added: {note} - {amount} ({category})")

add_expense("2025-08-22 19:30", "Food", "Shawarma", 2500, "Expense")
add_expense("2025-08-23 08:00", "Subscriptions", "Netflix Monthly Plan", 4500, "Expense")
add_expense("2025-08-24 14:00", "Entertainment", "Outdoor Games with friends", 7000, "Expense")

What is happening here:

  • def add_expense(...): We explained a function add_expense It takes details of a new transaction.

  • global data: This ensures new costs have been added to your main dataset (data) Instead of a temporary copy.

  • new_entry = {...}: We developed a dictionary for a new row, whose keys are similar to columns in our data frame.

  • data.append(...): Includes new entry to our datastas. ignore_index=True This ensures that the row index is properly reset.

  • print(...): It confirms what was just added.

Output:

Image showed additional costs data

  1. How to see recent costs

def view_expenses(n=5):
    return data.tail(n)
print(view_expenses(5))

What is happening here:

  • def view_expenses(n=5):: Describes a function that shows the last n Rows from our dataset. The default, n=5So it shows 5 recent costs.

  • data.tail(n): Pandas tail() The method returns down n Data frame rows.

  • print(view_expenses(5)): 5 print the latest expenses so we can quickly confirm that they are recorded properly.

Output:

Table columns show recent costs with history, category, notes, money, and income/spending currency.

  1. How to summarize the costs

def summarize_expenses(by="Category"):
    summary = data(data("Income/Expense")=="Expense").groupby(by)("Amount").sum()
    return summary.sort_values(ascending=False)
print(summarize_expenses())

What is happening here:

  1. data(data("Income/Expense")=="Expense"): Only filters the dataset to add costs (ignores revenue).

  2. .groupby(by)("Amount").sum(): Groups costs through a column (default = "Category") And each group increases all quantities. For example, all Dinner The costs are summarized simultaneously.

  3. .sort_values(ascending=False): Category types by high costs from high to minimum.

Output:

Showing a summary of table costs

This shows that the weekend:

This tracker makes it clear where your money goes. Even without AI.

How to make it smart with LLMS (auto category)

We will use LLM to read note column (like ClutterFor, for, for,. NetflixFor, for, for,. DigitFor, for, for,. The game of football) And then automatically assign the most relevant category.

  1. Choose LLM API

  2. Indicate LLM
    We will send something like this:

    “Rate this cost note in one of them: food, transport, entertainment, other. Note: Netflix.”
    The model will return: Subscription.

  3. Merge in our pipeline

    • Save the forecast category back to the dataset.
from openai import OpenAI  
client = OpenAI(api_key="YOUR_API_KEY")

def auto_categorize(note):
    prompt = f"""
    Categorize this expense note into one of these categories: 
    Food, Transportation, Entertainment, Other.
    Note: {note}
    """
    try:
        response = client.chat.completions.create(
            model="gpt-4o-mini",
            messages=({"role": "user", "content": prompt}),
            temperature=0
        )
        return response.choices(0).message.content.strip()
    except Exception as e:
        return "Other"

data('Category') = data.apply(
    lambda row: auto_categorize(row('Note')) if pd.isna(row('Category')) else row('Category'),
    axis=1
)

print(data(('Note', 'Category')).head(10))

What is happening here:

  1. Quick Engineering: We clearly educate the model:

    • Select from Food, transport, entertainment, other.

    • Let him Note (For example, ClutterFor, for, for,. Ober rideFor, for, for,. Netflix Monthly Plan,

  2. Openi API Call: Sends request gpt-4o-mini (A sharp, lightweight model).

  3. Prediction prediction: The model chooses the most potential category.

  4. If the category of a row is missing, it asks the LLM to predict someone from the note.

  5. Otherwise, it maintains the user manually entering the category.

  6. data(('Note', 'Category')): Only selects notes (user input) and category (AI-geneted or user provided) column.

  7. .head(10): Show the first 10 rows for a quick check.

Output:

Table that shows the cost of spending

Now, our tracker is smart enough, which automatically estimates the categories.

How to imagine costs

Currently, our tracker is smart – it can recognize such a line “Pay 7,000 for Netflix” And classify it under subscription. But the raw number in a table still doesn’t give you “Ah!” What we need for a moment is a way to see where the money is going.

Let’s imagine this is the end of the month. You are staring at your bank balance with surprise, “Where did all my money go?” Instead of scrolling endlessly through transactions, our tracker provides a clear dashboard with visuals that tell the story at a glance.

We will use the Metaplatlib to make a two charts:

  1. Pie Chart – to see percent of each category.

  2. Bar Chart – Compare the actual quantity spent in the category.

import matplotlib.pyplot as plt
expense_summary = data(data('Category') != 'Income').groupby("Category")("Amount").sum()


plt.figure(figsize=(6,6))
expense_summary.plot.pie(autopct='%1.1f%%', startangle=90, shadow=True)
plt.title("Expenses Breakdown by Category")
plt.ylabel("")
plt.show()


plt.figure(figsize=(8,5))
expense_summary.plot(kind="bar", color="skyblue", edgecolor="black")
plt.title("Expenses by Category")
plt.xlabel("Category")
plt.ylabel("Amount Spent")
plt.show()

What is happening here:

  1. groupby("Category")("Amount").sum(): Groups calculate the total costs spent in terms of category and per category.

  2. Pie Chart: Displays quickly Percentage Of costs in category. For example, if “food” is 20 % of costs, you will see it immediately.

  3. Bar Chart: Shows Absolute values Spending in terms of category, making it easier to see which category costs the most or less.

Output:

The pie chart, which shows a percentage of category costs, is represented by costs such as food, entertainment and transportation in each slice.

Bar charts, which have total costs that are created by category, highlight the differences such as food, transport, entertainment and gifts.

What do these visual tell us:

  • Pie Chart answers the question: “What are most of my money taking?”

  • The bar chart makes it easy to compare the category. For example, you may realize that you are spending as much as you combine on subscriptions and social life.

At this point, you have moved from raw numbers to viable insights.

How to build a simple cost tracker streamlit dashboard

Imagine that you have coded and now you want to see your spending habits in a sleek dashboard you’ve made yourself. This is where harmony comes.

With just a few lines, you can convert your cost tracker into an interactive web app where you can directly enter new costs from the app, update the data frame in real time, automatically classify them with LLM, and see the latest chart. And save them from your own expenses.csv

import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import os

from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY")

def predict_category(description):
    prompt = f"""
    You are a financial assistant. Categorize this expense into one of:
    ('Food', 'Transportation', 'Entertainment', 'Utilities', 'Shopping', 'Others').

    Expense: "{description}"
    Just return the category name.
    """
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=({"role": "user", "content": prompt}),
        temperature=0
    )
    return response.choices(0).message.content.strip()

csv_file = "expense_data_1.csv"
if os.path.exists(csv_file):
    data = pd.read_csv(csv_file)
else:
    data = pd.DataFrame(columns=("Date", "Description", "Amount", "Category"))

st.title("Smart Expense Tracker")

with st.form("expense_form"):
    date = st.date_input("Date")
    description = st.text_input("Description")
    amount = st.number_input("Amount", min_value=0.0, format="%.2f")

    predicted_category = ""
    if description:
        predicted_category = predict_category(description)

    category = st.text_input(
        "Category (auto-predicted, but you can edit)", 
        value=predicted_category
    )

    submitted = st.form_submit_button("Add Expense")

    if submitted:
        new_expense = {"Date": date, "Description": description, "Amount": amount, "Category": category}
        data = pd.concat((data, pd.DataFrame((new_expense))), ignore_index=True)
        data.to_csv(csv_file, index=False)
        st.success(f"Added: {description} - {amount} ({category})")

st.subheader("All Expenses")
st.dataframe(data)

if not data.empty:
    st.subheader("Expense Breakdown by Category")

    category_totals = data.groupby("Category")("Amount").sum()

    
    fig, ax = plt.subplots()
    category_totals.plot(kind="bar", ax=ax)
    ax.set_ylabel("Amount")
    st.pyplot(fig)

    
    st.subheader("Category Distribution")
    fig2, ax2 = plt.subplots()
    category_totals.plot(kind="pie", autopct="%1.1f%%", ax=ax2)
    st.pyplot(fig2)

What is happening here:

  1. Form input with smart forecasts

    • Consumers enter history, detail and money.

    • As soon as you type “Netflix Subscript”, LLM Auto Siggists Recreation.

  2. Storing costs in CSV file

    • Every new entry has been saved in the back expense_data_1.csvSo when you restart the app, your date does not end.
  3. Interactive Dashboard

Run File:

The picture is showing how to drive your streamlit app

Output:

The streamlit costs displayed with fields for the date, detail, money, and auto forecast category shows a picture of the tracker app, followed by a table of recorded expenses, and the chart category.

Conclusion

There is a practical way to collect data, concept and AI aid in a single interactive application. In addition to logging in entries, we integrated the LLM -powered feature in the self -forecast cost, making it easy for users who prefer not to tag each transaction manually.

This project shows how tools, including interactivity, panda for data processing, and LLMS for intelligent predictions, can be found in a simple but powerful way for intelligent predictions. Whether for personal use or as a portfolio project, this tracker shows how machine learning and data science skills can be applied to real -world use issues that make life easier.

You may also like

Leave a Comment

At Skillainest, we believe the future belongs to those who embrace AI, upgrade their skills, and stay ahead of the curve.

Get latest news

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

@2025 Skillainest.Designed and Developed by Pro