An end‑to‑end, agentic AI system that combines crop recommendation, plant disease detection, and farming Q&A — now with a modern Next.js + Tailwind frontend and a Flask API backend.
- 🌾 Crop Recommendation: Soil + climate‑aware crop prediction
- 🍃 Disease Detection: Image‑based plant disease classification
- ❓ Farming Q&A: RAG pipeline with semantic search + optional LLM
- 🧠 Agentic Routing: Smart intent routing between tools
- ⚡ Full‑Stack UI: Next.js 14 frontend with clean UX
| Component | Model/Method | Score | Status |
|---|---|---|---|
| Crop Recommendation | Random Forest + Feature Engineering | 99.39% | ✅ Excellent |
| Disease Detection | ResNet50 (Transfer Learning) | 98.97% | ✅ Research‑grade |
| RAG Q&A | FAISS + Sentence Transformers | Hit Rate: 100%, MRR: 1.0 | ✅ Production‑ready |
| Agent Routing | Intent Classification | 100% | ✅ Perfect |
┌─────────────┐
│ Browser │ ← User Interface
└──────┬──────┘
│ HTTP
▼
┌──────────────────┐
│ Next.js (3000) │ ← Frontend
│ - Pages │
│ - Components │
│ - API Client │
└──────┬───────────┘
│ REST API
▼
┌──────────────────┐
│ Flask (5000) │ ← Backend
│ - Agent Router │
│ - API Endpoints │
└──────┬───────────┘
│
├──────────┬─────────────┬──────────┐
▼ ▼ ▼ │
┌────────┐ ┌─────────┐ ┌─────────┐ │
│ Crop │ │ Disease │ │ RAG │ │
│ Tool │ │ Tool │ │ Tool │ │
└────┬───┘ └────┬────┘ └────┬────┘ │
│ │ │ │
▼ ▼ ▼ ▼
┌────────────────────────────────────────┐
│ Trained ML Models │
│ - crop_model.pkl │
│ - disease_model_resnet50.pth │
│ - faq_vector_store.index │
└────────────────────────────────────────┘
Frontend
- Next.js 14 + TypeScript
- Tailwind CSS
- Axios / Fetch
Backend
- Python 3.8+
- Flask + Flask‑CORS
- PyTorch, Scikit‑learn
- FAISS + Sentence Transformers
Double-click: START.batThis opens two terminals and starts both servers automatically!
Terminal 1 - Backend:
cd "c:\Users\LAPTOP CLINIC\Documents\Projects\smart-farming-advisor"
python app.pyTerminal 2 - Frontend:
cd "c:\Users\LAPTOP CLINIC\Documents\Projects\smart-farming-advisor\frontend"
npm install # First time only
npm run devAccess: http://localhost:3000
GET /health- Health checkPOST /api/crop/recommend- Get crop recommendationsPOST /api/disease/predict- Detect plant disease (multipart form‑data withfile)POST /api/qa- Ask farming questionsGET /api/system/info- Get system and model information
Backend (optional):
GOOGLE_API_KEY=your_gemini_api_key # For Gemini LLM (optional)Frontend:
NEXT_PUBLIC_API_BASE=http://localhost:5000smart-farming-advisor/
├── app.py # Flask API
├── config.py # Configuration
├── requirements.txt # Python dependencies
├── frontend/ # Next.js app
│ ├── app/ # Pages (home, crop, disease, qa, etc.)
│ ├── components/ # Reusable UI components
│ ├── lib/ # API client & utilities
│ └── package.json # Node dependencies
├── src/
│ ├── agent/ # Agent router
│ ├── tools/ # Crop / Disease / RAG tools
│ ├── models/ # Training scripts
│ ├── preprocessing/ # Data preprocessing
│ └── evaluation/ # Evaluation scripts
├── models/ # Trained models (large files ignored)
├── data/ # Datasets (ignored)
├── outputs/ # Results, plots (ignored)
└── notebooks/ # Jupyter notebooks
Test the backend:
# Test agent
python src/agent/farming_agent.py
# Test individual tools
python src/tools/crop_predictor_tool.py
python src/tools/disease_detector_tool.py
python src/tools/rag_qa_tool.py
# Evaluate RAG system
python src/evaluation/rag_evaluation.pyResults are saved under outputs/.
- Algorithm: Random Forest Classifier
- Features: N, P, K, Temperature, Humidity, pH, Rainfall + engineered features
- Test Accuracy: 99.39%
- Training Time: ~2 seconds
- Architecture: ResNet50 (Transfer Learning)
- Pretrained on: ImageNet
- Input: 224×224 RGB
- Test Accuracy: 98.97%
- Training Time: ~33 minutes (GPU)
- Embeddings:
sentence-transformers/all-MiniLM-L6-v2 - Vector Store: FAISS
- Optional LLM: Google Gemini 2.0 Flash
- Performance: 100% hit rate, MRR 1.0
| Dataset | Source | Purpose |
|---|---|---|
| Crop Recommendation | Kaggle | Soil‑based crop prediction (2,200 samples, 22 crops) |
| Plant Disease (PlantVillage) | Public | Disease classification (20,639 images, 15 diseases) |
| FAQ Knowledge Base | Custom | Farming Q&A (10 documents) |
Large datasets and model binaries are excluded from GitHub. See .gitignore.
This repo intentionally ignores:
data/raw/anddata/processed/- Raw and processed datasets- Large model weights (
*.pth,*.pt,*.onnx) - Trained model files - FAISS index (
*.index) - Vector store index - Frontend build artifacts (
frontend/.next,frontend/node_modules) - Outputs and uploads (
outputs/,uploads/)
Remember to add all these files by yourself, If you need any help running this project contact me at email.
✅ Multi-modal AI System - Text, images, and structured data
✅ Agentic Routing - Intelligent query classification
✅ Transfer Learning - ResNet50 pretrained on ImageNet
✅ RAG Implementation - Semantic search with FAISS
✅ Production-Ready - 98-99% accuracy across all models
✅ Modular Architecture - Easy to extend and maintain
✅ Full-Stack - Modern frontend with Next.js + Tailwind
✅ Comprehensive Testing - All components tested
Pull requests are welcome! Please open an issue for major changes.
MIT License
-
Datasets:
- Crop Recommendation Dataset (Kaggle)
- PlantVillage Disease Dataset
- Farmer Support FAQ Dataset
-
Pretrained Models:
- ResNet50 (ImageNet, PyTorch)
- sentence-transformers/all-MiniLM-L6-v2 (HuggingFace)
-
Tools:
- Google Colab (GPU training)
- FAISS (Facebook AI Similarity Search)
- Google Gemini API (LLM)
Author: juni2003
Email: juni.xatti@gmail.com
GitHub: @juni2003
⭐ If you find this project helpful, please consider giving it a star!