File size: 1,246 Bytes
8c30b41
2d38802
68c3d48
b8bf0c0
9c76db4
 
 
404b831
8c30b41
9c76db4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68c3d48
9c76db4
 
 
 
 
 
8c30b41
 
 
 
 
9c76db4
 
8c30b41
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import gradio as gr
from transformers import pipeline
from PIL import Image

# Dua model publik gratis
model1 = pipeline("image-classification", model="umm-maybe/ai-image-detector")
model2 = pipeline("image-classification", model="fal-ai/imagenet-real-or-fake")

def detect_ai(image):
    img = image.convert("RGB").resize((224, 224))

    res1 = model1(img)[0]
    res2 = model2(img)[0]

    label1, conf1 = res1['label'], res1['score']
    label2, conf2 = res2['label'], res2['score']

    # Voting sederhana
    labels = [label1.lower(), label2.lower()]
    ai_votes = sum(1 for l in labels if "fake" in l or "ai" in l)
    real_votes = len(labels) - ai_votes

    if ai_votes > real_votes:
        verdict = "🚨 Kemungkinan besar AI Generated"
    elif real_votes > ai_votes:
        verdict = "✅ Kemungkinan besar Foto Asli"
    else:
        verdict = "⚠️ Tidak Pasti (butuh cek manual)"

    return f"""{verdict}

Model 1: {label1} ({conf1*100:.2f}%)
Model 2: {label2} ({conf2*100:.2f}%)"""

demo = gr.Interface(
    fn=detect_ai,
    inputs=gr.Image(type="pil"),
    outputs="text",
    title="Deteksi Foto AI vs Asli (Ensemble)",
    description="Menggunakan dua model gratis sekaligus agar hasil lebih akurat."
)

demo.launch()