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
Upload demo/app.py with huggingface_hub
Browse files- demo/app.py +32 -18
demo/app.py
CHANGED
|
@@ -42,13 +42,13 @@ if str(PROJECT_ROOT) not in sys.path:
|
|
| 42 |
|
| 43 |
from demo.real_world_pipeline import ( # noqa: E402
|
| 44 |
DEFAULT_BBOX_MODEL,
|
| 45 |
-
|
| 46 |
DEFAULT_REAL_CONFIG_PATH,
|
| 47 |
DEFAULT_RUN_NAME,
|
| 48 |
DEFAULT_WORK_DIR,
|
| 49 |
run_real_world_pipeline,
|
| 50 |
)
|
| 51 |
-
from demo.hf_repo_assets import ensure_repo_assets # noqa: E402
|
| 52 |
|
| 53 |
|
| 54 |
DEFAULT_EXAMPLE_DIR = Path(
|
|
@@ -91,10 +91,10 @@ ZERO_GPU_DURATION = clamp(
|
|
| 91 |
|
| 92 |
MODEL_PREFETCH_STATUS = {
|
| 93 |
"enabled": os.environ.get("SYNLAYERS_DISABLE_PREFETCH", "0") != "1",
|
| 94 |
-
"
|
| 95 |
-
"
|
| 96 |
"bbox_done": False,
|
| 97 |
-
"
|
| 98 |
"error": "",
|
| 99 |
}
|
| 100 |
|
|
@@ -181,20 +181,28 @@ def prefetch_model_assets() -> None:
|
|
| 181 |
if not MODEL_PREFETCH_STATUS["enabled"]:
|
| 182 |
return
|
| 183 |
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
try:
|
| 189 |
-
ensure_repo_assets(
|
| 190 |
except Exception as exc:
|
| 191 |
MODEL_PREFETCH_STATUS["error"] += (
|
| 192 |
-
f"\n- Failed to prefetch runtime assets from `{
|
| 193 |
)
|
| 194 |
-
|
| 195 |
|
| 196 |
MODEL_PREFETCH_STATUS["bbox_done"] = bool(bbox_ok)
|
| 197 |
-
MODEL_PREFETCH_STATUS["
|
| 198 |
|
| 199 |
|
| 200 |
# Run prefetch during Space startup, outside the ZeroGPU-decorated function.
|
|
@@ -252,7 +260,12 @@ def is_zero_gpu_space() -> bool:
|
|
| 252 |
def get_runtime_status_markdown() -> str:
|
| 253 |
accelerator = os.environ.get("ACCELERATOR", "unknown")
|
| 254 |
space_id = os.environ.get("SPACE_ID", "local")
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
zero_gpu_enabled = is_zero_gpu_space()
|
| 257 |
|
| 258 |
lines = [
|
|
@@ -260,14 +273,15 @@ def get_runtime_status_markdown() -> str:
|
|
| 260 |
f"- `SPACE_ID`: `{space_id}`",
|
| 261 |
f"- `ACCELERATOR`: `{accelerator}`",
|
| 262 |
f"- `HF_HOME`: `{os.environ.get('HF_HOME', '')}`",
|
| 263 |
-
f"- `
|
|
|
|
| 264 |
"",
|
| 265 |
"## Model Asset Prefetch",
|
| 266 |
f"- `Prefetch enabled`: `{MODEL_PREFETCH_STATUS['enabled']}`",
|
| 267 |
-
f"- `
|
| 268 |
-
f"- `
|
| 269 |
-
f"- `
|
| 270 |
-
f"- `
|
| 271 |
]
|
| 272 |
|
| 273 |
if MODEL_PREFETCH_STATUS["error"]:
|
|
|
|
| 42 |
|
| 43 |
from demo.real_world_pipeline import ( # noqa: E402
|
| 44 |
DEFAULT_BBOX_MODEL,
|
| 45 |
+
DEFAULT_STAGE2_MODEL_REPO_ID,
|
| 46 |
DEFAULT_REAL_CONFIG_PATH,
|
| 47 |
DEFAULT_RUN_NAME,
|
| 48 |
DEFAULT_WORK_DIR,
|
| 49 |
run_real_world_pipeline,
|
| 50 |
)
|
| 51 |
+
from demo.hf_repo_assets import ensure_repo_assets, get_stage2_model_repo_id # noqa: E402
|
| 52 |
|
| 53 |
|
| 54 |
DEFAULT_EXAMPLE_DIR = Path(
|
|
|
|
| 91 |
|
| 92 |
MODEL_PREFETCH_STATUS = {
|
| 93 |
"enabled": os.environ.get("SYNLAYERS_DISABLE_PREFETCH", "0") != "1",
|
| 94 |
+
"stage1_bbox_model": str(DEFAULT_BBOX_MODEL),
|
| 95 |
+
"stage2_model_repo": get_stage2_model_repo_id(),
|
| 96 |
"bbox_done": False,
|
| 97 |
+
"stage2_done": False,
|
| 98 |
"error": "",
|
| 99 |
}
|
| 100 |
|
|
|
|
| 181 |
if not MODEL_PREFETCH_STATUS["enabled"]:
|
| 182 |
return
|
| 183 |
|
| 184 |
+
stage1_bbox_model = (
|
| 185 |
+
os.environ.get("SYNLAYERS_BBOX_MODEL")
|
| 186 |
+
or os.environ.get("SYNLAYERS_BBOX_MODEL_REPO")
|
| 187 |
+
or DEFAULT_BBOX_MODEL
|
| 188 |
+
)
|
| 189 |
+
stage2_model_repo = get_stage2_model_repo_id()
|
| 190 |
+
MODEL_PREFETCH_STATUS["stage1_bbox_model"] = str(stage1_bbox_model)
|
| 191 |
+
MODEL_PREFETCH_STATUS["stage2_model_repo"] = str(stage2_model_repo)
|
| 192 |
+
|
| 193 |
+
bbox_ok = prefetch_one_model(stage1_bbox_model, "Stage 1 bbox model")
|
| 194 |
+
stage2_ok = prefetch_one_model(stage2_model_repo, "Stage 2 model repo")
|
| 195 |
|
| 196 |
try:
|
| 197 |
+
ensure_repo_assets(stage2_model_repo)
|
| 198 |
except Exception as exc:
|
| 199 |
MODEL_PREFETCH_STATUS["error"] += (
|
| 200 |
+
f"\n- Failed to prefetch Stage 2 runtime assets from `{stage2_model_repo}`: {exc}"
|
| 201 |
)
|
| 202 |
+
stage2_ok = False
|
| 203 |
|
| 204 |
MODEL_PREFETCH_STATUS["bbox_done"] = bool(bbox_ok)
|
| 205 |
+
MODEL_PREFETCH_STATUS["stage2_done"] = bool(stage2_ok)
|
| 206 |
|
| 207 |
|
| 208 |
# Run prefetch during Space startup, outside the ZeroGPU-decorated function.
|
|
|
|
| 260 |
def get_runtime_status_markdown() -> str:
|
| 261 |
accelerator = os.environ.get("ACCELERATOR", "unknown")
|
| 262 |
space_id = os.environ.get("SPACE_ID", "local")
|
| 263 |
+
stage1_bbox_model = (
|
| 264 |
+
os.environ.get("SYNLAYERS_BBOX_MODEL")
|
| 265 |
+
or os.environ.get("SYNLAYERS_BBOX_MODEL_REPO")
|
| 266 |
+
or DEFAULT_BBOX_MODEL
|
| 267 |
+
)
|
| 268 |
+
stage2_model_repo = get_stage2_model_repo_id()
|
| 269 |
zero_gpu_enabled = is_zero_gpu_space()
|
| 270 |
|
| 271 |
lines = [
|
|
|
|
| 273 |
f"- `SPACE_ID`: `{space_id}`",
|
| 274 |
f"- `ACCELERATOR`: `{accelerator}`",
|
| 275 |
f"- `HF_HOME`: `{os.environ.get('HF_HOME', '')}`",
|
| 276 |
+
f"- `Stage 1 bbox repo/path`: `{stage1_bbox_model}`",
|
| 277 |
+
f"- `Stage 2 repo`: `{stage2_model_repo}`",
|
| 278 |
"",
|
| 279 |
"## Model Asset Prefetch",
|
| 280 |
f"- `Prefetch enabled`: `{MODEL_PREFETCH_STATUS['enabled']}`",
|
| 281 |
+
f"- `Stage 1 bbox model`: `{MODEL_PREFETCH_STATUS['stage1_bbox_model']}`",
|
| 282 |
+
f"- `Stage 2 model repo`: `{MODEL_PREFETCH_STATUS['stage2_model_repo']}`",
|
| 283 |
+
f"- `Stage 1 files prefetched`: `{MODEL_PREFETCH_STATUS['bbox_done']}`",
|
| 284 |
+
f"- `Stage 2 assets prefetched`: `{MODEL_PREFETCH_STATUS['stage2_done']}`",
|
| 285 |
]
|
| 286 |
|
| 287 |
if MODEL_PREFETCH_STATUS["error"]:
|