File size: 1,460 Bytes
15c46ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | """Publish the free static report, never provisioning compute hardware."""
import argparse
import json
from pathlib import Path
from huggingface_hub import HfApi, hf_hub_download
from huggingface_hub.utils import RepositoryNotFoundError
from build_report_site import build
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('repo_id')
args = parser.parse_args()
api = HfApi()
if args.repo_id.split('/')[0] != api.whoami()['name']:
raise ValueError('Only publish into the authenticated personal account.')
site = build()
try:
api.repo_info(args.repo_id, repo_type='space')
except RepositoryNotFoundError:
api.create_repo(args.repo_id, repo_type='space', space_sdk='static', private=False)
else:
data = json.loads(Path(hf_hub_download(args.repo_id,'provenance.json',repo_type='space')).read_text())
if data.get('project') != 'nextgpt-chapter6-static-report':
raise ValueError('Existing Space is not this report project.')
commit = api.upload_folder(repo_id=args.repo_id, repo_type='space', folder_path=str(site),
commit_message='Publish NExT-GPT course code and actual execution records')
print(json.dumps({'space':f'https://huggingface.co/spaces/{args.repo_id}',
'source':f'https://huggingface.co/spaces/{args.repo_id}/tree/main/code',
'commit':commit.oid}))
|