MetaQu commited on
Commit
b8bf0c0
·
verified ·
1 Parent(s): 489820a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load model dari Hugging Face (pretrained AI image detector)
5
+ classifier = pipeline("image-classification", model="dima806/fake-image-detection")
6
+
7
+ def detect_image(img):
8
+ results = classifier(img)
9
+ # Ambil hasil dengan skor tertinggi
10
+ top_result = max(results, key=lambda x: x["score"])
11
+ label = top_result["label"]
12
+ score = round(top_result["score"] * 100, 2)
13
+
14
+ if label.lower() == "fake":
15
+ return f"🚨 Gambar kemungkinan besar AI Generated ({score}%)"
16
+ else:
17
+ return f"✅ Gambar kemungkinan besar Asli ({score}%)"
18
+
19
+ # Gradio UI
20
+ demo = gr.Interface(
21
+ fn=detect_image,
22
+ inputs=gr.Image(type="filepath"),
23
+ outputs="text",
24
+ title="AI Image Detector",
25
+ description="Upload foto untuk mendeteksi apakah gambar asli atau AI generated."
26
+ )
27
+
28
+ demo.launch()