Upload agents/model_agent.py with huggingface_hub
Browse files- agents/model_agent.py +42 -7
agents/model_agent.py
CHANGED
|
@@ -77,16 +77,51 @@ def m05_autocorrelation(img):
|
|
| 77 |
h,w=ac.shape; cy,cx=h//2,w//2; acm=ac.copy()
|
| 78 |
re=max(h,w)//20; Y,X=np.mgrid[0:h,0:w]; cm=((X-cx)**2+(Y-cy)**2)<re**2; acm[cm]=0
|
| 79 |
ms=float(np.max(acm))
|
| 80 |
-
|
| 81 |
-
#
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
elif ms>0.3: s,n=0.6,f"Strong secondary peak ({ms:.3f}) β GAN checkerboard"
|
| 84 |
elif ms>0.15: s,n=0.3,f"Moderate peak ({ms:.3f})"
|
| 85 |
else: s,n=-0.2,f"Natural autocorrelation ({ms:.3f})"
|
| 86 |
-
|
| 87 |
-
if ms > 0.95:
|
| 88 |
-
result["override_suppression"] = True # Signal to utils.py: do NOT suppress this
|
| 89 |
-
return result
|
| 90 |
|
| 91 |
def m06_checkerboard(img):
|
| 92 |
gray=_g(img); h,w=gray.shape
|
|
|
|
| 77 |
h,w=ac.shape; cy,cx=h//2,w//2; acm=ac.copy()
|
| 78 |
re=max(h,w)//20; Y,X=np.mgrid[0:h,0:w]; cm=((X-cx)**2+(Y-cy)**2)<re**2; acm[cm]=0
|
| 79 |
ms=float(np.max(acm))
|
| 80 |
+
|
| 81 |
+
# Before firing hard override, check if high autocorrelation is explained by bokeh
|
| 82 |
+
# Macro/portrait photos have large uniform bokeh regions that create high autocorrelation
|
| 83 |
+
# from optical physics, not AI generation.
|
| 84 |
+
bokeh_explained = False
|
| 85 |
+
if ms > 0.95:
|
| 86 |
+
from scipy.signal import convolve2d
|
| 87 |
+
lap = np.array([[0,1,0],[1,-4,1],[0,1,0]], dtype=np.float64)
|
| 88 |
+
sharpness = gaussian_filter(np.abs(convolve2d(gray, lap, mode="same", boundary="symm")), sigma=10)
|
| 89 |
+
|
| 90 |
+
# Estimate bokeh region: pixels with sharpness below 10% of peak
|
| 91 |
+
peak_sharp = float(np.percentile(sharpness, 95))
|
| 92 |
+
if peak_sharp > 1:
|
| 93 |
+
bokeh_thresh = peak_sharp * 0.1 # Below 10% of peak = blurred
|
| 94 |
+
bokeh_region = sharpness < bokeh_thresh
|
| 95 |
+
bokeh_fraction = float(np.mean(bokeh_region))
|
| 96 |
+
|
| 97 |
+
bokeh_vals = sharpness[bokeh_region] if np.sum(bokeh_region) > 100 else np.array([1])
|
| 98 |
+
bokeh_uniformity = 1.0 - min(float(np.std(bokeh_vals)) / (float(np.mean(bokeh_vals)) + 1e-9), 1.0)
|
| 99 |
+
|
| 100 |
+
# The non-bokeh region must have genuine sharp detail (not smooth gradient)
|
| 101 |
+
has_genuine_sharp = peak_sharp > 10.0
|
| 102 |
+
|
| 103 |
+
# Bokeh explains autocorrelation if:
|
| 104 |
+
# 1. Large blur region (>25% of image below 10% of peak sharpness)
|
| 105 |
+
# 2. AND genuine sharp foreground detail exists
|
| 106 |
+
if bokeh_fraction > 0.25 and has_genuine_sharp:
|
| 107 |
+
bokeh_explained = True
|
| 108 |
+
else:
|
| 109 |
+
# Entire image is smooth β no bokeh, just low detail
|
| 110 |
+
bokeh_fraction = 0.0
|
| 111 |
+
bokeh_explained = True
|
| 112 |
+
|
| 113 |
+
if ms > 0.95 and not bokeh_explained:
|
| 114 |
+
s, n = 0.8, f"CRITICAL: Autocorrelation {ms:.3f} exceeds physical camera limit β AI generated"
|
| 115 |
+
result = {"test":"Autocorrelation Peak","max_secondary":round(ms,4),"score":s,"note":n}
|
| 116 |
+
result["override_suppression"] = True
|
| 117 |
+
return result
|
| 118 |
+
elif ms > 0.95 and bokeh_explained:
|
| 119 |
+
s, n = 0.15, f"High autocorrelation ({ms:.3f}) but large bokeh region ({bokeh_fraction:.0%}) β likely optical, not AI"
|
| 120 |
+
return {"test":"Autocorrelation Peak","max_secondary":round(ms,4),"score":s,"note":n,"bokeh_explained":True}
|
| 121 |
elif ms>0.3: s,n=0.6,f"Strong secondary peak ({ms:.3f}) β GAN checkerboard"
|
| 122 |
elif ms>0.15: s,n=0.3,f"Moderate peak ({ms:.3f})"
|
| 123 |
else: s,n=-0.2,f"Natural autocorrelation ({ms:.3f})"
|
| 124 |
+
return {"test":"Autocorrelation Peak","max_secondary":round(ms,4),"score":s,"note":n}
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
def m06_checkerboard(img):
|
| 127 |
gray=_g(img); h,w=gray.shape
|