Repository navigation
Releases
Releases · keylorpineda/healthycropping
v0.5.0
- Explanations saved per scan and citation badges (
#74): every explanation shown for a scan is copied to a new SQLite tablescan_explanations, and Scan Detail falls back to that copy when the API cannot be reached, so it stays readable in airplane mode even after switching the app language (a note says which language it was saved in). Citations are now badges (publisher · section) that expand on tap to the full reference (title, publisher, year, pages) with an Open source button. The Result screen waits until the scan is saved before requesting, so one diagnosis spends one request. - Cited explanations in the app (
#37): Result and Scan Detail show an explanation card for confident, non-healthy diagnoses with a skeleton while loading, the summary, numbered next steps, the cited source and section (publisher, year, pages), an AI disclaimer and, when read from the phone, a "saved offline" note.app/src/services/explanations.tssends only(crop, disease_class, severity, language)toPOST /explanationsthrough TanStack Query (@tanstack/react-query5.104.5) and keeps answers in a new SQLite tableexplanationskeyed by those four values, read first so answers stay available offline and repeated diagnoses do not spend the hourly quota.not_coveredrefusals are not kept. Offline, signed-out, rate-limited (429) and unavailable states have their ownes/enmessages, with a retry button where it helps. - Explanation cache, privacy guard and rate limit (
#50):POST /explanationsanswers are cached in process by(crop, disease_class, severity, language)only, so repeated diagnoses (from any user) skip Gemini; concurrent misses on one key make a single call, and model failures and refusals are not cached. The service refuses classes outside the crop's model taxonomy, and tests check every supported prompt contains only those four values (no names, emails, uid, coordinates or request headers). Each user (Firebaseuid, not IP) may send20requests per hour (slowapi); request21gets429 rate_limitedwithRetry-After. Unauthenticated and invalid requests do not spend quota. POST /explanations(#36): for an authenticated user and a diagnosis(crop, disease_class, severity, language)only, retrieves up to 4 passages from the local RAG index and asks Gemini (google-genai,GEMINI_MODEL) for a plain-language summary and next steps as JSON, citing passages by id. The response listssource_title,publisher,section, pages and URL for each cited section. It declines (covered: false) for healthy plants, when no passage matches, or when the model does not cite a provided passage; it returns503when Gemini or the index is unavailable. Request bodies reject any other field.- Local RAG index and retriever (
#49):api/scripts/build_rag_index.pyturnschunks.jsonlinto a byte-reproducible TF-IDF index (api/.cache/rag/index.json), andRagIndex.retrieve(crop, disease_class, query, k)filters by crop and disease class and ranks by cosine similarity, keeping source, section, pages and URL for citations. Queries are built only from(crop, disease_class, severity)with bilingual keywords, weighted toward symptoms forwatchand control foractNow. Sections can nowexcludeinterleaved blocks, which removes the reference list printed mid-column in the CORBANA bulletin. - Cacao and banana RAG sources (
#73): CATIE's Guía para el manejo integrado de enfermedades en el cultivo de cacao (2021) formoniliaandblack_pod, CORBANA's Manejo de la Sigatoka negra bulletin (2011) forblack_sigatoka, and FAO's Fusarium TR4 technical manual (2014, English) forfusarium_wilt, with pinned checksums. Every disease class of coffee, cacao and banana now has cited chunks (86in total), checked by a test. The chunker removes line-break hyphens for sources markedsoft_hyphensand spaces before punctuation. - Agronomic document fetcher and section chunker for RAG (
#35):api/rag_sources.tomllists official sources with pinned SHA-256 checksums and the sections to index;api/scripts/fetch_agronomic_docs.pydownloads them into the git-ignoredapi/.cache/rag/, extracts PDF text (pypdf+fonttools, newragextra), and writeschunks.jsonlwith(source, section, pages, crop, disease_classes)metadata and a per-class coverage report. The first source is ICAFE's Guía técnica para el cultivo de café (2020), covering all five coffee disease classes. - End-to-end multi-tenant sync contract verification and Render deployment configuration (
#48): shared fixture-based contract tests (app/src/services/fixtures/sync_contract.json, validated byapi/tests/test_contract.pyandapp/src/services/__tests__/contract.test.ts) asserting 100% schema and field parity for farms, plots, and scans, idempotent re-sync and tenant isolation; andrender.yamlBlueprint specification for deploying the FastAPI backend to Render's free tier with uv, Python 3.12, health check (/health), auto-deploy frommain, and secret files for Firebase Admin. - Account settings and local data claiming (
#72): the Settings account card shows the signed-in email, last sync time (persisted in AsyncStorage), pending change count, a Sync now button, and Sign out with a confirmation dialog (also used on the Account screen). On the first sign-in on a device, anonymous local farms, plots and scans are claimed for that account and synced; records the API refused earlier are re-queued. Data synced by a different account is left untouched. - Android sync engine (
#47):app/src/services/sync.tspushes pending farms, plots and scans to the API in dependency order (farms, plots, scans in batches of100, then deletions), falls back fromPOSTtoPATCHon409, treats404on delete as done, marks API-refused recordsfailed, and leaves everythingpendingwhen a run stops offline or on a401/5xx. Outcomes are recorded only if the row was not edited during the run.app/src/services/cloudinary.tsresizes scan photos to a1280 pxlonger side and uploads them with API-signed parameters. Sync runs on sign-in, when connectivity returns (@react-native-community/netinfo), on app foreground, and on tapping the new Home sync pill, which pulses while syncing and morphs into a checkmark (static with reduce motion). - Firebase Auth email/password in the app (
#34):app/src/services/auth.ts(Firebase JS SDK with AsyncStorage session persistence, lazily initialized fromEXPO_PUBLIC_FIREBASE_*, error codes mapped toes/enmessages), a Zustand session store, Sign In, Sign Up and Account screens with form validation, aTextFieldUI primitive, a Settings account card, andapp/src/services/api.ts, which attachesAuthorization: Bearer <idToken>when signed in and retries once with a refreshed token on401. Diagnosis, history and local farms keep working without an account or without Firebase configured. - Idempotent batch
POST /scans/sync(client UUIDs, last write wins onupdated_at, tombstones, per-itemcreated/updated/unchanged/rejectedresults),GET /scanswithfarm_id/plot_id/cropfilters, andPOST /uploads/scan-signaturereturning signed Cloudinary upload parameters scoped tousers/{uid}/scanswith a1280 pxlimit, plus User A vs. User B isolation tests (#46). CRUD /farmsandCRUD /plotsinapi/with client-generated UUID v4 IDs,ownerUidfiltering on every Firestore read and write (OwnedRepositoryover aDocumentStoreprotocol), soft deletes with farm-to-plot cascade,404for other users' records,409for duplicate IDs, and User A vs. User B isolation tests (#33).- FastAPI core in
api/:create_appfactory (healthycropping_api.main:app), environment settings, publicGET /health, Pydantic v2 schemas, structured{"error": {"code", "message"}}responses, CORS, a Firebase ID token verification dependency (firebase-admin) protectingGET /me(401for missing, malformed, or expired tokens), and deny-allfirestore.ruleswithfirebase.json(#32). - Multi-crop offline diagnosis in the app: banana model registry bundled in
app/src/ml/models/banana/, banana selectable on the Home screen next to coffee and cacao, with tests for registry parity, model resource names, and the coming-soon state for crops without a model (#31). - Float16 TFLite banana model export (
ml/scripts/export_banana_tflite.py,ml/models/banana/banana_v0.1.0_fp16.tflite,6.06 MB,97.50%test accuracy with0.00 ppdrop vs Keras and100.0%top-1 agreement),--threshold-floorexport option, confidence threshold0.80(98.45%test precision at97.0%coverage),ml/models/banana/registry.json, and Banana Model Card (docs/MODEL_CARD.md§4) (#71). - Banana
MobileNetV3-Largefrozen baseline (97.00%test accuracy,0.9676Macro-F1) and top-30 fine-tuned model (97.50%test accuracy,0.9731Macro-F1), CLI script (ml/scripts/train_banana.py), per-source evaluation (ml/scripts/evaluate_by_source.py), confusion matrices, and Grad-CAM visual explanations indocs/EXPERIMENTS.md(#30). - Banana leaf dataset pipeline: BananaLSD (
OriginalSetonly, CC BY 4.0) and NM-AIST Banana Leaves Imagery (Zenodo7670326, CC BY 4.0) downloaders, HTTP Range extraction of image subsets from multi-gigabyte ZIP archives (ml/src/healthycropping_ml/remote_zip.py),ml/configs/banana.yaml,ml/scripts/prepare_banana.py, and the data report (docs/data_reports/banana.md,docs/assets/data_reports/banana_grid.png):1,313deduplicated images (391healthy,622black_sigatoka,300fusarium_wilt) across770groups with zero cross-split leakage (#29). - Float16 TFLite cacao model export (
ml/scripts/export_cacao_tflite.py,ml/models/cacao/cacao_v0.1.0_fp16.tflite,6.06 MB,91.73%test accuracy with0.00 ppdrop vs Keras and100.0%top-1 agreement), validation-calibrated confidence threshold0.51(90.15%val precis...
v0.2.0 — Offline Android App & Coffee Diagnosis
Added
- Offline-first SQLite persistence (
expo-sqlite,expo-crypto), repository layer for farms, plots, and scans with sync queue metadata, History screen with multi-filter and swipe-to-delete with undo, Scan Detail screen with farm/plot location assignment, and Farms/Plots CRUD screens (#26). - Camera screen with viewfinder framing guide and shutter flash, crop-specific photo tips modal, analyzing sweep-line animation, and result screen with severity progress meter, confidence breakdown, pop-in status badge with haptics, low-confidence retake state, and agronomic disclaimer (
#25). - On-device TFLite inference pipeline (
app/src/ml/) withexpo-image-manipulator,jpeg-jsRGB decoding, training normalization,react-native-fast-tflite, threshold calibration, and Jest cross-platform tensor parity test (#24). - Onboarding (3-slide educational flow with mandatory agronomic disclaimer acceptance), Home (camera-first layout, primary Scan CTA, crop selector chips, offline status pill, and empty state), and Settings screens (instant
es/enlanguage switcher, light/dark theme toggle, model version, dataset licenses) (#23). - Reusable UI component library in
app/src/components/ui/(Button,Card,Chip,Badge,Sheet,Toast,Skeleton,EmptyState,ProgressMeter) with spring micro-interactions, haptics, >= 48 dp touch targets, reduced motion support, and RNTL unit tests (#22). - Agricultural design tokens (
app/src/theme/) covering colors, typography, spacing, radii, elevation, and motion with dark/light themes and WCAG 2.1 AA mathematical contrast tests (#21). ThemeProvideranduseTheme()hook integrating user theme preference with system appearance and reduced motion accessibility (#21).- Expo SDK 52 Android application setup (
app/app.json,app/package.json) with packagecom.keylorpineda.healthycrop, New Architecture, and Expo Router (#20). - Internationalization subsystem (
app/src/i18n/) with Spanish default, English secondary, symmetric translation keys, and mandatory agronomic disclaimer (#20). - Zustand preferences store (
app/src/stores/preferences.ts) managing locale, light/dark/system theme, and onboarding state (#20). - Jest + React Native Testing Library configuration (
jest-expo) with native module mocks and unit tests (#20).
v0.1.0 — Foundation & Coffee ML
Added
- Phase 0 repository foundation, monorepo workspace configuration (
pnpm+uv), and.gitignore/.gitattributes/.editorconfigrules. - GitHub Community Standards (
LICENSE,CODE_OF_CONDUCT.md,CONTRIBUTING.md,SECURITY.md,SUPPORT.md,CITATION.cff,CODEOWNERS, issue templates, PR template, anddependabot.yml). - Project documentation (
AGENTS.md,docs/PLAN.md,docs/ARCHITECTURE.md,docs/DATASETS.md,docs/MODEL_CARD.md,docs/EXPERIMENTS.md,docs/FIELD_VALIDATION.md,docs/DEVLOG.md, and Spanish setup guidedocs/SETUP_SERVICES_ES.md). - CI and release GitHub Actions workflows (
.github/workflows/ci.ymland.github/workflows/release.yml) and empty test suites forapp/,api/, andml/. - Idempotent, SHA-256 verified coffee dataset downloaders (
ml/scripts/download_rocole.py,ml/scripts/download_bracol.py) with truncated-ZIP recovery for BRACOL (#13). - Coffee dataset preparation pipeline (
ml/configs/coffee.yaml,ml/scripts/prepare_coffee.py,ml/src/healthycrop_ml/preprocess.py,dedup.py,split.py) performing EXIF orientation correction,224x224RGB conversion, perceptual-hash deduplication (imagehash.phash), and grouped stratified70/15/15splitting (#14). - Coffee dataset report (
docs/data_reports/coffee.md),224x224sample grid (docs/assets/data_reports/coffee_grid.png), and< 50training-image merging evaluation (#15). - Frozen-backbone
MobileNetV3-Largebaseline training pipeline (ml/src/healthycrop_ml/model.py,evaluate.py,train.py,ml/scripts/train_coffee.py,ml/notebooks/01_coffee_training.ipynb), confusion matrix (docs/assets/confusion_matrices/coffee_baseline.png), and baseline metrics (79.72%test accuracy,0.7135test Macro-F1) indocs/EXPERIMENTS.md(#16). - Top-block
MobileNetV3-Largefine-tuning, validation logit bias calibration (82.75%uncalibrated /81.35%calibrated test accuracy,0.87014-major-class F1), confusion matrix (docs/assets/confusion_matrices/coffee_finetuned.png), and per-class Grad-CAM visual explanations (ml/src/healthycrop_ml/gradcam.py,docs/assets/gradcam/coffee_gradcam.png) (#17). - Float16 TFLite export pipeline (
ml/src/healthycrop_ml/export_tflite.py,ml/scripts/export_coffee_tflite.py):6.06 MBcoffee model at81.12%test accuracy (0.23 ppbelow Keras), validation-calibrated confidence threshold0.79(90.9%accepted precision),ml/models/coffee/registry.json, and the shared preprocessing fixtureml/fixtures/preprocessing_fixture_224.json(#18). - Coffee model card (
docs/MODEL_CARD.md§2): intended use, data, Keras vs TFLite metrics, per-class results with abstention coverage, Grad-CAM, and limitations; TFLite export results indocs/EXPERIMENTS.md(#19).