Inspiration

Health data is some of the most sensitive data a person owns, yet the most useful AI features (a clear recap of the day, a report prepared for a consultation) usually mean sending that data to a server.

When we saw the #BuildHybridAI challenge, we realised hybrid inference could remove that trade-off. People who track their blood glucose every day deserve AI help without having to give up their privacy by default. So we asked a simple question: what if each AI task ran where it makes the most sense, and the user always knew which one was used?

What it does

GlucoNote is a blood-glucose journal with two AI features, each routed differently through Firebase AI Logic:

  • Summarize my day runs on-device with Gemini Nano in Chrome. Nothing leaves the computer, and it works offline once the model is downloaded.
  • Report for your doctor runs in the cloud with Gemini, but only after the user has seen the exact text that will be sent and clicked I agree to send. Cancelling makes zero AI calls.

Every AI answer carries a Local or Cloud badge, based on the SDK's inferenceSource, so the user never has to guess where their data went.

Around the AI, GlucoNote is a complete tracker: guided entry, history with CSV export, a dashboard, and dependency-free SVG charts (trend, daily range, distribution, hour-of-day heatmap).

GlucoNote is a tracking tool, not a medical device. It gives no diagnosis and no dosage.

How we built it

  • Backend: Python, Flask and SQLite. The data stays in a local file.
  • Frontend: server-rendered templates with vanilla JavaScript. Charts are hand-drawn SVG, so there is no chart library.
  • AI: the Firebase AI Logic Web SDK, called in the browser only. The Flask backend never calls an AI.
    • InferenceMode.ONLY_ON_DEVICE for the daily summary.
    • InferenceMode.ONLY_IN_CLOUD for the doctor report, behind a per-request consent dialog.
  • Firebase products: AI Logic and App Check (reCAPTCHA Enterprise in production, Debug provider on 127.0.0.1).
  • Offline by design: the Firebase SDK is bundled locally instead of loaded from a CDN, so the local summary works with no connection.

Safety is code, not prompting

Alerts are plain deterministic Python, never AI output. With $g$ the reading in g/L:

$$ \text{alert}(g) = \begin{cases} \text{low} & g < 0.70 \;\;(\approx 70\ \text{mg/dL}) \ \text{high} & g > 3.00 \;\;(= 300\ \text{mg/dL}) \ \text{none} & \text{otherwise} \end{cases} $$

Prompts forbid diagnosis and dosages, and a guard-rail hides any generated answer that contains a medication quantity such as "10 units". Free-text notes are never sent to the cloud.

Challenges we ran into

  • On-device AI is not guaranteed. Gemini Nano depends on Chrome Desktop, the hardware, disk space and a multi-minute model download. We handle every case (API missing, unavailable, downloadable while offline) with a clear message and no silent cloud fallback.
  • Proving where the answer came from. We only show the Local badge when inferenceSource confirms ON_DEVICE; otherwise the answer is labelled Unverified source.
  • App Check is mandatory. Firebase AI Logic requires it, so we had to set up reCAPTCHA Enterprise, plus a Debug provider and a registered debug token for local development.
  • User-gesture rules. The on-device model can only be initialised after a user interaction, so initialisation is tied to the click handlers.
  • Keeping the AI in its lane. Small models can drift into advice. Strict prompts alone were not enough, so we added the dose guard-rail and kept all alert logic outside the AI.
  • Routing vs. silent fallback. Automatic fallback to the cloud is convenient, but for health data it would quietly break the privacy promise. We chose task-based routing with explicit consent instead.

Accomplishments that we're proud of

  • A real hybrid design where the privacy level of the task decides where inference runs.
  • A cloud call that is impossible without explicit, informed consent, which you can verify in the Network tab.
  • A fully working app with zero external chart or UI dependencies.

What we learned

  • How InferenceMode lets one SDK serve on-device and cloud models with the same generateContent code.
  • That on-device models are fast and private but need defensive handling of availability, download and offline states.
  • That trust in AI features comes from transparency: badges, exact-payload consent and a visible cloud-call counter matter as much as the model itself.
  • That for sensitive domains, safety rules belong in deterministic code, not in a prompt.

What's next for GlucoNote

  • Optional PREFER_ON_DEVICE mode with a consent-gated cloud fallback.
  • Android (Gemini Nano via Firebase AI Logic) and iOS (Apple Foundation Models) versions, so the same hybrid logic runs on all three platforms.
  • Firebase Authentication and Firestore for optional, user-controlled sync.
  • Editing existing readings, and a production App Check provider for public deployment.

Built With

Share this project:

Updates

Submission history