File size: 1,405 Bytes
ad63a0f
8c30b41
2d38802
b8bf0c0
ad63a0f
 
 
 
404b831
ad63a0f
 
 
9c76db4
ad63a0f
 
 
9c76db4
ad63a0f
 
 
 
 
68c3d48
ad63a0f
9c76db4
ad63a0f
 
 
 
 
8c30b41
ad63a0f
8c30b41
ad63a0f
8c30b41
ad63a0f
 
 
 
8c30b41
 
ad63a0f
 
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
# app.py
import gradio as gr
from transformers import pipeline

# Muat pipeline deteksi AI-generated image (bisa ganti model sesuai kebutuhan)
# Model gratis: "microsoft/resnet-50" hanya sebagai contoh, 
# lebih baik gunakan model yang memang fine-tuned untuk AI vs Real
detector = pipeline("image-classification", model="falconsai/nsfw_image_detection")

# Fungsi untuk memproses input gambar
def detect_ai_image(image):
    results = detector(image)

    # Ambil prediksi dengan skor tertinggi
    label = results[0]['label']
    score = results[0]['score']

    # Tentukan kategori berdasarkan threshold
    if score > 0.85 and label.lower() in ["artificial", "ai", "fake"]:
        verdict = "⚠️ Pasti AI-Generated"
    elif score < 0.15 and label.lower() in ["real", "photo", "natural"]:
        verdict = "✅ Pasti Foto Asli"
    else:
        verdict = "❓ Tidak Pasti (perlu cek manual)"

    return {
        "Prediksi Label": label,
        "Tingkat Keyakinan": f"{score*100:.2f}%",
        "Kesimpulan": verdict
    }

# UI Gradio
demo = gr.Interface(
    fn=detect_ai_image,
    inputs=gr.Image(type="pil"),
    outputs="json",
    title="AI vs Real Image Detector",
    description="Unggah foto untuk mendeteksi apakah itu buatan AI atau foto asli. "
                "Gunakan threshold >85% untuk 'AI pasti' dan <15% untuk 'Asli pasti'."
)

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