File size: 947 Bytes
b8bf0c0
 
 
c75219f
b8bf0c0
54df4dd
 
d748331
 
 
 
 
 
 
 
b8bf0c0
d748331
 
 
b8bf0c0
 
54df4dd
 
 
c75219f
ec2e06c
b8bf0c0
 
54df4dd
 
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
import gradio as gr
from transformers import pipeline

classifier = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")

def detect_ai(image):
    results = classifier(image)

    output_str = "Hasil Deteksi:\n"
    for r in results:
        output_str += f"- {r['label']}: {r['score']:.2f}\n"

    best = max(results, key=lambda x: x['score'])
    if "real" in best['label'].lower():
        output_str = f"✅ Foto Asli (confidence: {best['score']:.2f})\n\n" + output_str
    else:
        output_str = f"🤖 Gambar AI / Fake (confidence: {best['score']:.2f})\n\n" + output_str

    return output_str

demo = gr.Interface(
    fn=detect_ai,
    inputs=gr.Image(type="pil", label="Upload Gambar"),
    outputs=gr.Textbox(label="Hasil Deteksi"),
    title="AI vs Real Image Detector",
    description="Upload gambar untuk mengecek apakah gambar asli atau buatan AI."
)

if __name__ == "__main__":
    demo.launch()