Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
classifier = pipeline("image-classification", model="
|
| 6 |
|
| 7 |
def detect_ai(image):
|
|
|
|
| 8 |
results = classifier(image)
|
| 9 |
label = results[0]['label']
|
| 10 |
score = results[0]['score']
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
else:
|
| 14 |
-
return f"🤖 Gambar AI (confidence: {score:.2f})"
|
| 15 |
|
| 16 |
-
#
|
| 17 |
demo = gr.Interface(
|
| 18 |
fn=detect_ai,
|
| 19 |
inputs=gr.Image(type="pil", label="Upload Gambar"),
|
| 20 |
outputs=gr.Textbox(label="Hasil Deteksi"),
|
| 21 |
-
title="AI Image Detector",
|
| 22 |
-
description="Upload gambar untuk
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Gunakan model publik yang valid
|
| 5 |
+
classifier = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")
|
| 6 |
|
| 7 |
def detect_ai(image):
|
| 8 |
+
# image dari Gradio
|
| 9 |
results = classifier(image)
|
| 10 |
label = results[0]['label']
|
| 11 |
score = results[0]['score']
|
| 12 |
+
# format output
|
| 13 |
+
if "Real" in label:
|
| 14 |
+
return f"✅ Foto Asli (confidence: {score:.2f})"
|
| 15 |
else:
|
| 16 |
+
return f"🤖 Gambar AI / Fake (confidence: {score:.2f})"
|
| 17 |
|
| 18 |
+
# Interface Gradio
|
| 19 |
demo = gr.Interface(
|
| 20 |
fn=detect_ai,
|
| 21 |
inputs=gr.Image(type="pil", label="Upload Gambar"),
|
| 22 |
outputs=gr.Textbox(label="Hasil Deteksi"),
|
| 23 |
+
title="AI vs Real Image Detector",
|
| 24 |
+
description="Upload gambar untuk mengecek apakah foto asli atau buatan AI.",
|
| 25 |
+
allow_flagging="never"
|
| 26 |
)
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|