Automating Grocery Expense Tracking with AI Vision

Here is a quick little project I made, again using GPTV. This time I wanted to know how much we spent on food for a month. 
Normally one would type in all the food items in an excel spreadsheet and then do all the calculations manually, but how has time for that. As the saying goes, why do something manually in 1 hour when it can take you 10 hours to automate! But at least I had fun doing it. 

The idea behind this project was to input all the till slips and have GPT only extract the food items from the slip. With other OCR applications it would extract ALL the text from the slips regardless if it was the total, a toilet brush or the date. Then one still needed to manually sort through all the data to only extract the food items. Using GPT I could do this in one go as GPT knows what is food and what is not. 
I recall resting it manually on a slip where we bought flowers and GPT noted that all the other items was food except for the flowers on the slip. That catch was that id did not say flowers it had the proper scientific name on the slip and GPT could still identify it and not add the item to the food list. 

I started off by taking a photo of each of the slips and saving it in a folder.

I then made a quick script to feed each image to GPTVision telling it to only extract the food items from the list, ignoring anything else. this it seemed to do very well. The script saved an CSV file for each image so that I could better troubleshoot (yes.. there where a few bugs) and then rename the image to “_done” so that if I ran the script again it would not reprocess the same image more than once. Tokens cost money you know! 

Once done I ended up with a CSV file for each of the slip images.

 

All I had to do then was to use another little script to combine all the CSV files and give me the total. 

But wait, we are not done yet! I then copied the new CSV file with all the items and asked CLAUDE to split them into categories so we know how much we spent on, drinks vs vegetables for example. Sometimes the new version of CLAUDE can understand me better than GPT. GPT might also not like me anymore after all the horrible things I called it when it did not do what I wanted, who knows. 

 

I might just put all this onto one script next time to automate this process even more, but we will see how I feel during next month’s audit. 

Below is the github link to the two script I used: