A Python tool that processes InBody body composition scan images using OpenAI GPT Vision to extract structured data and store it in a local SQLite database. Now includes a PDF Report Generator for beautiful progress tracking!
- AI-powered text extraction: Uses OpenAI GPT-4 Vision to analyze InBody scan images
- Unified data model: Combines data from different InBody machine models into a single schema
- Smart caching: Avoids reprocessing the same images using SHA-256 file hashes
- SQLite storage: Stores all extracted data in a local SQLite database
- Multi-language support: Handles InBody scans in different languages (English, Polish, etc.)
- Structured output: Uses JSON schema validation for consistent data extraction
- Batch processing: Process entire folders of images at once
- Export functionality: Export results to JSON for analysis
- π Beautiful Charts: Generate colorful progress reports with multiple chart types
- π Time Range Filtering: Create reports for any date range (entire history by default)
- π¨ Professional Design: High-quality PDF reports with modern styling
- π‘ Smart Insights: Automatic analysis of your fitness progress and achievements
- π§ Multiple Interfaces: Both command-line tool and Python API
- π Comprehensive Analysis: Weight, body composition, health metrics, and segmental analysis
-
Clone the repository:
git clone <repository-url> cd inbody-to-sqlite
-
Install dependencies using UV:
uv sync
-
Set up environment variables:
cp .env.example .env # Edit .env and add your OpenAI API key
You need an OpenAI API key to use GPT-4 Vision. Get one from OpenAI Platform.
Create a .env file:
OPENAI_API_KEY=your-api-key-hereProcess a folder of InBody images:
python -m inbody_to_sqlite /path/to/imagesGenerate beautiful progress reports from your processed data:
# Generate a complete report
uv run python -m inbody_reports
# Custom report with title and filename
uv run python -m inbody_reports --output "my_fitness_journey.pdf" --title "My Progress Report"
# Report for specific date range
uv run python -m inbody_reports --start-date 2024-01-01 --end-date 2024-12-31
# Check available data
uv run python -m inbody_reports --list-data-rangeOptions:
--force: Reprocess images even if already cached--export: Export results to JSON after processing--export-only: Only export existing results, don't process new images
Examples:
# Process all images in a folder
python -m inbody_to_sqlite ./my_inbody_scans
# Force reprocess all images and export results
python -m inbody_to_sqlite ./my_inbody_scans --force --export
# Export existing results only
python -m inbody_to_sqlite ./my_inbody_scans --export-onlyfrom inbody_to_sqlite.main import InBodyProcessor
# Initialize processor
processor = InBodyProcessor(api_key="your-api-key")
# Process a folder
stats = processor.process_folder("/path/to/images")
# Export results
output_file = processor.export_results()from inbody_reports import InBodyReportGenerator
from datetime import datetime, timedelta
# Initialize report generator
generator = InBodyReportGenerator('inbody_results.db')
# Generate complete report
report_path = generator.generate_report(
output_path="progress_report.pdf",
title="My Fitness Journey"
)
# Generate report for specific time range
six_months_ago = datetime.now() - timedelta(days=180)
recent_report = generator.generate_report(
start_date=six_months_ago,
title="Recent Progress"
)The tool extracts and unifies the following data from InBody scans:
- scan_date: Date and time of the scan
- height: Height in cm
- weight: Weight in kg
- age: Age in years
- gender: Gender (Male/Female)
- muscle_mass: Total muscle mass in kg
- body_fat_mass: Total body fat mass in kg
- body_fat_percentage: Body fat percentage
- total_body_water: Total body water in liters
- fat_free_mass: Fat-free mass in kg
- bmi: Body Mass Index
- bmr: Basal Metabolic Rate in kcal
- visceral_fat_level: Visceral fat level
- pbf: Percent body fat
- whr: Waist-hip ratio
- inbody_score: InBody score
- fitness_score: Fitness score
- muscle_control: Muscle control recommendation in kg
- fat_control: Fat control recommendation in kg
- segmental: Body part analysis for arms, trunk, and legs
- Lean mass for each body part
- Fat mass for each body part
The tool creates two main tables:
- Tracks which images have been processed
- Stores file hash for cache validation
- Records processing success/failure
- Stores extracted InBody data
- Links to processed images via file hash
- Contains all the structured data fields
- JPEG (.jpg, .jpeg)
- PNG (.png)
- BMP (.bmp)
- TIFF (.tiff)
- WebP (.webp)
The tool has been tested with multiple InBody models and handles:
- Different languages (English, Polish, etc.)
- Varying data layouts
The new report generator creates comprehensive PDF reports with:
- Weight Progression: Timeline with trend analysis
- Body Composition: Muscle vs fat mass over time
- Health Metrics: BMI, BMR, visceral fat levels
- Segmental Analysis: Body part measurements
- Progress Dashboard: Key metrics overview
- Before/After Comparison: First vs latest scans
- Summary Dashboard - Key progress indicators
- Weight Progression - Detailed weight analysis with trends
- Body Composition - Muscle and fat mass changes
- Health Metrics - BMI, BMR, visceral fat tracking
- Progress Comparison - First vs latest scan analysis
- Segmental Analysis - Body part distribution
- Insights & Recommendations - AI-generated progress insights
Your reports will show insights like:
- π Weight decreased by 17.6kg over 773 days
- πͺ Body fat decreased by 14.0% - Great progress!
- β Current BMI is in the healthy range
- π Good tracking consistency - 19 scans over 773 days
- Different measurement units (automatically normalized)
- Missing fields in different models
- Caching: Images are cached by hash to avoid reprocessing
- Validation: Pydantic models ensure data consistency
- Error logging: Failed extractions are logged with error messages
- Graceful degradation: Missing fields are handled as optional
π Scanning folder: ./images
π Found 5 image files
[1/5] π Processing inbody_scan_1.jpg...
β
Successfully processed inbody_scan_1.jpg
Date: 2023-06-03 06:53:00
Weight: 93.4kg, Height: 181.0cm
BMI: 28.5
[2/5] βοΈ Skipping inbody_scan_2.jpg (already processed)
==================================================
π Processing Summary:
Total files: 5
Successfully processed: 3
Failed: 1
Skipped (cached): 1
π Database Statistics:
Total processed images: 10
Successful extractions: 9
Failed extractions: 1
Total InBody results: 9
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
-
"OPENAI_API_KEY environment variable is required"
- Make sure you've created a
.envfile with your OpenAI API key
- Make sure you've created a
-
"No image files found"
- Check that your folder contains supported image formats
- Verify the folder path is correct
-
Processing failures
- Check your OpenAI API key is valid and has sufficient credits
- Ensure images are clear and readable InBody scans
- Check the processing logs for specific error messages
- Verify your OpenAI API key has access to GPT-4 Vision
- Ensure images are high quality and clearly show InBody data