shravyashetty123/grape-disease-detector
1
๐ Grape Disease Detection API
AI-powered grape disease detection using YOLOv8. This API detects Black Rot and ESCA diseases in grape leaves with high accuracy.
๐ฏ Features
- Real-time Disease Detection: Instant analysis of grape leaf images
- High Accuracy: 99.34% accuracy with robust performance
- AR Heatmap Generation: Explainable AI with Grad-CAM visualization
- Flutter-Ready: JSON responses optimized for mobile apps
- Treatment Recommendations: Actionable advice based on severity
- Chart Data: Pre-formatted data for pie charts and confidence graphs
๐ก API Endpoints
Health Check
GET /healthReturns server status and model information.
Disease Detection
POST /predict
Content-Type: application/json
{
"image": "base64_encoded_image_string",
"confidence_threshold": 0.25
}Simple Detection (No Filtering)
POST /predict_simple
Content-Type: application/json
{
"image": "base64_encoded_image_string",
"confidence_threshold": 0.25
}AR Heatmap Generation
POST /predict_with_heatmap
Content-Type: application/json
{
"image": "base64_encoded_image_string",
"precision_threshold": 0.7
}๐ Usage Example
Python
import requests
import base64
# Read and encode image
with open('grape_leaf.jpg', 'rb') as f:
image_data = base64.b64encode(f.read()).decode('utf-8')
# Send request
response = requests.post(
'YOUR_SPACE_URL/predict',
json={
'image': image_data,
'confidence_threshold': 0.25
}
)
result = response.json()
print(f"Status: {result['status']}")
print(f"Detections: {result['total_detections']}")
print(f"Message: {result['message']}")Flutter/Dart
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
Future<Map<String, dynamic>> detectDisease(File imageFile) async {
final bytes = await imageFile.readAsBytes();
final base64Image = base64Encode(bytes);
final response = await http.post(
Uri.parse('YOUR_SPACE_URL/predict'),
headers: {'Content-Type': 'application/json'},
body: json.encode({
'image': base64Image,
'confidence_threshold': 0.25,
}),
);
return json.decode(response.body);
}cURL
# Test health endpoint
curl https://YOUR_SPACE_URL/health
# Test with image
curl -X POST https://YOUR_SPACE_URL/predict \
-H "Content-Type: application/json" \
-d '{"image": "BASE64_IMAGE_STRING", "confidence_threshold": 0.25}'๐ Response Format
Successful Detection
{
"status": "success",
"message": "๐ด Severe black rot infection - 3 spots detected",
"detections": [
{
"class": "black_rot",
"confidence": 0.92,
"bbox": {"x": 120, "y": 80, "width": 150, "height": 120},
"detection_id": 1
}
],
"total_detections": 3,
"disease_summary": {
"black_rot_count": 3,
"esca_count": 0,
"healthy_areas": 2
},
"chart_data": {
"pie_chart": {
"labels": ["Black Rot", "ESCA", "Healthy"],
"values": [3, 0, 2],
"colors": ["#e74c3c", "#3498db", "#27ae60"]
},
"confidence_bars": [...]
},
"treatment_plan": {
"actions": ["Remove infected leaves immediately", "Apply copper-based fungicide", ...],
"urgency": "immediate",
"followup_days": 3
},
"ui_recommendations": {
"primary_color": "#e74c3c",
"severity": "high",
"alert_level": 3,
"icon_suggestion": "๐จ"
}
}Healthy Leaves
{
"status": "healthy",
"message": "๐ฟ Healthy leaves detected - no diseases found!",
"detections": [],
"total_detections": 0
}๐ฆ Detected Diseases
Black Rot
- Symptoms: Dark circular spots with concentric rings
- Severity Levels: Low (1 spot) โ Moderate (2 spots) โ High (3+ spots)
- Color Code: Red (#e74c3c)
ESCA
- Symptoms: Tiger-stripe patterns, chlorosis, necrosis
- Severity Levels: Low (1-2 areas) โ Moderate (3+ areas)
- Color Code: Blue (#3498db)
๐จ AR Heatmap Visualization
The heatmap endpoint provides Grad-CAM visualization showing exactly where the AI detected disease symptoms:
- Red areas: High confidence disease detection
- Yellow areas: Moderate attention regions
- Transparent: Healthy tissue (no AI attention)
โ๏ธ Model Information
- Architecture: YOLOv8 (Augmented Model)
- Training: 4 epochs with data augmentation
- Accuracy: 99.34%
- Classes: black_rot, esca
- Input Size: 640x640 pixels
- Features: Aspect-ratio preserving resize, color-based masking, precision filtering
๐ง Technical Details
- Framework: Flask + PyTorch + Ultralytics
- GPU Support: Automatic GPU detection (falls back to CPU)
- CORS: Enabled for cross-origin requests
- Caching: Prediction caching for consistency
- Error Handling: Comprehensive quality checks and error messages
๐ License
MIT License - Free to use for commercial and non-commercial purposes
๐ Credits
Developed for the Future Harvest agricultural AI project.
