Spaces:
Running
Running
Download deploy.py from minjiechen/ThinkPower: direct link, hf CLI and curl.
- Browser
- Download file 2.55 kB
-
https://huggingface.co/spaces/minjiechen/ThinkPower/resolve/main/deploy.py
- Command line
-
hf download hf://spaces/minjiechen/ThinkPower/deploy.py
-
curl -L -o deploy.py https://huggingface.co/spaces/minjiechen/ThinkPower/resolve/main/deploy.py
2.55 kB
| """Publish the explicit application files, preserving unrelated Space content.""" | |
| import argparse,base64,json,os,sys,urllib.request,urllib.error | |
| from pathlib import Path | |
| ROOT=Path(__file__).resolve().parent | |
| REPO='minjiechen/ThinkPower' | |
| def request(path,token=None,data=None): | |
| headers={'User-Agent':'ThinkPower-Deploy'} | |
| if token:headers['Authorization']='Bearer '+token | |
| if data:headers['Content-Type']='application/x-ndjson' | |
| with urllib.request.urlopen(urllib.request.Request('https://huggingface.co'+path,headers=headers,data=data),timeout=60) as r:return json.load(r) | |
| def main(): | |
| parser=argparse.ArgumentParser();parser.add_argument('--check',action='store_true');args=parser.parse_args() | |
| token=os.environ.get('HF_TOKEN') or os.environ.get('HUGGING_FACE_HUB_TOKEN') | |
| p=Path(os.environ.get('HF_HOME',str(Path.home()/'.cache/huggingface')))/'token' | |
| if not token and p.exists():token=p.read_text().strip() | |
| if not token:sys.exit('No Hugging Face login. Run hf auth login with a write token, then retry.') | |
| try:who=request('/api/whoami-v2',token) | |
| except urllib.error.HTTPError as e:sys.exit(f'Hugging Face login rejected (HTTP {e.code}). Run hf auth login with a valid write token, then retry.') | |
| print('Authenticated:',who.get('name')) | |
| meta=request('/api/spaces/'+REPO,token) | |
| print('Space:',meta['id'],'Current revision:',meta.get('sha')) | |
| if args.check:return | |
| files=['Dockerfile','README.md','requirements-xfly-compare.txt','app.py','models.py','agent.py','test_models.py','test_static_engine.py','test_per_unit.py','test_technology.py','test_two_to_one.py','test_recommendation.py','test_scoreboard.py','build_family_schematics.py','annotate_schematics.py','deploy.py'] | |
| files.extend(str(p.relative_to(ROOT)) for folder in ['static'] for p in (ROOT/folder).rglob('*') if p.is_file() and '__pycache__' not in p.parts) | |
| ops=[dict(key='header',value=dict(summary='Publish ThinkPower topology analysis website',description='Independent static website with browser-based analysis and optional direct vision inference. Links to the restored original XFLY simulation Space.',parentCommit=meta['sha']))] | |
| for name in sorted(files):ops.append(dict(key='file',value=dict(path=name,encoding='base64',content=base64.b64encode((ROOT/name).read_bytes()).decode()))) | |
| result=request('/api/spaces/'+REPO+'/commit/main',token,('\n'.join(json.dumps(o) for o in ops)+'\n').encode()) | |
| print('Published commit:',result.get('commitOid',result.get('commitUrl','success'))) | |
| print('Space: https://huggingface.co/spaces/'+REPO) | |
| if __name__=='__main__':main() | |