--- title: Plant Disease Detection emoji: 🌿 colorFrom: green colorTo: green sdk: gradio sdk_version: 5.29.0 app_file: app.py pinned: false license: mit tags: - plant-disease - agriculture - computer-vision - tensorflow - grad-cam --- # 🌿 Plant Disease Detection [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/WaqarMughal/Plant_Disease_Detection) AI-powered plant disease diagnosis using deep learning. Upload leaf images and get instant diagnosis with treatment recommendations through a conversational chatbot interface. Try the live demo here: **[Plant Disease Detection on Hugging Face](https://huggingface.co/spaces/WaqarMughal/Plant_Disease_Detection)** ## ✨ Features - **πŸ€– AI Diagnosis**: ResNet-18 model with **99.17% accuracy** across 38 disease classes - **πŸ” Grad-CAM Visualisation**: See exactly where the AI is looking on the leaf (heatmaps) - **πŸ’Š Treatment Recommendations**: Get actionable advice for each detected disease - **πŸ“Š Confidence Scores**: Know how certain the model is about each prediction - **πŸ’¬ Chatbot Interface**: Natural, conversational interaction powered by Gradio 5 - **πŸ–ΌοΈ Batch Processing**: Upload multiple images at once - **⚑ Fast Inference**: Optimized Keras 3 processing on CPU ## 🎯 Model Details | Property | Value | |----------|-------| | **Architecture** | Custom ResNet-18 (trained from scratch) | | **Training Data** | 54,305 images from PlantVillage dataset | | **Classes** | 38 disease + healthy classes | | **Accuracy** | 99.17% on test set | | **Preprocessing** | CLAHE enhancement in LAB color space | ## 🌱 Supported Crops - **Fruits**: Apple, Cherry, Peach, Raspberry, Strawberry, Grape, Orange/Citrus, Blueberry - **Vegetables**: Potato, Tomato, Pepper (Bell), Squash - **Grains**: Corn (Maize), Soybean ## 🦠 Disease Categories Detected | Type | Diseases | |------|----------| | **Fungal** | Scab, Black Rot, Powdery Mildew, Early/Late Blight, Leaf Spots, Leaf Mold, Rust | | **Bacterial** | Bacterial Spot, Bacterial Speck | | **Viral** | Mosaic Virus, Yellow Leaf Curl Virus | | **Pests** | Spider Mites (Two-spotted) | | **Healthy** | No disease detected | ## πŸ“– How to Use 1. **Upload** a clear photo of a plant leaf (drag & drop or click to browse) 2. **Click** "Analyse Leaves" (or auto-runs on upload) 3. **Review** the diagnosis, confidence score, and treatment recommendations 4. **Check** the Grad-CAM overlay to see AI attention areas ## πŸ’‘ Tips for Best Results - Use well-lit, close-up photos of a single leaf - Focus on the affected area of the leaf - Ensure the leaf fills most of the frame - Avoid blurry or dark images - Try example images from the gallery below the input ## πŸ’» Running Locally If you would like to run the Plant Disease Detection app on your own machine, you can easily set it up with the following steps: 1. **Clone the repository**: ```bash git clone https://huggingface.co/spaces/WaqarMughal/Plant_Disease_Detection cd Plant_Disease_Detection ``` 2. **Install the required dependencies**: ```bash pip install -r requirements.txt ``` 3. **Launch the app**: ```bash python app.py ``` 4. **Open your browser** and navigate to `http://localhost:7860` ## πŸ“ Files | File | Description | |------|-------------| | `app.py` | Main Gradio chatbot application | | `model_best_0.9917_ep040_acc0.9917.keras` | Trained model weights (99.17% accuracy) | | `normalization_stats.json` | Training dataset normalization statistics | | `requirements.txt` | Python dependencies | | `examples/` | Sample leaf images for testing | ## πŸ“Š Output Format For each uploaded image, you receive: 1. **Diagnosis**: Disease name with severity indicator 2. **Confidence**: Percentage with visual progress bar 3. **Pathogen**: Scientific name of causative agent 4. **Symptoms**: Key visual indicators to look for 5. **Treatment**: Actionable management recommendations 6. **Grad-CAM**: Visual heatmap showing AI attention areas ## πŸ“„ License MIT License - Feel free to use, modify, and deploy. ## πŸ™ Credits - **Dataset**: PlantVillage (Hughes & SalathΓ©, 2015) - **Framework**: TensorFlow/Keras, Gradio - **Visualization**: Grad-CAM (Selvaraju et al., 2017) - **Author**: Waqar Ul Hasan ## πŸ”— Links - [PlantVillage Dataset Paper](https://arxiv.org/abs/1511.08060) - [Grad-CAM Paper](https://arxiv.org/abs/1610.02391) - [Gradio Documentation](https://gradio.app/docs/)