A system that automatically analyzes your food photos from Google Photos and provides nutritional summaries.
Food Tracker connects to your Google Photos account, retrieves images that contain food, and uses AI vision models to analyze nutritional content. It runs as a scheduled task to give you weekly summaries of your eating habits.
- Google Photos Integration: Automatically retrieves your food photos
- AI-Powered Analysis: Uses GPT-4o or Claude to identify food items and estimate nutritional content
- Scheduled Reports: Runs as a weekly cron job to track your eating patterns
- Nutritional Insights: Provides calories, macronutrients, and vitamin/mineral information
- Multi-Model Support: Works with both OpenAI and Anthropic vision models
- Python 3.10+
- Poetry for dependency management
- Google Photos API credentials
- OpenAI API key and/or Anthropic API key
- Clone this repository
- Install dependencies:
poetry install
- Set up Google Photos API:
- Go to the Google Cloud Console
- Create a new project (or select an existing one)
- Navigate to "APIs & Services" > "Library"
- Search for "Google Photos Library API" and enable it
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Configure the OAuth consent screen:
- Set User Type to "External"
- Fill in the required application information
- Add the scope "https://www.googleapis.com/auth/photoslibrary.readonly"
- Add your email as a test user
- Create OAuth client ID:
- Select "Desktop app" as the application type
- Name your client
- Download the JSON file and rename it to
credentials.json
- Place the credentials.json file in the project's root directory
- Configure environment variables in
.env
:
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
DEFAULT_PROVIDER=openai # or anthropic
GOOGLE_CREDENTIALS_FILE=credentials.json
poetry run python scripts/google_photos_auth.py
This will:
- Open a browser window to authenticate with Google Photos
- Prompt you to log in and grant the necessary permissions
- Create a token.pickle file to store your credentials
- Test the connection by listing your recent photos
If you encounter authentication issues:
- Make sure you've completed all the Google Cloud Console setup steps
- Verify that your credentials.json file is in the project's root directory
- Check that you've added yourself as a test user in the OAuth consent screen
- Ensure the correct scope is enabled (photoslibrary.readonly)
poetry run python scripts/download-test-images.py
This will download sample food and non-food images to the test_images directory.
There are multiple options for running the analyzer:
poetry run python scripts/food_tracker_poc.py
poetry run python scripts/food_tracker.py
poetry run python scripts/food_tracker_async.py
Add to your crontab to run weekly:
0 9 * * 1 cd /path/to/food_tracker && poetry run python scripts/food_tracker.py
Alternatively, you can use the provided shell script:
Make the script executable
chmod +x scripts/run_food_tracker.sh
Edit the script to update the path to your project directory
nano scripts/run_food_tracker.sh
Add to crontab
0 9 * * 0 /path/to/food_tracker/scripts/run_food_tracker.sh
scripts/food_tracker.py
: Main analysis script (cached version with schema validation)scripts/food_tracker_async.py
: Asynchronous version for improved performancescripts/download-test-images.py
: Utility to download test imagesscripts/google_photos_auth.py
: Google Photos API authentication scriptscripts/photo_retriever.py
: Utility to retrieve photos from Google Photosscripts/run_food_tracker.sh
: Shell script for scheduled executioncredentials.json
: Google Cloud OAuth credentials (you must create this)token.pickle
: Stored Google Photos authentication token (created automatically)test_images/
: Directory of sample food and non-food imagesretrieved_photos/
: Directory where photos from Google Photos are savedanalysis_results/
: Output JSON and CSV files with analysis resultsapi_cache/
: Cache of API responses to minimize redundant API calls.env
: Environment variables configuration file (you must create this)
- Error: "credentials.json not found": Make sure you've downloaded the OAuth credentials from Google Cloud Console and placed them in the project root.
- Error: "Invalid client secrets file": The credentials.json file might be corrupt or have incorrect format. Try re-downloading it.
- Error: "Access denied": Ensure you've added yourself as a test user in the OAuth consent screen.
- Error: "Insufficient permissions": Verify that you've enabled the correct scope (photoslibrary.readonly).
- OpenAI API errors: Check that your OPENAI_API_KEY is valid and has sufficient quota.
- Anthropic API errors: Verify your ANTHROPIC_API_KEY is correct and active.
- If you encounter module import errors, make sure you're running the scripts using Poetry:
poetry run python scripts/script_name.py
- If the scripts aren't finding photos, check that the paths are correct and that you have permissions to access the directories.
- Make sure you're using Python 3.10+:
python -V
- Install Poetry if you haven't already: Poetry Installation Guide
- Set up the virtual environment:
poetry env use python3.10
- Install dependencies:
poetry install
- Format code:
poetry run black .
- Run tests:
poetry run pytest
- Activate the virtual environment for development:
poetry shell
- Set up Google Photos authentication first:
poetry run python scripts/google_photos_auth.py
- Download test images:
poetry run python scripts/download-test-images.py
- Run the analyzer in development mode:
poetry run python scripts/food_tracker.py
- Check the results in the
analysis_results/
directory
- Implement Google Photos API authentication
- Build food photo filtering and retrieval from Google Photos
- Implement basic food analysis with vision models
- Improve food recognition accuracy
- Add nutritional trends and insights
- Build weekly summary report generation
- Add visualization of eating patterns over time
- Create user dashboard for viewing results
- Support dietary restrictions and goals