SynLayers commited on
Commit
02f6539
·
verified ·
1 Parent(s): 917ee67

Upload demo/publish_space.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. demo/publish_space.py +82 -0
demo/publish_space.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ PROJECT_ROOT / "models" / "__init__.py": "models/__init__.py",
28
+ PROJECT_ROOT / "models" / "mmdit.py": "models/mmdit.py",
29
+ PROJECT_ROOT / "models" / "multiLayer_adapter.py": "models/multiLayer_adapter.py",
30
+ PROJECT_ROOT / "models" / "pipeline.py": "models/pipeline.py",
31
+ PROJECT_ROOT / "models" / "transp_vae.py": "models/transp_vae.py",
32
+ PROJECT_ROOT / "tools" / "__init__.py": "tools/__init__.py",
33
+ PROJECT_ROOT / "tools" / "tools.py": "tools/tools.py",
34
+ }
35
+
36
+
37
+ def iter_uploads():
38
+ for local_path, remote_path in STATIC_FILE_MAP.items():
39
+ if local_path.exists():
40
+ yield local_path, remote_path
41
+
42
+
43
+ def main():
44
+ parser = argparse.ArgumentParser(
45
+ description="Create or update a Hugging Face Space for the SynLayers demo."
46
+ )
47
+ parser.add_argument("--repo-id", type=str, required=True, help="Target Space repo id, e.g. SynLayers/synlayers-demo")
48
+ parser.add_argument("--token", type=str, default=os.environ.get("HF_TOKEN"))
49
+ parser.add_argument("--private", action="store_true", help="Create the Space as private")
50
+ args = parser.parse_args()
51
+
52
+ if not args.token:
53
+ raise ValueError("Missing Hugging Face token. Pass --token or set HF_TOKEN.")
54
+
55
+ api = HfApi(token=args.token)
56
+ api.create_repo(
57
+ repo_id=args.repo_id,
58
+ repo_type="space",
59
+ private=args.private,
60
+ space_sdk="gradio",
61
+ exist_ok=True,
62
+ )
63
+
64
+ for local_path, remote_path in iter_uploads():
65
+ print(f"Uploading {local_path} -> {remote_path}")
66
+ api.upload_file(
67
+ path_or_fileobj=str(local_path),
68
+ path_in_repo=remote_path,
69
+ repo_id=args.repo_id,
70
+ repo_type="space",
71
+ )
72
+
73
+ print("")
74
+ print(f"Space scaffold uploaded to https://huggingface.co/spaces/{args.repo_id}")
75
+ print("Model assets are not uploaded by this helper.")
76
+ print("Configure the Space variables before running:")
77
+ print(" SYNLAYERS_BBOX_MODEL_REPO=SynLayers/Bbox-caption-8b")
78
+ print(" SYNLAYERS_STAGE2_MODEL_REPO=SynLayers/synlayers")
79
+
80
+
81
+ if __name__ == "__main__":
82
+ main()