AI Food & Calories Recognition — Astrolab internship: meal photo -> food + calories/macros. ViT Food-101 + own fine-tuned Tunisian model. Live demo on Netlify + HF Space.
# AI Food & Calories Recognition
Upload one meal photo → the dominant food is identified (ViT fine-tuned on Food-101, 101 classes) → you get estimated **calories + protein/carbs/fat** for an adjustable portion. Built as a 4-week internship project at **Astrolab Group**, delivered demo-grade: no accounts, no stored user data.
> **Estimates only — not medical or dietary advice.** Every nutrition value is an average for a typical preparation of that dish.
## How it works
```
Browser (React + TS + Tailwind) Flask API (Python)
┌─────────────────────────────┐ multipart ┌──────────────────────────────┐
│ drag-drop / picker upload │──────────────▶│ POST /api/analyze │
│ preview + Replace │ │ ├─ validate type/size │
│ result screen │◀──────────────│ ├─ ViT nateraw/food (top-3) │
│ ├─ food + confidence badge │ JSON │ ├─ confidence policy │
│ ├─ kcal + 3 macro cards │ │ │ ≥0.70 ok │
│ ├─ portion S/M/L + grams │ │ │ 0.35–0.70 low_conf │
│ │ (client-side rescale) │ │ │ │
│ GET /api/health │
└───────────┬──────────────────┘
data/foods.json (names+aliases)
data/nutrition_table.json
(per-100g macros, 101 classes)
```
Portion math: values are stored **per 100 g**; the UI rescales linearly on the client (`grams / 100 × per_100g`), so portion changes cost zero requests. Presets small/medium/large = 0.7 / 1.0 / 1.4 × each food's default portion.
## Run locally
Backend (Python 3.11 venv):
```bash
python -m venv .venv && .venv/Scripts/pip install --index-url
download.pytorch.org torch && .venv/Scripts/pip install -r backend/requirements.txt
```
```bash
.venv/Scripts/python backend/app.py
```
Frontend (dev, hot reload — proxies `/api` to :8000):
```bash
cd frontend && npm install && npm run dev
```
Or one URL (build once, Flask serves it): `cd frontend && npm run buil …