Datasets:
Download code/publish.py from ahmed-wez/hidden-capability-math: direct link, hf CLI and curl.
- Browser
- Download file 4.48 kB
-
https://huggingface.co/datasets/ahmed-wez/hidden-capability-math/resolve/main/code/publish.py
- Command line
-
hf download hf://datasets/ahmed-wez/hidden-capability-math/code/publish.py
-
curl -L -o publish.py https://huggingface.co/datasets/ahmed-wez/hidden-capability-math/resolve/main/code/publish.py
4.48 kB
| """Upload ONLY the inspected development stage using official huggingface_hub APIs. | |
| No token values are accepted as command-line arguments or written to source/logs. | |
| """ | |
| import argparse,json,hashlib,os,sys,tempfile | |
| from pathlib import Path | |
| from huggingface_hub import HfApi,get_token,hf_hub_download | |
| ROOT=Path(__file__).resolve().parents[1] | |
| REPO='ahmed-wez/hidden-capability-math' | |
| def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() | |
| def preflight(stage): | |
| m=json.loads((stage/'manifest.json').read_text());expected=set(m['sha256'])|{'manifest.json'} | |
| actual={str(p.relative_to(stage)) for p in stage.rglob('*') if p.is_file() and '__pycache__' not in p.parts and '.pytest_cache' not in p.parts and p.name!='publication_status.json'} | |
| if actual!=expected:raise RuntimeError('Unmanifested/missing release files; run finalization again') | |
| for rel,h in m['sha256'].items(): | |
| if sha(stage/rel)!=h:raise RuntimeError('Hash mismatch: '+rel) | |
| if m['counts']!={'development':5000,'pilot':450,'main_screening':4550}:raise RuntimeError('Wrong release counts') | |
| for rel in actual: | |
| if any(part in ['private_evaluation','internal','.scratch','.history'] for part in Path(rel).parts):raise RuntimeError('Forbidden release path') | |
| if not (stage/'reports/export_integrity_report.json').exists():raise RuntimeError('Export integrity report required') | |
| return sorted(actual) | |
| def publish(stage,repo=REPO): | |
| if repo!=REPO:raise RuntimeError('This uploader is restricted to the authorized repository') | |
| files=preflight(stage);token=get_token() | |
| if not token:raise RuntimeError('No secure Hugging Face credential. Set HF_TOKEN or run hf auth login; never put a token in source.') | |
| api=HfApi(token=token);who=api.whoami();print('Authenticated Hugging Face account:',who['name']) | |
| if who['name']!='ahmed-wez' and not any(o.get('name')=='ahmed-wez' for o in who.get('orgs',[])): | |
| raise RuntimeError('Credential does not belong to the target account or its organization') | |
| from huggingface_hub.utils import RepositoryNotFoundError | |
| try:info=api.repo_info(repo,repo_type='dataset') | |
| except RepositoryNotFoundError: | |
| api.create_repo(repo,repo_type='dataset',private=False,exist_ok=True);info=api.repo_info(repo,repo_type='dataset') | |
| existing={s.rfilename for s in info.siblings};unexpected=existing-set(files)-{'.gitattributes'} | |
| if unexpected:raise RuntimeError('Unexpected existing remote files; inspect before upload: '+', '.join(sorted(unexpected))) | |
| print('Target visibility:', 'private' if info.private else 'public') | |
| # Parent SHA protects against changes since inspection; failures do not delete files. | |
| commit=api.upload_folder(repo_id=repo,repo_type='dataset',folder_path=str(stage),allow_patterns=files,commit_message='Candidate development release: 5000 verified tasks; evaluation withheld',parent_commit=info.sha) | |
| revision=commit.oid;remote=api.repo_info(repo,repo_type='dataset',revision=revision);remote_files={s.rfilename for s in remote.siblings} | |
| if remote_files-set(files)-{'.gitattributes'}:raise RuntimeError('Unexpected post-upload files') | |
| for rel in files: | |
| local=Path(hf_hub_download(repo_id=repo,repo_type='dataset',filename=rel,revision=revision,token=token)) | |
| if sha(local)!=sha(stage/rel):raise RuntimeError('Remote download hash mismatch: '+rel) | |
| from datasets import load_dataset | |
| questions=load_dataset(repo,revision=revision,token=token);labels=load_dataset(repo,'labels',revision=revision,token=token) | |
| assert len(questions['pilot'])==len(labels['pilot'])==450 | |
| assert len(questions['main_screening'])==len(labels['main_screening'])==4550 | |
| status={'status':'published_and_download_verified','repository':repo,'url':'https://huggingface.co/datasets/'+repo,'revision':revision,'private':remote.private,'files_verified':len(files),'heldout_uploaded':False} | |
| (ROOT/'publication_status.json').write_text(json.dumps(status,indent=2)+'\n');print(json.dumps(status,indent=2)) | |
| if __name__=='__main__': | |
| p=argparse.ArgumentParser();p.add_argument('--stage',type=Path,default=ROOT if (ROOT/'development').is_dir() and not (ROOT/'private_evaluation').exists() else ROOT/'public_release');p.add_argument('--check-only',action='store_true');a=p.parse_args() | |
| if a.check_only:print('Validated manifest for',len(preflight(a.stage)),'development-only files') | |
| else: | |
| try:publish(a.stage) | |
| except Exception as e: | |
| # Exception text from HTTP libraries may include URLs; avoid logging request headers. | |
| print(type(e).__name__+': '+str(e),file=sys.stderr);sys.exit(1) | |