AI-powered crop disease detection and agricultural intelligence platform for modern farmers.
AgriAidAI combines a fine-tuned MobileNetV2 computer vision model with a FastAPI backend and a React frontend to deliver instant crop disease diagnosis, expert treatment recommendations, live weather intelligence, and a persistent scan history β all in one platform.
| Feature | Description |
|---|---|
| π¬ AI Disease Detection | MobileNetV2 model trained on the PlantVillage dataset β 38 disease classes across 16 crops |
| π Structured Results | Per-scan: disease name, confidence score, symptoms, treatment plan, preventive tips |
| π€οΈ Live Weather | Real-time weather via Open-Meteo using GPS or IP geolocation β no API key required |
| π Prediction History | All scans persisted in-memory; auto-refreshes on the dashboard |
| π Admin Statistics | Real prediction counts, average confidence, 7-day activity chart |
| π Export to PDF | Print any scan result as a PDF directly from the browser |
| π Auth (lightweight) | Email + fixed password login; username derived from email; localStorage session |
| π Multilingual | English + Hindi support via LanguageContext |
| π± Responsive | Works across desktop, tablet, and mobile |
| Layer | Technology |
|---|---|
| Framework | FastAPI |
| ML Runtime | TensorFlow / Keras |
| Model | MobileNetV2 (fine-tuned, PlantVillage dataset) |
| Weather | Open-Meteo API + Nominatim reverse geocoding |
| HTTP client | httpx |
| Server | Uvicorn with ASGI lifespan |
| Layer | Technology |
|---|---|
| Framework | React 18 + TypeScript |
| Styling | Tailwind CSS (minimal design system) |
| UI Components | shadcn/ui |
| Charts | Recharts |
| Routing | React Router v6 |
| Data Fetching | Native fetch + useCallback hooks |
agri-aid-master/
βββ agriaidai_backend/ # FastAPI backend
β βββ main.py # App entry point, routes, lifespan
β βββ models/
β β βββ prediction_models.py # Pydantic schemas
β β βββ train_plant_disease.py # Model training script
β βββ services/
β βββ prediction_service.py # MobileNetV2 inference engine
β βββ history_service.py # In-memory prediction history
β βββ weather_service.py # Open-Meteo live weather
β βββ admin_service.py # Real admin stats from history
β
βββ agri-aid-bright/ # React frontend
β βββ src/
β βββ pages/
β β βββ Index.tsx # Home + login (merged)
β β βββ Dashboard.tsx # Live dashboard with stats & charts
β β βββ Predict.tsx # Split-screen: upload + results
β β βββ Admin.tsx # Admin stats dashboard
β β βββ About.tsx # Platform info & tech details
β βββ components/
β β βββ Navigation.tsx # Sticky nav with auth + logout
β βββ contexts/
β βββ LanguageContext.tsx
β
βββ models/ # Trained model artifacts
βββ plant_disease_model.h5
βββ class_labels.npy
- Python 3.10+
- Node.js 18+
- A trained model file at
models/plant_disease_model.h5(see Training)
cd agri-aid-master
# Create and activate a virtual environment
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # macOS/Linux
# Install dependencies
pip install fastapi uvicorn tensorflow httpx numpy pillow python-multipart
# Start the backend
python -m agriaidai_backend.mainBackend runs at: http://localhost:8000 Interactive API docs: http://localhost:8000/docs
Environment variables (optional β set to suppress TF noise):
TF_ENABLE_ONEDNN_OPTS=0 TF_CPP_MIN_LOG_LEVEL=2
cd agri-aid-bright
npm install
npm run devFrontend runs at: http://localhost:8081
The app uses a lightweight auth system with localStorage.
| Field | Value |
|---|---|
Any valid email (yourname@example.com) |
|
| Password | password123# |
Your username in the navigation is automatically derived from the email prefix (e.g. john@gmail.com β displays as john).
The model classifies 38 disease classes across 16 crops:
| Crop | Example Diseases |
|---|---|
| Tomato | Early Blight, Late Blight, Leaf Mold, Mosaic Virus |
| Corn | Common Rust, Northern Leaf Blight, Gray Leaf Spot |
| Potato | Early Blight, Late Blight |
| Apple | Apple Scab, Black Rot, Cedar Apple Rust |
| Grape | Black Rot, Esca, Leaf Blight |
| Pepper | Bacterial Spot |
| Strawberry | Leaf Scorch |
| Peach, Cherry, Squash, Soybean, Orange, Blueberry, Raspberry | Various |
All crops also include a Healthy class.
To retrain or improve the model:
# Place PlantVillage dataset inside:
# agriaidai_backend/models/dataset/PlantVillage/
python agriaidai_backend/models/train_plant_disease.pyTraining configuration (in train_plant_disease.py):
- Architecture: MobileNetV2 (ImageNet pre-trained)
- Input size: 224 Γ 224 RGB
- Phase 1: 20 epochs β top classifier only
- Phase 2: 20 epochs β fine-tune top 30 layers
- Augmentation: flip, rotation, zoom, brightness, contrast
- Callbacks: EarlyStopping, ReduceLROnPlateau, ModelCheckpoint
Artifacts saved to models/:
plant_disease_model.h5β Keras model weightsclass_labels.npyβ ordered class name array
| Method | Endpoint | Description |
|---|---|---|
POST |
/predict |
Multipart: crop (str) + file (image) β disease prediction |
GET |
/weather |
?city= or ?lat=&lon= β live weather object |
GET |
/history |
Returns last N predictions |
POST |
/history |
Save a prediction entry |
GET |
/admin/stats |
Returns real prediction counts and 7-day chart data |
Full schema available at http://localhost:8000/docs
Weather is fetched automatically using a 3-tier location strategy:
- Browser GPS β asks for location permission; uses real coordinates
- IP Geolocation (
ipapi.co) β no permission needed; returns city from IP - Fallback β Coimbatore (default if both above fail)
The backend uses Open-Meteo (free, no API key) and Nominatim for reverse geocoding.
- Persistent database (SQLite / PostgreSQL) for prediction history
- Real user authentication with JWT
- Crop calendar & seasonal advisories
- Batch image analysis
- Push notifications for disease alerts
- Offline PWA support
- OpenWeatherMap integration for extended forecast
MIT License β open for personal and commercial use. Contributions welcome.
- PlantVillage Dataset β disease image training data
- Open-Meteo β free, no-key weather API
- Nominatim / OpenStreetMap β reverse geocoding
- shadcn/ui β React component system
- TensorFlow / Keras β ML framework