CoolFace
Apppublic

shravyashetty123/grape-disease-detector

sourceHugging Facemitupdated 11mo agoView on Hugging Face
1likes
App README

๐Ÿ‡ 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

bash
GET /health

Returns server status and model information.

Disease Detection

bash
POST /predict
Content-Type: application/json

{
  "image": "base64_encoded_image_string",
  "confidence_threshold": 0.25
}

Simple Detection (No Filtering)

bash
POST /predict_simple
Content-Type: application/json

{
  "image": "base64_encoded_image_string",
  "confidence_threshold": 0.25
}

AR Heatmap Generation

bash
POST /predict_with_heatmap
Content-Type: application/json

{
  "image": "base64_encoded_image_string",
  "precision_threshold": 0.7
}

๐Ÿš€ Usage Example

Python

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

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

bash
# 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

json
{
  "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

json
{
  "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.