from pathlib import Path
import hashlib,json,sys
def inspect(directory):
 directory=Path(directory);assert directory.is_dir(),'Model directory missing'
 stems={p.stem for p in directory.iterdir()if p.suffix in ['.bin','.param']};assert stems,'No actual NCNN weights supplied';rows=[]
 for stem in sorted(stems):
  binary=directory/(stem+'.bin');param=directory/(stem+'.param')
  assert binary.is_file()and param.is_file(),f'Missing same-stem model pair: {stem}'
  assert binary.stat().st_size>0 and param.stat().st_size>0,'Empty model'
  lines=param.read_text().splitlines();assert lines[0].strip()=='7767517','Invalid NCNN param header'
  counts=lines[1].split();assert len(counts)==2 and all(x.isdigit()and int(x)>0 for x in counts),'Invalid NCNN graph counts'
  rows.append({'model':stem,'bin_sha256':hashlib.sha256(binary.read_bytes()).hexdigest(),'param_sha256':hashlib.sha256(param.read_bytes()).hexdigest(),'file_structure_only':True,'gpu_load_tested':False})
 return rows
if __name__=='__main__':
 rows=inspect(sys.argv[1]);Path('models-file-check.json').write_text(json.dumps(rows,indent=2)+'\n');print(json.dumps(rows))
