Spaces:
Running on Zero
Running on Zero
Upload demo/upload_used_bundle_to_hf.py with huggingface_hub
Browse files- demo/upload_used_bundle_to_hf.py +112 -0
demo/upload_used_bundle_to_hf.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
SHARE_ROOT = Path("/project/llmsvgen/share/data/kmw_layered_checkpoint")
|
| 11 |
+
|
| 12 |
+
USED_FILE_MAP = {
|
| 13 |
+
PROJECT_ROOT / "demo" / "__init__.py": "demo/__init__.py",
|
| 14 |
+
PROJECT_ROOT / "demo" / "app.py": "demo/app.py",
|
| 15 |
+
PROJECT_ROOT / "demo" / "hf_repo_assets.py": "demo/hf_repo_assets.py",
|
| 16 |
+
PROJECT_ROOT / "demo" / "README.md": "demo/README.md",
|
| 17 |
+
PROJECT_ROOT / "demo" / "publish_space.py": "demo/publish_space.py",
|
| 18 |
+
PROJECT_ROOT / "demo" / "real_world_pipeline.py": "demo/real_world_pipeline.py",
|
| 19 |
+
PROJECT_ROOT / "demo" / "requirements-hf-space.txt": "demo/requirements-hf-space.txt",
|
| 20 |
+
PROJECT_ROOT / "demo" / "upload_used_bundle_to_hf.py": "demo/upload_used_bundle_to_hf.py",
|
| 21 |
+
PROJECT_ROOT / "demo" / "infer" / "__init__.py": "demo/infer/__init__.py",
|
| 22 |
+
PROJECT_ROOT / "demo" / "infer" / "run_caption_bbox_infer.py": "demo/infer/run_caption_bbox_infer.py",
|
| 23 |
+
PROJECT_ROOT / "demo" / "infer" / "vlm_bbox_inference.py": "demo/infer/vlm_bbox_inference.py",
|
| 24 |
+
PROJECT_ROOT / "infer" / "__init__.py": "infer/__init__.py",
|
| 25 |
+
PROJECT_ROOT / "infer" / "common_infer.py": "infer/common_infer.py",
|
| 26 |
+
PROJECT_ROOT / "infer" / "infer.py": "infer/infer.py",
|
| 27 |
+
PROJECT_ROOT / "infer" / "infer.yaml": "infer/infer.yaml",
|
| 28 |
+
PROJECT_ROOT / "models" / "__init__.py": "models/__init__.py",
|
| 29 |
+
PROJECT_ROOT / "models" / "multiLayer_adapter.py": "models/multiLayer_adapter.py",
|
| 30 |
+
PROJECT_ROOT / "models" / "mmdit.py": "models/mmdit.py",
|
| 31 |
+
PROJECT_ROOT / "models" / "pipeline.py": "models/pipeline.py",
|
| 32 |
+
PROJECT_ROOT / "models" / "transp_vae.py": "models/transp_vae.py",
|
| 33 |
+
PROJECT_ROOT / "tools" / "__init__.py": "tools/__init__.py",
|
| 34 |
+
PROJECT_ROOT / "tools" / "tools.py": "tools/tools.py",
|
| 35 |
+
PROJECT_ROOT / "environment.yml": "environment.yml",
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
REQUIRED_ASSET_FILES = {
|
| 39 |
+
PROJECT_ROOT / "ckpt" / "trans_vae" / "0008000.pt": "ckpt/trans_vae/0008000.pt",
|
| 40 |
+
PROJECT_ROOT / "ckpt" / "pre_trained_LoRA" / "pytorch_lora_weights.safetensors": "ckpt/pre_trained_LoRA/pytorch_lora_weights.safetensors",
|
| 41 |
+
PROJECT_ROOT / "ckpt" / "prism_ft_LoRA" / "pytorch_lora_weights.safetensors": "ckpt/prism_ft_LoRA/pytorch_lora_weights.safetensors",
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
REQUIRED_ASSET_FOLDERS = {
|
| 45 |
+
SHARE_ROOT / "SynLayers_checkpoints" / "FLUX.1-dev": "SynLayers_checkpoints/FLUX.1-dev",
|
| 46 |
+
SHARE_ROOT / "SynLayers_ckpt" / "step_120000": "SynLayers_ckpt/step_120000",
|
| 47 |
+
SHARE_ROOT / "SynLayers_checkpoints" / "FLUX.1-dev-Controlnet-Inpainting-Alpha": "SynLayers_checkpoints/FLUX.1-dev-Controlnet-Inpainting-Alpha",
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def upload_files(api: HfApi, repo_id: str, repo_type: str):
|
| 52 |
+
for local_path, remote_path in USED_FILE_MAP.items():
|
| 53 |
+
if not local_path.exists():
|
| 54 |
+
print(f"Skipping missing file: {local_path}")
|
| 55 |
+
continue
|
| 56 |
+
print(f"Uploading file {local_path} -> {remote_path}")
|
| 57 |
+
api.upload_file(
|
| 58 |
+
path_or_fileobj=str(local_path),
|
| 59 |
+
path_in_repo=remote_path,
|
| 60 |
+
repo_id=repo_id,
|
| 61 |
+
repo_type=repo_type,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
for local_path, remote_path in REQUIRED_ASSET_FILES.items():
|
| 65 |
+
if not local_path.exists():
|
| 66 |
+
print(f"Skipping missing asset: {local_path}")
|
| 67 |
+
continue
|
| 68 |
+
print(f"Uploading asset {local_path} -> {remote_path}")
|
| 69 |
+
api.upload_file(
|
| 70 |
+
path_or_fileobj=str(local_path),
|
| 71 |
+
path_in_repo=remote_path,
|
| 72 |
+
repo_id=repo_id,
|
| 73 |
+
repo_type=repo_type,
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def upload_folders(api: HfApi, repo_id: str, repo_type: str):
|
| 78 |
+
for local_path, remote_path in REQUIRED_ASSET_FOLDERS.items():
|
| 79 |
+
if not local_path.exists():
|
| 80 |
+
print(f"Skipping missing folder: {local_path}")
|
| 81 |
+
continue
|
| 82 |
+
print(f"Uploading folder {local_path} -> {remote_path}")
|
| 83 |
+
api.upload_folder(
|
| 84 |
+
folder_path=str(local_path),
|
| 85 |
+
path_in_repo=remote_path,
|
| 86 |
+
repo_id=repo_id,
|
| 87 |
+
repo_type=repo_type,
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def main():
|
| 92 |
+
parser = argparse.ArgumentParser(
|
| 93 |
+
description="Upload the minimal used SynLayers demo bundle to a Hugging Face repo."
|
| 94 |
+
)
|
| 95 |
+
parser.add_argument("--repo-id", type=str, default="SynLayers/Bbox-caption-8b")
|
| 96 |
+
parser.add_argument("--repo-type", type=str, default="model", choices=["model", "space", "dataset"])
|
| 97 |
+
parser.add_argument("--token", type=str, default=os.environ.get("HF_TOKEN"))
|
| 98 |
+
args = parser.parse_args()
|
| 99 |
+
|
| 100 |
+
if not args.token:
|
| 101 |
+
raise ValueError("Missing Hugging Face token. Pass --token or set HF_TOKEN.")
|
| 102 |
+
|
| 103 |
+
api = HfApi(token=args.token)
|
| 104 |
+
upload_files(api, args.repo_id, args.repo_type)
|
| 105 |
+
upload_folders(api, args.repo_id, args.repo_type)
|
| 106 |
+
|
| 107 |
+
print("")
|
| 108 |
+
print(f"Finished uploading used demo bundle to https://huggingface.co/{args.repo_id}")
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
if __name__ == "__main__":
|
| 112 |
+
main()
|