"""Compact review of frozen visual prefixes and exact task/command ledgers.""" import argparse from collections import defaultdict import json from pathlib import Path import sys import textwrap import numpy as np from PIL import Image, ImageDraw, ImageFont from common import ROOT, WORK, write_json sys.path[:0]=[str(ROOT),str(ROOT/'src')] def main(): p=argparse.ArgumentParser() p.add_argument('--cohort',type=Path,default=WORK/'outputs/sessions2048') p.add_argument('--per-task',type=int,default=4) a=p.parse_args() path=a.cohort/'manifest.json' if not path.exists():path=a.cohort/'selection_progress.json' rows=json.loads(path.read_text())['rows'] groups=defaultdict(list) for r in rows:groups[r['task']].append(r) dest=a.cohort/'review';dest.mkdir(exist_ok=True) fonts=list(Path('/usr/share/fonts').rglob('*CJK*.ttc')) font=ImageFont.truetype(str(fonts[0]) if fonts else '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',18) manifest=[] from psi.data.seed.video_overlay import decode_video for task, candidates in groups.items(): # Spread cases by duration, rather than always the first/easiest ones. candidates.sort(key=lambda r:r['reference_frames']) choices=np.unique(np.linspace(0,len(candidates)-1,min(a.per_task,len(candidates))).astype(int)) for i in choices: r=candidates[i];o=r['overlay'];qend=o['question_end'] if r['visual_kind']=='video': times=np.linspace(0,qend,6) pixels,pts=decode_video(o['video_path'],times,end_seconds=o['camera_duration_seconds'],side=360) frames=[Image.fromarray(v) for v in pixels] else: frames=[Image.open(o['image_path']).convert('RGB').resize((360,360))];pts=[0.] board=Image.new('RGB',(1080,1100),'white');draw=ImageDraw.Draw(board) line=10 lines=[f"{r['sample_id']} | {task} | {r['turn_count']} turns | {r['voice']}", f"Question ends {qend:.2f}s; session {r['reference_frames']/50:.2f}s. All frames below precede question end.", 'Q: '+o['question'],'A: '+o['answer'], 'Motion: '+' -> '.join(s['caption'] for s in r['segments'])] for text in lines: for part in textwrap.wrap(text,95): draw.text((10,line),part,fill='black',font=font);line+=24 top=max(260,line+5) for k,(frame,t) in enumerate(zip(frames,pts)): x=(k%3)*360;y=top+(k//3)*390 board.paste(frame,(x,y));draw.text((x+8,y+363),f'PTS {t:.2f}s',fill='black',font=font) out=dest/(r['sample_id']+'.jpg');board.save(out,quality=92) manifest.append(dict(sample_id=r['sample_id'],task=task,contact_sheet=str(out), question=o['question'],answer=o['answer'],question_end=qend,pts=list(map(float,pts)))) write_json(dest/'cases.json',manifest) print(json.dumps(manifest,ensure_ascii=False,indent=2)) if __name__=='__main__':main()