Download tasks/01-A-content-batch-gui-v4/tests/deterministic_checks.py from refreshdotdev/Refresh-GUI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 7.56 kB
-
https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/01-A-content-batch-gui-v4/tests/deterministic_checks.py
- Command line
-
hf download hf://datasets/refreshdotdev/Refresh-GUI-dataset/tasks/01-A-content-batch-gui-v4/tests/deterministic_checks.py
-
curl -L -o deterministic_checks.py https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/01-A-content-batch-gui-v4/tests/deterministic_checks.py
7.56 kB
| """Private deterministic verifier support; failures of grading never become task deductions.""" | |
| import json, math, os, re, subprocess | |
| from pathlib import Path | |
| import numpy as np | |
| from PIL import Image | |
| TICKS=254016000000 | |
| class GradingError(RuntimeError): pass | |
| def commands(trajectory): | |
| for step in trajectory.get('steps',[]): | |
| if step.get('source')!='agent':continue | |
| obs=step.get('observation',{}).get('results',[]) | |
| for call in step.get('tool_calls',[]): | |
| args=call.get('arguments',{});text=args.get('command') or args.get('text') or '' | |
| response=next((o for o in obs if o.get('source_call_id')==call.get('tool_call_id')),{}) | |
| output='\n'.join(c.get('text','') for c in response.get('content',[]) if c.get('type')=='text') | |
| yield step.get('step_id'),text,output,response | |
| def _action_checks(trajectory, workspace, target_names, assets=None): | |
| entries=list(commands(trajectory));app=[];previews=[];queued=[];done=[];started=[];pixel_evidence={} | |
| for sid,cmd,out,obs in entries: | |
| # A successful editing/export response, rather than help/probe/agent prose. | |
| if 'filmcraft-cli' in cmd and any(x in cmd for x in ['timeline.place','file.save','export.queue',' render ',' import ',' exec ']) and ('status=ok' in out or '"ok": true' in out) and any(x in out for x in ['"added"','"item"','"items"','"project"','"result"','saved','"bytes"','"ok"']):app.append(sid) | |
| if 'export.queue.start' in cmd:started.append(sid) | |
| # Queue-state output proves names/status, not the command's claimed intent. | |
| for name in ['final01-1080p.mp4','final01-720p.mp4','final-1080p.mp4']: | |
| if re.search(re.escape(name)+r'[^\n]{0,100}\bready\b',out):queued.append((sid,name)) | |
| if re.search(re.escape(name)+r'[^\n]{0,100}\bdone\b',out):done.append((sid,name)) | |
| if any(x in cmd for x in ['display ','feh ','ristretto ','preview','source.open']) and any(c.get('type')=='image' for c in obs.get('content',[])) and ('status=ok' in out or not out):previews.append(sid) | |
| # GUI calls are corroborated by application window observations, not text claims. | |
| observations=workspace/'logs/artifacts/runtime-observations.jsonl' | |
| if observations.is_file(): | |
| for line in observations.read_text().splitlines(): | |
| try:r=json.loads(line) | |
| except ValueError:continue | |
| if 'filmcraft' in r.get('windows','').lower() and any(s.get('tool_calls') for s in trajectory.get('steps',[]) if s.get('source')=='agent'): | |
| app.append('observed-filmcraft-window');break | |
| pair=['final-1080p.mp4', 'final01-720p.mp4'] | |
| batch=any(all(any(qsid<start and name==n for qsid,name in queued) for n in pair) and all(any(dsid>=start and name==n for dsid,name in done) for n in pair) for start in started) | |
| # Source-associated observations require a source thumbnail creation and delivered preview. | |
| source_view={} | |
| for n in target_names: | |
| extracts=[sid for sid,cmd,out,obs in entries if ('ffmpeg' in cmd or 'preview' in cmd or 'source.open' in cmd) and (n in cmd or n in out) and ('status=ok' in out or not out)] | |
| source_view[n]=any(preview>=extract for preview in previews for extract in extracts) | |
| if assets is not None and (assets/'operator-screenshots').is_dir() and not all(source_view.values()) and not all(n.startswith(('coffee-','pouring-','hands-')) for n in target_names): | |
| from gui_evidence import viewed_sources | |
| pixel_view,pixel_evidence=viewed_sources(trajectory,assets,target_names) | |
| for name in target_names:source_view[name]=source_view[name] or pixel_view[name] | |
| if assets is not None and not batch and (assets/'operator-screenshots').is_dir() and json.loads((assets/'verifier-config.json').read_text()).get('queue_exports'): | |
| from gui_evidence import gui_queue | |
| gui=gui_queue(trajectory,assets,pair);batch=gui['batch'] | |
| queued.extend(('gui',e['names']) for e in gui['events'] if e['ready']);done.extend(('gui',e['names']) for e in gui['events'] if e['done']) | |
| return {'app_use':bool(app),'app_steps':app,'source_view':source_view,'preview_steps':previews,'source_view_evidence':pixel_evidence,'batch':batch,'queue_evidence':{'ready':queued,'started':started,'done':done}} | |
| def native_dissolve(selected,clips,j): | |
| if not selected or len(clips)<=j:return None | |
| a,b=clips[j-1],clips[j];cut=b['start']/TICKS | |
| return next((t for t in selected['transitions'] if t.get('effect',{}).get('effect')=='cross_dissolve' and t['effect'].get('enabled',True) and t.get('from')==a['id'] and t.get('to')==b['id'] and t.get('duration',0)>0 and t['start']/TICKS<=cut<=(t['start']+t['duration'])/TICKS),None) | |
| def blend_measure(A,B,O): | |
| A=A.astype(float);B=B.astype(float);O=O.astype(float);d=B-A;alpha=float(np.clip(((O-A)*d).sum()/max(1,float((d*d).sum())),0,1));error=float(np.abs(O-(A*(1-alpha)+B*alpha)).mean());return alpha,error | |
| def rendered_assembly(frames,clips,selected,refs): | |
| """Check every frame against its source or the paired blend, with source-edge holds.""" | |
| if frames is None or not len(frames):return {'full':False,'tails':[False]*3,'joins':[False]*2,'end':False,'errors':[]} | |
| errors=[];join_samples=[[],[]];tails=[[],[],[]] | |
| trans=[native_dissolve(selected,clips,j) for j in [1,2]] | |
| def source(i,t): | |
| c=clips[i];f=round((c['source_in']/TICKS+t-c['start']/TICKS)*30);return refs[i][max(0,min(len(refs[i])-1,f))] | |
| for f,O in enumerate(frames): | |
| t=f/30;beyond_picture=False;fps=selected.get('seq',{}).get('settings',{}).get('frame_rate',{'num':30,'den':1});tail_tolerance=fps['den']/fps['num']+1/30 | |
| picture_end=max((c['start']+c['duration'])/TICKS for c in clips) | |
| if picture_end<=t<picture_end+tail_tolerance:beyond_picture=True;t=picture_end-1e-7 | |
| i=next((i for i,c in enumerate(clips) if c['start']/TICKS<=t<(c['start']+c['duration'])/TICKS),None) | |
| if i is None:errors.append(255.);continue | |
| blend=next(((j,tr) for j,tr in enumerate(trans) if tr and tr['start']/TICKS<=t<(tr['start']+tr['duration'])/TICKS),None) | |
| if blend: | |
| j,tr=blend;alpha,err=blend_measure(source(j,t),source(j+1,t),O);join_samples[j].append((alpha,err));tails[j].append(err);tails[j+1].append(err) | |
| else: | |
| A=source(i,t).astype(float);err=float(abs(O.astype(float)-A).mean()) | |
| if not beyond_picture:tails[i].append(err) | |
| errors.append(err) | |
| def good(v):return bool(bool(v) and np.quantile(v,.99)<=12 and max(v)<=22) | |
| joins=[] | |
| for samples in join_samples: | |
| alphas=[x[0] for x in samples];errs=[x[1] for x in samples];mixed=sum(.12<a<.88 for a in alphas) | |
| joins.append(len(samples)>=3 and mixed>=max(2,len(samples)//5) and alphas[-1]-alphas[0]>.5 and all(b>=a-.08 for a,b in zip(alphas,alphas[1:])) and good(errs)) | |
| end=max((c['start']+c['duration'])/TICKS for c in clips);endok=abs(len(frames)/30-end)<=max(1/30,selected.get('seq',{}).get('settings',{}).get('frame_rate',{'num':30,'den':1})['den']/selected.get('seq',{}).get('settings',{}).get('frame_rate',{'num':30,'den':1})['num'])+1/30 and good(errors[-3:]) | |
| return {'full':good(errors) and all(joins),'tails':[good(v) for v in tails],'joins':joins,'end':endok,'p99_mae':float(np.quantile(errors,.99)),'max_mae':max(errors),'join_samples':join_samples} | |
| def require_complete(result): | |
| from verifier_runtime import validate_report | |
| return validate_report(result) | |
| # One immutable private trace is evaluated repeatedly for four exports in one grading process. | |
| _ACTION_CACHE={} | |
| def action_checks(trajectory,workspace,target_names,assets=None): | |
| import hashlib,copy | |
| key=(hashlib.sha256(json.dumps(trajectory,sort_keys=True).encode()).hexdigest(),str(workspace),tuple(target_names),str(assets)) | |
| if key not in _ACTION_CACHE:_ACTION_CACHE[key]=_action_checks(trajectory,workspace,target_names,assets) | |
| return copy.deepcopy(_ACTION_CACHE[key]) | |