Upload a leaf image. Get an instant disease diagnosis powered by deep learning + expert LLM advice for farmers.
LeafLens is an end-to-end plant disease detection web app that:
- Classifies leaf images into 38 disease/healthy categories across 14 crop types
- Shows top-3 predictions with confidence scores
- Provides AI-generated expert advice via LLM (Groq + LLaMA 3.1) — symptoms, prevention, and treatment in simple farmer-friendly language
Three architectures were benchmarked on the PlantVillage dataset before selecting the final model:
| Model | Val Accuracy | Params | Training Speed |
|---|---|---|---|
| ResNet18 | ~93.2% | 11.7M | Fast |
| DenseNet121 | ~95.8% | 8.0M | Moderate |
| EfficientNet-B0 ✅ | 98.65% | 5.3M | Fast |
EfficientNet-B0 was chosen — highest accuracy with the fewest parameters, making it efficient for deployment without sacrificing performance.
After classification, the top-3 predictions are passed to LLaMA 3.1-8B via Groq API which generates:
- Disease explanation
- Symptoms to look for
- Prevention methods
- Treatment options
All explained in simple language suitable for farmers — not just a label, but actionable advice.
| Crop | Conditions Covered |
|---|---|
| Tomato | Late blight, Early blight, Bacterial spot, Leaf mold, Mosaic virus, Yellow Leaf Curl, Septoria leaf spot, Spider mites, Target spot, Healthy |
| Apple | Apple scab, Black rot, Cedar apple rust, Healthy |
| Grape | Black rot, Esca (Black Measles), Leaf blight, Healthy |
| Corn | Northern Leaf Blight, Cercospora leaf spot, Common rust, Healthy |
| Potato | Late blight, Early blight, Healthy |
| Peach | Bacterial spot, Healthy |
| Cherry | Powdery mildew, Healthy |
| Strawberry | Leaf scorch, Healthy |
| Pepper | Bacterial spot, Healthy |
| Orange | Haunglongbing (Citrus greening) |
| Squash | Powdery mildew |
| Soybean | Healthy |
| Blueberry | Healthy |
| Raspberry | Healthy |
| Component | Technology |
|---|---|
| Model | EfficientNet-B0 (PyTorch, Transfer Learning) |
| Dataset | PlantVillage (Kaggle) — 87,000+ images |
| Frontend | Streamlit |
| LLM | LLaMA 3.1-8B via Groq API |
| LLM Framework | LangChain OpenAI |
git clone https://github.com/TheGhostLoop/leaflens.git
cd leaflenspip install -r requirements.txtCreate .streamlit/secrets.toml:
GROQ_KEY = "your_groq_api_key_here"Get a free key at console.groq.com
streamlit run app.pyleaflens/
├── app.py # Main Streamlit app
├── model.pth # Trained EfficientNet-B0 weights
├── requirements.txt
├── accuracy_graph.png # Training vs validation accuracy
├── confusion_matrix.png # Model evaluation
├── .gitignore
└── .streamlit/
└── secrets.toml # Local only — never pushed
streamlit
torch
torchvision
Pillow
langchain-openai
pandas
PlantVillage — publicly available on Kaggle
- 87,000+ leaf images
- 38 classes (healthy + diseased)
- 14 crop types
- RGB images, varied lighting and backgrounds
Prince Verma
- GitHub: @TheGhostLoop
- Email: princeverma2005@yahoo.com
This project is open source and available under the MIT License.

