File size: 1,154 Bytes
b8bf0c0
 
 
871fbb3
 
 
 
b8bf0c0
54df4dd
871fbb3
 
 
 
 
d748331
871fbb3
 
 
b8bf0c0
871fbb3
 
 
d748331
871fbb3
 
 
 
 
 
 
 
b8bf0c0
871fbb3
b8bf0c0
871fbb3
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
import gradio as gr
from transformers import pipeline

# load pipeline deteksi AI vs Real
pipe = pipeline("image-classification", model="microsoft/resnet-50")  
# ⚠️ ganti dengan model pendeteksi AI/real sesuai yang kamu pakai
# contoh lain: "microsoft/ai-image-detector"

def detect_ai(image):
    results = pipe(image)
    # Ambil hasil prediksi teratas
    results = sorted(results, key=lambda x: x['score'], reverse=True)
    label = results[0]['label']
    confidence = results[0]['score']

    # Ubah jadi lebih informatif
    if "AI" in label or "Fake" in label:
        status = "Kemungkinan besar AI"
    else:
        status = "Kemungkinan besar Foto Asli"

    return f"{status}\n\nLabel: {label}\nConfidence: {confidence*100:.2f}%"

with gr.Blocks() as demo:
    gr.Markdown("## 🖼️ AI Image Detector")
    with gr.Row():
        with gr.Column():
            image_input = gr.Image(type="pil", label="Upload Gambar")
            btn = gr.Button("Deteksi")
        with gr.Column():
            output_text = gr.Textbox(label="Hasil Deteksi", lines=5)

    btn.click(detect_ai, inputs=image_input, outputs=output_text)

demo.launch()