Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,26 @@
|
|
| 1 |
-
import
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
-
# Gunakan model
|
| 6 |
-
classifier = pipeline("image-classification", model="
|
| 7 |
-
|
| 8 |
-
st.title("Deteksi Foto Asli vs AI Generated")
|
| 9 |
-
st.write("Upload foto untuk mengecek apakah asli atau AI generated.")
|
| 10 |
-
|
| 11 |
-
uploaded_file = st.file_uploader("Upload gambar", type=["jpg","jpeg","png"])
|
| 12 |
-
|
| 13 |
-
if uploaded_file:
|
| 14 |
-
image = Image.open(uploaded_file)
|
| 15 |
-
st.image(image, caption="Gambar yang diupload", use_column_width=True)
|
| 16 |
-
|
| 17 |
-
result = classifier(image)
|
| 18 |
-
|
| 19 |
-
label = result[0]['label']
|
| 20 |
-
confidence = result[0]['score'] * 100
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
if label.lower() in ["fake", "ai-generated"]:
|
| 23 |
-
|
| 24 |
else:
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
+
# Gunakan model PUBLIC yang terbuka
|
| 6 |
+
classifier = pipeline("image-classification", model="umm-maybe/ai-image-detector")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
def detect_ai(image):
|
| 9 |
+
results = classifier(image)
|
| 10 |
+
label = results[0]['label']
|
| 11 |
+
confidence = results[0]['score'] * 100
|
| 12 |
+
|
| 13 |
if label.lower() in ["fake", "ai-generated"]:
|
| 14 |
+
return f"🚨 Kemungkinan besar AI Generated\nLabel: {label}\nConfidence: {confidence:.2f}%"
|
| 15 |
else:
|
| 16 |
+
return f"✅ Kemungkinan besar Foto Asli\nLabel: {label}\nConfidence: {confidence:.2f}%"
|
| 17 |
+
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=detect_ai,
|
| 20 |
+
inputs=gr.Image(type="pil"),
|
| 21 |
+
outputs="text",
|
| 22 |
+
title="Deteksi Foto AI vs Asli",
|
| 23 |
+
description="Upload foto untuk mengetahui apakah ini foto asli atau hasil AI-generated."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
demo.launch()
|