SynLayers commited on
Commit
f87e805
·
verified ·
1 Parent(s): a87a5ff

Upload demo/publish_space.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. demo/publish_space.py +83 -0
demo/publish_space.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import os
5
+ from pathlib import Path
6
+
7
+ from huggingface_hub import HfApi
8
+
9
+ PROJECT_ROOT = Path(__file__).resolve().parents[1]
10
+
11
+ STATIC_FILE_MAP = {
12
+ PROJECT_ROOT / "demo" / "__init__.py": "demo/__init__.py",
13
+ PROJECT_ROOT / "demo" / "app.py": "app.py",
14
+ PROJECT_ROOT / "demo" / "hf_repo_assets.py": "demo/hf_repo_assets.py",
15
+ PROJECT_ROOT / "demo" / "README.md": "README.md",
16
+ PROJECT_ROOT / "demo" / "publish_space.py": "demo/publish_space.py",
17
+ PROJECT_ROOT / "demo" / "requirements-hf-space.txt": "requirements.txt",
18
+ PROJECT_ROOT / "demo" / "real_world_pipeline.py": "demo/real_world_pipeline.py",
19
+ PROJECT_ROOT / "demo" / "upload_used_bundle_to_hf.py": "demo/upload_used_bundle_to_hf.py",
20
+ PROJECT_ROOT / "demo" / "infer" / "__init__.py": "demo/infer/__init__.py",
21
+ PROJECT_ROOT / "demo" / "infer" / "run_caption_bbox_infer.py": "demo/infer/run_caption_bbox_infer.py",
22
+ PROJECT_ROOT / "demo" / "infer" / "vlm_bbox_inference.py": "demo/infer/vlm_bbox_inference.py",
23
+ PROJECT_ROOT / "infer" / "__init__.py": "infer/__init__.py",
24
+ PROJECT_ROOT / "infer" / "common_infer.py": "infer/common_infer.py",
25
+ PROJECT_ROOT / "infer" / "infer.py": "infer/infer.py",
26
+ PROJECT_ROOT / "infer" / "infer.yaml": "infer/infer.yaml",
27
+ }
28
+
29
+ DIRECTORIES_TO_UPLOAD = [
30
+ PROJECT_ROOT / "models",
31
+ PROJECT_ROOT / "tools",
32
+ ]
33
+
34
+
35
+ def iter_uploads():
36
+ for local_path, remote_path in STATIC_FILE_MAP.items():
37
+ if local_path.exists():
38
+ yield local_path, remote_path
39
+
40
+ for directory in DIRECTORIES_TO_UPLOAD:
41
+ if not directory.exists():
42
+ continue
43
+ for local_path in directory.rglob("*.py"):
44
+ yield local_path, str(local_path.relative_to(PROJECT_ROOT))
45
+
46
+
47
+ def main():
48
+ parser = argparse.ArgumentParser(
49
+ description="Create or update a Hugging Face Space for the SynLayers demo."
50
+ )
51
+ parser.add_argument("--repo-id", type=str, required=True, help="Target Space repo id, e.g. SynLayers/synlayers-demo")
52
+ parser.add_argument("--token", type=str, default=os.environ.get("HF_TOKEN"))
53
+ parser.add_argument("--private", action="store_true", help="Create the Space as private")
54
+ args = parser.parse_args()
55
+
56
+ if not args.token:
57
+ raise ValueError("Missing Hugging Face token. Pass --token or set HF_TOKEN.")
58
+
59
+ api = HfApi(token=args.token)
60
+ api.create_repo(
61
+ repo_id=args.repo_id,
62
+ repo_type="space",
63
+ private=args.private,
64
+ space_sdk="gradio",
65
+ exist_ok=True,
66
+ )
67
+
68
+ for local_path, remote_path in iter_uploads():
69
+ print(f"Uploading {local_path} -> {remote_path}")
70
+ api.upload_file(
71
+ path_or_fileobj=str(local_path),
72
+ path_in_repo=remote_path,
73
+ repo_id=args.repo_id,
74
+ repo_type="space",
75
+ )
76
+
77
+ print("")
78
+ print(f"Space scaffold uploaded to https://huggingface.co/spaces/{args.repo_id}")
79
+ print("Model assets are not uploaded by this helper; configure them in Space storage or env vars before running.")
80
+
81
+
82
+ if __name__ == "__main__":
83
+ main()