Image-to-Image
Diffusers
Safetensors
image-decomposition
layered-image-editing
diffusion
flux
lora
transparent-rgba
Instructions to use SynLayers/synlayers with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use SynLayers/synlayers with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("fill-in-base-model", dtype=torch.bfloat16, device_map="cuda") pipe.load_lora_weights("SynLayers/synlayers") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps
- Draw Things
Delete demo/upload_used_bundle_to_hf.py with huggingface_hub
Browse files- demo/upload_used_bundle_to_hf.py +0 -173
demo/upload_used_bundle_to_hf.py
DELETED
|
@@ -1,173 +0,0 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
|
| 3 |
-
import argparse
|
| 4 |
-
import os
|
| 5 |
-
from pathlib import Path
|
| 6 |
-
|
| 7 |
-
from huggingface_hub import HfApi, snapshot_download
|
| 8 |
-
|
| 9 |
-
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
| 10 |
-
|
| 11 |
-
DEFAULT_BBOX_REPO_ID = "SynLayers/Bbox-caption-8b"
|
| 12 |
-
DEFAULT_STAGE2_REPO_ID = "SynLayers/synlayers"
|
| 13 |
-
DEFAULT_STAGE2_SOURCE_REPO_ID = DEFAULT_BBOX_REPO_ID
|
| 14 |
-
|
| 15 |
-
BBOX_FILE_MAP = {
|
| 16 |
-
PROJECT_ROOT / "demo" / "model_card.md": "README.md",
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
STAGE2_FILE_MAP = {
|
| 20 |
-
PROJECT_ROOT / "demo" / "stage2_model_card.md": "README.md",
|
| 21 |
-
PROJECT_ROOT / "demo" / "__init__.py": "demo/__init__.py",
|
| 22 |
-
PROJECT_ROOT / "demo" / "app.py": "demo/app.py",
|
| 23 |
-
PROJECT_ROOT / "demo" / "hf_repo_assets.py": "demo/hf_repo_assets.py",
|
| 24 |
-
PROJECT_ROOT / "demo" / "README.md": "demo/README.md",
|
| 25 |
-
PROJECT_ROOT / "demo" / "publish_space.py": "demo/publish_space.py",
|
| 26 |
-
PROJECT_ROOT / "demo" / "real_world_pipeline.py": "demo/real_world_pipeline.py",
|
| 27 |
-
PROJECT_ROOT / "demo" / "requirements-hf-space.txt": "demo/requirements-hf-space.txt",
|
| 28 |
-
PROJECT_ROOT / "demo" / "upload_used_bundle_to_hf.py": "demo/upload_used_bundle_to_hf.py",
|
| 29 |
-
PROJECT_ROOT / "demo" / "infer" / "__init__.py": "demo/infer/__init__.py",
|
| 30 |
-
PROJECT_ROOT / "demo" / "infer" / "run_caption_bbox_infer.py": "demo/infer/run_caption_bbox_infer.py",
|
| 31 |
-
PROJECT_ROOT / "demo" / "infer" / "vlm_bbox_inference.py": "demo/infer/vlm_bbox_inference.py",
|
| 32 |
-
PROJECT_ROOT / "infer" / "__init__.py": "infer/__init__.py",
|
| 33 |
-
PROJECT_ROOT / "infer" / "common_infer.py": "infer/common_infer.py",
|
| 34 |
-
PROJECT_ROOT / "infer" / "infer.py": "infer/infer.py",
|
| 35 |
-
PROJECT_ROOT / "infer" / "infer.yaml": "infer/infer.yaml",
|
| 36 |
-
PROJECT_ROOT / "models" / "__init__.py": "models/__init__.py",
|
| 37 |
-
PROJECT_ROOT / "models" / "multiLayer_adapter.py": "models/multiLayer_adapter.py",
|
| 38 |
-
PROJECT_ROOT / "models" / "mmdit.py": "models/mmdit.py",
|
| 39 |
-
PROJECT_ROOT / "models" / "pipeline.py": "models/pipeline.py",
|
| 40 |
-
PROJECT_ROOT / "models" / "transp_vae.py": "models/transp_vae.py",
|
| 41 |
-
PROJECT_ROOT / "tools" / "__init__.py": "tools/__init__.py",
|
| 42 |
-
PROJECT_ROOT / "tools" / "tools.py": "tools/tools.py",
|
| 43 |
-
PROJECT_ROOT / "dataset_scaleup" / "dataset_construction.sh": "dataset/dataset_construction.sh",
|
| 44 |
-
PROJECT_ROOT / "dataset_scaleup" / "scaleup_api.py": "dataset/scaleup_api.py",
|
| 45 |
-
PROJECT_ROOT / "dataset_scaleup" / "scaleup_dataset.py": "dataset/scaleup_dataset.py",
|
| 46 |
-
PROJECT_ROOT / "dataset_scaleup" / "scaleup_utils.py": "dataset/scaleup_utils.py",
|
| 47 |
-
PROJECT_ROOT / "environment.yml": "environment.yml",
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
STAGE2_SOURCE_ASSET_FILES = {
|
| 51 |
-
"ckpt/trans_vae/0008000.pt": "ckpt/trans_vae/0008000.pt",
|
| 52 |
-
"ckpt/pre_trained_LoRA/pytorch_lora_weights.safetensors": "ckpt/pre_trained_LoRA/pytorch_lora_weights.safetensors",
|
| 53 |
-
"ckpt/prism_ft_LoRA/pytorch_lora_weights.safetensors": "ckpt/prism_ft_LoRA/pytorch_lora_weights.safetensors",
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
STAGE2_SOURCE_ASSET_FOLDERS = {
|
| 57 |
-
"SynLayers_checkpoints/FLUX.1-dev": "SynLayers_checkpoints/FLUX.1-dev",
|
| 58 |
-
"SynLayers_ckpt/step_120000": "SynLayers_ckpt/step_120000",
|
| 59 |
-
"SynLayers_checkpoints/FLUX.1-dev-Controlnet-Inpainting-Alpha": "SynLayers_checkpoints/FLUX.1-dev-Controlnet-Inpainting-Alpha",
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
def upload_file_map(api: HfApi, repo_id: str, repo_type: str, file_map: dict[Path, str]):
|
| 64 |
-
for local_path, remote_path in file_map.items():
|
| 65 |
-
if not local_path.exists():
|
| 66 |
-
print(f"Skipping missing file: {local_path}")
|
| 67 |
-
continue
|
| 68 |
-
print(f"Uploading file {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 download_stage2_source_bundle(source_repo_id: str, token: str | None) -> Path:
|
| 78 |
-
allow_patterns = list(STAGE2_SOURCE_ASSET_FILES.keys()) + [
|
| 79 |
-
f"{remote_path}/**" for remote_path in STAGE2_SOURCE_ASSET_FOLDERS
|
| 80 |
-
]
|
| 81 |
-
local_root = snapshot_download(
|
| 82 |
-
repo_id=source_repo_id,
|
| 83 |
-
repo_type="model",
|
| 84 |
-
allow_patterns=allow_patterns,
|
| 85 |
-
token=token,
|
| 86 |
-
)
|
| 87 |
-
return Path(local_root)
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
def upload_stage2_asset_files(
|
| 91 |
-
api: HfApi,
|
| 92 |
-
repo_id: str,
|
| 93 |
-
repo_type: str,
|
| 94 |
-
source_root: Path,
|
| 95 |
-
):
|
| 96 |
-
for local_rel_path, remote_path in STAGE2_SOURCE_ASSET_FILES.items():
|
| 97 |
-
local_path = source_root / local_rel_path
|
| 98 |
-
if not local_path.exists():
|
| 99 |
-
print(f"Skipping missing asset: {local_path}")
|
| 100 |
-
continue
|
| 101 |
-
print(f"Uploading asset {local_path} -> {remote_path}")
|
| 102 |
-
api.upload_file(
|
| 103 |
-
path_or_fileobj=str(local_path),
|
| 104 |
-
path_in_repo=remote_path,
|
| 105 |
-
repo_id=repo_id,
|
| 106 |
-
repo_type=repo_type,
|
| 107 |
-
)
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
def upload_stage2_asset_folders(
|
| 111 |
-
api: HfApi,
|
| 112 |
-
repo_id: str,
|
| 113 |
-
repo_type: str,
|
| 114 |
-
source_root: Path,
|
| 115 |
-
):
|
| 116 |
-
for local_rel_path, remote_path in STAGE2_SOURCE_ASSET_FOLDERS.items():
|
| 117 |
-
local_path = source_root / local_rel_path
|
| 118 |
-
if not local_path.exists():
|
| 119 |
-
print(f"Skipping missing folder: {local_path}")
|
| 120 |
-
continue
|
| 121 |
-
print(f"Uploading folder {local_path} -> {remote_path}")
|
| 122 |
-
api.upload_folder(
|
| 123 |
-
folder_path=str(local_path),
|
| 124 |
-
path_in_repo=remote_path,
|
| 125 |
-
repo_id=repo_id,
|
| 126 |
-
repo_type=repo_type,
|
| 127 |
-
)
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
def main():
|
| 131 |
-
parser = argparse.ArgumentParser(
|
| 132 |
-
description="Upload either the Stage 1 bbox repo card or the Stage 2 SynLayers bundle."
|
| 133 |
-
)
|
| 134 |
-
parser.add_argument("--bundle", type=str, default="bbox", choices=["bbox", "stage2"])
|
| 135 |
-
parser.add_argument("--repo-id", type=str, default=None)
|
| 136 |
-
parser.add_argument("--repo-type", type=str, default="model", choices=["model"])
|
| 137 |
-
parser.add_argument(
|
| 138 |
-
"--source-repo-id",
|
| 139 |
-
type=str,
|
| 140 |
-
default=os.environ.get("SYNLAYERS_STAGE2_SOURCE_REPO", DEFAULT_STAGE2_SOURCE_REPO_ID),
|
| 141 |
-
help="Source model repo that currently stores the Stage 2 SynLayers assets.",
|
| 142 |
-
)
|
| 143 |
-
parser.add_argument("--token", type=str, default=os.environ.get("HF_TOKEN"))
|
| 144 |
-
args = parser.parse_args()
|
| 145 |
-
|
| 146 |
-
if not args.token:
|
| 147 |
-
raise ValueError("Missing Hugging Face token. Pass --token or set HF_TOKEN.")
|
| 148 |
-
|
| 149 |
-
api = HfApi(token=args.token)
|
| 150 |
-
repo_id = args.repo_id or (
|
| 151 |
-
DEFAULT_BBOX_REPO_ID if args.bundle == "bbox" else DEFAULT_STAGE2_REPO_ID
|
| 152 |
-
)
|
| 153 |
-
api.create_repo(repo_id=repo_id, repo_type=args.repo_type, exist_ok=True)
|
| 154 |
-
|
| 155 |
-
if args.bundle == "bbox":
|
| 156 |
-
upload_file_map(api, repo_id, args.repo_type, BBOX_FILE_MAP)
|
| 157 |
-
else:
|
| 158 |
-
source_root = download_stage2_source_bundle(args.source_repo_id, args.token)
|
| 159 |
-
upload_file_map(api, repo_id, args.repo_type, STAGE2_FILE_MAP)
|
| 160 |
-
upload_stage2_asset_files(api, repo_id, args.repo_type, source_root)
|
| 161 |
-
upload_stage2_asset_folders(
|
| 162 |
-
api,
|
| 163 |
-
repo_id,
|
| 164 |
-
args.repo_type,
|
| 165 |
-
source_root,
|
| 166 |
-
)
|
| 167 |
-
|
| 168 |
-
print("")
|
| 169 |
-
print(f"Finished uploading the {args.bundle} bundle to https://huggingface.co/{repo_id}")
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
if __name__ == "__main__":
|
| 173 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|