Welcome to Receipt Lens!
This project is a powerful, AI-driven web application that lets you scan receipts with your camera, automatically extract all the details, and save them into a structured Google Sheet. It's a fully-featured expense tracker built to be modern, easy to use, and completely free to run.
This project has been a fantastic learning experience, full of twists, turns, and pivots.
My original ambition was to build an AI agent in the cloud. A mobile app would upload receipt images to Google Cloud Storage, triggering a Cloud Function or Cloud Run service. This backend would process the image using Gemini AI, extract data, and save it to Google Sheets. A perfect server-side architecture.
Despite completing the architecture and code, I hit a major hurdle — Google Cloud required billing to be enabled, even within the free tier. My goal was zero-cost deployment without sharing payment details, so I had to rethink everything.
Instead of giving up, I pivoted.
"What if I eliminate the backend entirely?"
This led me to a 100% client-side solution. The browser itself would handle everything — image capture, AI communication, and data storage — directly via JavaScript.
After rounds of coding, debugging, and UI tuning, Receipt Lens was born — a single HTML file app you can host for free (e.g., GitHub Pages). It’s a testament to the power of modern web browsers.
This app combines several cutting-edge web technologies:
Built entirely with HTML and styled using Tailwind CSS for a sleek, responsive UI — no separate CSS files needed.
Using navigator.mediaDevices.getUserMedia API to securely access your device's camera to scan receipts.
Captured images are converted into Base64 strings and sent to the Gemini 1.5 Flash model via REST API. A well-engineered prompt returns structured JSON data from the receipt.
The structured data is appended directly to a Google Sheet via the Sheets API, enabling real-time expense logging.
A small Apps Script runs on every update. It merges related cells (vendor, date, totals) into a clean, readable format.
- Go to Google Cloud Console.
- Click the project dropdown → "New Project".
- Name your project (e.g., "My Receipt Scanner") → Create.
Click Enable for each.
- Go to Google AI Studio.
- Click "Create API key in new project".
- Copy and save it.
- Visit Google Cloud Credentials page.
- Click + CREATE CREDENTIALS → OAuth client ID.
- Select "Web application" and name it.
- Under Authorized JavaScript origins, add:
http://localhost:8000for local use.- Your live site URL if deploying (e.g.,
https://your-username.github.io).
- Click Create, and save the Client ID.
- Go to OAuth consent screen in Cloud Console.
- Choose External → Create.
- Fill required fields (App name, support email, etc.).
- Click Save and Continue through all sections.
- Under Test users, add your testing Google account.
- Create a new Google Sheet.
- Rename the first tab to:
Receipt - Add these exact headers to Row 1:
Photo Timestamp, Transaction ID, Vendor, Transaction Date, Transaction Time, Payment Type, Item Description, Quantity, Unit Price, Subtotal, Tax, Grand Total - Copy the Spreadsheet ID from the URL and save it.
- In the Sheet, go to Extensions → Apps Script.
- Delete any code in
Code.gs. - Paste code from the
apps-script.jsfile in this repo. - Save the project.
- Download the
index.htmlfile from this repo. - Open in a text editor.
- Inside the
<script>tag, set:const CLIENT_ID = "YOUR_CLIENT_ID"; const GEMINI_API_KEY = "YOUR_API_KEY"; const SPREADSHEET_ID = "YOUR_SPREADSHEET_ID";
- Save the file.
- To run locally:
python -m http.server 8000
- Open http://localhost:8000 in your browser.
You now have a serverless, AI-powered, privacy-respecting expense tracker — all in your browser, running for free.