Skip to content

Latest commit

 

History

History
983 lines (860 loc) · 27.5 KB

File metadata and controls

983 lines (860 loc) · 27.5 KB

🔍 NSFW Detection API - Complete Endpoints Documentation

🏆 TRIPLE-MODEL ENSEMBLE SYSTEM

This API uses a state-of-the-art Triple-Model Ensemble System for maximum NSFW detection accuracy:

  • ViT-L-14 (40% weight): Large Vision Transformer - Primary model
  • ViT-H-14 (35% weight): Huge Vision Transformer - Enhanced accuracy
  • ViT-g-14 (25% weight): Giant Vision Transformer - Maximum capacity

Classification Categories:

  • male_onlySAFE (single men without women)
  • female_presentUNSAFE (any woman/girl detected)
  • adult_objectUNSAFE (explicit content or adult toys)

📋 API Endpoints Overview

Method Endpoint Description Max Files Response Type
GET / API information and status - JSON
GET /health System health check - JSON
GET /config Configuration details - JSON
POST /predict/single Single image analysis 1 JSON
POST /predict/multi Batch image analysis 10 JSON
POST /predict/urls URL-based batch image analysis 10 URLs JSON
POST /predict/streaming Real-time streaming analysis 2500 Streaming JSON
GET /stats API usage statistics - JSON
GET /image/{image_id} Retrieve hosted image - Image
GET /ui Web interface - HTML

🔧 Detailed Endpoint Documentation

1. GET / - API Information

Purpose: Get basic API information and status

Response:

{
  "message": "NSFW Detection API",
  "version": "1.0.0",
  "status": "operational",
  "models_available": ["triple_ensemble", "openclip_fallback"],
  "endpoints": {
    "single_prediction": "/predict/single",
    "multi_prediction": "/predict/multi", 
    "streaming_prediction": "/predict/streaming",
    "health_check": "/health",
    "configuration": "/config",
    "statistics": "/stats",
    "web_interface": "/ui"
  }
}

2. GET /health - System Health Check

Purpose: Comprehensive health check for Triple-Model Ensemble System and database

Response:

{
  "status": "healthy",
  "timestamp": "2024-01-15T10:30:00Z",
  "models": {
    "status": {
      "triple_ensemble": true,
      "openclip_fallback": true
    },
    "details": {
      "triple_ensemble": {
        "loaded": true,
        "type": "Triple-Model Ensemble System",
        "models": ["ViT-L-14", "ViT-H-14", "ViT-g-14"],
        "weights": {"ViT-L-14": "40%", "ViT-H-14": "35%", "ViT-g-14": "25%"},
        "classification_categories": ["male_only", "female_present", "adult_object"],
        "ensemble_method": "weighted_average"
      },
      "openclip_fallback": {
        "loaded": true,
        "type": "OpenCLIP-L/14 - Fallback Model",
        "model_info": {
          "device": "cpu",
          "model_name": "ViT-L-14",
          "pretrained": "laion2b_s32b_b82k"
        }
      }
    },
    "total_enabled": 2
  },
  "database": {
    "connected": true,
    "ping_success": true,
    "response_time_ms": 15.2
  },
  "configuration": {
    "sensitivity_level": "medium",
    "nsfw_threshold": 0.5,
    "effective_threshold": 0.5,
    "enable_image_hosting": true,
    "image_expiry_hours": 24,
    "max_image_size_mb": 50
  },
  "system": {
    "api_version": "1.0.0",
    "python_version": "3.11.0"
  }
}

3. GET /config - Configuration Details

Purpose: Get current Triple-Model Ensemble System configuration

Response:

{
  "triple_model_ensemble": {
    "enabled": true,
    "models": [
      {
        "name": "ViT-L-14",
        "weight": 0.4,
        "description": "Large Vision Transformer - Primary model"
      },
      {
        "name": "ViT-H-14", 
        "weight": 0.35,
        "description": "Huge Vision Transformer - Enhanced accuracy"
      },
      {
        "name": "ViT-g-14",
        "weight": 0.25,
        "description": "Giant Vision Transformer - Maximum capacity"
      }
    ],
    "classification_categories": {
      "male_only": {
        "label": "male only",
        "safety": "SAFE",
        "description": "Single men without women"
      },
      "female_present": {
        "label": "female present", 
        "safety": "UNSAFE",
        "description": "Any woman/girl detected"
      },
      "adult_object": {
        "label": "adult object",
        "safety": "UNSAFE", 
        "description": "Explicit content or adult toys"
      }
    },
    "ensemble_method": "weighted_average",
    "confidence_threshold": 0.5,
    "agreement_threshold": 0.7
  },
  "fallback_model": {
    "openclip_model_name": "ViT-L-14",
    "openclip_pretrained": "laion2b_s32b_b82k",
    "enabled": true
  },
  "sensitivity_level": "medium",
  "nsfw_threshold": 0.5,
  "effective_threshold": 0.5,
  "enable_image_hosting": true,
  "image_expiry_hours": 24,
  "max_image_size_mb": 50,
  "max_total_request_size_mb": 1000,
  "database_connected": true
}

4. POST /predict/single - Single Image Analysis

Purpose: Analyze a single image using the Triple-Model Ensemble System

System Architecture:

  • ViT-L-14 (40% weight): Large Vision Transformer - Primary model
  • ViT-H-14 (35% weight): Huge Vision Transformer - Enhanced accuracy
  • ViT-g-14 (25% weight): Giant Vision Transformer - Maximum capacity

Classification Categories:

  • male_onlySAFE (single men without women)
  • female_presentUNSAFE (any woman/girl detected)
  • adult_objectUNSAFE (explicit content or adult toys)

Request Parameters:

  • Content-Type: multipart/form-data
  • Body: Single image file
  • Supported formats: JPEG, PNG, WebP, BMP, TIFF, GIF, AVIF
  • Max file size: 50MB

Input Example (cURL):

curl -X POST "http://localhost:8000/predict/single" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@example_image.jpg"

Input Example (Python):

import requests

url = "http://localhost:8000/predict/single"
files = {"file": open("example_image.jpg", "rb")}

response = requests.post(url, files=files)
result = response.json()
print(result)

Input Example (JavaScript):

const formData = new FormData();
formData.append('file', fileInput.files[0]);

fetch('http://localhost:8000/predict/single', {
  method: 'POST',
  body: formData
})
.then(response => response.json())
.then(data => console.log(data));

Success Response:

{
  "image": "example_image.jpg",
  "results": {
    "triple_ensemble": {
      "image_name": "example_image.jpg",
      "final_decision": "NSFW",
      "confidence": 0.87,
      "processing_time_ms": 1250.5,
      "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"],
      "per_model_predictions": {
        "ViT-L-14": {
          "predicted_category": "female_present",
          "confidence": 0.89,
          "category_probabilities": {
            "male_only": 0.12,
            "female_present": 0.89,
            "adult_object": 0.03
          },
          "inference_time_ms": 420.3
        },
        "ViT-H-14": {
          "predicted_category": "female_present",
          "confidence": 0.85,
          "category_probabilities": {
            "male_only": 0.15,
            "female_present": 0.85,
            "adult_object": 0.05
          },
          "inference_time_ms": 380.7
        },
        "ViT-g-14": {
          "predicted_category": "female_present",
          "confidence": 0.82,
          "category_probabilities": {
            "male_only": 0.18,
            "female_present": 0.82,
            "adult_object": 0.07
          },
          "inference_time_ms": 449.5
        }
      },
      "ensemble_prediction": {
        "predicted_category": "female_present",
        "confidence": 0.87,
        "safety_decision": "UNSAFE",
        "ensemble_method": "weighted_average",
        "model_agreement": 0.85,
        "category_ensemble_probabilities": {
          "male_only": 0.15,
          "female_present": 0.87,
          "adult_object": 0.05
        }
      }
    }
  },
  "final_decision": "NSFW",
  "confidence": 0.87,
  "total_time_ms": 1250.5,
  "ensemble_category": "female_present",
  "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"],
  "prediction_file": "predictions/example_image_prediction.json",
  "image_hosted": true,
  "image_url": "http://localhost:8000/image/abc123def456",
  "image_id": "abc123def456",
  "image_expires_hours": 24,
  "image_size_mb": 2.3
}

Error Response:

{
  "detail": "Invalid image file. Supported formats: jpg, jpeg, png, bmp, gif, webp, avif, tiff"
}

5. POST /predict/multi - Batch Image Analysis

Purpose: Analyze multiple images using the Triple-Model Ensemble System

System Architecture:

  • ViT-L-14 (40% weight): Large Vision Transformer - Primary model
  • ViT-H-14 (35% weight): Huge Vision Transformer - Enhanced accuracy
  • ViT-g-14 (25% weight): Giant Vision Transformer - Maximum capacity

Classification Categories:

  • male_onlySAFE (single men without women)
  • female_presentUNSAFE (any woman/girl detected)
  • adult_objectUNSAFE (explicit content or adult toys)

Request Parameters:

  • Content-Type: multipart/form-data
  • Body: Multiple image files (max 10 files per request)
  • Supported formats: JPEG, PNG, WebP, BMP, TIFF, GIF, AVIF
  • Max total size: 500MB

Input Example (cURL):

curl -X POST "http://localhost:8000/predict/multi" \
  -H "Content-Type: multipart/form-data" \
  -F "files=@image1.jpg" \
  -F "files=@image2.png" \
  -F "files=@image3.webp"

Input Example (Python):

import requests

url = "http://localhost:8000/predict/multi"
files = [
    ("files", open("image1.jpg", "rb")),
    ("files", open("image2.png", "rb")),
    ("files", open("image3.webp", "rb"))
]

response = requests.post(url, files=files)
result = response.json()
print(result)

# Close files
for _, file in files:
    file.close()

Input Example (JavaScript):

const formData = new FormData();
const fileInputs = document.getElementById('multipleFiles').files;

for (let i = 0; i < fileInputs.length; i++) {
    formData.append('files', fileInputs[i]);
}

fetch('http://localhost:8000/predict/multi', {
  method: 'POST',
  body: formData
})
.then(response => response.json())
.then(data => console.log(data));

Success Response:

{
  "predictions": [
    {
      "image": "image1.jpg",
      "results": {
        "triple_ensemble": {
          "final_decision": "Safe",
          "confidence": 0.92,
          "ensemble_prediction": {
            "predicted_category": "male_only",
            "safety_decision": "SAFE"
          }
        }
      },
      "final_decision": "Safe",
      "confidence": 0.92,
      "ensemble_category": "male_only",
      "total_time_ms": 1180.3,
      "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"],
      "image_hosted": true,
      "image_url": "http://localhost:8000/image/def456ghi789",
      "image_id": "def456ghi789"
    },
    {
      "image": "image2.png", 
      "results": {
        "triple_ensemble": {
          "final_decision": "NSFW",
          "confidence": 0.78,
          "ensemble_prediction": {
            "predicted_category": "female_present",
            "safety_decision": "UNSAFE"
          }
        }
      },
      "final_decision": "NSFW",
      "confidence": 0.78,
      "ensemble_category": "female_present",
      "total_time_ms": 1245.7,
      "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"],
      "image_hosted": true,
      "image_url": "http://localhost:8000/image/ghi789jkl012",
      "image_id": "ghi789jkl012"
    },
    {
      "image": "image3.webp",
      "results": {
        "triple_ensemble": {
          "final_decision": "NSFW",
          "confidence": 0.94,
          "ensemble_prediction": {
            "predicted_category": "adult_object",
            "safety_decision": "UNSAFE"
          }
        }
      },
      "final_decision": "NSFW",
      "confidence": 0.94,
      "ensemble_category": "adult_object",
      "total_time_ms": 1156.2,
      "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"],
      "image_hosted": true,
      "image_url": "http://localhost:8000/image/jkl012mno345",
      "image_id": "jkl012mno345"
    }
  ],
  "summary": {
    "total_images": 3,
    "nsfw_images": 2,
    "safe_images": 1,
    "total_time_ms": 3582.2,
    "average_time_per_image_ms": 1194.1,
    "errors": null
  }
}

Error Response:

{
  "detail": "File validation errors: Invalid file: corrupted_image.txt, File too large: huge_image.jpg"
}

6. POST /predict/urls - URL-based Batch Image Analysis

Purpose: Analyze multiple images from URLs using the Triple-Model Ensemble System

System Architecture:

  • ViT-L-14 (40% weight): Large Vision Transformer - Primary model
  • ViT-H-14 (35% weight): Huge Vision Transformer - Enhanced accuracy
  • ViT-g-14 (25% weight): Giant Vision Transformer - Maximum capacity

Classification Categories:

  • male_onlySAFE (single men without women)
  • female_presentUNSAFE (any woman/girl detected)
  • adult_objectUNSAFE (explicit content or adult toys)

Request Parameters:

  • Content-Type: application/json
  • Body: JSON with array of image URLs (max 10 URLs per request)
  • Supported formats: JPEG, PNG, GIF, WebP, BMP, AVIF, TIFF
  • Max individual file size: 50MB per image
  • Download timeout: 30 seconds per URL

Input Example (cURL):

curl -X POST "http://localhost:8000/predict/urls" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": [
      "https://example.com/image1.jpg",
      "https://example.com/image2.png",
      "https://cdn.example.com/sample.avif"
    ]
  }'

Input Example (Python):

import requests
import json

url = "http://localhost:8000/predict/urls"
headers = {"Content-Type": "application/json"}
data = {
    "urls": [
        "https://example.com/image1.jpg",
        "https://example.com/image2.png",
        "https://cdn.example.com/sample.avif"
    ]
}

response = requests.post(url, headers=headers, data=json.dumps(data))
result = response.json()
print(result)

Input Example (JavaScript):

const urls = [
  "https://example.com/image1.jpg",
  "https://example.com/image2.png",
  "https://cdn.example.com/sample.avif"
];

fetch('http://localhost:8000/predict/urls', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ urls: urls })
})
.then(response => response.json())
.then(data => console.log(data));

Success Response:

{
  "predictions": [
    {
      "url": "https://example.com/image1.jpg",
      "image": "image1.jpg",
      "results": {
        "triple_ensemble": {
          "final_decision": "Safe",
          "confidence": 0.92,
          "ensemble_prediction": {
            "predicted_category": "male_only",
            "safety_decision": "SAFE"
          }
        }
      },
      "final_decision": "Safe",
      "confidence": 0.92,
      "ensemble_category": "male_only",
      "total_time_ms": 1380.3,
      "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"],
      "image_hosted": true,
      "image_url": "http://localhost:8000/image/xyz789def012",
      "image_id": "xyz789def012"
    },
    {
      "url": "https://example.com/image2.png",
      "image": "image2.png",
      "results": {
        "triple_ensemble": {
          "final_decision": "NSFW",
          "confidence": 0.78,
          "ensemble_prediction": {
            "predicted_category": "female_present",
            "safety_decision": "UNSAFE"
          }
        }
      },
      "final_decision": "NSFW",
      "confidence": 0.78,
      "ensemble_category": "female_present",
      "total_time_ms": 1445.7,
      "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"],
      "image_hosted": true,
      "image_url": "http://localhost:8000/image/abc123def456",
      "image_id": "abc123def456"
    },
    {
      "url": "https://cdn.example.com/sample.avif",
      "image": "sample.avif",
      "results": {
        "triple_ensemble": {
          "final_decision": "NSFW",
          "confidence": 0.91,
          "ensemble_prediction": {
            "predicted_category": "adult_object",
            "safety_decision": "UNSAFE"
          }
        }
      },
      "final_decision": "NSFW",
      "confidence": 0.91,
      "ensemble_category": "adult_object",
      "total_time_ms": 1523.8,
      "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"],
      "image_hosted": true,
      "image_url": "http://localhost:8000/image/def456ghi789",
      "image_id": "def456ghi789"
    }
  ],
  "summary": {
    "total_images": 3,
    "nsfw_images": 2,
    "safe_images": 1,
    "total_time_ms": 4349.8,
    "average_time_per_image_ms": 1449.9,
    "errors": null
  }
}

Error Response:

{
  "detail": "URL validation errors: Invalid URL format: not-a-valid-url"
}

Error Response with Mixed Results:

{
  "predictions": [
    {
      "url": "https://example.com/valid-image.jpg",
      "image": "valid-image.jpg",
      "final_decision": "Safe",
      "confidence": 0.95,
      "ensemble_category": "male_only",
      "total_time_ms": 1234.5,
      "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"]
    }
  ],
  "summary": {
    "total_images": 1,
    "nsfw_images": 0,
    "safe_images": 1,
    "total_time_ms": 1234.5,
    "average_time_per_image_ms": 1234.5,
    "errors": [
      "Error for https://invalid-url.com/missing.jpg: Failed to download image from URL: HTTP 404",
      "Error for https://timeout-url.com/slow.png: Timeout downloading image from URL"
    ]
  }
}
      "image": "image2.png", 
      "final_decision": "NSFW",
      "confidence": 0.78,
      "ensemble_category": "female_present",
      "total_time_ms": 1445.7,
      "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"],
      "results": {
        "triple_ensemble": {
          "ensemble_prediction": {
            "predicted_category": "female_present",
            "confidence": 0.78,
            "safety_decision": "UNSAFE"
          }
        }
      },
      "image_hosted": true,
      "image_url": "http://localhost:8000/image/abc123def456"
    }
  ],
  "summary": {
    "total_images": 2,
    "nsfw_images": 1,
    "safe_images": 1,
    "total_time_ms": 2825.0,
    "average_time_per_image_ms": 1412.5,
    "errors": null
  }
}

Error Handling:

  • Invalid URLs will be rejected before processing
  • Download failures are reported in the summary errors array
  • Network timeouts result in specific error messages
  • Unsupported image formats trigger validation errors

7. POST /predict/streaming - Real-time Streaming Analysis

Purpose: Stream real-time NSFW analysis for up to 2500 images using the Triple-Model Ensemble System

System Architecture:

  • ViT-L-14 (40% weight): Large Vision Transformer - Primary model
  • ViT-H-14 (35% weight): Huge Vision Transformer - Enhanced accuracy
  • ViT-g-14 (25% weight): Giant Vision Transformer - Maximum capacity

Classification Categories:

  • male_onlySAFE (single men without women)
  • female_presentUNSAFE (any woman/girl detected)
  • adult_objectUNSAFE (explicit content or adult toys)

Request Parameters:

  • Content-Type: multipart/form-data
  • Body: Multiple image files (max 2500 files, max 1GB total)
  • Response: text/plain (streaming JSON-lines format)
  • Supported formats: JPEG, PNG, GIF, WebP, BMP, AVIF, TIFF
  • Max individual file size: 50MB per image

Input Example (cURL):

curl -X POST "http://localhost:8000/predict/streaming" \
  -H "Content-Type: multipart/form-data" \
  -F "files=@image1.jpg" \
  -F "files=@image2.png" \
  -F "files=@image3.avif" \
  --no-buffer

Input Example (Python with streaming):

import requests
import json

files = [
    ('files', ('image1.jpg', open('image1.jpg', 'rb'), 'image/jpeg')),
    ('files', ('image2.png', open('image2.png', 'rb'), 'image/png')),
    ('files', ('image3.avif', open('image3.avif', 'rb'), 'image/avif'))
]

response = requests.post(
    'http://localhost:8000/predict/streaming',
    files=files,
    stream=True
)

for line in response.iter_lines():
    if line:
        # Remove 'data: ' prefix if present
        data_line = line.decode('utf-8')
        if data_line.startswith('data: '):
            data_line = data_line[6:]
        
        result = json.loads(data_line)
        print(f"Processed: {result}")

# Close file handles
for _, (_, file_obj, _) in files:
    file_obj.close()

Input Example (JavaScript with EventSource-like handling):

const formData = new FormData();
formData.append('files', document.getElementById('file1').files[0]);
formData.append('files', document.getElementById('file2').files[0]);
formData.append('files', document.getElementById('file3').files[0]);

fetch('http://localhost:8000/predict/streaming', {
  method: 'POST',
  body: formData
})
.then(response => {
  const reader = response.body.getReader();
  const decoder = new TextDecoder();
  
  function readStream() {
    return reader.read().then(({ done, value }) => {
      if (done) return;
      
      const text = decoder.decode(value);
      const lines = text.split('\n');
      
      lines.forEach(line => {
        if (line.startsWith('data: ')) {
          const jsonData = line.substring(6);
          const result = JSON.parse(jsonData);
          console.log('Streaming result:', result);
        }
      });
      
      return readStream();
    });
  }
  
  return readStream();
});

Streaming Response Format: Each line is prefixed with data: followed by JSON:

data: {"image": "image1.jpg", "final_decision": "Safe", "confidence": 0.92, "ensemble_category": "male_only", "total_time_ms": 1180.3, "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"], "progress": {"current": 1, "total": 3}, "results": {"triple_ensemble": {"final_decision": "Safe", "confidence": 0.92, "ensemble_prediction": {"predicted_category": "male_only", "safety_decision": "SAFE"}}}, "image_hosted": true, "image_url": "http://localhost:8000/image/abc123def456", "image_id": "abc123def456"}

data: {"image": "image2.png", "final_decision": "NSFW", "confidence": 0.78, "ensemble_category": "female_present", "total_time_ms": 1245.7, "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"], "progress": {"current": 2, "total": 3}, "results": {"triple_ensemble": {"final_decision": "NSFW", "confidence": 0.78, "ensemble_prediction": {"predicted_category": "female_present", "safety_decision": "UNSAFE"}}}, "image_hosted": true, "image_url": "http://localhost:8000/image/def456ghi789", "image_id": "def456ghi789"}

data: {"image": "image3.avif", "final_decision": "NSFW", "confidence": 0.91, "ensemble_category": "adult_object", "total_time_ms": 1523.8, "models_used": ["ViT-L-14", "ViT-H-14", "ViT-g-14"], "progress": {"current": 3, "total": 3}, "results": {"triple_ensemble": {"final_decision": "NSFW", "confidence": 0.91, "ensemble_prediction": {"predicted_category": "adult_object", "safety_decision": "UNSAFE"}}}, "image_hosted": true, "image_url": "http://localhost:8000/image/ghi789jkl012", "image_id": "ghi789jkl012"}

data: {"type": "summary", "total_processed": 3, "nsfw_count": 2, "safe_count": 1, "total_time_ms": 3949.8, "average_time_per_image_ms": 1316.6, "errors": null}

Error Response (streaming):

data: {"type": "error", "image": "corrupted_image.jpg", "error": "Could not decode image file", "progress": {"current": 1, "total": 3}}

data: {"type": "summary", "total_processed": 2, "nsfw_count": 1, "safe_count": 1, "total_time_ms": 2500.0, "average_time_per_image_ms": 1250.0, "errors": ["Error processing corrupted_image.jpg: Could not decode image file"]}

8. GET /stats - API Usage Statistics

Purpose: Get comprehensive API usage statistics

Response:

{
  "total_requests": 15420,
  "total_images_processed": 45680,
  "nsfw_detections": 12340,
  "safe_detections": 33340,
  "average_confidence": 0.78,
  "average_processing_time_ms": 1250.5,
  "models_usage": {
    "triple_ensemble": 15420,
    "openclip_fallback": 0
  },
  "error_rate": 0.02,
  "uptime_hours": 168.5,
  "database_stats": {
    "total_predictions_stored": 45680,
    "total_images_hosted": 12340,
    "database_size_mb": 245.6
  },
  "performance_metrics": {
    "p95_processing_time_ms": 2100.0,
    "p99_processing_time_ms": 3500.0,
    "max_concurrent_requests": 25
  }
}

9. GET /image/{image_id} - Retrieve Hosted Image

Purpose: Retrieve a previously hosted image by ID

Parameters:

  • image_id (path): Unique image identifier

Response:

  • Content-Type: image/jpeg (or original format)
  • Body: Image binary data

10. GET /ui - Web Interface

Purpose: Access the interactive web interface

Response:

  • Content-Type: text/html
  • Body: Complete web interface with:
    • Single image analysis
    • Batch image analysis
    • Real-time streaming analysis
    • Detailed analysis popups
    • System health monitoring
    • Configuration display

🚨 Error Responses

Common Error Codes:

400 Bad Request:

{
  "detail": "Invalid image file. Supported formats: jpg, jpeg, png, bmp, gif, webp"
}

413 Payload Too Large:

{
  "detail": "File too large. Maximum size: 50MB"
}

500 Internal Server Error:

{
  "detail": "Error processing image: Model initialization failed"
}

🔧 Configuration Options

Sensitivity Levels:

  • low: Conservative detection (fewer false positives)
  • medium: Balanced detection (default)
  • high: Aggressive detection (catches more content)
  • ultra: Maximum sensitivity (catches everything)

Supported Image Formats:

  • JPEG (.jpg, .jpeg)
  • PNG (.png)
  • WebP (.webp)
  • BMP (.bmp)
  • TIFF (.tiff)

File Size Limits:

  • Single image: 50MB
  • Batch processing: 500MB total
  • Streaming: 1GB total, 2500 files max

📊 Performance Characteristics

Processing Times (CPU):

  • ViT-L-14: ~400-500ms per image
  • ViT-H-14: ~350-450ms per image
  • ViT-g-14: ~400-500ms per image
  • Ensemble Total: ~1200-1500ms per image

Accuracy Metrics:

  • Male Detection: 95%+ accuracy
  • Female Detection: 98%+ accuracy
  • Adult Content: 92%+ accuracy
  • Overall Ensemble: 96%+ accuracy

🔗 API Base URL

http://aimodel.ddns.net:8000

📝 Example Usage

cURL Examples:

Single Image Analysis:

curl -X POST "http://aimodel.ddns.net:8000/predict/single" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@image.jpg"

Batch Analysis:

curl -X POST "http://aimodel.ddns.net:8000/predict/multi" \
  -H "Content-Type: multipart/form-data" \
  -F "files=@image1.jpg" \
  -F "files=@image2.jpg"

Health Check:

curl -X GET "http://aimodel.ddns.net:8000/health"

🏆 System Architecture Benefits

  1. Maximum Accuracy: Triple-model ensemble provides superior detection
  2. Robust Fallback: OpenCLIP fallback ensures reliability
  3. Real-time Processing: Streaming endpoint for high-volume analysis
  4. Comprehensive Analysis: Detailed per-model breakdowns
  5. Scalable Design: Handles up to 2500 images per request
  6. Professional API: Complete documentation and error handling
  7. Web Interface: User-friendly testing environment
  8. Database Integration: Persistent storage and statistics
  9. Image Hosting: Temporary image storage for results
  10. Performance Monitoring: Detailed metrics and health checks

This API provides state-of-the-art NSFW detection using the most advanced vision-language models available, ensuring maximum accuracy and reliability for content moderation applications.