Extend3D / scripts /deploy_hf_space.py
junaid-simamdigital's picture
Deploy Extend3D Docker Space
d5811d7 verified
Raw History Blame Contribute Delete
1.58 kB
"""Create or update the Extend3D Hugging Face Space.
Usage:
$env:HF_TOKEN = "hf_..."
python scripts/deploy_hf_space.py YOUR_USERNAME/Extend3D
"""
from __future__ import annotations
import argparse
import os
from pathlib import Path
from huggingface_hub import HfApi, upload_folder
DEFAULT_IGNORE = [
".git/*",
".venv/*",
"venv/*",
"__pycache__/*",
"*.pyc",
"output/*",
".gradio/*",
".cache/*",
]
def main() -> None:
parser = argparse.ArgumentParser(description="Deploy this repo as a Hugging Face Docker Space.")
parser.add_argument("repo_id", help="Space repo id, for example YOUR_USERNAME/Extend3D")
parser.add_argument("--private", action="store_true", help="Create the Space as private if it does not exist.")
args = parser.parse_args()
token = os.environ.get("HF_TOKEN")
if not token:
raise SystemExit("HF_TOKEN is not set. Create a write token at https://huggingface.co/settings/tokens and set it first.")
root = Path(__file__).resolve().parents[1]
api = HfApi(token=token)
api.create_repo(
repo_id=args.repo_id,
repo_type="space",
space_sdk="docker",
private=args.private,
exist_ok=True,
)
upload_folder(
repo_id=args.repo_id,
repo_type="space",
folder_path=str(root),
ignore_patterns=DEFAULT_IGNORE,
token=token,
commit_message="Deploy Extend3D Docker Space",
)
print(f"Uploaded Space: https://huggingface.co/spaces/{args.repo_id}")
if __name__ == "__main__":
main()