Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,32 @@
|
|
| 1 |
-
from transformers import pipeline
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
classifier = pipeline("image-classification", model="
|
| 6 |
|
| 7 |
-
def
|
|
|
|
| 8 |
results = classifier(image)
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
if "fake" in label.lower() or "ai" in label.lower():
|
| 13 |
-
verdict = "Kemungkinan besar
|
| 14 |
else:
|
| 15 |
-
verdict = "Kemungkinan besar Foto Asli"
|
| 16 |
|
| 17 |
-
return f"{verdict}\n\nLabel: {label}\nConfidence: {
|
| 18 |
|
| 19 |
-
|
| 20 |
-
fn=
|
| 21 |
-
inputs=gr.Image(type="pil"),
|
| 22 |
-
outputs="
|
| 23 |
-
title="
|
| 24 |
-
description="
|
| 25 |
)
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
+
# Gunakan model deteksi publik
|
| 6 |
+
classifier = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")
|
| 7 |
|
| 8 |
+
def detect(image):
|
| 9 |
+
# image dari Gradio
|
| 10 |
results = classifier(image)
|
| 11 |
+
# hasil tertinggi
|
| 12 |
+
best = max(results, key=lambda x: x['score'])
|
| 13 |
+
label = best['label']
|
| 14 |
+
confidence = best['score'] * 100
|
| 15 |
|
| 16 |
+
if "fake" in label.lower() or "generated" in label.lower() or "ai" in label.lower():
|
| 17 |
+
verdict = "⚠️ Kemungkinan besar Gambar AI / Fake"
|
| 18 |
else:
|
| 19 |
+
verdict = "✅ Kemungkinan besar Foto Asli"
|
| 20 |
|
| 21 |
+
return f"{verdict}\n\nLabel: {label}\nConfidence: {confidence:.2f}%"
|
| 22 |
|
| 23 |
+
app = gr.Interface(
|
| 24 |
+
fn=detect,
|
| 25 |
+
inputs=gr.Image(type="pil", label="Upload Foto"),
|
| 26 |
+
outputs=gr.Textbox(label="Hasil Deteksi"),
|
| 27 |
+
title="Detektor Foto vs AI",
|
| 28 |
+
description="Unggah foto realistik untuk mendeteksi apakah foto asli atau hasil AI."
|
| 29 |
)
|
| 30 |
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
app.launch()
|