# Shamba AI 🌿
Crop disease detection for Kenyan smallholder farmers.
Upload or photograph a diseased leaf → get a diagnosis, treatment steps,
yield impact estimate, and nearest agro-vet — in English or Swahili.
---
## Quick start (local dev)
```bash
cp .env.example .env # fill in your keys
docker compose up # API + worker + Redis + Postgres + frontend
```
Frontend:
localhost
API docs:
localhost
---
## Project structure
```
shamba-ai/
├── backend/
│ ├── app/
│ │ ├── api/routes/ # FastAPI routers
│ │ │ ├── diagnosis.py # submit, poll result, feedback
│ │ │ └── knowledge.py # disease knowledge base
│ │ ├── core/ # config, database
│ │ ├── models/ # SQLAlchemy models
│ │ ├── schemas/ # Pydantic schemas
│ │ ├── services/
│ │ │ ├── preprocessing.py # CLAHE, unsharp mask, white balance
│ │ │ ├── inference.py # ONNX Runtime + TTA + temperature scaling
│ │ │ ├── gradcam.py # Grad-CAM heatmap generation
│ │ │ ├── knowledge.py # disease KB with Kenyan treatments
│ │ │ ├── storage.py # Cloudflare R2
│ │ │ └── sms.py # Africa is Talking SMS
│ │ └── tasks/
│ │ └── celery_app.py # async inference worker
│ └── ml/
│ ├── train.py # EfficientNet-B0 + Albumentations
│ ├── export_onnx.py # PyTorch → ONNX
│ └── calibrate.py # temperature scaling
└── frontend/
└── src/
├── components/
│ ├── capture/ # CaptureScreen with tips + quality check
│ ├── diagnosis/ # Result screen + diagnosing screen
│ ├── layout/ # AppLayout + header
│ └── ui/ # LanguageToggle
├── hooks/
│ └── useDiagnosis.ts # full flow: compress → quality check → upload → poll
├── lib/
│ ├── api.ts # API client
│ ├── imageUtils.ts # compression + blur detection
│ └── uploadQueue.ts # IndexedDB offline queue
└── i18 …