Spaces:
Sleeping
Sleeping
File size: 1,172 Bytes
8c30b41 2d38802 68c3d48 b8bf0c0 5827e30 9c76db4 5827e30 404b831 8c30b41 9c76db4 5827e30 9c76db4 5827e30 9c76db4 68c3d48 5827e30 9c76db4 5827e30 8c30b41 5827e30 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 |
import gradio as gr
from transformers import pipeline
from PIL import Image
# Model publik (tidak perlu token)
model1 = pipeline("image-classification", model="umm-maybe/ai-image-detector")
model2 = pipeline("image-classification", model="google/vit-base-patch16-224")
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: kalau model1 bilang FAKE, lebih dipercaya
if "fake" in label1.lower() or "ai" in label1.lower():
verdict = "🚨 Kemungkinan besar AI Generated"
elif "real" in label1.lower():
verdict = "✅ Kemungkinan besar Foto Asli"
else:
verdict = "⚠️ Tidak Pasti (cek manual)"
return f"""{verdict}
Model AI-detector: {label1} ({conf1*100:.2f}%)
Model General (ViT): {label2} ({conf2*100:.2f}%)"""
demo = gr.Interface(
fn=detect_ai,
inputs=gr.Image(type="pil"),
outputs="text",
title="Deteksi Foto AI vs Asli (Gratis)",
description="Menggunakan model publik gratis Hugging Face."
)
demo.launch()
|