Skip to content

About

🍏 Lightweight AI Food Vision & Macro Nutrition pipeline for iOS (SwiftUI + Apple HealthKit + Vision LLM)

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯‘ FoodVisionAI-iOS

Lightweight, privacy-first AI Food Vision & Macro Nutrition pipeline for iOS.
Powered by Multimodal Vision LLMs, SwiftUI Bento architecture, and Apple HealthKit auto-synchronization.

iOS 17+ Swift 5.10+ License: MIT App Store

NadY FoodVisionAI Banner

---

πŸ“± Live Production App: NadY

This architecture is in production inside NadY: Photo Calorie Tracker on the Apple App Store.

  • 1-Second Photo Scan: Snap any complex meal, plate, or restaurant takeout.
  • Discrete Segmentation: Automatically identifies sauces, cuts of meat, carbs, and dressings.
  • Apple HealthKit Sync: Automatically syncs active energy deficit, dietary energy, protein, fat, and carbohydrates.
  • Bento UI 2026: Single-screen viewport with net calorie tracking, water intake, and circadian 16:8 intermittent fasting timer.

πŸ‘‰ Download NadY on the App Store (iOS)


πŸ”¬ Architecture Overview

                      +------------------------+
                      |  iOS Camera / Library  |
                      |   (AVFoundation / PH)  |
                      +-----------+------------+
                                  | High-Res Frame
                                  v
                      +------------------------+
                      |  Local Pre-Processing  |
                      |  - Aspect Normalization|
                      |  - Exposure Correction |
                      |  - Ephemeral Memory    |
                      +-----------+------------+
                                  | Base64 Payload
                                  v
                      +------------------------+
                      |  Multimodal Vision AI  |
                      |  - Plate Segmentation  |
                      |  - Volumetric Density  |
                      |  - KBZHU Macro Parser  |
                      +-----------+------------+
                                  | Structured JSON
                                  v
           +----------------------+----------------------+
           |                                             |
           v                                             v
+------------------------+                    +------------------------+
|  Bento UI HUD (SwiftUI)|                    |  Apple HealthKit Sync  |
|  - Realtime Net Deficit|                    |  - Dietary Energy (cal)|
|  - Macro Ring Visuals  |                    |  - Protein, Fat, Carbs |
|  - 16:8 Fasting State  |                    |  - Passive Burn Reconc.|
+------------------------+                    +------------------------+

πŸš€ Quick Start (Swift Package Manager)

Add FoodVisionAI to your Package.swift:

dependencies: [
    .package(url: "https://github.com/UniversalSDK/FoodVisionAI-iOS.git", from: "1.0.0")
]

1. Meal Recognition Pipeline

import SwiftUI
import FoodVisionAI

struct FoodScanView: View {
    @State private var scanResult: MealMacroEstimation?
    @State private var isProcessing = false
    
    var body: some View {
        VStack {
            if let result = scanResult {
                MealSummaryCard(result: result)
            } else {
                Text("Snap a meal to see instant macros")
            }
        }
    }
    
    func analyzeMeal(image: UIImage) async {
        isProcessing = true
        defer { isProcessing = false }
        
        do {
            let result = try await FoodVisionEngine.shared.analyze(
                image: image,
                dietaryContext: .standardDeficit
            )
            self.scanResult = result
            
            // Auto-sync to HealthKit
            try await HealthKitNutritionSync.shared.recordMeal(result)
        } catch {
            print("Scan failed: \(error.localizedDescription)")
        }
    }
}

2. Apple HealthKit 2-Way Sync

import HealthKit

public final class HealthKitNutritionSync {
    public static let shared = HealthKitNutritionSync()
    private let healthStore = HKHealthStore()
    
    public func recordMeal(_ meal: MealMacroEstimation) async throws {
        guard HKHealthStore.isHealthDataAvailable() else { return }
        
        let now = Date()
        var samples: [HKQuantitySample] = []
        
        // 1. Dietary Energy (Calories)
        let energyType = HKQuantityType.quantityType(forIdentifier: .dietaryEnergyConsumed)!
        let energyQuantity = HKQuantity(unit: .kilocalorie(), doubleValue: meal.calories)
        samples.append(HKQuantitySample(type: energyType, quantity: energyQuantity, start: now, end: now))
        
        // 2. Macronutrients
        let proteinType = HKQuantityType.quantityType(forIdentifier: .dietaryProtein)!
        samples.append(HKQuantitySample(type: proteinType, quantity: HKQuantity(unit: .gram(), doubleValue: meal.protein), start: now, end: now))
        
        let fatType = HKQuantityType.quantityType(forIdentifier: .dietaryFatTotal)!
        samples.append(HKQuantitySample(type: fatType, quantity: HKQuantity(unit: .gram(), doubleValue: meal.fat), start: now, end: now))
        
        let carbType = HKQuantityType.quantityType(forIdentifier: .dietaryCarbohydrates)!
        samples.append(HKQuantitySample(type: carbType, quantity: HKQuantity(unit: .gram(), doubleValue: meal.carbs), start: now, end: now))
        
        try await healthStore.save(samples)
    }
}

πŸ”’ Privacy & Clinical Compliance

  • Zero Facial or Ambient Retention: Camera frames are evaluated solely for food textures, plate geometry, and food components.
  • Ephemeral Processing: Image buffers exist in volatile RAM only during active inference and are discarded immediately after parsing.
  • Apple Health Guidelines: All samples adhere to Apple Clinical & Dietary Data schema specifications.

πŸ‘¨β€πŸ’» Community & Live Support


πŸ“„ License

MIT License. See LICENSE for details.

About

🍏 Lightweight AI Food Vision & Macro Nutrition pipeline for iOS (SwiftUI + Apple HealthKit + Vision LLM)

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages