Tagline
Tagline: Offline-first mass-casualty triage. Gemini Nano tags patients on the device; the command post lights up the moment the network returns.
Category: Web / Chrome Live demo: https://tagline-121a3.web.app Repo: Video:
Built with: Firebase AI Logic · hybrid inference · Gemini Nano (Chrome built-in AI, Prompt API) · Gemini · Cloud Firestore (offline persistence) · Firebase App Check · Anonymous Auth · Remote Config · Firebase Hosting · React · TypeScript · Vite · Tailwind CSS · PWA · Leaflet · OpenStreetMap · qrcode · jsQR · Vitest · Playwright
Tagline in 30 seconds
- Problem: in the first hour of a mass-casualty incident, cell networks jam and the command post can't see how many patients there are, how bad they are, or where.
- Solution: offline-first triage. Gemini Nano reads the medic's note on the device, the START protocol assigns the tag, and the command board fills in the moment a connection returns, or the moment a medic holds a QR code up to its camera.
- Hybrid AI: two on-device tasks (note extraction, ambulance handoff) and two cloud tasks (transport plan, situation report), each running where it fits, with the route shown on every result.
- Safe and measured: the AI never picks the tag. On 53 hand-labelled notes in two sets, including 20 held out and written before the latest change, zero under-triage on Gemini Nano and in the cloud. Held-out field accuracy was 94.1% on-device and 98.6% in the cloud.
Inspiration
In the first hour of a mass-casualty incident, the hardest problem isn't medicine. It's information. Medics triage dozens of patients with paper tags while the cell network collapses under load. The incident commander, a few hundred metres away, can't answer three basic questions: how many, how bad, where? Ambulances get dispatched blind, and the nearest trauma centre gets overloaded while others sit empty.
We wanted triage that works with zero connectivity and a command post that catches up instantly when connectivity returns. Hybrid inference makes that possible.
What it does
Medic app (/medic). The medic says or types what they see, for example "adult male, not
walking, breathing about 34 a minute, radial pulse present". A few seconds later they get a huge
colour-coded tag (RED / YELLOW / GREEN / BLACK), the exact protocol path that produced it, and a
badge showing where the AI ran. A typed note works in airplane mode when Gemini Nano is ready, and
the START yes/no buttons work instantly with no AI and no network at all. Voice input uses
Chrome's speech recognition, which needs a connection; offline, the medic types or taps.
Built for gloves and gaps. Turn on Hands-free and the app reads each follow-up question aloud and listens for the answer: "yes", "twenty-four", "alert". It shows what it heard ("Heard: 24") with a two-second chance to cancel, and ignores anything ambiguous. If a measurement can't be taken, the medic says "skip" (or taps Can't assess) and the protocol tags up, and the tag records what was skipped. The buttons always work, and if speech recognition is unavailable the app keeps reading questions aloud and says so.
Re-check reminders. START expects RED patients to be reassessed about every 15 minutes and YELLOW every 30. Overdue patients appear on the medic's home screen, at the top of the command table with "overdue N min", and as a dashed ring on the map. The thresholds are Remote Config values. A commander overriding a category does not restart the clock; only a medic's reassessment does.
Offline QR tag relay. No signal at all? The medic taps Hand over by QR and holds the phone up to the command laptop. Scan tag reads each code with the webcam, and the patient lands on the board at once, marked "Received by QR", with no network on either device. The code carries the same patient id, so when the phone reconnects Firestore updates that patient instead of adding a duplicate. Scanned codes are treated as untrusted input and strictly validated. The whole tag fits in a QR payload of at most 1,100 characters.
Command board (/command). Live category counts, a map whose pins pulse as tags sync in, a
review queue for flagged patients, a per-medic list, and a "Where the AI ran" breakdown. With one
click, cloud Gemini produces a transport plan (which patient goes to which hospital, RED first)
and a situation report for the incident commander.
On-device ambulance handoff. When a patient is marked transported, Gemini Nano on the command laptop writes a short handoff for the crew: situation, findings and concerns. The Triage line is copied from the protocol, not written by the model, and model text that names a different category is rejected. If the tag changes after the handoff was written, the panel says so. With no model available, a template writes the same four blocks, so a crew never leaves without a handoff.
Safety by design. The AI never decides a triage category. A deterministic START/JumpSTART rules engine does, with exhaustive unit tests. The AI does what language models are good at: turning messy speech into structured observations. It also gives its own reading as a cross-check. If the AI and the rules disagree, the patient goes to the review queue.
This split is deliberate. When GPT-4 was asked to assign START categories directly to 391 simulated disaster patients, it was right 63.9% of the time and overtriaged a third of them, and the authors judged it insufficient for disaster triage (Franc et al., JMIR 2024, doi:10.2196/55648). Tagline doesn't ask the model that question. It asks only "what did the medic observe?", and the protocol answers the rest.
Who runs it, on what. Gemini Nano on the web needs desktop Chrome, so the on-device path is for the laptop or Chromebook at the casualty collection point, in the command vehicle or in an ambulance, where a medic or scribe enters tags for the patients in front of them. Medics on phones use the same app: they get cloud extraction while there is any signal and the rules-only yes/no flow when there is none, and their tags sync to the board when they reconnect. Nothing in the workflow depends on which path ran.
What sets it apart. Unlike triage apps built on sliders and forms, Tagline takes a free-text or spoken note, hands tags over by QR code with no network on either device, and writes the ambulance handoff on the device. One patient, one tag, at the scene, in seconds: built for the first hour of an incident, not for reporting over days. Children triaged with JumpSTART; a re-check timer on every tag; a review flag when the AI's reading and the protocol disagree; and a command board that fills in from offline devices the moment they reconnect.
How we use Firebase AI Logic hybrid inference
Each task runs where it makes the most sense:
| Task | Mode | Reasoning |
|---|---|---|
Speech/text → structured TriageInputs JSON |
PREFER_ON_DEVICE |
Must work with no network. On the on-device path the note never leaves the device (on the cloud fallback it is sent to Gemini). Single-turn, short, schema-constrained, which fits Gemini Nano well |
| Patient facts → ambulance handoff | PREFER_ON_DEVICE |
Must work at a command post with no network. On the on-device path patient details stay on the laptop. Short, single-turn and schema-constrained, with a template as the last fallback |
| Transport plan | ONLY_IN_CLOUD |
Reasons over every patient plus hospital capacity; the command post is online |
| SITREP | ONLY_IN_CLOUD |
Long-form summary of the whole incident |
Implementation details:
- One
getGenerativeModelcall configures both paths.onDeviceParamsgets a system prompt ininitialPromptsand a JSON-schemaresponseConstraint.inCloudParamsgets the same schema asresponseJsonSchema, so both paths return the same shape. - We read
response.inferenceSourceon every call and show it on screen (⚡ On-device / ☁ Cloud). The routing is visible to the user, not hidden. - A three-level fallback chain: ⚡ on-device → ☁ cloud → 📏 rules only. If every model is unavailable, the medic answers the START yes/no questions directly. Tagging is never blocked by AI. The handoff follows the same chain and ends in a template, and its router never throws.
- The model download is user-initiated through a Prepare offline AI button
(
initializeDeviceModel) with progress. Medics do it at shift start, before going into the field. - Remote Config has an
ondevice_enabledkill switch that forces the cloud, and acloud_modelvalue that can be changed without a redeploy.
Other Firebase services
- Cloud Firestore with persistent local cache. Offline tags queue in IndexedDB. When the
network returns they sync and the command board's map fills up in real time through
onSnapshot. - App Check protects every AI Logic and Firestore request.
- Anonymous Auth. Medics join an incident with no account creation. The user is persisted, so medics stay signed in offline.
- Remote Config.
triage_protocolswitches between adult START and JumpSTART for children live, mid-incident. Alsoflag_on_disagreement,ondevice_enabledandcloud_model. - Hosting. The app is served as a PWA, so it loads offline after the first visit.
How we built it
Vite, React 19, TypeScript, Tailwind CSS v4, Leaflet/OpenStreetMap, vite-plugin-pwa, qrcode and
jsQR, and the Firebase JS SDK. The triage engines were written test-first, with every branch of
START and JumpSTART covered. The project has 683 Vitest unit tests and 11 Playwright end-to-end
tests, including one that tags a patient offline in one browser, screenshots its QR code, and scans
it into the command board in another.
Challenges
- Keeping the AI out of the decision. We split "what did the medic observe?" (AI) from "what tag does that mean?" (protocol). This made the app safer and made on-device inference more reliable: extraction is a much smaller job than diagnosis.
- Offline everywhere. Auth, Remote Config, Firestore and the app shell all had to degrade gracefully with no network. Nothing is allowed to throw.
- Same schema on two very different models. Constraining Nano and cloud Gemini to one JSON schema keeps everything downstream identical, whichever path ran.
- Getting tags across with no network at all. Firestore syncs only when a device has signal. The QR relay fills that gap: a whole tag in one scannable code, decoded on the laptop and merged by patient id, so the later Firestore sync never creates a duplicate.
- A summary that can't contradict the tag. The handoff model never sees the category, the Triage line is built in code, and any output naming another category is rejected.
Accomplishments we're proud of
- A full offline → online demo: tag patients in airplane mode, reconnect, and watch the board fill up. Or skip the network entirely and hand the tag over by QR code.
- Two real on-device tasks, not one: Gemini Nano reads the medic's note and writes the ambulance handoff.
- Visible routing: every result says where the AI ran, and the board aggregates it.
- A safety story a real EMS director could accept.
- A hidden
/debug/evalpage measures extraction against 53 hand-labelled fictional notes in two sets; its Notes picker defaults to Held-out (20) and also offers Original (33). A deterministic grounding check on both routes requires every AI value to be traceable to words in the note, makes unsupported values null so the app asks the medic, and fills blanks from plain patterns without overwriting a model value. Measured in desktop Chrome on an RTX 4050 laptop, with 0 failed calls and zero under-triage in every run.
Held-out results, measured on 2026-11-29 with grounding:
- Gemini Nano: 94.1% (207/220) field accuracy, 65.0% (13/20) category agreement, median 7894 ms. Of 17 notes that should produce a tag, 11 got the right one at once, 4 waited on a question because a field was null (the safe way to fail), and 2 were over-triaged (the safe direction). Review flagged: 28.6% (4/14).
- Cloud: 98.6% (217/220) field accuracy, the expected result on 19 of 20 notes, median about 1.4 s (1414 ms). Review flagged: 16.7% (3/18).
On the original 33, on-device field accuracy was 95.3% (346/363), category agreement was 72.7% (24/33), and median latency was 7691 ms on 2026-11-29 with grounding. The original cloud run was also measured on 2026-11-29 with grounding: 99.4% (361/363) field accuracy, the expected result on 33 of 33 notes, and median about 1.4 s (1397 ms).
On the original set, grounding cut cloud fabrications from 8 to 2 and on-device fabrications from 7 to 0. These are development results, not an independent test.
The prompt is unchanged since 2026-11-21. The original notes were written on 2026-11-25; the held-out notes were written on 2026-11-29 before any code changed, in a separate pass that did not see the prompt, with labels reviewed by hand and checked against the rules engine by a unit test. Grounding was developed only on the original set, so its new results are development numbers and the held-out set is the independent check. The samples remain small; a larger independently written set is the next step. The full table, before/after comparison and sample-size bounds are in the README.
What we learned
On-device models are best when given a narrow, schema-constrained job, and the cloud is best for reasoning across the whole incident. Hybrid inference lets one app use each where it fits.
What's next
- Android medic app with Gemini Nano through ML Kit (the same AI Logic hybrid API).
- Peer-to-peer relay between medics (Wi-Fi Direct / Bluetooth), building on the QR relay, so tags hop from phone to phone until one reaches the command post.
- Wound photo input for the multimodal on-device model.
- Live hospital capacity feeds and ambulance tracking for the transport plan.
- A field trial with an EMS agency's mass-casualty drill.
Testing instructions for judges
- Open https://tagline-121a3.web.app/command in one window and
/medicin another (or on your phone). - On
/medic, tap + Tag patient and type a note, for example "adult, can't walk, breathing 34 a minute". Without Gemini Nano, the app falls back to the cloud automatically (☁ badge). - Confirm the tag and it appears on
/command. Click Load Route 9 demo for 25 fictional patients, then Generate transport plan. For on-device mode: desktop Chrome, set
chrome://flags/#prompt-apito Enabled, relaunch, then use Prepare offline AI on/medic. Turn Wi-Fi off and tag; the badge shows ⚡ On-device.For hands-free mode (desktop Chrome): on
/medicswitch Hands-free on, tag a patient with a note that leaves something out, and answer the spoken questions aloud. Say "skip" on a skippable one.Load the demo on
/command: patients past their re-check time show "overdue" in the table and a dashed ring on the map.QR relay: on a phone, open
/mediconce online, switch to airplane mode, tag a patient, and tap Hand over by QR. On a laptop's/command, click Scan tag and hold the phone up to the webcam. The patient appears marked "Received by QR". No webcam? Use Or choose a photo of the code with a screenshot of the QR code.Handoff: on
/command, click Handoff on any patient in the table or a map pin, then Prepare handoff. The badge shows where it was written.
All patient data is fictional.