nextgpt-chapter6-report / code /scripts /publish_report.py
CollinMa's picture
Publish NExT-GPT course code and actual execution records
15c46ce verified
Raw History Blame Contribute Delete
1.46 kB
"""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}))