#!/usr/bin/env python3 import collections from datetime import datetime, timezone import json from pathlib import Path import shutil import sys sys.dont_write_bytecode=True from rebuild_appworld_vox import sha, wave_info, NAMES, read, write ROOT=Path('/mnt/lynx1/datasets/Appworld-vox') SRC=Path('/home/hbcho/agent/appworld/data/tasks_llm') TIDS={'5a83b05_2','9871968_3'} PLAN=Path('/home/hbcho/agent/dataset_rebuild/update_two_selection.json') rows=[json.loads(s) for s in (ROOT/'manifest.jsonl').read_text().splitlines()] old={(r['task_id'],r['type']):r for r in rows} choices=read(PLAN);tasks={tid:next(ROOT.glob('*/'+tid)) for tid in TIDS} for e in read(ROOT/'reports/file_inventory.json'): assert sha(ROOT/e['path'])==e['sha256'],e['path'] updates=[] for group in choices: assert group['task_id'] in TIDS assert len(group['selected'])==1,(group['task_id'],group['kind'],'no eligible LLM default') s=group['selected'][0] updates.append((group['task_id'],NAMES[group['kind']],Path(s['audio']['path']),s)) for tid in sorted(TIDS): metas=list((SRC/tid/'audio_natural/clean').glob('*/*/metadata.json')) assert len(metas)==1 updates.append((tid,'clean',metas[0].parent/'speech.wav',None)) assert len(updates)==14 prepared=[] for tid,kind,wav,selection in updates: m=read(wav.parent/'metadata.json');prev=old[(tid,kind)] assert m['status']=='ok' and m['task_id']==tid and m['speaker_id']==prev['speaker_id'] assert m['original_instruction']==read(tasks[tid]/'specs.json')['instruction']==read(SRC/tid/'annotation.json')['instruction'] assert sha(wav)==m['wav_sha256'] if selection: assert selection['audio']['wav_sha256']==m['wav_sha256'] docs={} for path,digest in m['source_dependencies'].items(): assert sha(path)==digest,path docs[Path(path).name]={'original_path':path,'sha256':digest,'document':read(path)} info=wave_info(wav);sr=info['sample_rate'];intervals=[] for i,u in enumerate(m.get('utterance_reports',[])): base=0 if i==0 else m['long_boundaries'][i-1]['end_frame'] for event in u.get('timeline',[]): if 'output_insert_start_frame' not in event:continue start=base+event['output_insert_start_frame'];end=base+event['output_insert_end_frame'] assert 0<=start