Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,25 +2,42 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
def detect_ai(image):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
else:
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
demo = gr.Interface(
|
| 19 |
fn=detect_ai,
|
| 20 |
inputs=gr.Image(type="pil"),
|
| 21 |
outputs="text",
|
| 22 |
-
title="Deteksi Foto AI vs Asli",
|
| 23 |
-
description="
|
| 24 |
)
|
| 25 |
|
| 26 |
demo.launch()
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
+
# Dua model publik gratis
|
| 6 |
+
model1 = pipeline("image-classification", model="umm-maybe/ai-image-detector")
|
| 7 |
+
model2 = pipeline("image-classification", model="fal-ai/imagenet-real-or-fake")
|
| 8 |
|
| 9 |
def detect_ai(image):
|
| 10 |
+
img = image.convert("RGB").resize((224, 224))
|
| 11 |
+
|
| 12 |
+
res1 = model1(img)[0]
|
| 13 |
+
res2 = model2(img)[0]
|
| 14 |
+
|
| 15 |
+
label1, conf1 = res1['label'], res1['score']
|
| 16 |
+
label2, conf2 = res2['label'], res2['score']
|
| 17 |
+
|
| 18 |
+
# Voting sederhana
|
| 19 |
+
labels = [label1.lower(), label2.lower()]
|
| 20 |
+
ai_votes = sum(1 for l in labels if "fake" in l or "ai" in l)
|
| 21 |
+
real_votes = len(labels) - ai_votes
|
| 22 |
+
|
| 23 |
+
if ai_votes > real_votes:
|
| 24 |
+
verdict = "🚨 Kemungkinan besar AI Generated"
|
| 25 |
+
elif real_votes > ai_votes:
|
| 26 |
+
verdict = "✅ Kemungkinan besar Foto Asli"
|
| 27 |
else:
|
| 28 |
+
verdict = "⚠️ Tidak Pasti (butuh cek manual)"
|
| 29 |
+
|
| 30 |
+
return f"""{verdict}
|
| 31 |
+
|
| 32 |
+
Model 1: {label1} ({conf1*100:.2f}%)
|
| 33 |
+
Model 2: {label2} ({conf2*100:.2f}%)"""
|
| 34 |
|
| 35 |
demo = gr.Interface(
|
| 36 |
fn=detect_ai,
|
| 37 |
inputs=gr.Image(type="pil"),
|
| 38 |
outputs="text",
|
| 39 |
+
title="Deteksi Foto AI vs Asli (Ensemble)",
|
| 40 |
+
description="Menggunakan dua model gratis sekaligus agar hasil lebih akurat."
|
| 41 |
)
|
| 42 |
|
| 43 |
demo.launch()
|