Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,55 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
fn=detect_image,
|
| 47 |
inputs=gr.Image(type="pil"),
|
| 48 |
outputs="text",
|
| 49 |
-
title="
|
| 50 |
-
description="
|
| 51 |
)
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
| 54 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Model 1: Hugging Face AI Image Detector
|
| 7 |
+
detector_hf = pipeline("image-classification", model="falconsai/nsfw_image_detection")
|
| 8 |
+
|
| 9 |
+
# Model 2: ViT (ImageNet classification)
|
| 10 |
+
detector_vit = pipeline("image-classification", model="google/vit-base-patch16-224")
|
| 11 |
+
|
| 12 |
+
# Model 3: ResNet50
|
| 13 |
+
detector_resnet = pipeline("image-classification", model="microsoft/resnet-50")
|
| 14 |
+
|
| 15 |
+
def detect_image(img):
|
| 16 |
+
results = {}
|
| 17 |
+
|
| 18 |
+
# Model 1
|
| 19 |
+
try:
|
| 20 |
+
out1 = detector_hf(img)
|
| 21 |
+
results["HF AI-Detector"] = out1
|
| 22 |
+
except Exception as e:
|
| 23 |
+
results["HF AI-Detector"] = str(e)
|
| 24 |
+
|
| 25 |
+
# Model 2
|
| 26 |
+
try:
|
| 27 |
+
out2 = detector_vit(img)
|
| 28 |
+
results["ViT Model"] = out2
|
| 29 |
+
except Exception as e:
|
| 30 |
+
results["ViT Model"] = str(e)
|
| 31 |
+
|
| 32 |
+
# Model 3
|
| 33 |
+
try:
|
| 34 |
+
out3 = detector_resnet(img)
|
| 35 |
+
results["ResNet50"] = out3
|
| 36 |
+
except Exception as e:
|
| 37 |
+
results["ResNet50"] = str(e)
|
| 38 |
+
|
| 39 |
+
# Gabungkan skor sederhana
|
| 40 |
+
summary = "📊 Ringkasan Deteksi:\n"
|
| 41 |
+
for k, v in results.items():
|
| 42 |
+
summary += f"\n🔹 {k}: {v}\n"
|
| 43 |
+
|
| 44 |
+
return summary
|
| 45 |
+
|
| 46 |
+
demo = gr.Interface(
|
| 47 |
fn=detect_image,
|
| 48 |
inputs=gr.Image(type="pil"),
|
| 49 |
outputs="text",
|
| 50 |
+
title="🖼️ Multi-Model AI Image Detector",
|
| 51 |
+
description="Menggunakan 3 model (HF Detector, ViT, ResNet) untuk mendeteksi apakah gambar AI-generated atau asli."
|
| 52 |
)
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
| 55 |
+
demo.launch()
|