NeelakshSaxena commited on
Commit
513d223
Β·
1 Parent(s): b3b4bd5

Add fallback output polarity control

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -28,6 +28,8 @@ ADAPTER_SUBFOLDER = os.getenv("ADAPTER_SUBFOLDER", "")
28
 
29
  MODEL_MODE = os.getenv("MODEL_MODE", "cpu-fallback").strip().lower()
30
  CPU_FALLBACK_MODEL_ID = os.getenv("CPU_FALLBACK_MODEL_ID", "DaMsTaR/Detecto-DeepFake_Image_Detector")
 
 
31
 
32
  TMOS_PROMPT = "USER: <image>\nIs this video real or produced by AI?\nASSISTANT:"
33
  TARGET_IMAGE_SIZE = 336
@@ -322,6 +324,9 @@ def score_fallback_logits(logits: torch.Tensor, id2label: dict) -> tuple[float,
322
  else:
323
  prob_fake = float(probs.max().item()) if len(probs) == 1 else float(probs[1].item()) if len(probs) > 1 else 0.5
324
 
 
 
 
325
  label = "Fake" if prob_fake >= THRESHOLD else "Real"
326
  return prob_fake, label
327
 
@@ -384,7 +389,7 @@ with gr.Blocks(title="TMOS Deepfake Detector", theme=gr.themes.Soft()) as demo:
384
  demo_description = (
385
  "TMOS mode (GPU required) enabled.\n\n"
386
  if MODEL_MODE == "tmos"
387
- else f"CPU fallback mode using {CPU_FALLBACK_MODEL_ID}.\n\n"
388
  )
389
  gr.Markdown(
390
  "# TMOS Deepfake Detector\n"
 
28
 
29
  MODEL_MODE = os.getenv("MODEL_MODE", "cpu-fallback").strip().lower()
30
  CPU_FALLBACK_MODEL_ID = os.getenv("CPU_FALLBACK_MODEL_ID", "DaMsTaR/Detecto-DeepFake_Image_Detector")
31
+ DEFAULT_INVERT_FALLBACK = CPU_FALLBACK_MODEL_ID.lower() == "damstar/detecto-deepfake_image_detector"
32
+ INVERT_FALLBACK_OUTPUT = os.getenv("INVERT_FALLBACK_OUTPUT", str(DEFAULT_INVERT_FALLBACK)).strip().lower() == "true"
33
 
34
  TMOS_PROMPT = "USER: <image>\nIs this video real or produced by AI?\nASSISTANT:"
35
  TARGET_IMAGE_SIZE = 336
 
324
  else:
325
  prob_fake = float(probs.max().item()) if len(probs) == 1 else float(probs[1].item()) if len(probs) > 1 else 0.5
326
 
327
+ if INVERT_FALLBACK_OUTPUT:
328
+ prob_fake = 1.0 - prob_fake
329
+
330
  label = "Fake" if prob_fake >= THRESHOLD else "Real"
331
  return prob_fake, label
332
 
 
389
  demo_description = (
390
  "TMOS mode (GPU required) enabled.\n\n"
391
  if MODEL_MODE == "tmos"
392
+ else f"CPU fallback mode using {CPU_FALLBACK_MODEL_ID} (invert_output={INVERT_FALLBACK_OUTPUT}).\n\n"
393
  )
394
  gr.Markdown(
395
  "# TMOS Deepfake Detector\n"