MetaQu commited on
Commit
afd314f
·
verified ·
1 Parent(s): 0738ed7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -43,7 +43,7 @@ def high_freq_artifacts(image):
43
  return high_ratio
44
 
45
  # ----------------------------
46
- # DETEKSI AI HYBRID SENSITIF
47
  # ----------------------------
48
  def detect_image(image: Image.Image):
49
  blur_score = calculate_blur(image)
@@ -51,10 +51,17 @@ def detect_image(image: Image.Image):
51
  exif_present = has_camera_exif(image)
52
  high_freq_score = high_freq_artifacts(image)
53
 
54
- # ---------- Aturan tegas & sensitif ----------
55
- # Foto asli aman jika memiliki metadata atau noise > 10
 
 
 
 
 
 
 
56
  is_ai = False
57
- if (not exif_present) and (noise_score < 8) and (blur_score < 120) and (high_freq_score > 20):
58
  is_ai = True
59
 
60
  final_result = "🤖 AI Detected" if is_ai else "✅ Foto Asli"
@@ -64,6 +71,7 @@ def detect_image(image: Image.Image):
64
  f"Blur Score: {blur_score:.2f}",
65
  f"Noise Score: {noise_score:.2f}",
66
  f"High-Freq Artifacts Score: {high_freq_score:.2f}",
 
67
  f"Metadata Kamera: {'Ada' if exif_present else 'Tidak Ada'}"
68
  ]
69
 
@@ -72,7 +80,7 @@ def detect_image(image: Image.Image):
72
  # ----------------------------
73
  # GRADIO INTERFACE
74
  # ----------------------------
75
- with gr.Blocks(title="Hybrid AI Realistic Detector (Sensitif & Tegas)") as demo:
76
  gr.Markdown("Unggah gambar, sistem akan mendeteksi apakah gambar kemungkinan besar asli atau dihasilkan AI.")
77
  with gr.Row():
78
  img_input = gr.Image(type="pil", label="Unggah Gambar")
 
43
  return high_ratio
44
 
45
  # ----------------------------
46
+ # DETEKSI AI HYBRID ADAPTIF
47
  # ----------------------------
48
  def detect_image(image: Image.Image):
49
  blur_score = calculate_blur(image)
 
51
  exif_present = has_camera_exif(image)
52
  high_freq_score = high_freq_artifacts(image)
53
 
54
+ # ---------- Scoring adaptif ----------
55
+ # Normalisasi high_freq_score ke 0-10
56
+ hf_norm = min(high_freq_score / 10, 10)
57
+ # Noise invers (AI biasanya noise rendah)
58
+ noise_norm = max(0, 12 - noise_score)
59
+ # Weighted score
60
+ weighted_score = 0.5 * hf_norm + 0.5 * noise_norm
61
+
62
+ # Kondisi tegas: threshold > 5 → AI
63
  is_ai = False
64
+ if not exif_present and weighted_score > 5 and blur_score < 150:
65
  is_ai = True
66
 
67
  final_result = "🤖 AI Detected" if is_ai else "✅ Foto Asli"
 
71
  f"Blur Score: {blur_score:.2f}",
72
  f"Noise Score: {noise_score:.2f}",
73
  f"High-Freq Artifacts Score: {high_freq_score:.2f}",
74
+ f"Weighted Score: {weighted_score:.2f}",
75
  f"Metadata Kamera: {'Ada' if exif_present else 'Tidak Ada'}"
76
  ]
77
 
 
80
  # ----------------------------
81
  # GRADIO INTERFACE
82
  # ----------------------------
83
+ with gr.Blocks(title="Hybrid AI Realistic Detector (Adaptif & Tegas)") as demo:
84
  gr.Markdown("Unggah gambar, sistem akan mendeteksi apakah gambar kemungkinan besar asli atau dihasilkan AI.")
85
  with gr.Row():
86
  img_input = gr.Image(type="pil", label="Unggah Gambar")