A comprehensive system for analyzing patient eating patterns and nutritional intake using Fetch.ai agents, Supabase storage, and Gemini Vision API.
This system provides healthcare professionals with detailed analysis of patient meal patterns, including:
- Eating Pattern Analysis: Regular vs irregular eating schedules
- Nutritional Assessment: Calorie intake, food categories, portion analysis
- Professional Recommendations: Evidence-based suggestions for nutritionists/doctors
- Historical Data: Analysis of all stored meal images
Spectacles AR β Storage Agent β Analysis Agent β Frontend Web App
β β β β
Image Capture Supabase Upload Gemini Analysis Doctor Dashboard
- Storage Agent (
storage_agent.py) - Handles image uploads to Supabase - Analysis Agent (
nutrition_analysis_agent.py) - Performs comprehensive analysis - Frontend Web App (
nutrition_frontend.py) - Professional dashboard - Batch Upload (
upload_assets_folder.py) - Uploads multiple images
- Python 3.11+
- Supabase account and project
- Gemini API key
- Fetch.ai Agentverse account
Create .env file:
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your-anon-public-key
GEMINI_API_KEY=your-gemini-api-keycd backend
pip install -r requirements.txtRun this SQL in Supabase SQL Editor:
-- Create meal_images table
CREATE TABLE meal_images (
id SERIAL PRIMARY KEY,
session_id TEXT NOT NULL,
frame_id TEXT NOT NULL,
file_path TEXT NOT NULL,
url TEXT NOT NULL,
uploaded_at BIGINT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Disable RLS for testing
ALTER TABLE meal_images DISABLE ROW LEVEL SECURITY;
-- Create storage bucket
-- Go to Storage β Create bucket: "meals" (set to public)python setup_and_run.pypython setup_and_run.py
# Choose option 4 to run everythingpython upload_assets_folder.py- Uploads all images from
assets/folder - 30-second intervals between uploads
- Creates session tracking
python nutrition_analysis_agent.py- Runs on port 8003
- Provides REST API for analysis
- Integrates with Gemini Vision API
python nutrition_frontend.py- Runs on port 5000
- Professional dashboard for healthcare workers
- Access at: http://127.0.0.1:5000
- Meal Frequency: Number of meals per day
- Timing Patterns: Regular vs irregular eating schedules
- Consumption Patterns: Portion sizes and eating pace
- Interval Analysis: Time between meals
- Food Identification: AI-powered food recognition
- Calorie Estimation: Estimated caloric intake per meal
- Food Categories: Protein, carbs, vegetables, etc.
- Portion Analysis: Consumption percentage per meal
- Eating Schedule: Suggestions for regular meal timing
- Portion Control: Recommendations for appropriate serving sizes
- Nutritional Balance: Advice on food variety and nutrients
- Behavioral Patterns: Insights into eating habits
- Patient Analysis: Enter patient ID and date range
- Real-time Results: Live analysis of stored images
- Professional Interface: Designed for healthcare workers
- Comprehensive Reports: Detailed eating pattern analysis
- Open http://127.0.0.1:5000
- Enter patient ID
- Select date range (optional)
- Choose analysis type
- View comprehensive results
POST /analyze- Analyze patient dataGET /health- Health check
GET /- Main dashboardPOST /analyze_patient- Patient analysis requestGET /health- System health check
- Storage Agent: Port 8001
- Analysis Agent: Port 8003
- Frontend: Port 5000
- Bucket: "meals" (public access)
- Table: "meal_images"
- RLS: Disabled for testing
- Model: gemini-2.0-flash-exp
- Analysis: Food recognition and nutritional assessment
# Test Supabase upload
python test_supabase_upload.py
# Test custom image analysis
python upload_custom_image.py
# Query uploaded data
python query_uploads.py- Upload images using batch script
- Start analysis agent
- Start frontend
- Access dashboard and run analysis
backend/
βββ storage_agent.py # Storage Agent
βββ nutrition_analysis_agent.py # Analysis Agent
βββ nutrition_frontend.py # Flask Frontend
βββ upload_assets_folder.py # Batch Upload
βββ test.py # Core Analysis Logic
βββ templates/
β βββ nutrition_dashboard.html # Web Interface
βββ assets/ # Image Storage
βββ requirements.txt # Dependencies
βββ setup_and_run.py # Setup Script
βββ .env # Environment Variables
-
Supabase Upload Fails
- Check bucket exists and is public
- Verify SUPABASE_URL and SUPABASE_KEY
- Disable RLS:
ALTER TABLE meal_images DISABLE ROW LEVEL SECURITY;
-
Gemini Analysis Fails
- Verify GEMINI_API_KEY in .env
- Check API quota and limits
- Ensure images are accessible via URL
-
Agent Communication Issues
- Check agent addresses and ports
- Verify all agents are running
- Check network connectivity
-
Frontend Not Loading
- Ensure Flask is installed
- Check port 5000 is available
- Verify analysis agent is running
β Fetch.ai Agentverse Integration: Agents registered and deployed β Chat Protocol: All agents use Fetch.ai messaging β LLM Integration: Gemini Vision API for food analysis β Real-world Actions: File uploads, database operations, API calls β Professional Interface: Web dashboard for healthcare workers β Multi-agent Architecture: Specialized agents for different tasks β External API Integration: Supabase, Gemini, Flask
For issues or questions:
- Check troubleshooting section
- Verify all dependencies are installed
- Ensure .env file is properly configured
- Check Supabase and Gemini API access
- Complete Fetch.ai Integration: Pure chat protocols, no REST endpoints
- Professional Healthcare Interface: Designed for nutritionists/doctors
- Comprehensive Analysis: Eating patterns, nutritional assessment, recommendations
- Scalable Architecture: Microservices with specialized agents
- Real-world Application: Solving eating disorder support challenges