MetaQu's picture
Update app.py
c1ebb63 verified
raw
history blame
974 Bytes
import gradio as gr
from transformers import pipeline
from PIL import Image
# Gunakan model khusus deteksi AI-generated photo
detector = pipeline("image-classification", model="microsoft/ai-image-detector")
def detect(image):
results = detector(image)
results = sorted(results, key=lambda x: x['score'], reverse=True)
label = results[0]['label']
confidence = results[0]['score'] * 100
if "fake" in label.lower() or "ai" in label.lower():
return f"⚠️ Kemungkinan besar Gambar AI\n\nLabel: {label}\nConfidence: {confidence:.2f}%"
else:
return f"✅ Kemungkinan besar Foto Asli\n\nLabel: {label}\nConfidence: {confidence:.2f}%"
# UI dengan Gradio
app = gr.Interface(
fn=detect,
inputs=gr.Image(type="pil", label="Upload Foto"),
outputs="text",
title="AI vs Foto Detector",
description="Unggah foto untuk mendeteksi apakah ini foto asli atau hasil AI-generated."
)
if __name__ == "__main__":
app.launch()