topabaem commited on
Commit
d674757
·
verified ·
1 Parent(s): 642c64c

Authenticate the gated VAE download

Browse files
Files changed (2) hide show
  1. app.py +26 -15
  2. sync.sh +31 -0
app.py CHANGED
@@ -21,16 +21,16 @@ import time
21
  from fractions import Fraction
22
  from pathlib import Path
23
 
 
 
 
 
24
  import gradio as gr
25
  import spaces
26
  from huggingface_hub import hf_hub_download, snapshot_download
27
 
28
  # --------------------------------------------------------------------- layout
29
 
30
- # Roughly 22 GB arrives on a cold start; the accelerated transfer is the
31
- # difference between a few minutes and a startup timeout.
32
- os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")
33
-
34
  ROOT = Path(__file__).resolve().parent
35
  WORK = Path(os.environ.get("LTX_WORK", "/tmp/ltx"))
36
  COMFY = WORK / "ComfyUI"
@@ -70,26 +70,37 @@ def _clone(url: str, dest: Path, commit: str) -> None:
70
  _run(["git", "checkout", commit], cwd=dest)
71
 
72
 
 
 
 
 
 
73
  def bootstrap() -> dict[str, Path]:
74
  """Everything that does not need a GPU, done once at import."""
 
 
 
 
 
75
  _clone("https://github.com/comfyanonymous/ComfyUI.git", COMFY, COMFY_COMMIT)
76
  _clone("https://github.com/city96/ComfyUI-GGUF.git",
77
  COMFY / "custom_nodes" / "ComfyUI-GGUF", GGUF_NODE_COMMIT)
78
  MODELS.mkdir(parents=True, exist_ok=True)
79
  OUT.mkdir(parents=True, exist_ok=True)
80
 
81
- paths = {
82
- "packed": Path(hf_hub_download(ENCODER_REPO, ENCODER_FILE,
83
- cache_dir=str(MODELS))),
84
- "encoder_dir": Path(snapshot_download(ENCODER_REPO, allow_patterns=["encoder-hf/*"],
85
- cache_dir=str(MODELS))) / "encoder-hf",
86
- "gguf": Path(hf_hub_download(DIT_REPO, DIT_FILE, cache_dir=str(MODELS))),
87
- "video_vae": Path(hf_hub_download(VAE_REPO, VIDEO_VAE, revision=VAE_REVISION,
88
- cache_dir=str(MODELS))),
89
- "audio_vae": Path(hf_hub_download(VAE_REPO, AUDIO_VAE, revision=VAE_REVISION,
90
- cache_dir=str(MODELS))),
 
 
91
  }
92
- return paths
93
 
94
 
95
  PATHS = bootstrap()
 
21
  from fractions import Fraction
22
  from pathlib import Path
23
 
24
+ # Roughly 22 GB arrives on a cold start, and `huggingface_hub` reads this into
25
+ # a module constant at import - setting it any later has no effect at all.
26
+ os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")
27
+
28
  import gradio as gr
29
  import spaces
30
  from huggingface_hub import hf_hub_download, snapshot_download
31
 
32
  # --------------------------------------------------------------------- layout
33
 
 
 
 
 
34
  ROOT = Path(__file__).resolve().parent
35
  WORK = Path(os.environ.get("LTX_WORK", "/tmp/ltx"))
36
  COMFY = WORK / "ComfyUI"
 
70
  _run(["git", "checkout", commit], cwd=dest)
71
 
72
 
73
+ #: `Lightricks/LTX-2.5` is gated, so the VAEs need an authenticated request from
74
+ #: an account that has accepted the licence. Set HF_TOKEN as a Space secret.
75
+ TOKEN = os.environ.get("HF_TOKEN") or None
76
+
77
+
78
  def bootstrap() -> dict[str, Path]:
79
  """Everything that does not need a GPU, done once at import."""
80
+ if TOKEN is None:
81
+ raise RuntimeError(
82
+ "HF_TOKEN is not set. Lightricks/LTX-2.5 is a gated repo and its "
83
+ "VAEs cannot be fetched without a token from an account that has "
84
+ "accepted the licence.")
85
  _clone("https://github.com/comfyanonymous/ComfyUI.git", COMFY, COMFY_COMMIT)
86
  _clone("https://github.com/city96/ComfyUI-GGUF.git",
87
  COMFY / "custom_nodes" / "ComfyUI-GGUF", GGUF_NODE_COMMIT)
88
  MODELS.mkdir(parents=True, exist_ok=True)
89
  OUT.mkdir(parents=True, exist_ok=True)
90
 
91
+ def fetch(repo: str, filename: str, revision: str | None = None) -> Path:
92
+ return Path(hf_hub_download(repo, filename, revision=revision,
93
+ cache_dir=str(MODELS), token=TOKEN))
94
+
95
+ return {
96
+ "packed": fetch(ENCODER_REPO, ENCODER_FILE),
97
+ "encoder_dir": Path(snapshot_download(
98
+ ENCODER_REPO, allow_patterns=["encoder-hf/*"],
99
+ cache_dir=str(MODELS), token=TOKEN)) / "encoder-hf",
100
+ "gguf": fetch(DIT_REPO, DIT_FILE),
101
+ "video_vae": fetch(VAE_REPO, VIDEO_VAE, VAE_REVISION),
102
+ "audio_vae": fetch(VAE_REPO, AUDIO_VAE, VAE_REVISION),
103
  }
 
104
 
105
 
106
  PATHS = bootstrap()
sync.sh ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Copy the modules the Space needs out of the repo.
3
+ #
4
+ # A Space is a separate git repo, so it cannot import from `../scripts`. The
5
+ # copies are deliberately NOT tracked here: two tracked copies of
6
+ # `ltx_packed_codec.py` would drift, and the one that drifts is always the one
7
+ # nobody is running locally. Run this before uploading.
8
+ set -euo pipefail
9
+ cd "$(dirname "$0")"
10
+
11
+ MODULES=(ltx_av_generate ltx_av_guide ltx_prompt_encoder ltx_render_clips
12
+ ltx_conditioning_dump ltx_prompt_embedding_gate ltx_packed_codec
13
+ ltx_fake_quantize)
14
+
15
+ mkdir -p scripts src/pacific
16
+ for module in "${MODULES[@]}"; do
17
+ cp "../scripts/$module.py" scripts/
18
+ done
19
+ cp ../src/pacific/ltx_av.py ../src/pacific/strict_json.py src/pacific/
20
+
21
+ cat > src/pacific/__init__.py <<'PY'
22
+ """A deliberately empty `pacific` for the Space.
23
+
24
+ The real package's `__init__` re-exports the whole conversion toolchain, which
25
+ would drag training, quantization and benchmarking imports into a Space that
26
+ only needs two helpers. Importing `pacific.ltx_av` executes this file, so this
27
+ file has to stay empty for that import to stay cheap.
28
+ """
29
+ PY
30
+
31
+ echo "synced ${#MODULES[@]} modules + pacific shim"