carbon-a-release / verify_live.py
lvwerra's picture
lvwerra HF Staff
Move links and legend to a left column to give the tree more vertical space
b3a9cc3 verified
Raw History Blame Contribute Delete
1.37 kB
from pathlib import Path
import json,hashlib,requests,re
from huggingface_hub import HfApi,hf_hub_download,get_token
from check_presentation import check
R=Path(__file__).parent;repo='HuggingFaceBio/carbon-a-release';api=HfApi()
p=json.loads((R/'publication.json').read_text());info=api.repo_info(repo,repo_type='space')
assert info.private and info.sha==p['commit']
for name in ['index.html','carbon-a-strand-poc.png','provenance.json']:
downloaded=Path(hf_hub_download(repo,name,repo_type='space',revision=p['commit']))
assert hashlib.sha256(downloaded.read_bytes()).digest()==hashlib.sha256((R/name).read_bytes()).digest(),name
print('verified',name,flush=True)
url='https://huggingfacebio-carbon-a-release.static.hf.space/'
headers={'Authorization':'Bearer '+get_token()}
r=requests.get(url,headers=headers,timeout=30);r.raise_for_status()
# Static Spaces inject their public environment metadata into the head.
served=re.sub(rb'<script>window\.huggingface=\{variables:.*?</script>',b'',r.content,count=1)
assert served==(R/'index.html').read_bytes(),'Static app is still serving a different revision.'
result=check(url,headers)
p['verified']={'private':True,'runtime':api.get_space_runtime(repo).stage,'live_http_status':r.status_code,'files_match':True,'browser':result}
(R/'publication.json').write_text(json.dumps(p,indent=2));print(json.dumps(p['verified']))