AI Nutrition Coach is a small Flask web app that analyzes a food image and returns a structured nutrition summary. It uses a local multimodal model served by Ollama, so the app can run without external paid APIs.
The app lets a user:
- upload a food image
- ask a question about that image
- get an estimated calorie and nutrient breakdown
- read a formatted response directly in the browser
The current model backend is gemma3:4b through Ollama's local /api/chat endpoint.
This project intentionally keeps the stack small:
Flask: web server, routing, templates, and flash messagesrequests: HTTP client used to call the local Ollama APIbase64: built-in Python module used to encode uploaded imagesre: built-in Python module used to format model output into HTMLos: built-in Python module used for environment-based configuration
The application flow is organized in the same high-level structure used in app.py:
- Flask app setup
- Ollama client and model configuration
- Uploaded image encoding
- Response formatting
- Model inference through chat messages with image input
When a user submits the form, the app:
- reads the uploaded image
- converts it to base64
- sends the prompt, question, and image to Ollama
- formats the returned text into HTML for display
Install Python dependencies:
uv syncPull the Ollama model:
ollama pull gemma3:4bStart Ollama:
ollama serveRun the app:
uv run app.pyThen open:
http://127.0.0.1:5000
The app supports these environment variables:
OLLAMA_URL: overrides the Ollama server URLFLASK_SECRET_KEY: sets the Flask secret key
Example:
export OLLAMA_URL=http://127.0.0.1:11434
export FLASK_SECRET_KEY=change-me
uv run app.py.
├── app.py
├── assets/
│ └── app.png
├── pyproject.toml
├── static/
│ └── style.css
└── templates/
└── index.html
- The calorie and nutrient estimates are approximate.
- Response quality depends on the image quality and the local model.
- The app is configured for development and runs with Flask debug mode enabled.
