Spaces:
Running on Zero
Running on Zero
File size: 2,076 Bytes
0cdc216 | 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | """Upload the inference bundle to a Hugging Face model repo.
PYTHONPATH=. python space/upload_bundle.py --repo KanameYOkoYAMA/2d-motion-interface --private
"""
import argparse
import os
from huggingface_hub import HfApi
from os.path import join as pjoin
# local-only files that should not end up in the model repo
IGNORE = ["export_report.json", "README.md", ".git*", "**/.git*"]
def main():
p = argparse.ArgumentParser()
p.add_argument("--repo", required=True)
p.add_argument("--bundle", default="./space/bundle")
p.add_argument("--card", default="./space/model_card.md")
p.add_argument("--private", action="store_true")
p.add_argument("--dry_run", action="store_true")
a = p.parse_args()
api = HfApi()
files = []
for dp, _, fs in os.walk(a.bundle):
for f in fs:
full = pjoin(dp, f)
rel = os.path.relpath(full, a.bundle)
if rel in IGNORE or rel.startswith(".git"):
continue
files.append((rel, os.path.getsize(full)))
files.sort(key=lambda kv: -kv[1])
print(f"repo : {a.repo} ({'private' if a.private else 'PUBLIC'})")
print(f"card : {a.card}")
print("upload :")
for rel, size in files:
print(f" {rel:34s} {size/1e6:8.1f} MB")
print(f" {'TOTAL':34s} {sum(s for _, s in files)/1e6:8.1f} MB")
if a.dry_run:
print("\ndry run - nothing uploaded")
return
api.create_repo(a.repo, repo_type="model", private=a.private, exist_ok=True)
api.upload_folder(repo_id=a.repo, repo_type="model", folder_path=a.bundle,
ignore_patterns=IGNORE,
commit_message="Add inference-only bundle (fp32, 1.03 GB)")
api.upload_file(repo_id=a.repo, repo_type="model", path_or_fileobj=a.card,
path_in_repo="README.md", commit_message="Add model card")
print("\nuploaded:")
for f in sorted(api.list_repo_files(a.repo)):
print(f" {f}")
print(f"\nhttps://huggingface.co/{a.repo}")
if __name__ == "__main__":
main()
|