Spaces:
Running
Running
Initial: AI Image Detector with Organika/sdxl-detector baseline
Browse files- README.md +24 -8
- app.py +114 -0
- requirements.txt +4 -0
README.md
CHANGED
|
@@ -1,13 +1,29 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
-
pinned:
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: AI Image Detector
|
| 3 |
+
emoji: π‘οΈ
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
+
short_description: Open-baseline AI-generated image detection by Scam.AI
|
| 11 |
+
license: apache-2.0
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# AI Image Detector β Scam.AI π‘οΈ
|
| 15 |
+
|
| 16 |
+
Upload any image and an open-source baseline (`Organika/sdxl-detector`) will tell you whether it thinks the image is AI-generated.
|
| 17 |
+
|
| 18 |
+
**This is a baseline demo**, not a production system. Open detectors are known to fail on:
|
| 19 |
+
- Newer generators (GPT-Image-2, FLUX, Imagen 3)
|
| 20 |
+
- Post-processed images (super-resolution, JPEG re-compression)
|
| 21 |
+
- Out-of-domain content (documents, medical, surveillance)
|
| 22 |
+
|
| 23 |
+
We published a [comprehensive benchmark](https://huggingface.co/datasets/Scam-AI/gpt-image-2) showing >30 AUC point gaps between academic and real-world performance.
|
| 24 |
+
|
| 25 |
+
For production-grade detection (calibrated, adversarial-robust, domain-specific) β visit **[scam.ai](https://www.scam.ai)**.
|
| 26 |
+
|
| 27 |
+
## Built by Scam.AI
|
| 28 |
+
|
| 29 |
+
Detection systems for AI-driven fraud. See our [research](https://www.scam.ai/en/research) and [open datasets](https://huggingface.co/Scam-AI).
|
app.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""AI Image Detector (Open Baseline) β Scam.AI
|
| 2 |
+
|
| 3 |
+
Wraps the open-source Organika/sdxl-detector model in a Gradio interface.
|
| 4 |
+
The output explicitly positions this as a community baseline, with a CTA
|
| 5 |
+
toward Scam.AI's production-grade detection systems.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
from transformers import pipeline
|
| 10 |
+
|
| 11 |
+
# Open-source baseline (192K downloads, Swin-based, ~110MB)
|
| 12 |
+
BASELINE_MODEL = "Organika/sdxl-detector"
|
| 13 |
+
|
| 14 |
+
print(f"Loading baseline model: {BASELINE_MODEL}")
|
| 15 |
+
clf = pipeline("image-classification", model=BASELINE_MODEL)
|
| 16 |
+
print("Model loaded.")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def detect(img):
|
| 20 |
+
if img is None:
|
| 21 |
+
return None, "Upload an image to analyze."
|
| 22 |
+
|
| 23 |
+
results = clf(img)
|
| 24 |
+
# results: list of dicts {label, score}
|
| 25 |
+
scores = {r["label"]: float(r["score"]) for r in results}
|
| 26 |
+
|
| 27 |
+
# Find the AI-generated probability
|
| 28 |
+
ai_keys = [k for k in scores if "artificial" in k.lower() or "ai" in k.lower() or "fake" in k.lower() or "generated" in k.lower()]
|
| 29 |
+
if ai_keys:
|
| 30 |
+
ai_prob = scores[ai_keys[0]]
|
| 31 |
+
else:
|
| 32 |
+
# fallback β highest score label is "ai" if model uses different naming
|
| 33 |
+
ai_prob = max(scores.values()) if list(scores.keys())[0].lower() not in ("human", "real") else 1 - max(scores.values())
|
| 34 |
+
|
| 35 |
+
if ai_prob > 0.85:
|
| 36 |
+
verdict = "π€ **Likely AI-generated**"
|
| 37 |
+
explanation = (
|
| 38 |
+
f"This open-source baseline is **{ai_prob*100:.0f}% confident** "
|
| 39 |
+
f"the image is AI-generated."
|
| 40 |
+
)
|
| 41 |
+
elif ai_prob > 0.5:
|
| 42 |
+
verdict = "β οΈ **Possibly AI-generated**"
|
| 43 |
+
explanation = (
|
| 44 |
+
f"The baseline leans toward AI ({ai_prob*100:.0f}%) but with low "
|
| 45 |
+
f"confidence. In our experience this is exactly the regime where "
|
| 46 |
+
f"open models fail β they catch the obvious cases but miss the "
|
| 47 |
+
f"sophisticated ones."
|
| 48 |
+
)
|
| 49 |
+
else:
|
| 50 |
+
verdict = "π· **Likely real photograph**"
|
| 51 |
+
explanation = (
|
| 52 |
+
f"Baseline confidence in 'real': {(1-ai_prob)*100:.0f}%. "
|
| 53 |
+
f"Note: open baselines have well-known false-negative blind spots "
|
| 54 |
+
f"on newer generators (GPT-Image-2, FLUX, etc)."
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
cta = (
|
| 58 |
+
"\n\n---\n\n"
|
| 59 |
+
"### π About this baseline\n\n"
|
| 60 |
+
f"Model: [`{BASELINE_MODEL}`](https://huggingface.co/{BASELINE_MODEL}) "
|
| 61 |
+
"β a community Swin-Transformer trained for SDXL detection. "
|
| 62 |
+
"Useful as a sanity check but does **not** generalize well to:\n"
|
| 63 |
+
"- Newer generators (GPT-Image-2, FLUX.1, Imagen 3)\n"
|
| 64 |
+
"- Heavily post-processed images (super-resolution, JPEG re-compression)\n"
|
| 65 |
+
"- Domain shift (medical, document, surveillance)\n\n"
|
| 66 |
+
"Our team published [a comprehensive benchmark](https://huggingface.co/datasets/Scam-AI/gpt-image-2) "
|
| 67 |
+
"showing 30+ AUC-point gaps between in-distribution academic tests "
|
| 68 |
+
"and real-world performance.\n\n"
|
| 69 |
+
"**For production deployment** β APIs, on-premise inference, custom "
|
| 70 |
+
"domain fine-tuning β talk to us at **[scam.ai](https://www.scam.ai)**."
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
return scores, verdict + "\n\n" + explanation + cta
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
with gr.Blocks(
|
| 77 |
+
title="AI Image Detector β Scam.AI",
|
| 78 |
+
theme=gr.themes.Soft(primary_hue="blue"),
|
| 79 |
+
) as demo:
|
| 80 |
+
gr.Markdown(
|
| 81 |
+
"# π‘οΈ AI Image Detector\n"
|
| 82 |
+
"*Drop an image to check whether an open-source baseline thinks it's "
|
| 83 |
+
"AI-generated.*\n\n"
|
| 84 |
+
"*Built by [Scam.AI](https://www.scam.ai) Β· Powered by "
|
| 85 |
+
f"[`{BASELINE_MODEL}`](https://huggingface.co/{BASELINE_MODEL})*"
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
with gr.Row():
|
| 89 |
+
with gr.Column():
|
| 90 |
+
inp = gr.Image(type="pil", label="Upload an image")
|
| 91 |
+
btn = gr.Button("Analyze", variant="primary", size="lg")
|
| 92 |
+
gr.Examples(
|
| 93 |
+
examples=[],
|
| 94 |
+
inputs=inp,
|
| 95 |
+
)
|
| 96 |
+
with gr.Column():
|
| 97 |
+
scores = gr.Label(label="Class scores")
|
| 98 |
+
verdict = gr.Markdown()
|
| 99 |
+
|
| 100 |
+
btn.click(detect, inputs=inp, outputs=[scores, verdict])
|
| 101 |
+
inp.change(detect, inputs=inp, outputs=[scores, verdict])
|
| 102 |
+
|
| 103 |
+
gr.Markdown(
|
| 104 |
+
"---\n"
|
| 105 |
+
"**About:** This Space uses a community-trained open baseline to "
|
| 106 |
+
"demonstrate the AI-image-detection task. Real production systems "
|
| 107 |
+
"(higher accuracy, calibrated probabilities, robust to adversarial "
|
| 108 |
+
"post-processing) are not open. Visit [scam.ai](https://www.scam.ai) "
|
| 109 |
+
"if you need detection for actual deployment."
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0
|
| 2 |
+
transformers>=4.40
|
| 3 |
+
torch
|
| 4 |
+
pillow
|