Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # load pipeline deteksi AI vs Real | |
| pipe = pipeline("image-classification", model="microsoft/resnet-50") | |
| # ⚠️ ganti dengan model pendeteksi AI/real sesuai yang kamu pakai | |
| # contoh lain: "microsoft/ai-image-detector" | |
| def detect_ai(image): | |
| results = pipe(image) | |
| # Ambil hasil prediksi teratas | |
| results = sorted(results, key=lambda x: x['score'], reverse=True) | |
| label = results[0]['label'] | |
| confidence = results[0]['score'] | |
| # Ubah jadi lebih informatif | |
| if "AI" in label or "Fake" in label: | |
| status = "Kemungkinan besar AI" | |
| else: | |
| status = "Kemungkinan besar Foto Asli" | |
| return f"{status}\n\nLabel: {label}\nConfidence: {confidence*100:.2f}%" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## 🖼️ AI Image Detector") | |
| with gr.Row(): | |
| with gr.Column(): | |
| image_input = gr.Image(type="pil", label="Upload Gambar") | |
| btn = gr.Button("Deteksi") | |
| with gr.Column(): | |
| output_text = gr.Textbox(label="Hasil Deteksi", lines=5) | |
| btn.click(detect_ai, inputs=image_input, outputs=output_text) | |
| demo.launch() | |