MetaQu commited on
Commit
0a662d5
·
verified ·
1 Parent(s): 3148ed2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -5,10 +5,10 @@ import numpy as np
5
  import cv2
6
 
7
  # ----------------------------
8
- # MODEL DETEKSI AI
9
  # ----------------------------
10
  try:
11
- hf_detector = pipeline("image-classification", model="umm-maybe/AI-image-detector")
12
  except Exception as e:
13
  hf_detector = None
14
  print("HF AI-detector gagal dimuat:", e)
@@ -44,7 +44,7 @@ def has_camera_exif(image):
44
  return False
45
 
46
  # ----------------------------
47
- # DETEKSI HYBRID DENGAN THRESHOLD LAMA
48
  # ----------------------------
49
  def detect_image(image: Image.Image):
50
  output_lines = []
@@ -58,12 +58,12 @@ def detect_image(image: Image.Image):
58
  result = hf_detector(image)
59
  hf_label = result[0]['label']
60
  hf_conf = result[0]['score'] * 100
61
- if any(x in hf_label.lower() for x in ["fake", "ai", "artificial"]):
62
  hf_score = hf_conf
63
  except:
64
  hf_score = 0
65
 
66
- if hf_score > 50: # threshold HF lama
67
  final_result = "🤖 AI Detected"
68
  weighted_score = hf_score
69
  output_lines.append(f"### Hasil Deteksi:\n{final_result}")
@@ -89,8 +89,8 @@ def detect_image(image: Image.Image):
89
  noise_score = calculate_noise(image)
90
  exif_present = has_camera_exif(image)
91
  local_score = 0
92
- if blur_score < 100 or noise_score < 10:
93
- local_score += 50
94
  if not exif_present:
95
  local_score += 10
96
 
@@ -114,9 +114,9 @@ def detect_image(image: Image.Image):
114
  return "\n".join(output_lines)
115
 
116
  # ----------------------------
117
- # Gradio Interface (5.x syntax)
118
  # ----------------------------
119
- with gr.Blocks(title="AI vs Foto Asli Detector (Versi Akurat)") as demo:
120
  gr.Markdown("Unggah gambar, sistem akan mendeteksi apakah gambar kemungkinan besar asli atau dihasilkan AI.")
121
 
122
  with gr.Row():
 
5
  import cv2
6
 
7
  # ----------------------------
8
+ # MODEL DETEKSI AI REALISTIS
9
  # ----------------------------
10
  try:
11
+ hf_detector = pipeline("image-classification", model="danielgatis/rembg-image-ai-detector")
12
  except Exception as e:
13
  hf_detector = None
14
  print("HF AI-detector gagal dimuat:", e)
 
44
  return False
45
 
46
  # ----------------------------
47
+ # DETEKSI HYBRID
48
  # ----------------------------
49
  def detect_image(image: Image.Image):
50
  output_lines = []
 
58
  result = hf_detector(image)
59
  hf_label = result[0]['label']
60
  hf_conf = result[0]['score'] * 100
61
+ if any(x in hf_label.lower() for x in ["ai", "synthetic", "generated"]):
62
  hf_score = hf_conf
63
  except:
64
  hf_score = 0
65
 
66
+ if hf_score > 40: # threshold lebih sensitif
67
  final_result = "🤖 AI Detected"
68
  weighted_score = hf_score
69
  output_lines.append(f"### Hasil Deteksi:\n{final_result}")
 
89
  noise_score = calculate_noise(image)
90
  exif_present = has_camera_exif(image)
91
  local_score = 0
92
+ if blur_score < 80 or noise_score < 8:
93
+ local_score += 30 # lebih ringan
94
  if not exif_present:
95
  local_score += 10
96
 
 
114
  return "\n".join(output_lines)
115
 
116
  # ----------------------------
117
+ # Gradio 5.x Interface
118
  # ----------------------------
119
+ with gr.Blocks(title="AI Realistic Detector (Gratis & Akurat)") as demo:
120
  gr.Markdown("Unggah gambar, sistem akan mendeteksi apakah gambar kemungkinan besar asli atau dihasilkan AI.")
121
 
122
  with gr.Row():