AI-Powered Calorie Tracker with Local Food Recognition
Cal AI is a full-stack calorie tracking web application that uses a locally-running AI model to recognize food from images. Simply snap a photo of your meal, and the app identifies the food, estimates nutritional values, and logs it to your daily tracker β all without sending your data to any external AI service.
- π€ Local AI Model β Food recognition runs on your machine via a ViT (Vision Transformer) model trained on Food-101. No cloud API keys needed for scanning.
- πΈ Snap & Scan β Take a photo or upload an image to instantly classify food and get nutritional breakdown.
- βοΈ Adjustable Portions β Slide to set portion size (25gβ800g) and watch macro values recalculate live.
- π Dashboard & Progress β Track daily calories, macros, weight trends, and streaks with smooth animated charts.
- π Supabase Auth β Secure email-based authentication with Row Level Security.
- π± Mobile-First Design β Optimized for phones with bottom navigation, swipeable calendars, and touch-friendly interactions.
- Camera capture or image upload for food recognition
- Text search β type a food name (e.g., "pizza", "sushi") for quick lookup against 101 food categories
- AI confidence score displayed for each classification
- Portion size slider (25gβ800g) with live macro recalculation
- Editable results β adjust food name, ingredients, and individual macro values before logging
- Daily macro rings β visual progress for Calories, Protein, Carbs, and Fat
- Swipeable weekly calendar β tap any day to view that day's meals
- Monthly heatmap view β see goal adherence at a glance (green = met goal, red = exceeded)
- Meal cards β view, edit, or delete logged meals with inline editing
- Weight tracking chart β interactive line chart with 7D/30D/60D/90D timeframes
- Streak counter β consecutive days of meal logging
- Weight logging modal β quick weight entry with unit preference (lbs/kg)
- Avatar upload β profile photo with Supabase Storage
- Personal details β name, weight, goal weight, unit preference
- Daily goals β customizable targets for calories, protein, carbs, and fat
| Layer | Technology |
|---|---|
| Frontend | Next.js 16, React 19, TypeScript |
| Styling | Tailwind CSS 4 |
| Animations | Framer Motion |
| Charts | Recharts |
| Icons | Lucide React |
| Auth & Database | Supabase (PostgreSQL + Auth + Storage) |
| AI Model | PyTorch + HuggingFace Transformers (nateraw/food β ViT on Food-101) |
| Model Server | Python Flask |
| Nutritional Data | Bundled JSON database (101 food categories, per-100g macros) |
calorie_tracker_webapp/
βββ src/
β βββ app/
β β βββ page.tsx # Landing/splash page
β β βββ layout.tsx # Root layout
β β βββ globals.css # Global styles
β β βββ auth/ # Authentication page
β β βββ actions/
β β β βββ scan.ts # Server actions (calls model API)
β β βββ (app)/ # Authenticated app routes
β β βββ layout.tsx # App layout (header + nav)
β β βββ home/page.tsx # Dashboard
β β βββ scan/page.tsx # Food scanner
β β βββ progress/page.tsx # Weight & progress charts
β β βββ profile/page.tsx # User profile & settings
β βββ components/
β β βββ ui/ # Reusable UI components
β β βββ layout/ # Navigation components
β β βββ auth/ # Auth components
β β βββ shared/ # Shared components
β βββ lib/
β βββ supabase.ts # Supabase client
β βββ utils.ts # Utility functions
βββ food-recognition-model/
β βββ server.py # Flask API server
β βββ requirements.txt # Python dependencies
β βββ config.json # Model configuration
β βββ nutritional_database.json # 101 food categories (per-100g macros)
β βββ classification_model.h5 # Model reference
βββ supabase/
β βββ schema.sql # Database schema + RLS policies
βββ start.sh # One-command startup script
βββ .env.example # Environment template
βββ package.json # Node dependencies
- Node.js β₯ 18
- Python β₯ 3.10
- Supabase account (free tier works)
git clone https://github.com/your-username/calorie_tracker_webapp.git
cd calorie_tracker_webapp
npm install- Create a new project at supabase.com
- Run the SQL from
supabase/schema.sqlin the Supabase SQL Editor - Copy your project URL and anon key
cp .env.example .envEdit .env with your Supabase credentials:
NEXT_PUBLIC_SUPABASE_URL="https://your-project.supabase.co"
NEXT_PUBLIC_SUPABASE_ANON_KEY="your-anon-key"
FOOD_MODEL_URL=http://localhost:5001cd food-recognition-model
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtNote: The first run downloads the ViT model (~350 MB). After that, it loads from cache instantly.
Option A β Single command (recommended):
./start.shThis starts both servers concurrently and handles cleanup on Ctrl+C.
Option B β Manual (two terminals):
# Terminal 1 β AI Model Server
cd food-recognition-model
source venv/bin/activate
python server.py
# Terminal 2 β Next.js
npm run devNavigate to http://localhost:3000 in your browser.
The Python model server runs at http://localhost:5001:
| Endpoint | Method | Description |
|---|---|---|
/api/health |
GET | Health check β returns model status and food count |
/api/classify |
POST | Image classification β accepts multipart/form-data with image field |
/api/classify-text |
POST | Text search β accepts JSON {"text": "pizza"} |
{
"food_name": "Pizza",
"calories": 500,
"protein": 24,
"carbs": 60,
"fat": 20,
"portion_grams": 200,
"confidence": 94.2,
"per_100g": {
"calories": 250,
"protein": 12.0,
"carbs": 30.0,
"fat": 10.0
},
"ingredients": [
{ "name": "Pizza", "calories": 500, "protein": 24, "carbs": 60, "fat": 20 }
],
"all_predictions": [
{ "label": "Pizza", "confidence": 94.2 },
{ "label": "Bruschetta", "confidence": 2.1 }
]
}The app uses three main tables in Supabase:
profiles meals weight_logs
βββ id (UUID) βββ id (UUID) βββ id (UUID)
βββ display_name βββ user_id (FK) βββ user_id (FK)
βββ weight βββ food_name βββ weight
βββ goal_weight βββ calories βββ logged_date
βββ daily_*_goal βββ protein
βββ avatar_url βββ carbs
βββ fat
βββ ingredients
βββ image_url
βββ created_at
All tables use Row Level Security (RLS) β users can only access their own data.
The model recognizes 101 food categories from the Food-101 dataset, including:
View all 101 categories
| Apple Pie | Baby Back Ribs | Baklava | Beef Carpaccio |
| Beef Tartare | Beet Salad | Beignets | Bibimbap |
| Bread Pudding | Breakfast Burrito | Bruschetta | Caesar Salad |
| Cannoli | Caprese Salad | Cappuccino | Carrot Cake |
| Ceviche | Cheesecake | Cheese Plate | Chicken Curry |
| Chicken Quesadilla | Chicken Wings | Chocolate Cake | Chocolate Mousse |
| Churros | Clam Chowder | Club Sandwich | Crab Cakes |
| Crème Brûlée | Croque Madame | Cupcakes | Deviled Eggs |
| Donuts | Dumplings | Eggs Benedict | Escargots |
| Falafel | Filet Mignon | Fish And Chips | Foie Gras |
| French Fries | French Onion Soup | French Toast | Fried Calamari |
| Fried Rice | Frozen Yogurt | Garlic Bread | Gnocchi |
| Greek Salad | Grilled Cheese Sandwich | Grilled Salmon | Guacamole |
| Gyoza | Hamburger | Hot And Sour Soup | Hot Dog |
| Huevos Rancheros | Hummus | Ice Cream | Lasagna |
| Lobster Bisque | Lobster Roll Sandwich | Macaroni And Cheese | Macarons |
| Miso Soup | Mussels | Nachos | Omelette |
| Onion Rings | Oysters | Pad Thai | Paella |
| Pancakes | Panna Cotta | Peking Duck | Pho |
| Pizza | Pork Chop | Poutine | Prime Rib |
| Pulled Pork Sandwich | Ramen | Ravioli | Red Velvet Cake |
| Risotto | Samosa | Sashimi | Scallops |
| Seaweed Salad | Shrimp And Grits | Spaghetti Bolognese | Spaghetti Carbonara |
| Spring Rolls | Steak | Strawberry Shortcake | Sushi |
| Tacos | Takoyaki | Tiramisu | Tuna Tartare |
| Waffles |
MIT
Built with β€οΈ by Anvesh Mishra