Spaces:
Sleeping
Sleeping
| # app.py | |
| import gradio as gr | |
| from transformers import pipeline | |
| # Muat pipeline deteksi AI-generated image (bisa ganti model sesuai kebutuhan) | |
| # Model gratis: "microsoft/resnet-50" hanya sebagai contoh, | |
| # lebih baik gunakan model yang memang fine-tuned untuk AI vs Real | |
| detector = pipeline("image-classification", model="falconsai/nsfw_image_detection") | |
| # Fungsi untuk memproses input gambar | |
| def detect_ai_image(image): | |
| results = detector(image) | |
| # Ambil prediksi dengan skor tertinggi | |
| label = results[0]['label'] | |
| score = results[0]['score'] | |
| # Tentukan kategori berdasarkan threshold | |
| if score > 0.85 and label.lower() in ["artificial", "ai", "fake"]: | |
| verdict = "⚠️ Pasti AI-Generated" | |
| elif score < 0.15 and label.lower() in ["real", "photo", "natural"]: | |
| verdict = "✅ Pasti Foto Asli" | |
| else: | |
| verdict = "❓ Tidak Pasti (perlu cek manual)" | |
| return { | |
| "Prediksi Label": label, | |
| "Tingkat Keyakinan": f"{score*100:.2f}%", | |
| "Kesimpulan": verdict | |
| } | |
| # UI Gradio | |
| demo = gr.Interface( | |
| fn=detect_ai_image, | |
| inputs=gr.Image(type="pil"), | |
| outputs="json", | |
| title="AI vs Real Image Detector", | |
| description="Unggah foto untuk mendeteksi apakah itu buatan AI atau foto asli. " | |
| "Gunakan threshold >85% untuk 'AI pasti' dan <15% untuk 'Asli pasti'." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |