{"slug": "healthycropping-offline-crop-disease-diagnosis-on-android-tflite-and-rag", "title": "HealthyCropping – Offline crop disease diagnosis on Android (TFLite and RAG)", "summary": "HealthyCropping, an open-source, non-commercial Android app published under the package name com.keylorpineda.healthycropping, runs quantized MobileNetV3 TFLite models on-device to diagnose coffee leaf rust, cacao frosty pod rot and banana black Sigatoka in under 50ms without a cellular connection, storing scans in SQLite and syncing to a FastAPI backend with a Gemini RAG advisory layer grounded in ICAFE, CATIE and CORBANA literature when connectivity returns. The project's docs/PLAN.md tracks 9 phases: Phases 1 through 5 (monorepo foundation, coffee model pipeline with INT8/FP16 export and verified 224x224 RGB parity, Expo React Native shell, edge inference and scanner, and cacao and banana specialist models) are completed, while Phase 6 (FastAPI and cloud sync) and Phase 7 (grounded Gemini RAG) are in progress. Phase 8 (low-end Android benchmarks and field daylight testing) and Phase 9 (signed APK distribution and a farmer pilot in Tarrazu, Costa Rica) are scheduled, and the app's disclaimer states it supports field decisions and does not replace a certified agronomist or phytosanitary laboratory.", "body_md": "Smallholder and medium-scale producers of coffee (*Coffea arabica* / *canephora*), cacao (*Theobroma cacao*), and banana (*Musa* spp.) in Central America frequently work in mountainous or rural plots with intermittent or zero cellular connectivity. Identifying pathogens early—such as coffee leaf rust (*Hemileia vastatrix*), cacao frosty pod rot (*Moniliophthora roreri*), or banana black Sigatoka (*Pseudocercospora fijiensis*)—is critical to timing cultural controls and preventing yield loss, yet cloud-only diagnostic tools fail in the field when connectivity drops.\n\n**HealthyCropping** (`com.keylorpineda.healthycropping`) is an open-source, non-commercial, offline-first Android application. It runs quantized computer vision models directly on the phone with sub-50ms inference, records scans and plot geometries locally in SQLite, and synchronizes with a FastAPI backend and Gemini RAG advisory layer grounded in certified institutional literature (ICAFE, CATIE, CORBANA) once connectivity is restored.\n\n**Agronomic Disclaimer**: HealthyCropping is a non-commercial, open-source decision-support tool designed initially for Costa Rica. **It supports field decisions and does not replace a certified agronomist or phytosanitary laboratory.** Always consult an agricultural professional before applying agrochemicals or removing plants.\n\nThe project is structured into 9 execution phases according to [`docs/PLAN.md`](https://github.com/keylorpineda/healthycropping/blob/develop/docs/PLAN.md):\n\n| Phase | Milestone | Scope | Status | \n|---|---|---|---|\n| **Phase 1** | Foundation & Governance | Monorepo layout, strict linting ( `ruff` ,`mypy` , ESLint), CI quality gates | Completed | \n| **Phase 2** | Coffee Model Pipeline | MobileNetV3 TFLite, INT8/FP16 export, verified 224x224 RGB parity | Completed | \n| **Phase 3** | Core Mobile Shell | Expo React Native, SQLite schema, agricultural design system, Spanish UI | Completed | \n| **Phase 4** | Edge Inference & Scanner | On-device TFLite camera, reticle framing, confidence thresholding, triage | Completed | \n| **Phase 5** | Multi-Crop Expansion | Cacao pod and banana leaf specialist models, multi-crop app routing | Completed | \n| **Phase 6** | FastAPI & Cloud Sync | Farm/plot sync endpoints, Firebase Admin auth, Cloudinary image ingestion | In Progress | \n| **Phase 7** | Grounded Gemini RAG | Institutional agronomy corpus, citation retrieval, safe treatment advice | In Progress | \n| **Phase 8** | Performance & Hardening | Low-end Android hardware benchmarks, field daylight testing | Scheduled | \n| **Phase 9** | Field Validation & Release | Signed APK distribution, farmer pilot in Tarrazu, Costa Rica | Scheduled | \n\n``` php\nflowchart LR\n    A[\"1. Select Crop\\n(Coffee / Cacao / Banana)\"] --> B[\"2. Capture Photo\\n(Guided framing tips)\"]\n    B --> C[\"3. On-Device Preprocessing\\n(224x224 RGB + normalize)\"]\n    C --> D[\"4. Offline TFLite Inference\\n(MobileNetV3 float16 / INT8)\"]\n    D --> E[\"5. Instant Local Result\\n(Class, Severity, SQLite)\"]\n    E -. \"Optional when online\" .-> F[\"6. Cloud Sync & Gemini RAG\\n(FastAPI + Cited Manuals)\"]\n```\n\n1. **Crop Selection** : The user selects**Coffee** (leaf underside),**Cacao** (pod), or**Banana** (leaf) prior to scanning so a dedicated specialist model runs for that crop.\n2. **Offline On-Device Inference** : The captured photo is resized to`224x224` , decoded to raw RGB, normalized with exact training statistics, and evaluated locally in`< 50ms` using`react-native-fast-tflite` .\n3. **Actionable Triage & Thresholding** : If confidence falls below the calibrated validation threshold, the app instructs the user to retake the photo. Otherwise, it reports predicted class, severity level, confidence, and recommended triage action (`healthy` ,`watch` , or`act now` ).\n4. **Local Persistence & Optional Sync** : Scans, farms, and plots are stored locally in`expo-sqlite` with client-generated UUIDs. Account creation is optional and used solely to synchronize records idempotently through the FastAPI backend (`api/` ).\n5. **Grounded RAG Advisory** : When online, the backend retrieves passages from official technical manuals (ICAFE for coffee, CATIE for cacao, CORBANA for banana) and utilizes Gemini to summarize recommendations without hallucinated chemical remedies.\n\nOne fine-tuned `MobileNetV3` model is trained, evaluated, and exported per crop (`224x224` RGB input, quantized TFLite `< 10 MB`):\n\n| Crop | Target Organ | Target Classes | Evaluation Metric | Export Format | Documentation | \n|---|---|---|---|---|---|\n| **Coffee** | Leaf (underside) | `healthy` ,`leaf_rust` (+ severity),`leaf_miner` ,`cercospora` ,`brown_leaf_spot` ,`red_spider_mite` | `> 90%` Macro-F1 | FP16 / INT8 TFLite | [Model Card](https://github.com/keylorpineda/healthycropping/blob/develop/docs/MODEL_CARD.md#2-coffee-leaf-model-coffee) | \n| **Cacao** | Pod | `healthy` ,`monilia` (by stage),`black_pod` (*Phytophthora* ) | `> 92%` Macro-F1 | FP16 / INT8 TFLite | [Model Card](https://github.com/keylorpineda/healthycropping/blob/develop/docs/MODEL_CARD.md#3-cacao-pod-model-cacao) | \n| **Banana** | Leaf | `healthy` ,`black_sigatoka` ,`fusarium_wilt` ,`cordana` | `> 92%` Macro-F1 | FP16 / INT8 TFLite | [Model Card](https://github.com/keylorpineda/healthycropping/blob/develop/docs/MODEL_CARD.md#4-banana-leaf-model-banana) | \n\nTensor preprocessing parity between Python (`ml/`) and React Native (` app/src/ml/`) is enforced by shared fixture tests.\n\n```\nhealthycropping/\n├── app/       # Expo React Native (Android, pnpm): on-device TFLite, SQLite, UI\n├── api/       # Python 3.12 (uv): FastAPI, Firebase Admin, Cloudinary, RAG\n├── ml/        # Python 3.12 (uv): data preprocessing, training, eval, TFLite export\n└── docs/      # ARCHITECTURE, PLAN, MODEL_CARD, DATASETS, EXPERIMENTS, DEVLOG\n```\n\n| Workspace | Stack | Purpose | \n|---|---|---|\n| [`app/`](https://github.com/keylorpineda/healthycropping/blob/develop/app/README.md) | React Native 0.76, Expo 52, TypeScript, SQLite, TFLite | Offline mobile application for Android | \n| `api/` | Python 3.12, FastAPI, Firebase Admin, Cloudinary, Gemini | Sync endpoints, token verification & RAG advisory | \n| `ml/` | Python 3.12, TensorFlow 2.16, TFLite, Pillow | Training pipelines, evaluation & quantized edge export | \n\n- **Mobile** : Node.js 20+,`pnpm` (configured with`node-linker=hoisted` ), Android SDK.\n- **Backend & ML** : Python 3.12,`uv` package manager.\n\n```\ncd app\npnpm install\npnpm typecheck\npnpm lint\npnpm test\npnpm start\ncd api\nuv sync --all-extras\nuv run ruff check .\nuv run mypy src tests\nuv run pytest\nuv run uvicorn src.main:app --reload\ncd ml\nuv sync --all-extras\nuv run ruff check .\nuv run mypy src scripts tests\nuv run pytest\n```\n\nContributions are welcome. Please check our open issues and guidelines before opening a pull request:\n\n- **Roadmap & Tasks** :[https://github.com/keylorpineda/healthycropping/issues](https://github.com/keylorpineda/healthycropping/issues)\n- **Community Spotlight** :[GitHub Discussions Announcement](https://github.com/community/community/discussions/137746#discussioncomment-19118448)\n- **Contributing Guidelines** :[`CONTRIBUTING.md`](https://github.com/keylorpineda/healthycropping/blob/develop/CONTRIBUTING.md)\n- **Architecture Overview** :[`docs/ARCHITECTURE.md`](https://github.com/keylorpineda/healthycropping/blob/develop/docs/ARCHITECTURE.md)\n- **Code of Conduct** :[`CODE_OF_CONDUCT.md`](https://github.com/keylorpineda/healthycropping/blob/develop/CODE_OF_CONDUCT.md)\n\n1. **Decision Support Only** : Visual symptoms cannot distinguish every microscopic pathogen strain or nutrient deficiency. Laboratory diagnostics remain necessary for high-impact interventions.\n2. **Field Lighting Sensitivity** : Direct specular glare on wet foliage or extreme motion blur can reduce model confidence.\n3. **Backend Cold Starts** : The optional FastAPI synchronization API runs on Render's free tier (sleeps after 15 minutes of inactivity). Core disease diagnosis and SQLite storage operate 100% offline on the phone and are never affected.\n\nThe MIT license in [`LICENSE`](https://github.com/keylorpineda/healthycropping/blob/develop/LICENSE) applies **solely to the source code** in this repository. Training datasets remain under their respective upstream licenses documented in [`docs/DATASETS.md`](https://github.com/keylorpineda/healthycropping/blob/develop/docs/DATASETS.md):\n\n- **RoCoLe** (Coffee — Mendeley Data, DOI[`10.17632/c5yvn32dzg.2`](https://doi.org/10.17632/c5yvn32dzg.2) )\n- **BRACOL** (Coffee — Mendeley Data, DOI[`10.17632/yy2k5y8mxg.1`](https://doi.org/10.17632/yy2k5y8mxg.1) )\n- **CocoaMoniliaDataSet** (Cacao — Zenodo, DOI[`10.5281/zenodo.17156051`](https://doi.org/10.5281/zenodo.17156051) , CC BY 4.0)\n- **UNAB Cocoa Diseases** (Cacao — Kaggle`serranosebas/enfermedades-cacao-yolov4` )\n- **Banana Leaves Imagery** (Banana — NM-AIST DSpace[`20.500.12479/3003`](https://dspace.nm-aist.ac.tz/handle/20.500.12479/3003) ; DOI[`10.1038/s41597-025-04456-4`](https://doi.org/10.1038/s41597-025-04456-4) )\n- **BananaLSD** (Banana — Mendeley Data, DOI[`10.17632/9tb7k297ff.1`](https://doi.org/10.17632/9tb7k297ff.1) )\n\n**HealthyCropping** (`com.keylorpineda.healthycropping`) is strictly non-commercial. It is distributed free of charge as an installable Android `.apk` exclusively through [GitHub Releases](https://github.com/keylorpineda/healthycropping/releases), with no advertisements or paid subscriptions.\n\n```\n@software{pineda2026healthycropping,\n  author       = {Pineda, Keylor},\n  title        = {{HealthyCropping: Offline-First Crop Disease Detection for Coffee, Cacao, and Banana}},\n  year         = {2026},\n  url          = {https://github.com/keylorpineda/healthycropping},\n  version      = {0.1.0},\n  license      = {MIT}\n}\n```\n\n- **Keylor Pineda** —[@keylorpineda](https://github.com/keylorpineda)\n- **Jefferson Abarca** —[@JAbarca74](https://github.com/JAbarca74)", "url": "https://wpnews.pro/news/healthycropping-offline-crop-disease-diagnosis-on-android-tflite-and-rag", "canonical_source": "https://github.com/keylorpineda/healthycropping", "published_at": "2026-10-22 10:55:27+00:00", "updated_at": "2026-10-22 11:11:05.317304+00:00", "lang": "en", "topics": ["artificial-intelligence", "computer-vision", "ai-tools", "ai-agents"], "entities": ["HealthyCropping", "Keylor Pineda", "MobileNetV3", "TensorFlow Lite", "Gemini", "FastAPI", "ICAFE", "CATIE"], "also_reported_by": [{"url": "https://dev.to/keylorpineda/building-an-offline-first-crop-disease-detector-with-react-native-on-device-tflite-and-grounded-1l12", "source": "dev.to", "title": "Building an Offline-First Crop Disease Detector with React Native, On-Device TFLite, and Grounded RAG", "published_at": "2026-10-22T11:04:59+00:00"}], "alternates": {"html": "https://wpnews.pro/news/healthycropping-offline-crop-disease-diagnosis-on-android-tflite-and-rag", "markdown": "https://wpnews.pro/news/healthycropping-offline-crop-disease-diagnosis-on-android-tflite-and-rag.md", "text": "https://wpnews.pro/news/healthycropping-offline-crop-disease-diagnosis-on-android-tflite-and-rag.txt", "jsonld": "https://wpnews.pro/news/healthycropping-offline-crop-disease-diagnosis-on-android-tflite-and-rag.jsonld"}}