Upload agents/model_agent.py with huggingface_hub
Browse files- agents/model_agent.py +7 -14
agents/model_agent.py
CHANGED
|
@@ -90,8 +90,8 @@ def m06_checkerboard(img):
|
|
| 90 |
h1=float(np.corrcoef(gray[:,:-1].ravel()[::100],gray[:,1:].ravel()[::100])[0,1])
|
| 91 |
v1=float(np.corrcoef(gray[:-1,:].ravel()[::100],gray[1:,:].ravel()[::100])[0,1])
|
| 92 |
delta=((ha-h1)+(va-v1))/2
|
| 93 |
-
if delta>0.
|
| 94 |
-
elif delta>0.
|
| 95 |
else: s,n=-0.1,f"No checkerboard ({delta:.4f})"
|
| 96 |
return {"test":"Checkerboard Pattern","delta":round(delta,6),"score":s,"note":n}
|
| 97 |
|
|
@@ -163,7 +163,7 @@ def m11_color_consistency(img):
|
|
| 163 |
for i in range(0,hc,ps):
|
| 164 |
for j in range(0,wc,ps):
|
| 165 |
p=rgb[i:i+ps,j:j+ps]; m=np.mean(p,axis=(0,1))
|
| 166 |
-
if m[1]>
|
| 167 |
if len(ratios)<4: return {"test":"Color Ratio Consistency","score":0.0,"note":"Few patches"}
|
| 168 |
cv=float(np.std(ratios))/(float(np.mean(ratios))+1e-9)
|
| 169 |
if cv>0.1: s,n=-0.2,f"Varied color ratios (CV={cv:.3f})"
|
|
@@ -239,14 +239,7 @@ ALL_TESTS=[m01_fft_grid_8x8,m02_fft_grid_16x16,m03_spectral_slope,m04_diffusion_
|
|
| 239 |
m13_texture_repetition,m14_highfreq_noise_structure,m15_phase_coherence]
|
| 240 |
|
| 241 |
def run_model_agent(img):
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
avg=float(np.mean(scores)) if scores else 0.0; conf=min(1.0,0.5+0.5*abs(avg))
|
| 247 |
-
viol=[f["test"] for f in findings if f.get("score",0)>0.2]
|
| 248 |
-
comp=[f["test"] for f in findings if f.get("score",0)<-0.1]
|
| 249 |
-
rat=f"Model signatures: {', '.join(viol)}." if viol else f"No artifacts: {', '.join(comp)}." if comp else "Model analysis inconclusive."
|
| 250 |
-
for f in findings:
|
| 251 |
-
if f.get("note"): rat+=f" [{f['test']}]: {f['note']}."
|
| 252 |
-
return AgentEvidence("Generative Model Agent",np.clip(avg,-1,1),conf,max(0,1-len(scores)/len(ALL_TESTS)),rat,findings)
|
|
|
|
| 90 |
h1=float(np.corrcoef(gray[:,:-1].ravel()[::100],gray[:,1:].ravel()[::100])[0,1])
|
| 91 |
v1=float(np.corrcoef(gray[:-1,:].ravel()[::100],gray[1:,:].ravel()[::100])[0,1])
|
| 92 |
delta=((ha-h1)+(va-v1))/2
|
| 93 |
+
if delta>0.1: s,n=0.5,f"Strong checkerboard (Δ={delta:.4f})"
|
| 94 |
+
elif delta>0.05: s,n=0.25,f"Mild checkerboard (Δ={delta:.4f})"
|
| 95 |
else: s,n=-0.1,f"No checkerboard ({delta:.4f})"
|
| 96 |
return {"test":"Checkerboard Pattern","delta":round(delta,6),"score":s,"note":n}
|
| 97 |
|
|
|
|
| 163 |
for i in range(0,hc,ps):
|
| 164 |
for j in range(0,wc,ps):
|
| 165 |
p=rgb[i:i+ps,j:j+ps]; m=np.mean(p,axis=(0,1))
|
| 166 |
+
if m[1]>30: ratios.append(m[0]/(m[1]+1e-9)) # min green=30 to avoid near-black patches
|
| 167 |
if len(ratios)<4: return {"test":"Color Ratio Consistency","score":0.0,"note":"Few patches"}
|
| 168 |
cv=float(np.std(ratios))/(float(np.mean(ratios))+1e-9)
|
| 169 |
if cv>0.1: s,n=-0.2,f"Varied color ratios (CV={cv:.3f})"
|
|
|
|
| 239 |
m13_texture_repetition,m14_highfreq_noise_structure,m15_phase_coherence]
|
| 240 |
|
| 241 |
def run_model_agent(img):
|
| 242 |
+
from agents.utils import run_agent_tests
|
| 243 |
+
from agents.optical_agent import AgentEvidence
|
| 244 |
+
findings, avg, conf, fail, rat = run_agent_tests(ALL_TESTS, img, "Generative Model Agent")
|
| 245 |
+
return AgentEvidence("Generative Model Agent",np.clip(avg,-1,1),conf,fail,rat,findings)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|