MetaQu commited on
Commit
9c76db4
·
verified ·
1 Parent(s): 19b1e5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -11
app.py CHANGED
@@ -2,25 +2,42 @@ import gradio as gr
2
  from transformers import pipeline
3
  from PIL import Image
4
 
5
- # Gunakan model PUBLIC yang terbuka
6
- classifier = pipeline("image-classification", model="umm-maybe/ai-image-detector")
 
7
 
8
  def detect_ai(image):
9
- results = classifier(image)
10
- label = results[0]['label']
11
- confidence = results[0]['score'] * 100
12
-
13
- if label.lower() in ["fake", "ai-generated"]:
14
- return f"🚨 Kemungkinan besar AI Generated\nLabel: {label}\nConfidence: {confidence:.2f}%"
 
 
 
 
 
 
 
 
 
 
 
15
  else:
16
- return f" Kemungkinan besar Foto Asli\nLabel: {label}\nConfidence: {confidence:.2f}%"
 
 
 
 
 
17
 
18
  demo = gr.Interface(
19
  fn=detect_ai,
20
  inputs=gr.Image(type="pil"),
21
  outputs="text",
22
- title="Deteksi Foto AI vs Asli",
23
- description="Upload foto untuk mengetahui apakah ini foto asli atau hasil AI-generated."
24
  )
25
 
26
  demo.launch()
 
2
  from transformers import pipeline
3
  from PIL import Image
4
 
5
+ # Dua model publik gratis
6
+ model1 = pipeline("image-classification", model="umm-maybe/ai-image-detector")
7
+ model2 = pipeline("image-classification", model="fal-ai/imagenet-real-or-fake")
8
 
9
  def detect_ai(image):
10
+ img = image.convert("RGB").resize((224, 224))
11
+
12
+ res1 = model1(img)[0]
13
+ res2 = model2(img)[0]
14
+
15
+ label1, conf1 = res1['label'], res1['score']
16
+ label2, conf2 = res2['label'], res2['score']
17
+
18
+ # Voting sederhana
19
+ labels = [label1.lower(), label2.lower()]
20
+ ai_votes = sum(1 for l in labels if "fake" in l or "ai" in l)
21
+ real_votes = len(labels) - ai_votes
22
+
23
+ if ai_votes > real_votes:
24
+ verdict = "🚨 Kemungkinan besar AI Generated"
25
+ elif real_votes > ai_votes:
26
+ verdict = "✅ Kemungkinan besar Foto Asli"
27
  else:
28
+ verdict = "⚠️ Tidak Pasti (butuh cek manual)"
29
+
30
+ return f"""{verdict}
31
+
32
+ Model 1: {label1} ({conf1*100:.2f}%)
33
+ Model 2: {label2} ({conf2*100:.2f}%)"""
34
 
35
  demo = gr.Interface(
36
  fn=detect_ai,
37
  inputs=gr.Image(type="pil"),
38
  outputs="text",
39
+ title="Deteksi Foto AI vs Asli (Ensemble)",
40
+ description="Menggunakan dua model gratis sekaligus agar hasil lebih akurat."
41
  )
42
 
43
  demo.launch()