Skip to content

Repository files navigation

🌿 LeafLens — AI Plant Disease Classifier

Upload a leaf image. Get an instant disease diagnosis powered by deep learning + expert LLM advice for farmers.

Python PyTorch Streamlit Accuracy Dataset


📌 What It Does

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

🧠 Model Comparison

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.

Accuracy & Loss Curves

Accuracy Graph

Confusion Matrix

Confusion Matrix


🤖 LLM Integration

After classification, the top-3 predictions are passed to LLaMA 3.1-8B via Groq API which generates:

  1. Disease explanation
  2. Symptoms to look for
  3. Prevention methods
  4. Treatment options

All explained in simple language suitable for farmers — not just a label, but actionable advice.


🌱 Supported Crops & Diseases (38 Classes)

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

🛠️ Tech Stack

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

🚀 Run Locally

1. Clone the repo

git clone https://github.com/TheGhostLoop/leaflens.git
cd leaflens

2. Install dependencies

pip install -r requirements.txt

3. Add your Groq API key

Create .streamlit/secrets.toml:

GROQ_KEY = "your_groq_api_key_here"

Get a free key at console.groq.com

4. Run the app

streamlit run app.py

📁 Project Structure

leaflens/
├── 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

📦 Requirements

streamlit
torch
torchvision
Pillow
langchain-openai
pandas

📊 Dataset

PlantVillage — publicly available on Kaggle

  • 87,000+ leaf images
  • 38 classes (healthy + diseased)
  • 14 crop types
  • RGB images, varied lighting and backgrounds

👤 Author

Prince Verma


📄 License

This project is open source and available under the MIT License.

About

Plant disease classifier using EfficientNet-B0 (98.65% accuracy) + LLM-powered expert advice for farmers. Built with PyTorch & Streamlit.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages