Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ model1 = pipeline("image-classification", model="microsoft/resnet-50")
|
|
| 10 |
model2 = pipeline("image-classification", model="google/vit-base-patch16-224")
|
| 11 |
|
| 12 |
# ----------------------------
|
| 13 |
-
# Fungsi deteksi dengan ensemble
|
| 14 |
# ----------------------------
|
| 15 |
def detect_image(image):
|
| 16 |
results = []
|
|
@@ -28,24 +28,29 @@ def detect_image(image):
|
|
| 28 |
results.append((label2_final, score2))
|
| 29 |
|
| 30 |
# ----------------------------
|
| 31 |
-
# Voting
|
| 32 |
# ----------------------------
|
| 33 |
votes = [r[0] for r in results]
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
final_result = f"✅ Foto Asli ({
|
| 45 |
else:
|
| 46 |
-
final_result = f"🤖 AI Detected ({
|
| 47 |
|
| 48 |
-
# Detail per model
|
| 49 |
output = f"""
|
| 50 |
### Hasil Deteksi:
|
| 51 |
{final_result}
|
|
@@ -63,7 +68,7 @@ iface = gr.Interface(
|
|
| 63 |
inputs=gr.Image(type="pil"),
|
| 64 |
outputs="markdown",
|
| 65 |
title="AI vs Foto Asli Detector",
|
| 66 |
-
description="Unggah gambar, sistem akan mendeteksi apakah gambar
|
| 67 |
)
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
|
|
|
| 10 |
model2 = pipeline("image-classification", model="google/vit-base-patch16-224")
|
| 11 |
|
| 12 |
# ----------------------------
|
| 13 |
+
# Fungsi deteksi dengan ensemble tanpa "Tidak Pasti"
|
| 14 |
# ----------------------------
|
| 15 |
def detect_image(image):
|
| 16 |
results = []
|
|
|
|
| 28 |
results.append((label2_final, score2))
|
| 29 |
|
| 30 |
# ----------------------------
|
| 31 |
+
# Voting atau ambil confidence tertinggi
|
| 32 |
# ----------------------------
|
| 33 |
votes = [r[0] for r in results]
|
| 34 |
+
if votes[0] == votes[1]:
|
| 35 |
+
final_label = votes[0] # mayoritas sama
|
| 36 |
+
final_conf = np.mean([r[1] for r in results if r[0]==final_label])*100
|
| 37 |
+
else:
|
| 38 |
+
# ambil model dengan confidence tertinggi
|
| 39 |
+
if results[0][1] > results[1][1]:
|
| 40 |
+
final_label = results[0][0]
|
| 41 |
+
final_conf = results[0][1]*100
|
| 42 |
+
else:
|
| 43 |
+
final_label = results[1][0]
|
| 44 |
+
final_conf = results[1][1]*100
|
| 45 |
|
| 46 |
+
# ----------------------------
|
| 47 |
+
# Hasil akhir
|
| 48 |
+
# ----------------------------
|
| 49 |
+
if final_label == 'human':
|
| 50 |
+
final_result = f"✅ Foto Asli ({final_conf:.2f}%)"
|
| 51 |
else:
|
| 52 |
+
final_result = f"🤖 AI Detected ({final_conf:.2f}%)"
|
| 53 |
|
|
|
|
| 54 |
output = f"""
|
| 55 |
### Hasil Deteksi:
|
| 56 |
{final_result}
|
|
|
|
| 68 |
inputs=gr.Image(type="pil"),
|
| 69 |
outputs="markdown",
|
| 70 |
title="AI vs Foto Asli Detector",
|
| 71 |
+
description="Unggah gambar, sistem akan mendeteksi apakah gambar AI atau Foto Asli berdasarkan 2 model publik."
|
| 72 |
)
|
| 73 |
|
| 74 |
if __name__ == "__main__":
|