Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,9 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
-
#
|
| 6 |
model1 = pipeline("image-classification", model="umm-maybe/ai-image-detector")
|
| 7 |
-
model2 = pipeline("image-classification", model="
|
| 8 |
|
| 9 |
def detect_ai(image):
|
| 10 |
img = image.convert("RGB").resize((224, 224))
|
|
@@ -15,29 +15,25 @@ def detect_ai(image):
|
|
| 15 |
label1, conf1 = res1['label'], res1['score']
|
| 16 |
label2, conf2 = res2['label'], res2['score']
|
| 17 |
|
| 18 |
-
# Voting sederhana
|
| 19 |
-
|
| 20 |
-
ai_votes = sum(1 for l in labels if "fake" in l or "ai" in l)
|
| 21 |
-
real_votes = len(labels) - ai_votes
|
| 22 |
-
|
| 23 |
-
if ai_votes > real_votes:
|
| 24 |
verdict = "🚨 Kemungkinan besar AI Generated"
|
| 25 |
-
elif
|
| 26 |
verdict = "✅ Kemungkinan besar Foto Asli"
|
| 27 |
else:
|
| 28 |
-
verdict = "⚠️ Tidak Pasti (
|
| 29 |
|
| 30 |
return f"""{verdict}
|
| 31 |
|
| 32 |
-
Model
|
| 33 |
-
Model
|
| 34 |
|
| 35 |
demo = gr.Interface(
|
| 36 |
fn=detect_ai,
|
| 37 |
inputs=gr.Image(type="pil"),
|
| 38 |
outputs="text",
|
| 39 |
-
title="Deteksi Foto AI vs Asli (
|
| 40 |
-
description="Menggunakan
|
| 41 |
)
|
| 42 |
|
| 43 |
demo.launch()
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
+
# Model publik (tidak perlu token)
|
| 6 |
model1 = pipeline("image-classification", model="umm-maybe/ai-image-detector")
|
| 7 |
+
model2 = pipeline("image-classification", model="google/vit-base-patch16-224")
|
| 8 |
|
| 9 |
def detect_ai(image):
|
| 10 |
img = image.convert("RGB").resize((224, 224))
|
|
|
|
| 15 |
label1, conf1 = res1['label'], res1['score']
|
| 16 |
label2, conf2 = res2['label'], res2['score']
|
| 17 |
|
| 18 |
+
# Voting sederhana: kalau model1 bilang FAKE, lebih dipercaya
|
| 19 |
+
if "fake" in label1.lower() or "ai" in label1.lower():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
verdict = "🚨 Kemungkinan besar AI Generated"
|
| 21 |
+
elif "real" in label1.lower():
|
| 22 |
verdict = "✅ Kemungkinan besar Foto Asli"
|
| 23 |
else:
|
| 24 |
+
verdict = "⚠️ Tidak Pasti (cek manual)"
|
| 25 |
|
| 26 |
return f"""{verdict}
|
| 27 |
|
| 28 |
+
Model AI-detector: {label1} ({conf1*100:.2f}%)
|
| 29 |
+
Model General (ViT): {label2} ({conf2*100:.2f}%)"""
|
| 30 |
|
| 31 |
demo = gr.Interface(
|
| 32 |
fn=detect_ai,
|
| 33 |
inputs=gr.Image(type="pil"),
|
| 34 |
outputs="text",
|
| 35 |
+
title="Deteksi Foto AI vs Asli (Gratis)",
|
| 36 |
+
description="Menggunakan model publik gratis Hugging Face."
|
| 37 |
)
|
| 38 |
|
| 39 |
demo.launch()
|