Spaces:
Sleeping
Sleeping
File size: 4,007 Bytes
32e2644 7a11d7a 32e2644 7a11d7a 32e2644 7a11d7a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | ---
title: Plant Disease Prediction API
emoji: 🌱
colorFrom: green
colorTo: blue
sdk: docker
pinned: false
license: apache-2.0
app_port: 7860
---
# Plant Disease Prediction API 🌱
A FastAPI-based web service that predicts plant diseases from leaf images using a deep learning model trained on plant pathology data.
## Features
- **38 Disease Classes**: Supports detection of various diseases across multiple plant species including Apple, Corn, Grape, Tomato, Potato, and more
- **Batch Processing**: Process up to 10 images simultaneously
- **High Accuracy**: Uses a pre-trained CNN model for reliable disease classification
- **Easy Integration**: RESTful API with comprehensive documentation
- **Model Pre-warming**: Fast inference with pre-loaded model
## Supported Plants & Diseases
### Apple
- Apple Scab, Black Rot, Cedar Apple Rust, Healthy
### Corn (Maize)
- Cercospora Leaf Spot, Common Rust, Northern Leaf Blight, Healthy
### Tomato
- Bacterial Spot, Early Blight, Late Blight, Leaf Mold, Septoria Leaf Spot, Spider Mites, Target Spot, Yellow Leaf Curl Virus, Mosaic Virus, Healthy
### Grape
- Black Rot, Esca (Black Measles), Leaf Blight, Healthy
### Potato
- Early Blight, Late Blight, Healthy
### Other Plants
- Blueberry, Cherry, Orange, Peach, Bell Pepper, Raspberry, Soybean, Squash, Strawberry
## API Endpoints
### `POST /predict`
Upload one or more images to get disease predictions.
**Request:**
- Content-Type: `multipart/form-data`
- Body: Image files (jpg, png, bmp, gif, tiff, webp)
**Response:**
```json
{
"success": true,
"results": [
{
"predicted_class": "Tomato___Late_blight",
"clean_class_name": "Tomato - Late blight",
"confidence": 0.95,
"all_predictions": {
"Apple - Apple scab": 0.001,
"Tomato - Late blight": 0.95
// ... other classes
}
}
],
"message": "Successfully processed 1 image(s)"
}
```
### `GET /health`
Check API and model status.
### `GET /classes`
Get all supported disease classes.
### `GET /`
API information and status.
## Usage Examples
### Python
```python
import requests
# Single image prediction
with open("leaf_image.jpg", "rb") as f:
files = {"files": ("leaf_image.jpg", f, "image/jpeg")}
response = requests.post("https://your-space-url/predict", files=files)
result = response.json()
print(f"Predicted: {result['results'][0]['clean_class_name']}")
print(f"Confidence: {result['results'][0]['confidence']:.2%}")
```
### cURL
```bash
curl -X POST "https://your-space-url/predict" \
-F "files=@leaf_image.jpg"
```
### JavaScript
```javascript
const formData = new FormData();
formData.append("files", fileInput.files[0]);
fetch("/predict", {
method: "POST",
body: formData,
})
.then((response) => response.json())
.then((data) => console.log(data));
```
## Model Information
- **Architecture**: Convolutional Neural Network (CNN)
- **Input Size**: 300x300 RGB images
- **Training Data**: PlantVillage dataset
- **Classes**: 38 plant disease categories
- **Framework**: TensorFlow/Keras
## Performance
- **Batch Size**: Up to 10 images per request
- **Response Time**: ~1-3 seconds per image
- **Memory Usage**: ~2GB for model loading
- **Accuracy**: >95% on validation set
## Limitations
- Best results with clear, well-lit leaf images
- Works optimally with images similar to training data
- Single leaf per image recommended
- Supported image formats: JPG, PNG, BMP, GIF, TIFF, WEBP
## Environment Variables
- `HF_MODEL_REPO`: Hugging Face model repository (default: "yasyn14/smart-leaf-model")
- `HF_MODEL_FILENAME`: Model file name (default: "best_model_32epochs.keras")
- `HF_HOME`: Cache directory for models (default: "/tmp/huggingface")
## License
Apache 2.0 License
## Support
For issues and questions, please visit the [model repository](https://huggingface.co/yasyn14/smart-leaf-model) or create an issue in this space.
---
_Built with FastAPI, TensorFlow, and 🤗 Transformers_
|