Spaces:
Sleeping
Sleeping
| 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() | |