Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def detect_ai(image):
|
| 7 |
-
results =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
best = max(results, key=lambda x: x['score'])
|
| 14 |
-
if "real" in best['label'].lower():
|
| 15 |
-
output_str = f"✅ Foto Asli (confidence: {best['score']:.2f})\n\n" + output_str
|
| 16 |
else:
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
fn=detect_ai,
|
| 23 |
-
inputs=gr.Image(type="pil", label="Upload Gambar"),
|
| 24 |
-
outputs=gr.Textbox(label="Hasil Deteksi"),
|
| 25 |
-
title="AI vs Real Image Detector",
|
| 26 |
-
description="Upload gambar untuk mengecek apakah gambar asli atau buatan AI."
|
| 27 |
-
)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# load pipeline deteksi AI vs Real
|
| 5 |
+
pipe = pipeline("image-classification", model="microsoft/resnet-50")
|
| 6 |
+
# ⚠️ ganti dengan model pendeteksi AI/real sesuai yang kamu pakai
|
| 7 |
+
# contoh lain: "microsoft/ai-image-detector"
|
| 8 |
|
| 9 |
def detect_ai(image):
|
| 10 |
+
results = pipe(image)
|
| 11 |
+
# Ambil hasil prediksi teratas
|
| 12 |
+
results = sorted(results, key=lambda x: x['score'], reverse=True)
|
| 13 |
+
label = results[0]['label']
|
| 14 |
+
confidence = results[0]['score']
|
| 15 |
|
| 16 |
+
# Ubah jadi lebih informatif
|
| 17 |
+
if "AI" in label or "Fake" in label:
|
| 18 |
+
status = "Kemungkinan besar AI"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
else:
|
| 20 |
+
status = "Kemungkinan besar Foto Asli"
|
| 21 |
+
|
| 22 |
+
return f"{status}\n\nLabel: {label}\nConfidence: {confidence*100:.2f}%"
|
| 23 |
|
| 24 |
+
with gr.Blocks() as demo:
|
| 25 |
+
gr.Markdown("## 🖼️ AI Image Detector")
|
| 26 |
+
with gr.Row():
|
| 27 |
+
with gr.Column():
|
| 28 |
+
image_input = gr.Image(type="pil", label="Upload Gambar")
|
| 29 |
+
btn = gr.Button("Deteksi")
|
| 30 |
+
with gr.Column():
|
| 31 |
+
output_text = gr.Textbox(label="Hasil Deteksi", lines=5)
|
| 32 |
|
| 33 |
+
btn.click(detect_ai, inputs=image_input, outputs=output_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
demo.launch()
|
|
|