effectlab-transition-assets / tools /verify_remote.py
Visecall's picture
Verify ZIP-only catalog and anonymous previews/packages
1f5b39a verified
Raw History Blame Contribute Delete
2.88 kB
"""Confirm release completeness and anonymous individual downloads from the catalog."""
import argparse
import hashlib
import json
from pathlib import Path
import sqlite3
import urllib.request
from huggingface_hub import HfApi
from asset_client import AssetCatalog
ROOT=Path(__file__).resolve().parents[1]
def main():
p=argparse.ArgumentParser();p.add_argument('--repo',default='Visecall/effectlab-transition-assets');p.add_argument('--release',default='assets-v2');args=p.parse_args()
cache=ROOT/'.cache/anonymous-download';cache.mkdir(parents=True,exist_ok=True)
url=f'https://huggingface.co/datasets/{args.repo}/resolve/{args.release}/catalog.db'
request=urllib.request.Request(url,headers={'User-Agent':'effectLabAssets/1'})
with urllib.request.urlopen(request,timeout=180) as response:
remote_db=response.read();assert len(remote_db)==(ROOT/'catalog.db').stat().st_size
assert hashlib.sha256(remote_db).hexdigest()==hashlib.sha256((ROOT/'catalog.db').read_bytes()).hexdigest()
database=cache/'catalog.db';database.write_bytes(remote_db)
db=sqlite3.connect(database);db.row_factory=sqlite3.Row
files={r[0] for column in ('package_path','preview_path','poster_path') for r in db.execute('SELECT '+column+' FROM effects WHERE '+column+' IS NOT NULL')}
remote=set(HfApi(token=False).list_repo_files(args.repo,repo_type='dataset',revision=args.release))
assert files<=remote,f'{len(files-remote)} declared files missing remotely'
client=AssetCatalog(database,cache);selected=[]
def sample(id,role):
rows=client.files(id,role)
assert rows,f'missing {role} for {id}'
row=rows[0];local=client.fetch(row);selected.append({'path':row['path'],'role':role,'bytes':local.stat().st_size,'sha256':row['sha256']})
print(f'Anonymous download verified: {role} {row["path"]}',flush=True)
first=db.execute("SELECT id FROM effects WHERE render_status='ready' ORDER BY id LIMIT 1").fetchone()[0]
odd=db.execute("SELECT id FROM effects WHERE preview_width=99 AND preview_height=100 LIMIT 1").fetchone()[0]
gif=db.execute("SELECT id FROM effects WHERE preview_format='GIF'").fetchone()[0]
sample(first,'preview');sample(first,'poster');sample(first,'package')
sample(odd,'preview');sample(gif,'preview')
result={'repo':args.repo,'revision':args.release,'anonymous_catalog_download':True,'catalog_sha256':hashlib.sha256(remote_db).hexdigest(),
'declared_files':len(files),'remote_files':len(remote),'missing_declared_files':0,'samples':selected,'token_required':False}
(ROOT/'remote_verification_v2.local.json').write_text(json.dumps(result,indent=2)+'\n',encoding='utf-8')
print(json.dumps({k:v for k,v in result.items() if k!='samples'}));client.close();db.close();return 0
if __name__=='__main__':raise SystemExit(main())