Bbox-caption-8b / demo /publish_space.py
SynLayers's picture
Upload demo/publish_space.py with huggingface_hub
499b2f6 verified
from __future__ import annotations
import argparse
import os
from pathlib import Path
from huggingface_hub import HfApi
PROJECT_ROOT = Path(__file__).resolve().parents[1]
STATIC_FILE_MAP = {
PROJECT_ROOT / "demo" / "__init__.py": "demo/__init__.py",
PROJECT_ROOT / "demo" / "app.py": "app.py",
PROJECT_ROOT / "demo" / "hf_repo_assets.py": "demo/hf_repo_assets.py",
PROJECT_ROOT / "demo" / "README.md": "README.md",
PROJECT_ROOT / "demo" / "publish_space.py": "demo/publish_space.py",
PROJECT_ROOT / "demo" / "requirements-hf-space.txt": "requirements.txt",
PROJECT_ROOT / "demo" / "real_world_pipeline.py": "demo/real_world_pipeline.py",
PROJECT_ROOT / "demo" / "upload_used_bundle_to_hf.py": "demo/upload_used_bundle_to_hf.py",
PROJECT_ROOT / "demo" / "infer" / "__init__.py": "demo/infer/__init__.py",
PROJECT_ROOT / "demo" / "infer" / "run_caption_bbox_infer.py": "demo/infer/run_caption_bbox_infer.py",
PROJECT_ROOT / "demo" / "infer" / "vlm_bbox_inference.py": "demo/infer/vlm_bbox_inference.py",
PROJECT_ROOT / "infer" / "__init__.py": "infer/__init__.py",
PROJECT_ROOT / "infer" / "common_infer.py": "infer/common_infer.py",
PROJECT_ROOT / "infer" / "infer.py": "infer/infer.py",
PROJECT_ROOT / "infer" / "infer.yaml": "infer/infer.yaml",
PROJECT_ROOT / "models" / "__init__.py": "models/__init__.py",
PROJECT_ROOT / "models" / "mmdit.py": "models/mmdit.py",
PROJECT_ROOT / "models" / "multiLayer_adapter.py": "models/multiLayer_adapter.py",
PROJECT_ROOT / "models" / "pipeline.py": "models/pipeline.py",
PROJECT_ROOT / "models" / "transp_vae.py": "models/transp_vae.py",
PROJECT_ROOT / "tools" / "__init__.py": "tools/__init__.py",
PROJECT_ROOT / "tools" / "tools.py": "tools/tools.py",
}
def iter_uploads():
for local_path, remote_path in STATIC_FILE_MAP.items():
if local_path.exists():
yield local_path, remote_path
def main():
parser = argparse.ArgumentParser(
description="Create or update a Hugging Face Space for the SynLayers demo."
)
parser.add_argument("--repo-id", type=str, required=True, help="Target Space repo id, e.g. SynLayers/synlayers-demo")
parser.add_argument("--token", type=str, default=os.environ.get("HF_TOKEN"))
parser.add_argument("--private", action="store_true", help="Create the Space as private")
args = parser.parse_args()
if not args.token:
raise ValueError("Missing Hugging Face token. Pass --token or set HF_TOKEN.")
api = HfApi(token=args.token)
api.create_repo(
repo_id=args.repo_id,
repo_type="space",
private=args.private,
space_sdk="gradio",
exist_ok=True,
)
for local_path, remote_path in iter_uploads():
print(f"Uploading {local_path} -> {remote_path}")
api.upload_file(
path_or_fileobj=str(local_path),
path_in_repo=remote_path,
repo_id=args.repo_id,
repo_type="space",
)
print("")
print(f"Space scaffold uploaded to https://huggingface.co/spaces/{args.repo_id}")
print("Model assets are not uploaded by this helper; configure them in Space storage or env vars before running.")
if __name__ == "__main__":
main()