File size: 974 Bytes
b8bf0c0
 
c1ebb63
b8bf0c0
c1ebb63
 
b8bf0c0
c1ebb63
 
871fbb3
 
c1ebb63
d748331
c1ebb63
 
b8bf0c0
c1ebb63
871fbb3
c1ebb63
 
 
 
 
 
 
 
d748331
c1ebb63
 
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
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()