Spaces:
Sleeping
Download docs/API.md from darshhh32/nutrivision-ai: direct link, hf CLI and curl.
- Browser
- Download file 3.36 kB
-
https://huggingface.co/spaces/darshhh32/nutrivision-ai/resolve/main/docs/API.md
- Command line
-
hf download hf://spaces/darshhh32/nutrivision-ai/docs/API.md
-
curl -L -o API.md https://huggingface.co/spaces/darshhh32/nutrivision-ai/resolve/main/docs/API.md
API Reference
Base URL: http://localhost:8000 · API prefix: /api/v1 · Interactive docs: /docs
All responses are JSON unless noted. Errors use standard HTTP status codes with
a {"detail": "..."} body.
Meta
GET /
Landing info (name, version, docs link).
GET /health
{ "status": "ok", "version": "1.0.0", "model_loaded": false, "database": "sqlite" }
Analysis
POST /api/v1/analyze
Analyse a meal image end-to-end. multipart/form-data.
| Field | Type | Default | Description |
|---|---|---|---|
file |
file | — | Meal image (JPEG/PNG/…) required |
school_name |
str | — | School name (for analytics) |
district |
str | — | District |
category |
str | primary |
Compliance standard key |
assess_freshness |
bool | true |
Run freshness assessment |
include_image |
bool | true |
Return annotated image (base64 PNG) |
store |
bool | true |
Persist to the database |
generate_report |
bool | false |
Also create a PDF report |
Response (AnalyzeResponse, abridged):
{
"image_size": {"width": 640, "height": 640},
"num_items": 4,
"detections": [{"class_id": 0, "food_item": "rice", "confidence": 0.92, "bbox": [50,300,300,600]}],
"meal": {"num_items": 4, "items": [ ... ], "totals": {"calories": 556.5, "protein_g": 23.2, ...}},
"macro_distribution": {"protein": 15.1, "carbohydrates": 63.7, "fat": 21.2},
"daily_values": {"calories": 27.8, "protein_g": 58.0, ...},
"compliance": {"status": "Compliant", "calorie_pct": 123.7, "recommendations": ["..."], ...},
"quality": {"assessed": true, "items_flagged": 0, "min_freshness_score": 0.91},
"annotated_image": "<base64 PNG>",
"analysis_id": 12,
"report_available": true
}
Errors: 400 empty/invalid image · 413 too large · 503 ML stack missing.
Example:
curl -F "file=@meal.jpg" -F "category=primary" -F "generate_report=true" \
http://localhost:8000/api/v1/analyze
POST /api/v1/nutrition/analyze
Compute nutrition + compliance from detections only (no image). JSON body:
{
"detections": [{"food_item": "rice", "confidence": 0.9}, {"food_item": "dal"}],
"image_width": 640, "image_height": 640, "category": "primary"
}
Returns meal, compliance, macro_distribution, daily_values.
422 if none of the items are in the nutrition database.
Nutrition reference
GET /api/v1/foods
List every food in the nutrition database with per-100 g values.
GET /api/v1/compliance-standards
[{"key": "primary", "label": "Primary (Class I-V)", "calories": 450, "protein_g": 12}, ...]
History & statistics
GET /api/v1/history?limit=50&offset=0&school_name=...
List stored analyses (most recent first).
GET /api/v1/history/{id}
Full stored analysis including all detected items. 404 if not found.
DELETE /api/v1/history/{id}
Delete an analysis (cascades to items).
GET /api/v1/stats
Aggregate analytics: totals, compliance rate, averages, by_status,
by_school, top_foods.
Reports
GET /api/v1/reports/{id}
Download the PDF report for an analysis (application/pdf). 404 if none.
POST /api/v1/reports/{id}/generate
(Re)generate the PDF for a stored analysis; returns a download_url.