Spaces:
Sleeping
Sleeping
File size: 4,289 Bytes
934a06c 56e6316 934a06c 56e6316 934a06c 52d0c20 934a06c 56e6316 | 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 | ---
title: Tomato Blight Classifier
emoji: π
colorFrom: green
colorTo: red
sdk: gradio
sdk_version: 4.26.0
python_version: '3.10'
app_file: app.py
pinned: false
license: mit
short_description: Tomato disease classifier with Gradio
---
# π
Tomato Disease Classifier
A Gradio-based web application that uses a Vision Transformer (ViT) model from Hugging Face to classify tomato leaf diseases in real-time.
## Features
- **Real-time Classification**: Upload tomato leaf images to instantly identify diseases
- **Three Disease Categories**:
- π’ **Healthy**: No disease detected
- π΄ **Early Blight**: Fungal disease in early stages (easier to treat)
- π΄π΄ **Late Blight**: Advanced fungal disease (more severe, requires immediate action)
- **Confidence Scores**: View the model's confidence level for each prediction
- **Visual Interface**: Easy-to-use web interface powered by Gradio
- **Pre-trained Model**: Uses `nexusbert/tomato-disease-vit` from Hugging Face
## π Quick Start
Simply upload an image of a tomato leaf and click "Classify Disease" to get instant predictions!
## Installation
1. **Clone or use this space directly on Hugging Face**
2. **Create a virtual environment** (if running locally):
```bash
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. **Install dependencies**:
```bash
pip install -r requirements.txt
```
## Usage
Run the application:
```bash
python app.py
```
The application will launch a web interface (typically at `http://localhost:7860`) where you can:
1. Upload an image of a tomato leaf
2. Click "Classify Disease" to get predictions
3. View confidence scores for each disease category
4. See a bar chart showing the prediction distribution
## Model Details
- **Model Name**: `nexusbert/tomato-disease-vit`
- **Architecture**: Vision Transformer (ViT)
- **Task**: Image Classification
- **Input**: RGB images of tomato leaves
- **Output**: Classification scores for disease categories
## How It Works
The classifier uses two approaches:
1. **Pipeline API**: For quick, simple predictions
```python
from transformers import pipeline
classifier = pipeline("image-classification", model="nexusbert/tomato-disease-vit")
results = classifier("path/to/tomato_image.jpg")
```
2. **Direct Model & Processor**: For more detailed control
```python
from transformers import AutoImageProcessor, AutoModelForImageClassification
processor = AutoImageProcessor.from_pretrained("nexusbert/tomato-disease-vit")
model = AutoModelForImageClassification.from_pretrained("nexusbert/tomato-disease-vit")
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
```
## Requirements
- Python 3.8+
- PyTorch
- Transformers
- Gradio
- CUDA (optional, for GPU acceleration)
See `requirements.txt` for complete dependency list.
## Project Structure
```
tomato_blight_classifier/
βββ app.py # Main Gradio application
βββ requirements.txt # Python dependencies
βββ README.md # This file
```
## Performance Notes
- First run will download the model (takes a few minutes)
- Subsequent runs are faster as the model is cached
- GPU recommended for faster inference (CUDA)
- CPU inference is supported but slower
## π Example Workflow
1. **Prepare**: Take a clear photo of a tomato leaf (both sides work)
2. **Upload**: Click the upload area and select your image
3. **Analyze**: Click "Classify Disease"
4. **Review**: Check the predictions and confidence scores
## Troubleshooting
### Model Download Issues
If the model fails to download, ensure you have internet connection and sufficient disk space (~300MB).
### Memory Issues
If you encounter out-of-memory errors, close other applications or use CPU inference.
### Slow Performance
Enable GPU acceleration by installing PyTorch with CUDA support.
## Model Source
This classifier uses the pre-trained model: **nexusbert/tomato-disease-vit**
[View Model on Hugging Face](https://huggingface.co/nexusbert/tomato-disease-vit)
## References
- [Hugging Face Model Hub](https://huggingface.co/)
- [Gradio Documentation](https://www.gradio.app/)
- [Transformers Library](https://huggingface.co/docs/transformers/)
## License
MIT License - See LICENSE file for details
|