Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,25 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
-
|
| 3 |
-
from PIL import ExifTags
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
classifier = pipeline("image-classification", model="
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
exif_result = "⚠️ Tidak ada metadata kamera"
|
| 11 |
-
try:
|
| 12 |
-
raw_exif = image._getexif()
|
| 13 |
-
if raw_exif:
|
| 14 |
-
exif_result = "✅ Metadata kamera terdeteksi"
|
| 15 |
-
except:
|
| 16 |
-
pass
|
| 17 |
|
| 18 |
-
|
| 19 |
-
results = classifier(image)
|
| 20 |
-
label = results[0]["label"]
|
| 21 |
-
score = results[0]["score"] * 100
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
verdict = "📷 Kemungkinan besar Foto Asli"
|
| 27 |
-
|
| 28 |
-
return f"""{verdict}
|
| 29 |
|
| 30 |
-
|
| 31 |
-
Confidence: {score:.2f}%
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
outputs="text",
|
| 41 |
-
title="AI Image Detector (Gratis)",
|
| 42 |
-
description="Upload gambar untuk mendeteksi apakah foto asli atau hasil AI"
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
iface.launch()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
|
|
|
| 4 |
|
| 5 |
+
# Gunakan model AI detector (gratis di HuggingFace)
|
| 6 |
+
classifier = pipeline("image-classification", model="shuhuai/AI-image-detector")
|
| 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 |
+
st.error(f"🚨 Kemungkinan besar **AI Generated**\n\nLabel: {label}\nConfidence: {confidence:.2f}%")
|
| 24 |
+
else:
|
| 25 |
+
st.success(f"✅ Kemungkinan besar **Foto Asli**\n\nLabel: {label}\nConfidence: {confidence:.2f}%")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|