NOBODY204 commited on
Commit
3662828
Β·
verified Β·
1 Parent(s): a277df2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -11
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import matplotlib
2
  matplotlib.use('Agg') # OBLIGATOIRE avant tout import plt β€” Γ©vite crash HF Spaces
3
  import matplotlib.pyplot as plt
 
4
 
5
  import gradio as gr
6
  import numpy as np
@@ -14,7 +15,7 @@ import cv2
14
  # ═══════════════════════════════════════════════════════════════
15
 
16
  NOISE_THRESHOLD = 0.55
17
- FREQ_THRESHOLD = 500
18
  ELA_THRESHOLD = 0.30 # relevΓ© de 0.25 β†’ 0.30 pour attraper les retouches lΓ©gΓ¨res
19
  MIN_SIGNALS = 2
20
 
@@ -163,7 +164,7 @@ def detect_deepfake(img):
163
  # > 55% zones silencieuses = bruit effacΓ© globalement par un outil IA
164
  # Nano Banana Γ©crase le bruit uniformΓ©ment donc inter_block_var reste faible
165
  if silent_ratio > 0.55:
166
- ai_confidence += 22; signals_triggered += 1
167
  reasons.append(
168
  f"⚠️ Traitement IA global β€” {silent_ratio*100:.0f}% zones sans bruit "
169
  f"(seuil > 55%) β€” Nano Banana / Gemini Edit / filtre IA detecte"
@@ -190,7 +191,7 @@ def detect_deepfake(img):
190
 
191
  final_score = min(ai_confidence, 100)
192
 
193
- if final_score > 55:
194
  label = "🚨 DEEPFAKE / GΓ‰NΓ‰RΓ‰ / RETOUCHΓ‰"
195
  elif final_score > 28:
196
  label = "βš–οΈ SUSPICIEUX / MODIFIΓ‰"
@@ -215,6 +216,10 @@ def process(input_img):
215
  if input_img is None:
216
  return None, "⚠️ Veuillez charger une image."
217
 
 
 
 
 
218
  try:
219
  (score, label, reasons,
220
  fft, ela, noise,
@@ -227,8 +232,9 @@ def process(input_img):
227
  except Exception as e:
228
  return None, f"❌ Erreur d'analyse : {str(e)}"
229
 
230
- # ── Figure 2Γ—3 ──────────────────────────────────────────
231
- fig, axes = plt.subplots(2, 3, figsize=(16, 10))
 
232
 
233
  axes[0, 0].imshow(input_img)
234
  axes[0, 0].set_title("Original")
@@ -251,9 +257,10 @@ def process(input_img):
251
  for ax in axes.flatten():
252
  ax.axis('off')
253
 
254
- color = 'red' if score > 55 else ('orange' if score > 28 else 'green')
255
- plt.suptitle(f"{label} β€” {score}%", fontsize=13, fontweight='bold', color=color)
256
- plt.tight_layout()
 
257
 
258
  # ── Rapport ─────────────────────────────────────────────
259
  report = f"RΓ‰SULTAT : {label}\n"
@@ -270,7 +277,7 @@ def process(input_img):
270
  report += f" [S6] Texture peau : zone chair insuffisante (<2%)\n"
271
  report += f"\nSignaux actifs :\n"
272
  report += "\n".join(reasons) if reasons else " Aucune trace de manipulation dΓ©tectΓ©e."
273
- report += "\n\n── ImageShield PRO v2.5 Β· ACoNum / Trusted Sound 2026 ──"
274
 
275
  return fig, report
276
 
@@ -280,9 +287,9 @@ def process(input_img):
280
  # ──────────────────────────────────────────────────────────────
281
  with gr.Blocks() as demo:
282
  gr.Markdown(
283
- "# πŸ›‘οΈ ImageShield PRO v2.5\n"
284
  "### Analyse Forensic : Authentique vs Deepfake / Retouche\n"
285
- "_v2.5 : 6 signaux β€” bruit capteur, FFT, ELA, gradients, retouche locale, skin smoothing_"
286
  )
287
  with gr.Row():
288
  with gr.Column():
 
1
  import matplotlib
2
  matplotlib.use('Agg') # OBLIGATOIRE avant tout import plt β€” Γ©vite crash HF Spaces
3
  import matplotlib.pyplot as plt
4
+ from matplotlib.figure import Figure # thread-safe pour HF Spaces
5
 
6
  import gradio as gr
7
  import numpy as np
 
15
  # ═══════════════════════════════════════════════════════════════
16
 
17
  NOISE_THRESHOLD = 0.55
18
+ FREQ_THRESHOLD = 450 # abaissΓ© 500β†’450 pour armoires pro / photos HDR retouchΓ©es
19
  ELA_THRESHOLD = 0.30 # relevΓ© de 0.25 β†’ 0.30 pour attraper les retouches lΓ©gΓ¨res
20
  MIN_SIGNALS = 2
21
 
 
164
  # > 55% zones silencieuses = bruit effacΓ© globalement par un outil IA
165
  # Nano Banana Γ©crase le bruit uniformΓ©ment donc inter_block_var reste faible
166
  if silent_ratio > 0.55:
167
+ ai_confidence += 28; signals_triggered += 1
168
  reasons.append(
169
  f"⚠️ Traitement IA global β€” {silent_ratio*100:.0f}% zones sans bruit "
170
  f"(seuil > 55%) β€” Nano Banana / Gemini Edit / filtre IA detecte"
 
191
 
192
  final_score = min(ai_confidence, 100)
193
 
194
+ if final_score > 45:
195
  label = "🚨 DEEPFAKE / GΓ‰NΓ‰RΓ‰ / RETOUCHΓ‰"
196
  elif final_score > 28:
197
  label = "βš–οΈ SUSPICIEUX / MODIFIΓ‰"
 
216
  if input_img is None:
217
  return None, "⚠️ Veuillez charger une image."
218
 
219
+ # SΓ©curitΓ© RGBA β†’ RGB (images PNG avec canal alpha)
220
+ if len(input_img.shape) == 3 and input_img.shape[2] == 4:
221
+ input_img = cv2.cvtColor(input_img, cv2.COLOR_RGBA2RGB)
222
+
223
  try:
224
  (score, label, reasons,
225
  fft, ela, noise,
 
232
  except Exception as e:
233
  return None, f"❌ Erreur d'analyse : {str(e)}"
234
 
235
+ # ── Figure OO 2Γ—3 β€” thread-safe pour HF Spaces ──────────
236
+ fig = Figure(figsize=(16, 10))
237
+ axes = fig.subplots(2, 3)
238
 
239
  axes[0, 0].imshow(input_img)
240
  axes[0, 0].set_title("Original")
 
257
  for ax in axes.flatten():
258
  ax.axis('off')
259
 
260
+ # ← seuil 45 (fix v2.5) β€” la version proposΓ©e avait encore 55 ici
261
+ color = 'red' if score > 45 else ('orange' if score > 28 else 'green')
262
+ fig.suptitle(f"{label} β€” {score}%", fontsize=13, fontweight='bold', color=color)
263
+ fig.tight_layout()
264
 
265
  # ── Rapport ─────────────────────────────────────────────
266
  report = f"RΓ‰SULTAT : {label}\n"
 
277
  report += f" [S6] Texture peau : zone chair insuffisante (<2%)\n"
278
  report += f"\nSignaux actifs :\n"
279
  report += "\n".join(reasons) if reasons else " Aucune trace de manipulation dΓ©tectΓ©e."
280
+ report += "\n\n── ImageShield PRO v2.6 Β· ACoNum / Trusted Sound 2026 ──"
281
 
282
  return fig, report
283
 
 
287
  # ──────────────────────────────────────────────────────────────
288
  with gr.Blocks() as demo:
289
  gr.Markdown(
290
+ "# πŸ›‘οΈ ImageShield PRO v2.6\n"
291
  "### Analyse Forensic : Authentique vs Deepfake / Retouche\n"
292
+ "_v2.6 : 6 signaux + Figure thread-safe + fix RGBA β€” bruit capteur, FFT, ELA, gradients, retouche locale, skin smoothing_"
293
  )
294
  with gr.Row():
295
  with gr.Column():