Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Gunakan model publik valid
|
| 5 |
classifier = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")
|
| 6 |
|
| 7 |
def detect_ai(image):
|
| 8 |
results = classifier(image)
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
else:
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
# Buat interface Gradio
|
| 18 |
demo = gr.Interface(
|
| 19 |
fn=detect_ai,
|
| 20 |
inputs=gr.Image(type="pil", label="Upload Gambar"),
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
| 4 |
classifier = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")
|
| 5 |
|
| 6 |
def detect_ai(image):
|
| 7 |
results = classifier(image)
|
| 8 |
+
|
| 9 |
+
output_str = "Hasil Deteksi:\n"
|
| 10 |
+
for r in results:
|
| 11 |
+
output_str += f"- {r['label']}: {r['score']:.2f}\n"
|
| 12 |
+
|
| 13 |
+
best = max(results, key=lambda x: x['score'])
|
| 14 |
+
if "real" in best['label'].lower():
|
| 15 |
+
output_str = f"✅ Foto Asli (confidence: {best['score']:.2f})\n\n" + output_str
|
| 16 |
else:
|
| 17 |
+
output_str = f"🤖 Gambar AI / Fake (confidence: {best['score']:.2f})\n\n" + output_str
|
| 18 |
+
|
| 19 |
+
return output_str
|
| 20 |
|
|
|
|
| 21 |
demo = gr.Interface(
|
| 22 |
fn=detect_ai,
|
| 23 |
inputs=gr.Image(type="pil", label="Upload Gambar"),
|