Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
results =
|
| 9 |
results = sorted(results, key=lambda x: x['score'], reverse=True)
|
| 10 |
label = results[0]['label']
|
| 11 |
-
confidence = results[0]['score']
|
| 12 |
|
| 13 |
-
if "
|
| 14 |
-
|
| 15 |
else:
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
with gr.Row():
|
| 23 |
-
with gr.Column():
|
| 24 |
-
image_input = gr.Image(type="pil", label="Upload Gambar")
|
| 25 |
-
btn = gr.Button("Deteksi")
|
| 26 |
-
with gr.Column():
|
| 27 |
-
output_text = gr.Textbox(label="Hasil Deteksi", lines=5)
|
| 28 |
-
|
| 29 |
-
btn.click(detect_ai, inputs=image_input, outputs=output_text)
|
| 30 |
-
|
| 31 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
+
# Gunakan model khusus deteksi AI-generated photo
|
| 6 |
+
detector = pipeline("image-classification", model="microsoft/ai-image-detector")
|
| 7 |
|
| 8 |
+
def detect(image):
|
| 9 |
+
results = detector(image)
|
| 10 |
results = sorted(results, key=lambda x: x['score'], reverse=True)
|
| 11 |
label = results[0]['label']
|
| 12 |
+
confidence = results[0]['score'] * 100
|
| 13 |
|
| 14 |
+
if "fake" in label.lower() or "ai" in label.lower():
|
| 15 |
+
return f"⚠️ Kemungkinan besar Gambar AI\n\nLabel: {label}\nConfidence: {confidence:.2f}%"
|
| 16 |
else:
|
| 17 |
+
return f"✅ Kemungkinan besar Foto Asli\n\nLabel: {label}\nConfidence: {confidence:.2f}%"
|
| 18 |
|
| 19 |
+
# UI dengan Gradio
|
| 20 |
+
app = gr.Interface(
|
| 21 |
+
fn=detect,
|
| 22 |
+
inputs=gr.Image(type="pil", label="Upload Foto"),
|
| 23 |
+
outputs="text",
|
| 24 |
+
title="AI vs Foto Detector",
|
| 25 |
+
description="Unggah foto untuk mendeteksi apakah ini foto asli atau hasil AI-generated."
|
| 26 |
+
)
|
| 27 |
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|