MetaQu's picture
Update app.py
9c76db4 verified
raw
history blame
1.25 kB
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()