"""Publish one triad for each additional source-name string."""
import html,json
from pathlib import Path
R=Path(__file__).resolve().parents[1];D=R/'results/r112/species-breadth';O=D/'mask-hypotheses';a=json.loads((D/'assets.json').read_text());v=json.loads((O/'verify.json').read_text());seen=set();cards=[];E=html.escape
for x in a['records']:
 name=x['source_species']
 if name in seen:continue
 seen.add(name);ident=x['annotation_id'];record=json.loads((O/'records'/f'{ident}.json').read_text());imgs=[('Source crop','../'+x['source_crop'])]+[(k+' proposal','masks/'+ident+'-'+k+'.png') for k in ('center','minus','plus')];cards.append('<article><h3>'+E(name)+' · '+E(ident)+'</h3><p>Geometric triage: '+E(record['triage'])+'</p><div class="views">'+''.join('<figure><a href="'+E(path)+'"><img loading="lazy" src="'+E(path)+'" alt="'+E(label)+'"></a><figcaption>'+E(label)+'</figcaption></figure>' for label,path in imgs)+'</div><p><a href="records/'+E(ident)+'.json">Source, prompts, scores and mask hashes</a></p></article>')
assert len(cards)==137;page='''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Additional source mask proposals</title><style>body{font:16px/1.5 system-ui;color:#193b37;background:#f2f6f2;margin:0}main{max-width:1200px;margin:auto;padding:24px}a{color:#076c59}.notice{background:#fff8df;border-left:5px solid #b88418;padding:15px}article{background:white;border:1px solid #cbd8d1;padding:12px;margin:14px 0}.views{display:grid;grid-template-columns:repeat(4,1fr);gap:8px}figure{margin:0}.views img{width:100%;height:180px;object-fit:contain;background:#e8eee8}figcaption{font-size:.85rem}@media(max-width:600px){.views{grid-template-columns:repeat(2,1fr)}}</style><main><nav><a href="/results/r112/species-breadth/">Additional source pool</a> · <a href="/results/r112/">Synthetic training</a></nav><h1>Additional source-mask proposals</h1><p class="notice"><strong>Model proposals, not validated specimen boundaries.</strong> The same model produced all three masks and can agree on background or the wrong organism. Public source names are not independently reconciled; source crops can contain neighbors. Triage reflects geometric agreement, not accuracy.</p><p>Three proposals were generated for each of 1,096 source crops. File, shape and geometric checks passed for all 1,096; '''+str(v['triage']['consistent-unverified'])+''' were geometrically consistent and '''+str(v['triage']['needs-inspection'])+''' were flagged for inspection. Neither category is approved as a training label. Some source locations overlap the earlier 80-name tuning and check groups; see the <a href="../prior-split-exposure.json">exposure audit</a>.</p><p><a href="protocol.json">Protocol</a> · <a href="results.json">All proposal records</a> · <a href="verify.json">File and geometry checks</a></p><p><a href="/results/r112/source-mask-polygon-proxy/">Compare the agreement rule against published polygons on a small oracle-assisted development set</a>.</p><h2>First crop from each of 137 source-name strings</h2><p>Binary masks are shown next to the original image. White indicates proposed support; click any image for native pixels.</p>'''+''.join(cards)+'''</main></html>''';(O/'index.html').write_text(page);print('published',len(cards),'proposal triads')
