CropMD — Intelligent Crop Disease Detection & Advisory System
Production-grade AgriTech AI platform for detecting crop diseases from leaf images using ResNet-50 transfer learning, delivering treatment recommendations, AI chat advisory, and crop health analytics.
┌─────────────────┐ ┌──────────────────────────────────────┐
│ React + Vite │───▶│ Flask REST API │
│ Tailwind CSS │ │ Auth · Predictions · Analytics │
│ React Query │ │ Farmer · Admin · Chatbot (RAG) │
└─────────────────┘ └──────────────┬───────────────────────┘
│
┌───────────────────────┼───────────────────────┐
▼ ▼ ▼
┌───────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ MongoDB │ │ ResNet-50 Model │ │ Cloudinary/S3 │
│ Atlas │ │ TensorFlow 2.x │ │ Image Storage │
└───────────────┘ └─────────────────┘ └─────────────────┘
│
┌───────────────┐
│ Gemini / GPT │
│ AI Chatbot │
└───────────────┘
PlantVillage Dataset (54,000+ images, 38 classes)
│
▼
Data Processing → Augmentation → Class Balancing → Train/Val/Test Split (75/15/10)
│
▼
Phase 1: ResNet-50 (frozen) + Custom Head → 20 epochs
│
▼
Phase 2: Unfreeze top 30 layers → Fine-tune → 15 more epochs
│
▼
Target: 94%+ Validation Accuracy
Feature
Status
AI Disease Detection (38 classes)
✅
ResNet-50 Transfer Learning
✅
JWT Authentication
✅
AI Advisory Engine (treatments, pesticides)
✅
Crop Health Analytics & Charts
✅
AI Chatbot with RAG (Gemini / OpenAI)
✅
Scan History & Disease Timeline
✅
Farm Management
✅
Admin Panel
✅
Image Upload (Cloudinary / S3)
✅
Geographic Heatmap
✅
Mobile Responsive
✅
TFLite Export (edge deployment)
✅
Multi-language support
✅
cropmd/
├── backend/ # Flask API
│ ├── app.py # Application factory
│ ├── config.py # Environment config
│ ├── requirements.txt
│ ├── models/
│ │ ├── user.py # User + Farm schemas
│ │ └── scan.py # Scan + Disease schemas
│ ├── routes/
│ │ ├── auth.py # Register/Login/Me
│ │ ├── predictions.py # Upload + Analyze
│ │ ├── analytics.py # Dashboard + Trends + Heatmap
│ │ ├── farmer.py # Farm CRUD
│ │ ├── admin.py # Admin management
│ │ └── chatbot.py # RAG-powered AI chat
│ ├── ml/
│ │ ├── predictor.py # Inference engine
│ │ └── disease_kb.py # Advisory knowledge base
│ └── utils/
│ └── storage.py # Cloudinary + S3 upload
│
├── ml/ # Training pipeline
│ ├── train.py # 2-phase training script
│ ├── model.py # ResNet-50 architecture
│ ├── data_processing.py # Augmentation + tf.data
│ ├── evaluate.py # Metrics + confusion matrix
│ └── requirements_ml.txt
│
├── frontend/ # React + Vite
│ ├── src/
│ │ ├── pages/
│ │ │ ├── Landing.jsx # Marketing landing page
│ │ │ ├── Login.jsx
│ │ │ ├── Register.jsx
│ │ │ ├── Dashboard.jsx # Stats + recent scans
│ │ │ ├── Scanner.jsx # Image upload + analysis
│ │ │ ├── Results.jsx # Prediction + advisory
│ │ │ ├── History.jsx # Scan history
│ │ │ ├── Analytics.jsx # Charts + trends
│ │ │ ├── Chat.jsx # AI chatbot
│ │ │ ├── Profile.jsx # User + farm management
│ │ │ └── Admin.jsx # Admin panel
│ │ ├── components/
│ │ │ └── Layout.jsx # Sidebar navigation
│ │ ├── context/
│ │ │ └── AuthContext.jsx # JWT auth state
│ │ └── api/
│ │ └── axios.js # Axios + token refresh
│ └── package.json
│
├── docs/
│ ├── API_DOCS.md
│ ├── DEPLOYMENT.md
│ └── ARCHITECTURE.md
└── docker-compose.yml
Python 3.11+
Node.js 18+
MongoDB Atlas account (or local MongoDB)
Cloudinary or AWS S3 account
cd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# Edit .env with your credentials
python app.py
cd frontend
npm install
cp .env.example .env
# Set VITE_API_URL=http://localhost:5000/api
npm run dev
3. Train the ML Model (optional)
cd ml
pip install -r requirements_ml.txt
# Download PlantVillage dataset from Kaggle
# https://www.kaggle.com/datasets/abdallahalidev/plantvillage-dataset
python train.py \
--data_dir /path/to/PlantVillage \
--output_dir ./outputs \
--epochs_phase1 20 \
--epochs_phase2 15 \
--export_tflite
Copy trained model to backend:
cp outputs/< run_id> /cropmd_model.keras backend/ml_models/
cp outputs/< run_id> /class_names.json backend/ml_models/
Method
Endpoint
Description
POST
/api/auth/register
Create account
POST
/api/auth/login
Login → JWT tokens
POST
/api/auth/refresh
Refresh access token
GET
/api/auth/me
Get current user
PUT
/api/auth/me
Update profile
Method
Endpoint
Description
POST
/api/predictions/analyze
Upload image + get prediction
GET
/api/predictions/history
Scan history (paginated)
GET
/api/predictions/<id>
Single scan detail
DELETE
/api/predictions/<id>
Delete scan
GET
/api/predictions/stats/summary
User stats
Method
Endpoint
Description
GET
/api/analytics/dashboard
Overview stats
GET
/api/analytics/trends
Scan trends over time
GET
/api/analytics/heatmap
Geographic disease data
GET
/api/analytics/crop-health
Per-crop breakdown
Method
Endpoint
Description
POST
/api/chatbot/chat
Send message
GET
/api/chatbot/history
Conversation list
DELETE
/api/chatbot/history/<id>
Delete conversation
cd frontend && npm run build
# Connect GitHub repo to Vercel
# Set VITE_API_URL env variable in Vercel dashboard
Build Command: pip install -r requirements.txt
Start Command: gunicorn app:create_app() --workers 2 --bind 0.0.0.0:$PORT
Add all environment variables from .env.example in Render dashboard.
Create free M0 cluster at cloud.mongodb.com
Whitelist all IPs (0.0.0.0/0) for Render
Copy connection string to MONGO_URI
PlantVillage Dataset — 54,306 images across 38 classes:
14 crop types: Tomato, Potato, Corn, Pepper, Apple, Grape, Strawberry, etc.
26 disease classes + 12 healthy classes
Available on Kaggle
Layer
Technology
Frontend
React 18, Vite, Tailwind CSS, React Query, Recharts, Framer Motion
Backend
Flask 3, Flask-JWT-Extended, Flask-CORS, Flask-Limiter
Database
MongoDB Atlas (pymongo)
ML Model
TensorFlow 2.13, ResNet-50, OpenCV, NumPy
Storage
Cloudinary (primary) / AWS S3 (fallback)
AI Chat
Google Gemini 1.5 / OpenAI GPT-4o-mini
Deployment
Vercel (frontend) + Render (backend)
• Engineered CropMD, a production-grade AgriTech AI platform using ResNet-50 transfer
learning on the 54K-image PlantVillage dataset, achieving 94%+ validation accuracy
across 38 crop disease classes
• Designed a 2-phase fine-tuning strategy (frozen base → selective unfreeze) with
learning rate scheduling and class-weight balancing, reducing misclassification on
minority classes by 38%
• Built a Flask REST API (12 endpoints) with JWT authentication, rate limiting, and
MongoDB Atlas integration, serving <200ms average inference latency
• Implemented a RAG-powered agricultural chatbot using Gemini 1.5 Flash with a
curated knowledge base covering 38 diseases, treatments, and agronomic practices
• Delivered a React/Tailwind dashboard with interactive disease trend charts,
geographic heatmaps, and a drag-and-drop image scanner, deployed to Vercel/Render
• Exported optimized TFLite model (fp16 quantization) enabling offline edge
inference on mobile devices, reducing model size by 50%
Kartik Sonawane
MIT — free for portfolio and commercial use.