Spaces:
Runtime error
Runtime error
judge the whole frame, not just the centre square
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ THRESHOLD_OVERRIDE = float(os.environ.get("THRESHOLD", "0.71"))
|
|
| 41 |
TOKEN = os.environ.get("HF_TOKEN")
|
| 42 |
|
| 43 |
sys.path.insert(0, snapshot_download(CODE_REPO, repo_type="dataset", token=TOKEN))
|
| 44 |
-
from preprocess import canonical_pil,
|
| 45 |
from transforms import CLIP_MEAN, CLIP_STD # noqa: E402
|
| 46 |
from models import build_model, load_checkpoint_into # noqa: E402
|
| 47 |
|
|
@@ -130,9 +130,11 @@ def predict(image: Image.Image):
|
|
| 130 |
dev = "cuda" if torch.cuda.is_available() else "cpu"
|
| 131 |
MODEL.to(dev)
|
| 132 |
|
| 133 |
-
#
|
| 134 |
-
#
|
| 135 |
-
|
|
|
|
|
|
|
| 136 |
batch = torch.stack([_to_tensor(c) for c in crops]).to(dev)
|
| 137 |
logits = MODEL(batch).float().cpu().numpy() / TEMPERATURE
|
| 138 |
logit = float(np.mean(logits))
|
|
@@ -150,8 +152,8 @@ def predict(image: Image.Image):
|
|
| 150 |
f"**{verdict}**\n\n"
|
| 151 |
f"- P(AI-generated) = **{p_ai:.1%}** (calibrated, T={TEMPERATURE:.2f})\n"
|
| 152 |
f"- decision threshold = {THRESHOLD:.2f}, tuned on **unseen-generator** data\n"
|
| 153 |
-
f"- agreement across the
|
| 154 |
-
f"{'(consistent)' if spread < 0.15 else '(
|
| 155 |
f"*Trained on {RUN}. Detectors are weaker on generators they have never seen; "
|
| 156 |
f"treat this as evidence, not proof.*"
|
| 157 |
)
|
|
|
|
| 41 |
TOKEN = os.environ.get("HF_TOKEN")
|
| 42 |
|
| 43 |
sys.path.insert(0, snapshot_download(CODE_REPO, repo_type="dataset", token=TOKEN))
|
| 44 |
+
from preprocess import canonical_pil, whole_frame_tiles # noqa: E402
|
| 45 |
from transforms import CLIP_MEAN, CLIP_STD # noqa: E402
|
| 46 |
from models import build_model, load_checkpoint_into # noqa: E402
|
| 47 |
|
|
|
|
| 130 |
dev = "cuda" if torch.cuda.is_available() else "cpu"
|
| 131 |
MODEL.to(dev)
|
| 132 |
|
| 133 |
+
# Windows spanning the WHOLE frame, each cropped at native resolution and then put
|
| 134 |
+
# through the training pipeline. Averaged in LOGIT space (averaging probabilities
|
| 135 |
+
# would let one saturated window dominate). See preprocess.whole_frame_tiles for
|
| 136 |
+
# why centre-only cropping was wrong.
|
| 137 |
+
crops = whole_frame_tiles(image)
|
| 138 |
batch = torch.stack([_to_tensor(c) for c in crops]).to(dev)
|
| 139 |
logits = MODEL(batch).float().cpu().numpy() / TEMPERATURE
|
| 140 |
logit = float(np.mean(logits))
|
|
|
|
| 152 |
f"**{verdict}**\n\n"
|
| 153 |
f"- P(AI-generated) = **{p_ai:.1%}** (calibrated, T={TEMPERATURE:.2f})\n"
|
| 154 |
f"- decision threshold = {THRESHOLD:.2f}, tuned on **unseen-generator** data\n"
|
| 155 |
+
f"- agreement across the {len(crops)} frame windows: ±{spread:.1%} "
|
| 156 |
+
f"{'(consistent)' if spread < 0.15 else '(windows disagree — treat with caution)'}\n\n"
|
| 157 |
f"*Trained on {RUN}. Detectors are weaker on generators they have never seen; "
|
| 158 |
f"treat this as evidence, not proof.*"
|
| 159 |
)
|