| title | AgroScan |
|---|---|
| emoji | 🌿 |
| colorFrom | green |
| colorTo | green |
| sdk | docker |
| app_port | 7860 |
AgroScan helps Indian farmers instantly detect crop diseases using AI — in Hindi and English.
India loses ₹50,000 crore+ worth of crops every year due to diseases that go undetected until it's too late. Farmers in rural areas don't have easy access to agricultural experts, and by the time they identify a disease, it has already spread.
AgroScan solves this problem.
A farmer standing in their field can:
- Open AgroScan on their phone browser (no app download needed)
- Take a live photo of the diseased leaf OR upload from gallery
- Get instant AI diagnosis in Hindi or English within 3 seconds
- See which pesticide to buy, at what dose, from which store
- Get the result directly on WhatsApp without even opening a website
Built specifically for Indian farmers with data from ICAR and PAU Ludhiana.
- 96.11% accuracy on 87 crop disease classes
- EfficientNet-B0 — lightweight model, fast on mobile
- Grad-CAM heatmap — shows exactly which part of leaf the AI analyzed
- Confidence score — how sure the model is about its prediction
- 2-stage transfer learning — ImageNet pretrained + fine-tuned
- Live camera scan — point phone camera at leaf, instant result
- Drag & drop upload — upload from gallery
- Hindi / English toggle — entire UI switches language instantly
- Dark / Light mode — comfortable in any lighting condition
- Mobile responsive — works on any phone browser
- Disease cure — exact treatment steps
- Prevention tips — how to avoid next season
- Pesticide recommendations — name, dose, application method
- Cause analysis — why the disease happened
- Select crop + planting date
- Get expected harvest date
- Days remaining countdown
- Signs of readiness
- Best harvest time
- 23 crops supported
- Temperature, humidity, light, watering for each crop
- Pot/container size recommendations
- Do's and Don'ts
- 23 crops with Hindi + English support
- Recommended pesticide name
- Exact dose per litre
- Available at local agri store
- Kisan Call Centre: 1800-180-1551 (Free, 24/7, Hindi)
- Find nearest KVK (Krishi Vigyan Kendra)
- Find nearest Agri Market/Mandi
- Farmer sends leaf photo on WhatsApp
- Bot replies in Hindi with disease + cure + pesticide
- No app download, no website — just WhatsApp
- Works on any basic Android phone
| Layer | Technology | Purpose |
|---|---|---|
| ML Model | EfficientNet-B0 (PyTorch) | Disease classification |
| Explainability | Grad-CAM | Heatmap visualization |
| Backend | FastAPI + Uvicorn | REST API server |
| Frontend | Vanilla HTML/CSS/JS | Web interface |
| Twilio | Bot integration | |
| Training | Apple Silicon MPS | GPU acceleration |
| Deployment | Hugging Face Spaces | Free cloud hosting |
| Stage | Description | Val Accuracy | Val Loss |
|---|---|---|---|
| Stage 1 | Frozen backbone, head only | 87.08% | 0.4070 |
| Stage 2 Ep 1 | Full fine-tune starts | 91.46% | 0.2559 |
| Stage 2 Ep 5 | Continued improvement | 94.91% | 0.1603 |
| Stage 2 Ep 10 | Strong convergence | 95.63% | 0.1401 |
| Stage 2 Ep 14 | Best checkpoint | 96.11% | 0.1309 |
| Dataset | Crops | Images | Classes |
|---|---|---|---|
| PlantVillage | 14 crops | 54,303 | 38 |
| Rice Leaf Diseases | Rice | 1,500 | 3 |
| Wheat Plant Diseases | Wheat | 13,104 | 15 |
| Multi-Crop Disease | 5 crops | 42,638 | 30 |
| Total (merged) | 20+ crops | 67,368 | 87 |
| Parameter | Stage 1 | Stage 2 |
|---|---|---|
| Backbone | Frozen | Unfrozen |
| Epochs | 5 | 15 |
| Learning Rate | 1e-3 | 1e-4 |
| Scheduler | CosineAnnealingLR | CosineAnnealingLR |
| Optimizer | Adam | Adam |
| Early Stopping | patience=5 | patience=5 |
| Image Size | 224×224 | 224×224 |
| Batch Size | 32 | 32 |
| Class Weighting | Balanced | Balanced |
git clone https://github.com/B2prakash/Agroscan.git
cd Agroscanpip install -r requirements.txt# Place your datasets under data/
# Then merge them:
python scripts/merge_datasets.py# Both stages in one go:
python train.py --data data/merged --epochs_stage1 5 --epochs_stage2 15
# Or stage by stage (recommended — review Stage 1 before fine-tuning):
python train.py --data data/merged --epochs_stage1 5 --epochs_stage2 15 --stage 1
python train.py --data data/merged --epochs_stage1 5 --epochs_stage2 15 --stage 2Training outputs saved to models/:
best_model.pth— best checkpoint (by val accuracy)class_names.json— ordered class liststage1_history.json— Stage 1 metricstraining_curves.png— loss / accuracy plots
uvicorn main:app --host 0.0.0.0 --port 8000Open index.html in a browser, or serve it:
python -m http.server 3000
# then visit http://localhost:3000Returns model status and device info.
{
"status": "ok",
"model_loaded": true,
"num_classes": 87,
"device": "mps"
}Upload a leaf image, get disease diagnosis.
Request: multipart/form-data with field file (image)
Response:
{
"class": "Tomato___Late_blight",
"confidence": 94.37,
"severity": "high",
"disease_info": {
"name_en": "Late Blight",
"name_hi": "पछेती झुलसा",
"cure_en": "...",
"cure_hi": "...",
"prevention_en": "...",
"prevention_hi": "...",
"pesticide_en": "...",
"pesticide_hi": "..."
},
"gradcam_image": "<base64 JPEG>"
}Twilio WhatsApp webhook. Accepts a multipart form with Body, MediaUrl0, From, NumMedia. Returns TwiML with Hindi diagnosis reply.
agroscan/
├── main.py # FastAPI app — /health, /predict, /whatsapp
├── train.py # 2-stage training script
├── index.html # Single-file frontend (HTML + CSS + JS)
├── requirements.txt # Python dependencies
│
├── src/
│ ├── model.py # EfficientNet-B0 model builder
│ ├── gradcam.py # Grad-CAM implementation
│ ├── utils.py # DataLoaders, preprocessing, class weights
│ └── disease_info.py # Bilingual disease info for 87 classes
│
├── scripts/
│ ├── merge_datasets.py # Merge multiple datasets into one folder
│ ├── augment_rice.py # Data augmentation for rice classes
│ ├── augment_weak_classes.py # Augment under-represented classes
│ └── convert_multicrop.py # Convert multi-crop dataset to standard format
│
└── models/
├── best_model.pth # Trained weights (not in repo — large file)
├── class_names.json # 87 class names in order
├── stage1_history.json # Stage 1 training history
└── training_curves.png # Loss/accuracy plot
87 disease classes across 20+ crops including:
| Crop | # Diseases |
|---|---|
| Tomato | 10 |
| Potato | 3 |
| Corn/Maize | 4 |
| Rice | 3 |
| Wheat | 15 |
| Apple | 4 |
| Grape | 4 |
| Peach | 2 |
| Cherry | 2 |
| Pepper | 2 |
| Strawberry | 2 |
| Squash | 1 |
| Soybean | 1 |
| Raspberry | 1 |
| + more | ... |
Each disease entry includes: English name, Hindi name, cure, prevention, cause, and pesticide recommendation.
- Create a Twilio account and enable WhatsApp Sandbox
- Add your Twilio credentials to
.env:
TWILIO_ACCOUNT_SID=your_sid
TWILIO_AUTH_TOKEN=your_token- Set your Twilio webhook URL to:
https://your-domain.com/whatsapp
- Farmers can now send leaf photos to your WhatsApp number and receive Hindi diagnosis replies instantly.
Currently collecting field datasets from Haryana farmers:
- 🧅 Onion
- 🧄 Garlic
- 🍆 Brinjal/Eggplant
- 🥒 Cucumber
- 🌻 Mustard (Sarson)
- 🫘 Pulses: Chana, Moong Dal, Arhar Dal
- 🥕 Carrot
- 🥬 Spinach
- Flutter mobile app (Android + iOS)
- Offline mode (works without internet)
- Visual maturity detection (harvest readiness)
- Soil health analysis
- Weather-based disease prediction
Pull requests are welcome. For major changes, open an issue first.
- Fork the repo
- Create your branch:
git checkout -b feature/my-feature - Commit:
git commit -m "Add my feature" - Push:
git push origin feature/my-feature - Open a Pull Request
Distributed under the MIT License. See LICENSE for details.
Bittu (B2prakash) BE-IT, Chandigarh University GSoC 2026 Contributor — Mesa / NumFOCUS
- PlantVillage Dataset — Penn State University
- ICAR — Indian Council of Agricultural Research
- PAU Ludhiana — Punjab Agricultural University
- EfficientNet — Tan & Le, Google Brain
- Grad-CAM — Selvaraju et al.
- Twilio — WhatsApp API