Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 +=
|
| 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 >
|
| 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
|
|
|
|
| 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 |
-
|
| 255 |
-
|
| 256 |
-
|
|
|
|
| 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.
|
| 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.
|
| 284 |
"### Analyse Forensic : Authentique vs Deepfake / Retouche\n"
|
| 285 |
-
"_v2.
|
| 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():
|