Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| from PIL import Image | |
| # Gunakan model deteksi publik | |
| classifier = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection") | |
| def detect(image): | |
| # image dari Gradio | |
| results = classifier(image) | |
| # hasil tertinggi | |
| best = max(results, key=lambda x: x['score']) | |
| label = best['label'] | |
| confidence = best['score'] * 100 | |
| if "fake" in label.lower() or "generated" in label.lower() or "ai" in label.lower(): | |
| verdict = "⚠️ Kemungkinan besar Gambar AI / Fake" | |
| else: | |
| verdict = "✅ Kemungkinan besar Foto Asli" | |
| return f"{verdict}\n\nLabel: {label}\nConfidence: {confidence:.2f}%" | |
| app = gr.Interface( | |
| fn=detect, | |
| inputs=gr.Image(type="pil", label="Upload Foto"), | |
| outputs=gr.Textbox(label="Hasil Deteksi"), | |
| title="Detektor Foto vs AI", | |
| description="Unggah foto realistik untuk mendeteksi apakah foto asli atau hasil AI." | |
| ) | |
| if __name__ == "__main__": | |
| app.launch() | |