CoolFace
Apppublic

RaidenIppen/antai-detector

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

Antai AI Image Detector – Inference API

FastAPI service implementing a two-stage multi-model routing architecture for AI vs human image detection.

Architecture

Image Input
    │
    ▼
Stage 1 — Router (openai/clip-vit-base-patch32)
    │  Zero-shot classification into 5 content buckets
    │
    ▼
Stage 2 — Specialist (per-bucket, all default to Ateeqq/ai-vs-human-image-detector)
    │  AI vs human classification tuned for the detected content type
    │
    ▼
JSON Response

Routing Table

BucketCLIP Candidate LabelSpecialist Env Var
portrait_face"portrait or face photo"SPECIALIST_FACE_MODEL_ID
document_ui_screenshot"document screenshot or UI"SPECIALIST_DOCUMENT_MODEL_ID
art_illustration"artwork illustration or painting"SPECIALIST_ART_MODEL_ID
nature_landscape"nature landscape or outdoor"SPECIALIST_NATURE_MODEL_ID
general"general photo or other" (also fallback)SPECIALIST_GENERAL_MODEL_ID

Environment Variables

VariableDefaultDescription
ROUTER_MODEL_IDopenai/clip-vit-base-patch32Router model (zero-shot-image-classification task)
SPECIALIST_GENERAL_MODEL_IDAteeqq/ai-vs-human-image-detectorSpecialist for the general / fallback bucket
SPECIALIST_FACE_MODEL_IDAteeqq/ai-vs-human-image-detectorSpecialist for portrait / face imagery
SPECIALIST_DOCUMENT_MODEL_IDAteeqq/ai-vs-human-image-detectorSpecialist for screenshots and documents
SPECIALIST_ART_MODEL_IDAteeqq/ai-vs-human-image-detectorSpecialist for art and illustrations
SPECIALIST_NATURE_MODEL_IDAteeqq/ai-vs-human-image-detectorSpecialist for nature and landscapes
AI_THRESHOLD0.5Confidence threshold for isAI: true
DEBUGfalseWhen true, adds rawRouter and rawSpecialist to response

See space/.env.example for a copy-paste template.

Endpoints

POST /detect

json
{ "imageUrl": "https://..." }
// or
{ "imageData": "data:image/jpeg;base64,..." }

Returns:

json
{
  "confidence": 0.87,
  "isAI": true,
  "provider": "huggingface",
  "routerLabel": "portrait_face",
  "routerConfidence": 0.73,
  "specialistModel": "Ateeqq/ai-vs-human-image-detector"
}

With DEBUG=true, also includes:

json
{
  "rawRouter":     [{ "label": "portrait or face photo", "score": 0.73 }, ...],
  "rawSpecialist": [{ "label": "ai", "score": 0.87 }, { "label": "hum", "score": 0.13 }]
}

GET /health

Returns { "status": "ok" } — used by the Node.js backend to check if the Space is awake.

Docker / Space Build Notes

The Dockerfile uses huggingface-cli download (from huggingface_hub[cli]) to pre-cache both the router and default specialist at build time. Each model is a separate RUN layer for Docker cache granularity.

Memory footprint (default config): ~600 MB (CLIP router) + ~350 MB (one Ateeqq specialist shared across all 5 buckets) ≈ ~950 MB — well within the HF Spaces free-tier limit.

Custom specialists: If you override a specialist via an env var, that model is not pre-cached in the Docker image and will download on the first cold start. For production use, extend the Dockerfile with additional huggingface-cli download <model-id> lines or accept the first-request latency.

ZeroGPU: If deploying to a HuggingFace ZeroGPU Space, wrap specialist inference with the @spaces.GPU decorator and lazy-load pipelines inside it to avoid pre-allocating all VRAM at startup.