Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,27 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
results =
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
confidence = results[0]['score'] * 100
|
| 13 |
|
| 14 |
if "fake" in label.lower() or "ai" in label.lower():
|
| 15 |
-
|
| 16 |
else:
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
inputs=gr.Image(type="pil", label="Upload Foto"),
|
| 23 |
outputs="text",
|
| 24 |
-
title="AI vs
|
| 25 |
-
description="
|
| 26 |
)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
app.launch()
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
|
| 4 |
+
# Ganti model dengan yang khusus AI detection
|
| 5 |
+
classifier = pipeline("image-classification", model="microsoft/ai-image-detector")
|
| 6 |
|
| 7 |
+
def detect_image(image):
|
| 8 |
+
results = classifier(image)
|
| 9 |
+
label = results[0]["label"]
|
| 10 |
+
score = results[0]["score"] * 100
|
|
|
|
| 11 |
|
| 12 |
if "fake" in label.lower() or "ai" in label.lower():
|
| 13 |
+
verdict = "Kemungkinan besar Hasil AI"
|
| 14 |
else:
|
| 15 |
+
verdict = "Kemungkinan besar Foto Asli"
|
| 16 |
+
|
| 17 |
+
return f"{verdict}\n\nLabel: {label}\nConfidence: {score:.2f}%"
|
| 18 |
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=detect_image,
|
| 21 |
+
inputs=gr.Image(type="pil"),
|
|
|
|
| 22 |
outputs="text",
|
| 23 |
+
title="Deteksi Foto AI vs Asli",
|
| 24 |
+
description="Upload foto untuk mendeteksi apakah asli atau hasil AI."
|
| 25 |
)
|
| 26 |
|
| 27 |
+
iface.launch()
|
|
|