Inspiration
A conuco is the small family plot of the Caribbean: plantain, beans, cassava, a few cacao or coffee trees. Small farms like these grow about a third of the world's food, yet pests and diseases take 20–40 % of crops every year (FAO). In the hills of the Dominican Republic, agronomists are few, the signal is weak and data is expensive. A farmer looking at a sick plantain leaf needs an answer in the field, in Spanish, without uploading their life to a server.
On-device AI changes that. Gemini Nano can look at the leaf where the farmer stands, and the cloud becomes a second opinion the farmer chooses, not a requirement.
What it does
- Crop doctor. Photo of a leaf → the problem, an honest confidence, severity, what I see, what to do now and how to prevent it. Gemini Nano answers on the device; when it is unsure, Conuco asks before sending the photo to a larger cloud model and shows whether both opinions agree.
- Today. The forecast becomes decisions: is it safe to spray now (or when is the next window), do I water, how high is fungus pressure, heat and heavy-rain warnings. Gemini Nano explains the day in plain words and can read it aloud.
- Neighbour outbreak map. One tap warns nearby farms: crop, problem and an 11 km area, never a farm location or a name. Alerts appear when a disease spreads near you.
- Market prices. Farmers share what buyers pay; Conuco shows the median, range, trend and best nearby market per crop and unit (pound, quintal, bunch…).
- Farm log. Plots, work, costs and sales, dictated by voice, fully offline.
- Ask Conuco. Voice or text questions, answered on the device.
- Symptom guide. No model at all? Tick what you see and get the likely problems, on any phone.
How we built it
Firebase AI Logic hybrid inference is the core, on the web (Chrome) and natively on Android.
getGenerativeModel(ai, {
mode: InferenceMode.ONLY_ON_DEVICE, // the router picks per request
inCloudParams: { model: rc.cloudModel,
generationConfig: { responseMimeType: 'application/json', responseSchema } },
onDeviceParams: {
createOptions: { expectedInputs: [{ type: 'text', languages: ['en', 'es'] }, { type: 'image' }],
expectedOutputs: [{ type: 'text', languages: ['es'] }] },
promptOptions: { responseConstraint: jsonSchema },
},
});
Conuco's router decides where every request runs and shows the farmer why, in a "How Conuco decided where to run" panel:
The photo is redrawn on the device (GPS and phone metadata removed, 768 px) after a blur/brightness check.
Gemini Nano diagnoses it with ONLY_ON_DEVICE; response.inferenceSource drives the badge "On this device · photo never left".
A cloud second opinion is offered only when the on-device confidence $c$ is below a floor $\tau$ set in Remote Config (default $\tau = 0.65$), or the problem is unknown:
$$
\text{route} =
\begin{cases}
\text{on device} & c \ge \tau \\
\text{ask consent} \rightarrow \texttt{ONLY\_IN\_CLOUD} & c < \tau
\end{cases}
$$
Three privacy modes: Private (device only, falls back to the symptom guide), Smart (default) and Cloud first (for devices without Nano; it always asks).
The numbers come from rules, not the AI. The irrigation advice is a three-day crop water balance in the style of FAO-56, using crop coefficients $K_c$ and reference evapotranspiration $ET_0$ from Open-Meteo:
$$\text{deficit} = K_c \sum_{d=1}^{3} ET_{0,d} \;-\; 0.8 \sum_{d=1}^{3} P_d$$
Fungus risk counts the hours of leaf wetness (relative humidity $\ge 90\,\%$ at $15$–$30,^\circ\text{C}$) over the last 24 h and the next 48 h. Gemini Nano then explains these facts with PREFER_ON_DEVICE, and it only receives the rule results: no location, no names.
On Android (Kotlin + Jetpack Compose), the same router uses the Firebase AI Logic Android SDK with firebase-ai-ondevice. Gemini Nano on Android is validated for English and short outputs, so the on-device prompt asks for a compact line format (PROBLEM|name|category|confidence|severity, SIGN|…, DO|…) that a small model fills reliably, while the cloud uses a JSON schema.
Other Firebase products
App Check: reCAPTCHA Enterprise on the web, Play Integrity on Android, enforced on AI Logic.
Cloud Firestore with offline persistence: the farm log, plots, tasks and the last prices and outbreak reports work with no signal, and pending writes show "waiting to sync". Security rules keep farm data owner-only and validate every shared row (own uid, server timestamp, coarse 0.1° cell, allowed values).
Authentication: start without an account (anonymous), upgrade to email later without losing data.
Remote Config: cloud model, Nano languages per platform, confidence floor, a kill switch for cloud photos, a Google Search grounding switch, outbreak radius and threshold, price window and spray wind limit.
Analytics: which feature and where the AI ran, never photos, notes, places or prices.
Stack: vanilla JavaScript + esbuild, Leaflet/OpenStreetMap, Open-Meteo, the Web Speech API (on-device recognition where Chrome supports it); Kotlin, Jetpack Compose, RecognizerIntent (offline preferred) and TextToSpeech on Android.
Challenges we ran into
Honest confidence from a small model. We ask for a calibrated probability, clamp it and route on it. Low confidence triggers a consented second opinion instead of a confident wrong answer.
Safety. Pesticide doses are dangerous and country-specific. Prompts forbid them, and a filter removes doses and banned chemicals from any AI text and tells the farmer when it did.
Three output shapes, two engines. Chrome's Prompt API takes a JSON Schema responseConstraint, the cloud takes a Firebase Schema, and Android Nano needs a line format. One normaliser turns all three into the same diagnosis.
A strict Content-Security-Policy. On-device image input converts the photo with fetch("data:…"), so data: had to be allowed in connect-src.
Grounding on the free tier. Google Search grounding works in the code but needs a paid Gemini API tier, so it sits behind a Remote Config switch and falls back to a normal answer.
Testing on real hardware. Our Galaxy S24 Ultra has no Gemini Nano (AICore), so the Android app had to handle "no local model" gracefully: it asks first, then uses the cloud through Play Integrity.
Accomplishments that we're proud of
Verified on the device, in Chrome on a CPU-only laptop: Gemini Nano diagnosed a Black Sigatoka leaf correctly (fungus, 70 %) in about 24 s with "photo never left", wrote the Spanish day plan in 18–50 s, and answered farming questions in about 20 s.
The cloud second opinion read coffee leaf rust (95–98 %) in 2–4 s through App Check, on the web and on Android.
One offline-first app, in Spanish and English, with privacy built in at every step.
What we learned
Hybrid AI is a product decision, not a fallback flag. The farmer should see where the AI ran, decide when a photo leaves the phone, and get the facts from rules while the AI explains them.
What's next for Conuco
More crops, Haitian Kreyòl, and on-device Spanish on Android as soon as Gemini Nano supports it (a Remote Config change, no new build).
Work with extension services and producer associations so outbreak alerts reach technicians.
SMS summaries for farmers without smartphones.
Built With
- android
- chrome-prompt-api
- cloud-firestore
- css3
- esbuild
- firebase-ai-logic
- firebase-app-check
- firebase-authentication
- firebase-remote-config
- gemini
- gemini-nano
- google-analytics-for-firebase
- html5
- javascript
- jetpack-compose
- kotlin
- leaflet.js
- open-meteo
- openstreetmap
- play-integrity
- pwa
- recaptcha-enterprise
- web-speech-api
