DEV Community

Cover image for Mazorca: an offline AI agronomist for my cacao plot, powered by Gemma 4
Jesus Manuel Garcia Torres
Jesus Manuel Garcia Torres

Posted on

Mazorca: an offline AI agronomist for my cacao plot, powered by Gemma 4

Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle Submission đź’¸

This is a submission for the Hacktoberfest Open-Source AI Challenge: Side Hustle

A row of cacao trees on my plot in Cárdenas, Tabasco, with a ripe pod hanging from the trunk

What I Built

I grow cacao. My family's plot is 3 hectares in Cárdenas, Tabasco, in the Chontalpa region of southern Mexico. Our biggest problem is moniliasis (frosty pod rot, Moniliophthora roreri). It can take a large share of the harvest when sick pods aren't found and removed in time. Most smallholders around here don't have a technician who comes every week, and there's usually no mobile signal under the canopy.

Mazorca ("cacao pod" in Spanish) is a pocket agronomist that works offline. You walk the plot with your phone, take photos lot by lot, and an open-weight model running on a laptop (Gemma 4 via Ollama, on a phone hotspot) tells you what it sees:

  • Photo walk: for each photo, a diagnosis card with findings (moniliasis, black pod, witches' broom, overripe pods, excess shade, pruning, weeds, waterlogging), a confidence level for each finding, healthy and affected pod counts, and up to four practical actions.
  • 7-day report for each lot: photos, issues, the share of affected pods, and whether it went up, went down or stayed the same compared with the week before. This part is computed without the model, so it's deterministic.
  • Weekly action plan: written by the local model from that report, and it can be read aloud with ElevenLabs for people who'd rather listen than read in the sun.
  • Cut test: a bean cut test that estimates how many beans are well fermented, purple, slaty or moldy.
  • CSV export: a file to take to the cooperative or a technician.
  • Weekly Kestra flow: on Monday at 6:00 it builds every lot's report and plan, writes a markdown summary, and sends a Slack alert only if a lot got worse.

It only suggests cultural practices: remove and bury sick pods, prune, manage shade, drain, harvest on time. It never recommends agrochemical doses; for any product it tells you to ask a technician.

Who would pay? Not the individual farmer at first; many are paid per kilo and run on thin margins. The paying customers are the people who already pay for field visits:

  • Cacao cooperatives and collection centers. They need consistent monitoring across dozens of members and prefer a weekly CSV per lot over WhatsApp photos. A yearly license per cooperative plus a cheap laptop or mini PC as the "field box" costs less than one extra technician.
  • Chocolate makers who buy direct and have sustainability or traceability programs. They want evidence of good farm practices from their sourcing regions.
  • Extension technicians and agronomy consultants. One technician can cover more farms when producers send structured weekly reports instead of random photos, and the technician can offer that as a premium service.

The farmer uses it for free. Whoever needs the data at scale pays for setup, support and the Kestra reporting.

Demo

This demo runs entirely on my laptop with Gemma 4 E4B in Ollama: I upload a photo from my plot, Mazorca describes what it sees, gives a diagnosis with confidence levels, and then I open the weekly report and generate the plan.

Mazorca demo: photo walk, diagnosis card, weekly report and plan

The diagnosis card starts with "Lo que la IA ve" ("What the AI sees"), so the farmer can tell at a glance whether the model is looking at the same thing they are:

Mazorca diagnosis card in Spanish with findings and confidence levels

The 7-day report for the lot and the weekly plan written by the local model:

Mazorca 7-day report and weekly action plan

These are the photos I took on my own plot to test it:

Understory of the cacao plot with shade trees

Path between cacao trees on the plot

Cacao tree with young pods on the trunk

Pile of opened cacao husks after harvest

Bucket of fresh cacao beans from the harvest

There is no hosted demo on purpose. The whole point is that it runs on a laptop at the farm, with no internet. To run it yourself:

ollama pull gemma4:e4b-it-qat
git clone https://github.com/gartox/mazorca && cd mazorca
npm start
Enter fullscreen mode Exit fullscreen mode

Code

GitHub logo gartox / mazorca

Mazorca: a pocket agronomist for small cacao farmers in Tabasco, Mexico. Walk the plot, photograph pods and trees, and a local Gemma model (Ollama) flags moniliasis risk and builds a weekly action plan. Works offline.

Mazorca

Mazorca is a local, mobile-first cacao-plantation walk assistant for small producers in Tabasco. A producer photographs pods, leaves and trees, and an open model running through Ollama on a laptop returns a cautious, confidence-labeled observation by lot.

It is designed for places without signal: images stay local, farm data stays private, there is no cloud service and no per-photo cost. The model is replaceable. Mazorca never gives agrochemical doses and does not replace a technician, a laboratory or a definitive diagnosis.

Run it

Install Ollama separately, then download the default model:

ollama pull gemma4:e4b-it-qat
npm start

Open http://127.0.0.1:3000 on the laptop, or open the laptop's local network IP from a phone connected to the same hotspot. Use OLLAMA_URL, MAZORCA_MODEL, DATA_DIR, PORT and OLLAMA_TIMEOUT_MS to configure the local setup. The default Ollama timeout is 180 seconds.

Kestra is optional. kestra/mazorca-weekly-plan.yaml is disabled by default and can request…

How I Built It

  • Model: Gemma 4 E4B (gemma4:e4b-it-qat, the quantization-aware 4-bit build) running locally in Ollama. It's multimodal, it fits in a 16 GB laptop next to Docker, and it answers a photo in seconds. I also tried the 12B model, but on my machine it ran out of memory and timed out, so E4B is the default. The model can be changed with MAZORCA_MODEL.
  • Two-step diagnosis. If the prompt tells a vision model "this is a cacao plot, look for diseased pods", it is primed to find pods and disease even where there are none. So Mazorca makes two calls:
    1. A neutral observation whose prompt never mentions cacao, disease or farming: describe the scene, count people, say whether any fruit is visible and estimate how many.
    2. The diagnosis, which receives that observation and must not contradict it.

After that, the server enforces hard rules instead of trusting the model: if no fruit is visible, pod-level findings and counts are removed, and counts far above the observed estimate are scaled down.

  • Robust JSON. Some Ollama builds return 501 for format or silently ignore it. So the JSON schema always goes inside the prompt too, JSON is extracted even when it comes wrapped in markdown, there's one retry, and a 501 is remembered. Every model output is normalized: unknown enums become unknown, confidence defaults to low, arrays are capped, numbers are clamped, and extra fields are dropped.
  • Zero-dependency Node. It uses only node:* modules. There's no npm install, so it's easy to copy to an old laptop with a USB stick. The frontend is a small offline PWA in Spanish (Mexico), with high-contrast colors for direct sun. Every piece of model text is inserted with textContent. Photos are re-encoded in a <canvas> before upload, which also removes EXIF/GPS, so farm locations never leave the phone.
  • ElevenLabs. POST /api/lotes/:id/plan/audio turns the weekly plan into Spanish speech with eleven_multilingual_v2. Many producers in my area prefer a voice message to reading a list. This is the only feature that needs internet; if there's no signal, everything else keeps working and the API key only lives in an environment variable. To be transparent: the automated tests run it against a mock ElevenLabs server, and you need your own key to hear real audio.
  • Kestra. kestra/mazorca-weekly-plan.yaml loops over the lots with concurrencyLimit: 1 so it doesn't overload the local model. It calls the report and plan endpoints, writes a markdown summary, and an If sends a Slack webhook only when a lot's trend is "subiĂł" (went up). I validated it end to end on a real Kestra instance.
  • Tests: 18 tests with node --test against a mocked Ollama on port 0. They cover broken JSON, adversarial output, the 501 fallback, Ollama being down, trend math, division by zero, CSV escaping, the two-step rules and the ElevenLabs endpoint.

Why Does Open Innovation Matter?

For a cacao plot it isn't a philosophical point; it's what makes the product possible at all:

  • No signal in the field. A closed vision API needs a connection at the moment the photo is taken. An open-weight model runs on a laptop on a phone hotspot under the trees.
  • The farm's data stays on the farm. Photos of a plot, its yields and its disease levels are sensitive for a smallholder who sells to intermediaries. Here nothing leaves the laptop except, optionally, the plan text for audio.
  • Zero cost per photo. A full walk is 30 to 60 photos a week for each farm. Per-image pricing would kill the business model for a cooperative with hundreds of members; local inference costs a laptop's electricity.
  • Swappable and auditable. When a better or more specialized model comes out, or a cooperative fine-tunes one on its own disease photos, it's a single environment variable. The prompts, the normalization and the safety rules are in the open, so a technician can read exactly what the tool is told and what it's forbidden to say.

My First User

Me. I'm the farmer. I tested Mazorca with photos from my own 3 hectares in Cárdenas. Honest results:

  • Scenes: it described them well (understory, shade, harvest piles, buckets of beans, young pods on the trunk), and "What the AI sees" made mistakes easy to spot.
  • Counts: pod counts are approximate, an estimate rather than an inventory.
  • A real miss: it read my pile of opened husks as "overripe pods on the ground". That's a reasonable visual mistake, and it's exactly why every finding carries a confidence level and the tool tells you to confirm with a technician.
  • Moniliasis not validated yet: we're in the post-harvest period, so I had no photos of active moniliasis. Detecting it on my own pods is the next thing I'll test when the new pods come in.
  • Something I clarified: an early prompt hinted that husk piles cause moniliasis. That's not right: husks from healthy pods don't cause it, but if diseased pods get mixed in they can spread spores. I fixed the prompt, so now it only suggests spreading or composting husks away from the trees.

Mazorca is an observation aid, not a diagnosis; it doesn't replace a technician or a laboratory. It already gives me a weekly, structured view of my lots that I didn't have before.

Prize Categories

  • Best Use of Gemma: Gemma 4 E4B, running fully locally and multimodal, is the core of the project: the neutral observation, the diagnosis, the cut test and the weekly plan.
  • Best Use of ElevenLabs: the weekly plan is read aloud in Spanish, so producers can listen to it in the field.

Top comments (0)