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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Joy-LTX 2.5 - one prompt, one take, picture + sound (ZeroGPU demo).
|
| 2 |
+
|
| 3 |
+
JoyAI-Echo's performance on LTX-2.5: the Echo video attention / feed-forward delta on the official
|
| 4 |
+
LTX-2.5 dev transformer with the official distilled LoRA baked in at 0.5. This Space runs ComfyUI
|
| 5 |
+
headless with the ComfyUI-JoyLTX25 node pack and the comfy-native int8 checkpoint - the same graph as
|
| 6 |
+
the released JoyLTX25 canvases (the Multishot sampler with one shot: two passes, x2 latent upscale,
|
| 7 |
+
joint audio).
|
| 8 |
+
|
| 9 |
+
Everything GPU-side runs in a subprocess (ComfyUI's own venv) INSIDE the @spaces.GPU call, so the
|
| 10 |
+
Gradio process never touches CUDA. First call after a cold start builds the venv and pulls ~36 GB of
|
| 11 |
+
models; later calls only start ComfyUI (~40 s) + render.
|
| 12 |
+
"""
|
| 13 |
+
import os
|
| 14 |
+
os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
|
| 15 |
+
|
| 16 |
+
import json
|
| 17 |
+
import shutil
|
| 18 |
+
import subprocess
|
| 19 |
+
import sys
|
| 20 |
+
import time
|
| 21 |
+
import urllib.request
|
| 22 |
+
from pathlib import Path
|
| 23 |
+
|
| 24 |
+
import gradio as gr
|
| 25 |
+
import spaces
|
| 26 |
+
from huggingface_hub import hf_hub_download
|
| 27 |
+
|
| 28 |
+
ROOT = Path("/tmp/joyltx25")
|
| 29 |
+
COMFY = ROOT / "ComfyUI"
|
| 30 |
+
VENV = COMFY / ".venv"
|
| 31 |
+
VENV_PY = VENV / "bin" / "python"
|
| 32 |
+
PORT = 8199
|
| 33 |
+
|
| 34 |
+
DIT_REPO = "joeygambino/joyai-echo-ltx25-echoVid-comfy-native"
|
| 35 |
+
DIT_FILE = "LTX25dist-echoVid-070T30-v2-DiT-comfy-int8.safetensors"
|
| 36 |
+
DIT_100 = "LTX25dist-echoVid-100T50-v2-DiT-comfy-int8.safetensors"
|
| 37 |
+
LTX_REPO = "Lightricks/LTX-2.5"
|
| 38 |
+
VAE_V = "vae/ltx-2.5-video-vae-bf16.safetensors"
|
| 39 |
+
VAE_A = "vae/ltx-2.5-audio-vae-bf16.safetensors"
|
| 40 |
+
UPS = "latent_upscale_models/ltx-2.5-latent-spatial-upscaler-x2-bf16-1.0.safetensors"
|
| 41 |
+
TENC = "text_encoders/gemma4-12b-with-proj-ltx-2.5-comfy-int8-convrot.safetensors"
|
| 42 |
+
PACK_GIT = "https://github.com/jlucasmcrell/ComfyUI-JoyLTX25.git"
|
| 43 |
+
COMFY_GIT = "https://github.com/comfyanonymous/ComfyUI.git"
|
| 44 |
+
|
| 45 |
+
TOKEN = os.environ.get("HF_TOKEN")
|
| 46 |
+
SETUP_OK, SETUP_ERR = True, ""
|
| 47 |
+
|
| 48 |
+
EXAMPLE = ("A woman in her thirties with dark hair tied back, in a rust-orange sweater, sits at a kitchen table "
|
| 49 |
+
"late at night with a mug of coffee going cold, warm tungsten light, a dark window behind her. She looks "
|
| 50 |
+
"at the camera and says, in a dry unhurried American voice, \"The whole street went dark for six minutes, "
|
| 51 |
+
"and my lights got brighter.\" Her hands stay around the mug; a fridge hums; quiet room tone; no music. "
|
| 52 |
+
"Static camera, one continuous take.")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _run(cmd, cwd=None, check=True):
|
| 56 |
+
print("[setup] $", cmd, flush=True)
|
| 57 |
+
p = subprocess.run(cmd, shell=True, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
| 58 |
+
tail = p.stdout[-3000:] if p.stdout else ""
|
| 59 |
+
if tail:
|
| 60 |
+
print(tail, flush=True)
|
| 61 |
+
if check and p.returncode != 0:
|
| 62 |
+
raise RuntimeError(tail)
|
| 63 |
+
return p.stdout
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def _link(src, dst):
|
| 67 |
+
dst = Path(dst); dst.parent.mkdir(parents=True, exist_ok=True)
|
| 68 |
+
if dst.exists():
|
| 69 |
+
return
|
| 70 |
+
try:
|
| 71 |
+
os.symlink(src, dst)
|
| 72 |
+
except OSError:
|
| 73 |
+
shutil.copy2(src, dst)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def setup():
|
| 77 |
+
ROOT.mkdir(parents=True, exist_ok=True)
|
| 78 |
+
if not (COMFY / "main.py").exists():
|
| 79 |
+
_run(f"git clone --depth 1 {COMFY_GIT} ComfyUI", ROOT)
|
| 80 |
+
pack = COMFY / "custom_nodes" / "ComfyUI-JoyLTX25"
|
| 81 |
+
if not pack.exists():
|
| 82 |
+
_run(f"git clone --depth 1 {PACK_GIT} ComfyUI-JoyLTX25", COMFY / "custom_nodes")
|
| 83 |
+
if not VENV_PY.exists():
|
| 84 |
+
print("[setup] building the ComfyUI venv (uv, torch cu128)...", flush=True)
|
| 85 |
+
_run(f"{sys.executable} -m uv venv --python 3.12 {VENV}", COMFY)
|
| 86 |
+
_run(f"{sys.executable} -m uv pip install --python {VENV_PY} --extra-index-url https://download.pytorch.org/whl/cu128 "
|
| 87 |
+
f"torch torchvision torchaudio -r requirements.txt comfy-kitchen av", COMFY)
|
| 88 |
+
models = COMFY / "models"
|
| 89 |
+
dm = models / "diffusion_models"; dm.mkdir(parents=True, exist_ok=True)
|
| 90 |
+
for f in (DIT_FILE, DIT_100):
|
| 91 |
+
if not (dm / f).exists():
|
| 92 |
+
print(f"[setup] downloading {f} ...", flush=True)
|
| 93 |
+
_link(hf_hub_download(DIT_REPO, f, token=TOKEN), dm / f)
|
| 94 |
+
for rel in (VAE_V, VAE_A, UPS, TENC):
|
| 95 |
+
if not (models / rel).exists():
|
| 96 |
+
print(f"[setup] downloading {rel} ...", flush=True)
|
| 97 |
+
_link(hf_hub_download(LTX_REPO, rel, token=TOKEN), models / rel)
|
| 98 |
+
print("[setup] ready", flush=True)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
try:
|
| 102 |
+
setup()
|
| 103 |
+
except Exception as e: # the UI still loads and shows the error
|
| 104 |
+
SETUP_OK, SETUP_ERR = False, str(e)[-1500:]
|
| 105 |
+
print("[setup] FAILED:", SETUP_ERR, flush=True)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
# --------------------------------------------------------------------------- graph
|
| 109 |
+
def graph(prompt, negative, width, height, frames, two_pass, seed, dose, video_cfg):
|
| 110 |
+
dit = DIT_FILE if dose.startswith("070") else DIT_100
|
| 111 |
+
return {
|
| 112 |
+
"1": {"class_type": "UNETLoader", "inputs": {"unet_name": dit, "weight_dtype": "default"}},
|
| 113 |
+
"2": {"class_type": "CLIPLoader", "inputs": {"clip_name": Path(TENC).name, "type": "ltxv", "device": "default"}},
|
| 114 |
+
"3": {"class_type": "VAELoader", "inputs": {"vae_name": Path(VAE_V).name}},
|
| 115 |
+
"4": {"class_type": "VAELoader", "inputs": {"vae_name": Path(VAE_A).name}},
|
| 116 |
+
"5": {"class_type": "LatentUpscaleModelLoader", "inputs": {"model_name": Path(UPS).name}},
|
| 117 |
+
"7": {"class_type": "JoyLTX_Multishot", "inputs": {
|
| 118 |
+
"model": ["1", 0], "clip": ["2", 0], "video_vae": ["3", 0], "audio_vae": ["4", 0], "upscale_model": ["5", 0],
|
| 119 |
+
"prompts": json.dumps({"prompts": [prompt]}), "negative": negative or "pc game, console game, video game, cartoon, childish, ugly",
|
| 120 |
+
"width": int(width), "height": int(height), "frames_per_shot": int(frames), "shot_count": 1,
|
| 121 |
+
"join": "fresh (independent shots)", "overlap": 3, "seed": int(seed), "seed_per_shot": True,
|
| 122 |
+
"sampler_name": "euler_ancestral",
|
| 123 |
+
"sigmas_pass1": "1.0, 0.99375, 0.9875, 0.98125, 0.975, 0.909375, 0.725, 0.421875, 0.0",
|
| 124 |
+
"two_pass": bool(two_pass), "sigmas_pass2": "0.85, 0.7250, 0.4219, 0.0",
|
| 125 |
+
"video_cfg": float(video_cfg), "audio_cfg": 1.0, "frame_rate": 24.0, "save_every_shot": False,
|
| 126 |
+
"identity_ref": "off", "identity_strength": 0.0, "image_strength": 1.0, "keyframe_strength": 0.8, "ref_strength": 0.0}},
|
| 127 |
+
"8": {"class_type": "CreateVideo", "inputs": {"images": ["7", 0], "audio": ["7", 1], "fps": 24.0}},
|
| 128 |
+
"9": {"class_type": "SaveVideo", "inputs": {"video": ["8", 0], "filename_prefix": "video/joyltx25_space", "format": "auto", "codec": "auto"}},
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def _post(url, data=None):
|
| 133 |
+
req = urllib.request.Request(url, data=json.dumps(data).encode() if data is not None else None,
|
| 134 |
+
headers={"Content-Type": "application/json"}, method="POST" if data is not None else "GET")
|
| 135 |
+
return json.loads(urllib.request.urlopen(req, timeout=60).read())
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def _estimate(prompt, seconds=6, size="960 x 544 (16:9)", two_pass=True, *a, **k):
|
| 139 |
+
frames = 1 + 8 * round((float(seconds) * 24) / 8)
|
| 140 |
+
base = 150 # ComfyUI start + model load
|
| 141 |
+
per_frame = 1.6 if two_pass else 0.8
|
| 142 |
+
return int(min(1500, base + frames * per_frame))
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
@spaces.GPU(duration=_estimate)
|
| 146 |
+
def generate(prompt, seconds=6, size="960 x 544 (16:9)", two_pass=True, dose="070T30 (default)", seed=553010,
|
| 147 |
+
video_cfg=1.0, negative=""):
|
| 148 |
+
if not SETUP_OK:
|
| 149 |
+
raise gr.Error(f"Setup failed at startup: {SETUP_ERR}")
|
| 150 |
+
if not str(prompt).strip():
|
| 151 |
+
raise gr.Error("Write a prompt first.")
|
| 152 |
+
w, h = [int(x) for x in size.split("(")[0].replace(" ", "").split("x")]
|
| 153 |
+
frames = max(9, 1 + 8 * round((float(seconds) * 24) / 8))
|
| 154 |
+
log = COMFY / "comfy_space.log"
|
| 155 |
+
proc = subprocess.Popen([str(VENV_PY), "main.py", "--listen", "127.0.0.1", "--port", str(PORT),
|
| 156 |
+
"--disable-auto-launch", "--output-directory", str(COMFY / "output")],
|
| 157 |
+
cwd=COMFY, stdout=open(log, "w"), stderr=subprocess.STDOUT)
|
| 158 |
+
try:
|
| 159 |
+
t0 = time.time()
|
| 160 |
+
while True:
|
| 161 |
+
try:
|
| 162 |
+
urllib.request.urlopen(f"http://127.0.0.1:{PORT}/system_stats", timeout=3); break
|
| 163 |
+
except Exception:
|
| 164 |
+
if proc.poll() is not None or time.time() - t0 > 240:
|
| 165 |
+
raise gr.Error("ComfyUI did not start:\n" + open(log, errors="ignore").read()[-2000:])
|
| 166 |
+
time.sleep(2)
|
| 167 |
+
g = graph(prompt, negative, w, h, frames, two_pass, seed, dose, video_cfg)
|
| 168 |
+
r = _post(f"http://127.0.0.1:{PORT}/prompt", {"prompt": g, "client_id": "space"})
|
| 169 |
+
if "prompt_id" not in r:
|
| 170 |
+
raise gr.Error("ComfyUI rejected the graph:\n" + json.dumps(r)[:1500])
|
| 171 |
+
pid = r["prompt_id"]
|
| 172 |
+
while True:
|
| 173 |
+
hist = _post(f"http://127.0.0.1:{PORT}/history/{pid}")
|
| 174 |
+
if pid in hist:
|
| 175 |
+
st = hist[pid]["status"]
|
| 176 |
+
if st.get("status_str") == "error":
|
| 177 |
+
msgs = [m[1].get("exception_message", "") for m in st.get("messages", []) if m[0] == "execution_error"]
|
| 178 |
+
raise gr.Error("Render failed: " + (msgs[0][:1200] if msgs else open(log, errors="ignore").read()[-1500:]))
|
| 179 |
+
outs = [o for v in hist[pid].get("outputs", {}).values() for o in v.get("images", []) + v.get("video", [])]
|
| 180 |
+
if not outs:
|
| 181 |
+
raise gr.Error("No output file produced.")
|
| 182 |
+
o = outs[0]
|
| 183 |
+
path = COMFY / "output" / o.get("subfolder", "") / o["filename"]
|
| 184 |
+
dst = Path("/tmp") / f"joyltx25_{int(time.time())}.mp4"
|
| 185 |
+
shutil.copy2(path, dst)
|
| 186 |
+
return str(dst), f"{w}x{h} · {frames} frames ({frames/24:.1f} s) · {'two-pass x2' if two_pass else 'single pass'} · {dose} · seed {seed} · {time.time()-t0:.0f} s incl. startup"
|
| 187 |
+
if proc.poll() is not None:
|
| 188 |
+
raise gr.Error("ComfyUI exited during the render:\n" + open(log, errors="ignore").read()[-2000:])
|
| 189 |
+
time.sleep(3)
|
| 190 |
+
finally:
|
| 191 |
+
try:
|
| 192 |
+
proc.terminate(); proc.wait(timeout=20)
|
| 193 |
+
except Exception:
|
| 194 |
+
proc.kill()
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
CSS = "#col-container {max-width: 1100px; margin: 0 auto;} video {max-height: 560px;}"
|
| 198 |
+
|
| 199 |
+
with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
|
| 200 |
+
with gr.Column(elem_id="col-container"):
|
| 201 |
+
gr.Markdown(
|
| 202 |
+
"# 🎬 Joy-LTX 2.5 — one prompt, one take, picture + sound\n"
|
| 203 |
+
"**JoyAI-Echo's performance on LTX-2.5's engine.** The Echo video attention / feed-forward delta on the official "
|
| 204 |
+
"LTX-2.5 dev transformer with the official distilled LoRA baked in at 0.5 — few-step, joint audio + video, "
|
| 205 |
+
"lip-sync and expression from Echo, any length on your own card. This demo renders one take with the same "
|
| 206 |
+
"Multishot sampler the ComfyUI canvases use (two passes, x2 latent upscale).\n\n"
|
| 207 |
+
"Models: [GGUF](https://huggingface.co/joeygambino/joyai-echo-ltx25-echoVid-gguf) (RTX 30/40) · "
|
| 208 |
+
"[comfy-native](https://huggingface.co/joeygambino/joyai-echo-ltx25-echoVid-comfy-native) (RTX 50) · "
|
| 209 |
+
"[DEV merges](https://huggingface.co/joeygambino/joyai-echo-ltx25-echoVid-dev) · "
|
| 210 |
+
"Workflows: [ComfyUI-JoyLTX25](https://github.com/jlucasmcrell/ComfyUI-JoyLTX25). "
|
| 211 |
+
"LTX-2.x Community License; generated content is machine-generated."
|
| 212 |
+
)
|
| 213 |
+
if not SETUP_OK:
|
| 214 |
+
gr.Markdown(f"⚠️ **Startup setup failed:** `{SETUP_ERR}`")
|
| 215 |
+
with gr.Row():
|
| 216 |
+
with gr.Column(scale=3):
|
| 217 |
+
prompt = gr.Textbox(label="Prompt (who, where, what they say in quotes, the sounds, the camera)", lines=7, value=EXAMPLE)
|
| 218 |
+
with gr.Row():
|
| 219 |
+
seconds = gr.Slider(4, 12, value=6, step=1, label="seconds")
|
| 220 |
+
size = gr.Dropdown(["960 x 544 (16:9)", "544 x 960 (9:16)", "768 x 768 (1:1)"], value="960 x 544 (16:9)", label="render size (pass 1)")
|
| 221 |
+
with gr.Row():
|
| 222 |
+
two_pass = gr.Checkbox(value=True, label="two-pass x2 (1920x1088 out)")
|
| 223 |
+
dose = gr.Dropdown(["070T30 (default)", "100T50 (livelier)"], value="070T30 (default)", label="dose")
|
| 224 |
+
with gr.Row():
|
| 225 |
+
seed = gr.Number(value=553010, precision=0, label="seed")
|
| 226 |
+
video_cfg = gr.Slider(0.6, 1.2, value=1.0, step=0.05, label="video_cfg (1.0 = distilled; 0.7-0.85 = cooler grade, slower)")
|
| 227 |
+
negative = gr.Textbox(label="negative (mostly inert at cfg 1.0)", value="")
|
| 228 |
+
btn = gr.Button("Render", variant="primary")
|
| 229 |
+
with gr.Column(scale=4):
|
| 230 |
+
video = gr.Video(label="result (video + audio)", autoplay=True)
|
| 231 |
+
info = gr.Markdown("")
|
| 232 |
+
gr.Markdown("Tips: say the sounds you want (LTX invents drones for anything left unsaid), say the accent, keep the camera still or slow, "
|
| 233 |
+
"quote the line. Multishot (seamless joins, identity across cuts, refs by name) lives in the ComfyUI canvases.")
|
| 234 |
+
btn.click(generate, [prompt, seconds, size, two_pass, dose, seed, video_cfg, negative], [video, info])
|
| 235 |
+
|
| 236 |
+
if __name__ == "__main__":
|
| 237 |
+
demo.queue(default_concurrency_limit=1).launch()
|