Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
classifier = pipeline("image-classification", model="
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
results = classifier(
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
if label.lower() == "fake":
|
| 15 |
-
return f"🚨 Gambar kemungkinan besar AI Generated ({score}%)"
|
| 16 |
else:
|
| 17 |
-
return f"
|
| 18 |
|
| 19 |
-
# Gradio
|
| 20 |
demo = gr.Interface(
|
| 21 |
-
fn=
|
| 22 |
-
inputs=gr.Image(type="
|
| 23 |
-
outputs="
|
| 24 |
title="AI Image Detector",
|
| 25 |
-
description="Upload
|
| 26 |
)
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Pakai model yang masih tersedia (public)
|
| 5 |
+
classifier = pipeline("image-classification", model="orpatashnik/StyleGAN-nada-detector")
|
| 6 |
|
| 7 |
+
def detect_ai(image):
|
| 8 |
+
results = classifier(image)
|
| 9 |
+
label = results[0]['label']
|
| 10 |
+
score = results[0]['score']
|
| 11 |
+
if "real" in label.lower():
|
| 12 |
+
return f"🌍 Foto Asli (confidence: {score:.2f})"
|
|
|
|
|
|
|
|
|
|
| 13 |
else:
|
| 14 |
+
return f"🤖 Gambar AI (confidence: {score:.2f})"
|
| 15 |
|
| 16 |
+
# Buat interface Gradio
|
| 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 mendeteksi apakah gambar asli atau buatan AI."
|
| 23 |
)
|
| 24 |
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
demo.launch()
|