Inspiration

I build quality-control software for food factories. On the floor the connection drops, inspectors fall back to paper, and a label or seal defect is found days later by a retailer. Cloud-only AI does not survive a tin roof. Hybrid inference does.

What it does

An inspector photographs a pack. Gemini reads the printed label fields and the seal into JSON through Firebase AI Logic hybrid inference: on the device when a local model is available, in the cloud when it is not. Plain, deterministic rules (not the model) decide PASS, FAIL or NEEDS REVIEW, and every result carries a chip saying where it ran.

With no network the inspector keeps working: results and cloud jobs are saved in Firestore's offline cache and drain on reconnect. Critical or low-confidence on-device results get a cloud second opinion. When failures cluster on a batch, cloud Gemini writes an 8D-style root-cause and corrective-action (CAPA) report that a supervisor approves in a Chrome console, which puts the batch on HOLD on every phone. A routing ledger totals where every call ran, the reasons, latency per path, offline minutes, bytes and photos sent to cloud.

How we used Firebase AI Logic

  • One router per platform wraps the hybrid SDK: android/.../ai/HybridRouter.kt and web/src/ai/hybridRouter.ts. UI code never calls the SDK.
  • Six tasks across the inference modes: label extraction (image + text, structured output) and defect-note classification prefer on-device; the shift digest is routed by size (on-device under the web token budget, cloud above it); second opinions, CAPA reports and the Hindi SOP explainer are cloud-only and queue in Firestore when offline.
  • inferenceSource from every response drives the on-screen chip and the routing ledger. Nothing about where a call ran is hard-coded.
  • Remote Config holds model names, thresholds, token budgets and the prompt version. During testing we fixed a seal-reading weakness by publishing prompt v2 from Remote Config; the phone picked it up without a new build.
  • App Check is enforced for AI Logic on both platforms (reCAPTCHA Enterprise on the web, the debug provider with a registered token for the judge APK). Sign-in with email, Google, phone or a demo guest; Firestore rules scope every read and write to the member's plant; Firebase Hosting serves the console.
  • The Android model lifecycle (status, download, warm-up, base model name) is a first-class screen; on web, the console downloads Chrome's built-in model from a button.

How we built it

Native Android in Kotlin and Jetpack Compose with CameraX; React, Vite and TypeScript on the web; no custom backend. Both platforms implement one written contract and run the same shared test vectors (validator, router, parser, resolved verdict), so the phone and the console agree on every field and rule. The UI is an "inspector's notebook": hand-lettered headings, a dot-grid page and verdicts as rubber stamps. Built with Claude Code. All data is synthetic.

Challenges

  • Free-tier limits. The Gemini Developer API free tier allows 15 requests a minute on the fast model; an unpaced evaluation hit HTTP 429 on 11 of 30 labels. Evaluation now paces itself, and on the phone a 429 defers the read to the queue instead of showing an error.
  • "Offline" is harder than it looks. The test phone runs a VPN that stays "validated" with Wi-Fi and data off, so the app never went offline. Offline now means no validated non-VPN network.
  • Thinking latency. The stronger cloud model took 87 s for a 60-word Hindi explanation. The inspector waits for that answer, so it moved to the fast model (about 1–2.5 s); the background reasoning tasks (second opinion, CAPA) keep the stronger model.
  • Hardware for on-device. Our only Android phone has no on-device Gemini Nano, so the Android path runs as "Cloud (no local model)" with a deferred cloud read when offline. Chrome's built-in model carried the on-device measurements.

Accomplishments (measured, see docs/RESULTS.md)

  • Cloud extraction on 30 synthetic seed labels: 240/240 fields and 30/30 verdicts correct, median 1.4 s.
  • Chrome on-device (Gemini Nano in Chrome 158, all 30 calls on the device): 238/240 fields and 28/30 verdicts correct. It missed a torn seal and a missing veg mark, the subtle visual defects a cloud second opinion is for. Median 24.5 s on this laptop.
  • Android end to end on a real phone: offline scans saved and queued, the queue survived a force-stop, drained about 20 s after reconnect, the deferred cloud reads found the right failures (an expired bar, a wrong net quantity), three failures on one batch produced a CAPA report, and approving it in the console put the batch on HOLD on the phone within seconds.

What we learned

Hybrid is a routing policy, not a switch. The interesting decisions are which tasks are allowed on the device, what happens when the device cannot run them, and how to show the user honestly where each answer came from.

What's next

Measure Android on-device accuracy on a Gemini Nano phone, goods-receipt checks, kitchen hygiene audits, an iOS auditor app, and a pilot in a plant.

Try it

  • Web console: https://nirik-fe193.web.app, join the demo plant with invite code DEMO-SUPERVISOR.
  • Android: install the APK from the v1.0.1 release; sign in with Google, email, phone (test number +91 99999 00001, code 123456; no SMS is sent) or Try the demo, then join with DEMO-PLANT. Seed label images to scan are in seed/labels/.

New project built during the submission period. Open-source libraries only. No employer code or data.

Built With

  • android
  • camerax
  • claude-code
  • firebase
  • firebase-ai-logic
  • firebase-app-check
  • firebase-authentication
  • firebase-hosting
  • firebase-remote-config
  • firestore
  • gemini
  • gemini-nano
  • jetpack-compose
  • kotlin
  • react
  • typescript
  • vite
Share this project:

Updates

Submission history