Skip to content

SimoneFiorellino/cal_coach_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Nutrition Coach

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.

App screenshot

Overview

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.

Libraries

This project intentionally keeps the stack small:

  • Flask: web server, routing, templates, and flash messages
  • requests: HTTP client used to call the local Ollama API
  • base64: built-in Python module used to encode uploaded images
  • re: built-in Python module used to format model output into HTML
  • os: built-in Python module used for environment-based configuration

How It Works

The application flow is organized in the same high-level structure used in app.py:

  1. Flask app setup
  2. Ollama client and model configuration
  3. Uploaded image encoding
  4. Response formatting
  5. Model inference through chat messages with image input

When a user submits the form, the app:

  1. reads the uploaded image
  2. converts it to base64
  3. sends the prompt, question, and image to Ollama
  4. formats the returned text into HTML for display

Requirements

  • Python 3.11+
  • uv or pip
  • Ollama
  • the local model gemma3:4b

Setup

Install Python dependencies:

uv sync

Pull the Ollama model:

ollama pull gemma3:4b

Start Ollama:

ollama serve

Run the app:

uv run app.py

Then open:

http://127.0.0.1:5000

Configuration

The app supports these environment variables:

  • OLLAMA_URL: overrides the Ollama server URL
  • FLASK_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

Project Structure

.
├── app.py
├── assets/
│   └── app.png
├── pyproject.toml
├── static/
│   └── style.css
└── templates/
    └── index.html

Notes

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors