Spaces:
Sleeping
A newer version of the Gradio SDK is available: 6.24.0
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-vitfrom Hugging Face
π Quick Start
Simply upload an image of a tomato leaf and click "Classify Disease" to get instant predictions!
Installation
Clone or use this space directly on Hugging Face
Create a virtual environment (if running locally):
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
Usage
Run the application:
python app.py
The application will launch a web interface (typically at http://localhost:7860) where you can:
- Upload an image of a tomato leaf
- Click "Classify Disease" to get predictions
- View confidence scores for each disease category
- 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:
- Pipeline API: For quick, simple predictions
from transformers import pipeline
classifier = pipeline("image-classification", model="nexusbert/tomato-disease-vit")
results = classifier("path/to/tomato_image.jpg")
- Direct Model & Processor: For more detailed control
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
- Prepare: Take a clear photo of a tomato leaf (both sides work)
- Upload: Click the upload area and select your image
- Analyze: Click "Classify Disease"
- 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
References
License
MIT License - See LICENSE file for details