signsur4739379373 commited on
Commit
5fab075
·
1 Parent(s): 1c1fd11

add keyframes, singlepass checkbox, settings import/export

Browse files
Files changed (1) hide show
  1. app.py +580 -5
app.py CHANGED
@@ -736,11 +736,11 @@ MAX_GPU_SECONDS = int(os.environ.get("MAX_GPU_SECONDS", "600"))
736
  DEFAULT_ENHANCE_BUDGET = 80
737
 
738
  SULPHUR_REPO = "SulphurAI/Sulphur-2-base"
739
- SULPHUR_MODEL_FILE = "prompt_enhancer/sulphur_prompt_enhancer_model-q8_0.gguf"
740
- SULPHUR_MMPROJ_FILE = "prompt_enhancer/mmproj-BF16.gguf"
741
  SULPHUR_MODEL_DIR = ROOT / "sulphur_enhancer"
742
- SULPHUR_MODEL_PATH = SULPHUR_MODEL_DIR / "sulphur_prompt_enhancer_model-q8_0.gguf"
743
- SULPHUR_MMPROJ_PATH = SULPHUR_MODEL_DIR / "mmproj-BF16.gguf"
744
 
745
  LLAMA_CPP_DIR = ROOT / "llama.cpp"
746
  LLAMA_SERVER_BIN = LLAMA_CPP_DIR / "build" / "bin" / "llama-server"
@@ -1839,6 +1839,11 @@ def _inject_params(
1839
  audio_ref_guidance_scale: float = 3.0,
1840
  audio_ref_stem_sep: bool = False,
1841
  audio_ref_normalize: bool = True,
 
 
 
 
 
1842
  ) -> dict[str, Any]:
1843
  # MSR (multi-reference) mode patches the workflow heavily - bypasses the
1844
  # likeness/anchor system, inserts IC-LoRA conditioning, adds crop guides
@@ -2066,6 +2071,23 @@ def _inject_params(
2066
  mid_scene_guide_strength=float(scene_chain_mid_guide_strength),
2067
  )
2068
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2069
  return workflow
2070
 
2071
 
@@ -2159,6 +2181,275 @@ def _resolve_sigmas(preset: str, custom: str) -> str:
2159
  return SIGMA_PRESETS.get(preset, SIGMA_PRESETS["original"])
2160
 
2161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2162
  def _inject_refine_sigmas(workflow: dict[str, Any], sigma_str: str) -> None:
2163
  node = workflow.get(NODE_REFINE_SIGMAS)
2164
  if node is None:
@@ -2808,6 +3099,80 @@ def _inject_audio_reference(
2808
  return True
2809
 
2810
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2811
  def _safe_frames(seconds: float, fps: int = 24) -> int:
2812
  frames = max(9, int(seconds * fps) + 1)
2813
  return ((frames - 1 + 7) // 8) * 8 + 1
@@ -2968,6 +3333,21 @@ def get_gpu_duration(
2968
  audio_ref_guidance_scale: float = 3.0,
2969
  audio_ref_stem_sep: bool = False,
2970
  audio_ref_normalize: bool = True,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2971
  progress: gr.Progress | None = None,
2972
  ) -> int:
2973
  # Manual override: gen_budget > 0 forces an exact GPU budget.
@@ -3069,6 +3449,21 @@ def generate(
3069
  audio_ref_guidance_scale: float = 3.0,
3070
  audio_ref_stem_sep: bool = False,
3071
  audio_ref_normalize: bool = True,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3072
  progress: gr.Progress = gr.Progress(track_tqdm=True),
3073
  ) -> tuple[str, str, int]:
3074
  seed_value = random.randint(0, 2**32 - 1) if randomize_seed or seed < 0 else int(seed)
@@ -3114,6 +3509,25 @@ def generate(
3114
  msr_ref4_name = _save_ref(msr_ref4, "ref4") if msr_enabled else None
3115
  msr_bg_name = _save_ref(msr_background, "bg") if any_msr else None
3116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3117
  # Copy audio reference into comfy's INPUT dir so LoadAudio can find it.
3118
  audio_ref_name: str | None = None
3119
  if audio_ref_enabled and audio_ref_file:
@@ -3212,13 +3626,19 @@ def generate(
3212
  audio_ref_guidance_scale=float(audio_ref_guidance_scale),
3213
  audio_ref_stem_sep=bool(audio_ref_stem_sep),
3214
  audio_ref_normalize=bool(audio_ref_normalize),
 
 
 
 
 
3215
  )
3216
 
3217
  mode_label = " (MSR-original)" if msr_original else (" (MSR)" if msr_enabled else "")
3218
  progress(0.15, desc=f"generating {width}x{height}, {frames} frames + audio{mode_label}")
3219
  print(
3220
  f"[gen] {width}x{height} {frames}f seed={seed_value} mode={mode} "
3221
- f"preset={preset} sigmas={repr(sigma_string[:20])} face={mode} "
 
3222
  f"kv={kv_enabled}@{kv_strength:.2f} "
3223
  f"sulphur_fro99={sulphur_lora_strength:.2f}/{sulphur_audio_strength:.2f} "
3224
  f"sulphur_v1={sulphur_v1_lora_strength:.2f}/{sulphur_v1_audio_strength:.2f} "
@@ -3399,6 +3819,29 @@ with gr.Blocks(title="10Eros LTX 2.3 image-to-video") as demo:
3399
  )
3400
  negative = gr.Textbox(label="negative prompt", value=DEFAULT_NEGATIVE, lines=2)
3401
  seconds = gr.Slider(1.0, 41.0, value=4.0, step=0.5, label="duration (seconds, up to ~1000 frames)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3402
  with gr.Accordion("loras", open=False):
3403
  sulphur_lora_strength = gr.Slider(
3404
  0.0, 1.0, value=0.15, step=0.05,
@@ -3631,6 +4074,10 @@ with gr.Blocks(title="10Eros LTX 2.3 image-to-video") as demo:
3631
  placeholder="comma-separated decreasing values in [0,1] ending at 0",
3632
  label="refine sigmas",
3633
  )
 
 
 
 
3634
  with gr.Accordion("zerogpu budget", open=False):
3635
  enhance_budget = gr.Slider(
3636
  20, 540, value=DEFAULT_ENHANCE_BUDGET, step=10,
@@ -3643,6 +4090,36 @@ with gr.Blocks(title="10Eros LTX 2.3 image-to-video") as demo:
3643
  with gr.Row():
3644
  seed = gr.Number(label="seed", value=-1, precision=0)
3645
  randomize = gr.Checkbox(label="randomize seed", value=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3646
  button = gr.Button("generate", variant="primary")
3647
  with gr.Column():
3648
  video = gr.Video(label="output")
@@ -3725,6 +4202,21 @@ with gr.Blocks(title="10Eros LTX 2.3 image-to-video") as demo:
3725
  audio_ref_guidance_scale,
3726
  audio_ref_stem_sep,
3727
  audio_ref_normalize,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3728
  ],
3729
  outputs=[video, status, used_seed],
3730
  )
@@ -3778,6 +4270,16 @@ with gr.Blocks(title="10Eros LTX 2.3 image-to-video") as demo:
3778
  msr_settings_acc],
3779
  )
3780
 
 
 
 
 
 
 
 
 
 
 
3781
  def _on_prompt_relay_toggle(enabled: bool):
3782
  # Registered LAST so it takes the highest fn_index and doesn't shift
3783
  # /generate, /enhance_prompt, or any other handler the proxy depends
@@ -3799,6 +4301,79 @@ with gr.Blocks(title="10Eros LTX 2.3 image-to-video") as demo:
3799
  outputs=[custom_res_row],
3800
  )
3801
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3802
  demo.queue()
3803
 
3804
  if __name__ == "__main__":
 
736
  DEFAULT_ENHANCE_BUDGET = 80
737
 
738
  SULPHUR_REPO = "SulphurAI/Sulphur-2-base"
739
+ SULPHUR_MODEL_FILE = "prompt_enhancer_uncensored/prompt_enhancer_uncensored-q8_0.gguf"
740
+ SULPHUR_MMPROJ_FILE = "prompt_enhancer_uncensored/mmproj-prompt_enhancer_uncensored.gguf"
741
  SULPHUR_MODEL_DIR = ROOT / "sulphur_enhancer"
742
+ SULPHUR_MODEL_PATH = SULPHUR_MODEL_DIR / "prompt_enhancer_uncensored-q8_0.gguf"
743
+ SULPHUR_MMPROJ_PATH = SULPHUR_MODEL_DIR / "mmproj-prompt_enhancer_uncensored.gguf"
744
 
745
  LLAMA_CPP_DIR = ROOT / "llama.cpp"
746
  LLAMA_SERVER_BIN = LLAMA_CPP_DIR / "build" / "bin" / "llama-server"
 
1839
  audio_ref_guidance_scale: float = 3.0,
1840
  audio_ref_stem_sep: bool = False,
1841
  audio_ref_normalize: bool = True,
1842
+ kf_last_name: str | None = None,
1843
+ kf_strength: float = 0.82,
1844
+ kf_mid_enabled: bool = False,
1845
+ kf_mid_entries: list[tuple[str, float]] | None = None,
1846
+ skip_refine: bool = False,
1847
  ) -> dict[str, Any]:
1848
  # MSR (multi-reference) mode patches the workflow heavily - bypasses the
1849
  # likeness/anchor system, inserts IC-LoRA conditioning, adds crop guides
 
2071
  mid_scene_guide_strength=float(scene_chain_mid_guide_strength),
2072
  )
2073
 
2074
+ # Skip refine: auto-on for MSR (artifacts with tiled refine), or manual.
2075
+ if msr_enabled or skip_refine:
2076
+ _inject_skip_refine(workflow)
2077
+
2078
+ # Keyframe conditioning - skip when MSR is on (node 772 already rewired).
2079
+ if not msr_enabled:
2080
+ active_mid = []
2081
+ if kf_mid_enabled and kf_mid_entries:
2082
+ active_mid = [(n, p) for n, p in kf_mid_entries if n]
2083
+ _inject_keyframes(
2084
+ workflow,
2085
+ frames=int(frames),
2086
+ kf_last_name=kf_last_name,
2087
+ kf_mid_entries=active_mid,
2088
+ kf_strength=float(kf_strength),
2089
+ )
2090
+
2091
  return workflow
2092
 
2093
 
 
2181
  return SIGMA_PRESETS.get(preset, SIGMA_PRESETS["original"])
2182
 
2183
 
2184
+ # ---------------------------------------------------------------------------
2185
+ # Settings profile import / export
2186
+ # ---------------------------------------------------------------------------
2187
+
2188
+ _PROFILE_SCHEMA_VERSION = 1
2189
+
2190
+
2191
+ def _build_settings_dict(
2192
+ preset, mode, seconds,
2193
+ target_mp, snap_multiple, custom_res_enabled, max_width, max_height,
2194
+ sulphur_lora_strength, sulphur_v1_lora_strength, vbvr_lora_strength,
2195
+ dreamly_lora_strength, synth_lora_strength, plora_lora_strength,
2196
+ singularity_lora_strength, omninft_lora_strength, omninft_bf16_lora_strength,
2197
+ better_motion_lora_strength, physics_v2_lora_strength,
2198
+ hardcut_lora_strength, transition_lora_strength,
2199
+ sulphur_audio_strength, sulphur_v1_audio_strength, vbvr_audio_strength,
2200
+ dreamly_audio_strength, synth_audio_strength, plora_audio_strength,
2201
+ singularity_audio_strength, omninft_audio_strength, omninft_bf16_audio_strength,
2202
+ better_motion_audio_strength, physics_v2_audio_strength,
2203
+ hardcut_audio_strength, transition_audio_strength,
2204
+ likeness_strength, likeness_anchor_strength, latent_anchor_strength,
2205
+ first_frame_strength, face_bbox,
2206
+ kv_enabled, kv_strength,
2207
+ scene_chain_enabled, scene_chain_prompt, scene_chain_max_scenes,
2208
+ scene_chain_frame_overlap, scene_chain_mid_guide, scene_chain_mid_guide_strength,
2209
+ audio_ref_enabled, audio_ref_guidance_scale, audio_ref_stem_sep, audio_ref_normalize,
2210
+ anchor_similarity_threshold, cache_at_step, cache_warmup,
2211
+ energy_threshold, sigma_string,
2212
+ prompt_relay_enabled, prompt_segments,
2213
+ msr_frame_count, msr_guide_strength, msr_lora_strength,
2214
+ enhance_budget, gen_budget,
2215
+ seed, randomize,
2216
+ kf_strength=0.82,
2217
+ kf_mid_enabled=False,
2218
+ ) -> dict:
2219
+ return {
2220
+ "schema_version": _PROFILE_SCHEMA_VERSION,
2221
+ "preset": preset,
2222
+ "mode": mode,
2223
+ "seconds": seconds,
2224
+ "resolution": {
2225
+ "target_mp": target_mp,
2226
+ "snap_multiple": snap_multiple,
2227
+ "custom_res_enabled": custom_res_enabled,
2228
+ "max_width": max_width,
2229
+ "max_height": max_height,
2230
+ },
2231
+ "loras": {
2232
+ "sulphur_fro99": {"video": sulphur_lora_strength, "audio": sulphur_audio_strength},
2233
+ "sulphur_v1": {"video": sulphur_v1_lora_strength, "audio": sulphur_v1_audio_strength},
2234
+ "vbvr": {"video": vbvr_lora_strength, "audio": vbvr_audio_strength},
2235
+ "dreamly": {"video": dreamly_lora_strength, "audio": dreamly_audio_strength},
2236
+ "synth": {"video": synth_lora_strength, "audio": synth_audio_strength},
2237
+ "plora": {"video": plora_lora_strength, "audio": plora_audio_strength},
2238
+ "singularity": {"video": singularity_lora_strength, "audio": singularity_audio_strength},
2239
+ "omninft": {"video": omninft_lora_strength, "audio": omninft_audio_strength},
2240
+ "omninft_bf16": {"video": omninft_bf16_lora_strength, "audio": omninft_bf16_audio_strength},
2241
+ "better_motion": {"video": better_motion_lora_strength,"audio": better_motion_audio_strength},
2242
+ "physics_v2": {"video": physics_v2_lora_strength, "audio": physics_v2_audio_strength},
2243
+ "hardcut": {"video": hardcut_lora_strength, "audio": hardcut_audio_strength},
2244
+ "transition": {"video": transition_lora_strength, "audio": transition_audio_strength},
2245
+ },
2246
+ "targeting": {
2247
+ "likeness_strength": likeness_strength,
2248
+ "likeness_anchor_strength": likeness_anchor_strength,
2249
+ "latent_anchor_strength": latent_anchor_strength,
2250
+ "first_frame_strength": first_frame_strength,
2251
+ "face_bbox": face_bbox,
2252
+ },
2253
+ "identity": {
2254
+ "anchor_similarity_threshold": anchor_similarity_threshold,
2255
+ "cache_at_step": cache_at_step,
2256
+ "cache_warmup": cache_warmup,
2257
+ "energy_threshold": energy_threshold,
2258
+ "sigma_string": sigma_string,
2259
+ },
2260
+ "funpack": {
2261
+ "kv_enabled": kv_enabled,
2262
+ "kv_strength": kv_strength,
2263
+ "scene_chain_enabled": scene_chain_enabled,
2264
+ "scene_chain_prompt": scene_chain_prompt,
2265
+ "scene_chain_max_scenes": scene_chain_max_scenes,
2266
+ "scene_chain_frame_overlap": scene_chain_frame_overlap,
2267
+ "scene_chain_mid_guide": scene_chain_mid_guide,
2268
+ "scene_chain_mid_guide_strength": scene_chain_mid_guide_strength,
2269
+ },
2270
+ "audio_ref": {
2271
+ "enabled": audio_ref_enabled,
2272
+ "guidance_scale": audio_ref_guidance_scale,
2273
+ "stem_sep": audio_ref_stem_sep,
2274
+ "normalize": audio_ref_normalize,
2275
+ },
2276
+ "prompt_relay": {
2277
+ "enabled": prompt_relay_enabled,
2278
+ "segments": prompt_segments,
2279
+ },
2280
+ "msr": {
2281
+ "frame_count": msr_frame_count,
2282
+ "guide_strength": msr_guide_strength,
2283
+ "lora_strength": msr_lora_strength,
2284
+ },
2285
+ "budget": {
2286
+ "enhance": enhance_budget,
2287
+ "generation": gen_budget,
2288
+ },
2289
+ "seed": {
2290
+ "value": seed,
2291
+ "randomize": randomize,
2292
+ },
2293
+ "keyframes": {
2294
+ "strength": kf_strength,
2295
+ "mid_enabled": kf_mid_enabled,
2296
+ },
2297
+ "input_mode": "i2v",
2298
+ }
2299
+
2300
+
2301
+ def export_settings(*args):
2302
+ """Collect all current UI values and write them to a temp JSON file.
2303
+ args[0:65] = settable components; args[65:67] = kf params; args[67] = name."""
2304
+ base_args = args[:65]
2305
+ kf_args = args[65:67] if len(args) > 65 else ()
2306
+ profile_name = str(args[67]).strip() if len(args) > 67 else ""
2307
+
2308
+ kf_kwargs: dict = {}
2309
+ kf_keys = ["kf_strength", "kf_mid_enabled"]
2310
+ for k, v in zip(kf_keys, kf_args):
2311
+ kf_kwargs[k] = v
2312
+ data = _build_settings_dict(*base_args, **kf_kwargs)
2313
+
2314
+ if profile_name:
2315
+ data["name"] = profile_name
2316
+
2317
+ safe_name = re.sub(r"[^\w\-]", "_", profile_name)[:40] if profile_name else ""
2318
+ prefix = f"ltx23_profile_{safe_name}_" if safe_name else "ltx23_profile_"
2319
+ tmp = tempfile.NamedTemporaryFile(
2320
+ suffix=".json", delete=False,
2321
+ prefix=prefix,
2322
+ mode="w", encoding="utf-8",
2323
+ )
2324
+ json.dump(data, tmp, indent=2)
2325
+ tmp.close()
2326
+ return tmp.name, "exported"
2327
+
2328
+
2329
+ def import_settings(file_path: str):
2330
+ """Parse a profile JSON and return gr.update() for every settable component."""
2331
+ _NC = gr.update() # no-change sentinel
2332
+ n_outputs = 68 # 65 original + 2 keyframe params + 1 profile name
2333
+
2334
+ def _fail(msg):
2335
+ return tuple([_NC] * n_outputs) + (msg,)
2336
+
2337
+ if not file_path:
2338
+ return _fail("")
2339
+
2340
+ try:
2341
+ data = json.loads(pathlib.Path(file_path).read_text(encoding="utf-8"))
2342
+ except Exception as exc:
2343
+ return _fail(f"error reading file: {exc}")
2344
+
2345
+ if not isinstance(data, dict):
2346
+ return _fail("invalid profile: expected a JSON object")
2347
+
2348
+ version = data.get("schema_version", 1)
2349
+ if not isinstance(version, int) or version > _PROFILE_SCHEMA_VERSION:
2350
+ status = f"warning: schema v{version} newer than supported v{_PROFILE_SCHEMA_VERSION}, applying known fields"
2351
+ else:
2352
+ status = "profile loaded"
2353
+
2354
+ def _get(path: str):
2355
+ """Dot-path accessor. Returns _NC sentinel when key is absent."""
2356
+ parts = path.split(".")
2357
+ cur = data
2358
+ for p in parts:
2359
+ if not isinstance(cur, dict) or p not in cur:
2360
+ return _NC
2361
+ cur = cur[p]
2362
+ return cur
2363
+
2364
+ def _upd(path: str):
2365
+ val = _get(path)
2366
+ return _NC if val is _NC else gr.update(value=val)
2367
+
2368
+ updates = (
2369
+ _upd("preset"),
2370
+ _upd("mode"),
2371
+ _upd("seconds"),
2372
+ _upd("resolution.target_mp"),
2373
+ _upd("resolution.snap_multiple"),
2374
+ _upd("resolution.custom_res_enabled"),
2375
+ _upd("resolution.max_width"),
2376
+ _upd("resolution.max_height"),
2377
+ # loras - video
2378
+ _upd("loras.sulphur_fro99.video"),
2379
+ _upd("loras.sulphur_v1.video"),
2380
+ _upd("loras.vbvr.video"),
2381
+ _upd("loras.dreamly.video"),
2382
+ _upd("loras.synth.video"),
2383
+ _upd("loras.plora.video"),
2384
+ _upd("loras.singularity.video"),
2385
+ _upd("loras.omninft.video"),
2386
+ _upd("loras.omninft_bf16.video"),
2387
+ _upd("loras.better_motion.video"),
2388
+ _upd("loras.physics_v2.video"),
2389
+ _upd("loras.hardcut.video"),
2390
+ _upd("loras.transition.video"),
2391
+ # loras - audio
2392
+ _upd("loras.sulphur_fro99.audio"),
2393
+ _upd("loras.sulphur_v1.audio"),
2394
+ _upd("loras.vbvr.audio"),
2395
+ _upd("loras.dreamly.audio"),
2396
+ _upd("loras.synth.audio"),
2397
+ _upd("loras.plora.audio"),
2398
+ _upd("loras.singularity.audio"),
2399
+ _upd("loras.omninft.audio"),
2400
+ _upd("loras.omninft_bf16.audio"),
2401
+ _upd("loras.better_motion.audio"),
2402
+ _upd("loras.physics_v2.audio"),
2403
+ _upd("loras.hardcut.audio"),
2404
+ _upd("loras.transition.audio"),
2405
+ # targeting
2406
+ _upd("targeting.likeness_strength"),
2407
+ _upd("targeting.likeness_anchor_strength"),
2408
+ _upd("targeting.latent_anchor_strength"),
2409
+ _upd("targeting.first_frame_strength"),
2410
+ _upd("targeting.face_bbox"),
2411
+ # funpack
2412
+ _upd("funpack.kv_enabled"),
2413
+ _upd("funpack.kv_strength"),
2414
+ _upd("funpack.scene_chain_enabled"),
2415
+ _upd("funpack.scene_chain_prompt"),
2416
+ _upd("funpack.scene_chain_max_scenes"),
2417
+ _upd("funpack.scene_chain_frame_overlap"),
2418
+ _upd("funpack.scene_chain_mid_guide"),
2419
+ _upd("funpack.scene_chain_mid_guide_strength"),
2420
+ # audio ref
2421
+ _upd("audio_ref.enabled"),
2422
+ _upd("audio_ref.guidance_scale"),
2423
+ _upd("audio_ref.stem_sep"),
2424
+ _upd("audio_ref.normalize"),
2425
+ # identity
2426
+ _upd("identity.anchor_similarity_threshold"),
2427
+ _upd("identity.cache_at_step"),
2428
+ _upd("identity.cache_warmup"),
2429
+ _upd("identity.energy_threshold"),
2430
+ _upd("identity.sigma_string"),
2431
+ # prompt relay
2432
+ _upd("prompt_relay.enabled"),
2433
+ _upd("prompt_relay.segments"),
2434
+ # msr
2435
+ _upd("msr.frame_count"),
2436
+ _upd("msr.guide_strength"),
2437
+ _upd("msr.lora_strength"),
2438
+ # budget
2439
+ _upd("budget.enhance"),
2440
+ _upd("budget.generation"),
2441
+ # seed
2442
+ _upd("seed.value"),
2443
+ _upd("seed.randomize"),
2444
+ # keyframes
2445
+ _upd("keyframes.strength"),
2446
+ _upd("keyframes.mid_enabled"),
2447
+ # profile name
2448
+ _upd("name"),
2449
+ )
2450
+ return updates + (status,)
2451
+
2452
+
2453
  def _inject_refine_sigmas(workflow: dict[str, Any], sigma_str: str) -> None:
2454
  node = workflow.get(NODE_REFINE_SIGMAS)
2455
  if node is None:
 
3099
  return True
3100
 
3101
 
3102
+ def _inject_skip_refine(workflow: dict[str, Any]) -> None:
3103
+ """Bypass the tiled refine pass by routing pass-1 sampler output
3104
+ directly to the final AV separate node.
3105
+
3106
+ Standard path: 510(slot1) -> 556 -> 744 -> 770 -> 591 -> 802 -> 596
3107
+ After: 510(slot1) -> 596
3108
+
3109
+ Node 596 (LTXVSeparateAVLatent) still separates video->740->597
3110
+ and audio->593->597 unchanged. All intermediate nodes (556, 744,
3111
+ 770, 591, 789, 802) simply fall out of the execution graph.
3112
+ """
3113
+ node_596 = workflow.get(NODE_FINAL_SEPARATE)
3114
+ if node_596 is None:
3115
+ return
3116
+ node_596["inputs"]["av_latent"] = [NODE_FIRST_PASS_SAMPLER, 1]
3117
+
3118
+
3119
+ KF_LAST_LOADER = "kf_last_loader"
3120
+ KF_MID_LOADER_PREFIX = "kf_mid_loader_"
3121
+
3122
+
3123
+ def _inject_keyframes(
3124
+ workflow: dict[str, Any],
3125
+ *,
3126
+ frames: int,
3127
+ kf_last_name: str | None,
3128
+ kf_mid_entries: list[tuple[str, float]], # [(image_name, pct_position), ...]
3129
+ kf_strength: float,
3130
+ ) -> None:
3131
+ """Inject last-frame and/or intermediate keyframes into node 772
3132
+ (LTXVImgToVideoInplaceKJ). The first frame (image_1 / index_1 / strength_1)
3133
+ is already wired in the template workflow and left untouched.
3134
+
3135
+ Middle frames are sorted by position and placed before the last frame so
3136
+ the model receives them in temporal order: first → mid_1 → mid_2 → last.
3137
+ Skipped when MSR mode is active (node 772 is already rewired by that path).
3138
+ """
3139
+ if not kf_last_name and not kf_mid_entries:
3140
+ return
3141
+
3142
+ node_772 = workflow.get(NODE_I2V_REF_LATENT)
3143
+ if node_772 is None:
3144
+ return
3145
+
3146
+ # Build ordered list: (loader_node_id, pixel_frame_index)
3147
+ ordered: list[tuple[str, int]] = []
3148
+ for i, (name, pct) in enumerate(
3149
+ sorted(kf_mid_entries, key=lambda x: x[1]), start=1
3150
+ ):
3151
+ loader_id = f"{KF_MID_LOADER_PREFIX}{i}"
3152
+ workflow[loader_id] = {
3153
+ "class_type": "LoadImage",
3154
+ "inputs": {"image": name, "upload": "image"},
3155
+ }
3156
+ frame_idx = max(1, min(frames - 2, round(pct / 100.0 * (frames - 1))))
3157
+ ordered.append((loader_id, frame_idx))
3158
+
3159
+ if kf_last_name:
3160
+ workflow[KF_LAST_LOADER] = {
3161
+ "class_type": "LoadImage",
3162
+ "inputs": {"image": kf_last_name, "upload": "image"},
3163
+ }
3164
+ ordered.append((KF_LAST_LOADER, -1))
3165
+
3166
+ # image_1 / index_1 / strength_1 already in the template for the first frame.
3167
+ # We append starting at image_2.
3168
+ total = 1 + len(ordered)
3169
+ node_772["inputs"]["num_images"] = str(total)
3170
+ for slot, (loader_id, fidx) in enumerate(ordered, start=2):
3171
+ node_772["inputs"][f"num_images.image_{slot}"] = [loader_id, 0]
3172
+ node_772["inputs"][f"num_images.index_{slot}"] = int(fidx)
3173
+ node_772["inputs"][f"num_images.strength_{slot}"] = float(kf_strength)
3174
+
3175
+
3176
  def _safe_frames(seconds: float, fps: int = 24) -> int:
3177
  frames = max(9, int(seconds * fps) + 1)
3178
  return ((frames - 1 + 7) // 8) * 8 + 1
 
3333
  audio_ref_guidance_scale: float = 3.0,
3334
  audio_ref_stem_sep: bool = False,
3335
  audio_ref_normalize: bool = True,
3336
+ kf_last_image: str | None = None,
3337
+ kf_strength: float = 0.82,
3338
+ kf_mid_enabled: bool = False,
3339
+ kf_mid_1_image: str | None = None,
3340
+ kf_mid_1_pos: float = 50.0,
3341
+ kf_mid_2_image: str | None = None,
3342
+ kf_mid_2_pos: float = 50.0,
3343
+ kf_mid_3_image: str | None = None,
3344
+ kf_mid_3_pos: float = 50.0,
3345
+ kf_mid_4_image: str | None = None,
3346
+ kf_mid_4_pos: float = 50.0,
3347
+ kf_mid_5_image: str | None = None,
3348
+ kf_mid_5_pos: float = 50.0,
3349
+ profile_name: str = "",
3350
+ skip_refine: bool = False,
3351
  progress: gr.Progress | None = None,
3352
  ) -> int:
3353
  # Manual override: gen_budget > 0 forces an exact GPU budget.
 
3449
  audio_ref_guidance_scale: float = 3.0,
3450
  audio_ref_stem_sep: bool = False,
3451
  audio_ref_normalize: bool = True,
3452
+ kf_last_image: str | None = None,
3453
+ kf_strength: float = 0.82,
3454
+ kf_mid_enabled: bool = False,
3455
+ kf_mid_1_image: str | None = None,
3456
+ kf_mid_1_pos: float = 50.0,
3457
+ kf_mid_2_image: str | None = None,
3458
+ kf_mid_2_pos: float = 50.0,
3459
+ kf_mid_3_image: str | None = None,
3460
+ kf_mid_3_pos: float = 50.0,
3461
+ kf_mid_4_image: str | None = None,
3462
+ kf_mid_4_pos: float = 50.0,
3463
+ kf_mid_5_image: str | None = None,
3464
+ kf_mid_5_pos: float = 50.0,
3465
+ profile_name: str = "",
3466
+ skip_refine: bool = False,
3467
  progress: gr.Progress = gr.Progress(track_tqdm=True),
3468
  ) -> tuple[str, str, int]:
3469
  seed_value = random.randint(0, 2**32 - 1) if randomize_seed or seed < 0 else int(seed)
 
3509
  msr_ref4_name = _save_ref(msr_ref4, "ref4") if msr_enabled else None
3510
  msr_bg_name = _save_ref(msr_background, "bg") if any_msr else None
3511
 
3512
+ # Save keyframe images into comfy's INPUT dir.
3513
+ kf_last_name: str | None = None
3514
+ if kf_last_image:
3515
+ kf_last_name = _save_ref(kf_last_image, "kf_last")
3516
+
3517
+ kf_mid_raw = [
3518
+ (kf_mid_1_image, kf_mid_1_pos),
3519
+ (kf_mid_2_image, kf_mid_2_pos),
3520
+ (kf_mid_3_image, kf_mid_3_pos),
3521
+ (kf_mid_4_image, kf_mid_4_pos),
3522
+ (kf_mid_5_image, kf_mid_5_pos),
3523
+ ]
3524
+ kf_mid_entries: list[tuple[str, float]] = []
3525
+ for raw_img, raw_pos in kf_mid_raw:
3526
+ if raw_img:
3527
+ saved = _save_ref(raw_img, f"kf_mid_{len(kf_mid_entries)+1}")
3528
+ if saved:
3529
+ kf_mid_entries.append((saved, float(raw_pos)))
3530
+
3531
  # Copy audio reference into comfy's INPUT dir so LoadAudio can find it.
3532
  audio_ref_name: str | None = None
3533
  if audio_ref_enabled and audio_ref_file:
 
3626
  audio_ref_guidance_scale=float(audio_ref_guidance_scale),
3627
  audio_ref_stem_sep=bool(audio_ref_stem_sep),
3628
  audio_ref_normalize=bool(audio_ref_normalize),
3629
+ kf_last_name=kf_last_name,
3630
+ kf_strength=float(kf_strength),
3631
+ kf_mid_enabled=bool(kf_mid_enabled),
3632
+ kf_mid_entries=kf_mid_entries,
3633
+ skip_refine=bool(skip_refine),
3634
  )
3635
 
3636
  mode_label = " (MSR-original)" if msr_original else (" (MSR)" if msr_enabled else "")
3637
  progress(0.15, desc=f"generating {width}x{height}, {frames} frames + audio{mode_label}")
3638
  print(
3639
  f"[gen] {width}x{height} {frames}f seed={seed_value} mode={mode} "
3640
+ f"preset={preset} custom_preset={bool(profile_name and profile_name.strip())} "
3641
+ f"sigmas={repr(sigma_string[:20])} face={mode} "
3642
  f"kv={kv_enabled}@{kv_strength:.2f} "
3643
  f"sulphur_fro99={sulphur_lora_strength:.2f}/{sulphur_audio_strength:.2f} "
3644
  f"sulphur_v1={sulphur_v1_lora_strength:.2f}/{sulphur_v1_audio_strength:.2f} "
 
3819
  )
3820
  negative = gr.Textbox(label="negative prompt", value=DEFAULT_NEGATIVE, lines=2)
3821
  seconds = gr.Slider(1.0, 41.0, value=4.0, step=0.5, label="duration (seconds, up to ~1000 frames)")
3822
+ with gr.Accordion("keyframes", open=False):
3823
+ kf_last_image = gr.Image(label="last frame (optional)", type="filepath")
3824
+ kf_strength = gr.Slider(
3825
+ 0.0, 1.0, value=0.82, step=0.01,
3826
+ label="keyframe strength (applies to last frame + all middle frames)",
3827
+ )
3828
+ kf_mid_enabled = gr.Checkbox(value=False, label="add intermediate keyframes")
3829
+ with gr.Column(visible=False) as kf_mid_col:
3830
+ with gr.Group(visible=True) as kf_slot_1_grp:
3831
+ kf_mid_1_image = gr.Image(label="keyframe 1", type="filepath", elem_id="kf_mid_1_img")
3832
+ kf_mid_1_pos = gr.Slider(0, 100, value=50, step=1, label="position (% of video)")
3833
+ with gr.Group(visible=False) as kf_slot_2_grp:
3834
+ kf_mid_2_image = gr.Image(label="keyframe 2", type="filepath", elem_id="kf_mid_2_img")
3835
+ kf_mid_2_pos = gr.Slider(0, 100, value=50, step=1, label="position (% of video)")
3836
+ with gr.Group(visible=False) as kf_slot_3_grp:
3837
+ kf_mid_3_image = gr.Image(label="keyframe 3", type="filepath", elem_id="kf_mid_3_img")
3838
+ kf_mid_3_pos = gr.Slider(0, 100, value=50, step=1, label="position (% of video)")
3839
+ with gr.Group(visible=False) as kf_slot_4_grp:
3840
+ kf_mid_4_image = gr.Image(label="keyframe 4", type="filepath", elem_id="kf_mid_4_img")
3841
+ kf_mid_4_pos = gr.Slider(0, 100, value=50, step=1, label="position (% of video)")
3842
+ with gr.Group(visible=False) as kf_slot_5_grp:
3843
+ kf_mid_5_image = gr.Image(label="keyframe 5", type="filepath", elem_id="kf_mid_5_img")
3844
+ kf_mid_5_pos = gr.Slider(0, 100, value=50, step=1, label="position (% of video)")
3845
  with gr.Accordion("loras", open=False):
3846
  sulphur_lora_strength = gr.Slider(
3847
  0.0, 1.0, value=0.15, step=0.05,
 
4074
  placeholder="comma-separated decreasing values in [0,1] ending at 0",
4075
  label="refine sigmas",
4076
  )
4077
+ skip_refine = gr.Checkbox(
4078
+ value=False,
4079
+ label="single pass (skip refiner)",
4080
+ )
4081
  with gr.Accordion("zerogpu budget", open=False):
4082
  enhance_budget = gr.Slider(
4083
  20, 540, value=DEFAULT_ENHANCE_BUDGET, step=10,
 
4090
  with gr.Row():
4091
  seed = gr.Number(label="seed", value=-1, precision=0)
4092
  randomize = gr.Checkbox(label="randomize seed", value=True)
4093
+ with gr.Accordion("settings profile", open=False):
4094
+ gr.Markdown(
4095
+ "export all current settings to a json file, or import a previously saved profile. "
4096
+ "images, prompts, and audio files are not included.",
4097
+ line_breaks=True,
4098
+ )
4099
+ profile_name = gr.Textbox(
4100
+ label="profile name (optional)",
4101
+ placeholder="e.g. my_portrait_settings",
4102
+ max_lines=1,
4103
+ )
4104
+ with gr.Row():
4105
+ profile_import = gr.File(
4106
+ label="import profile (.json)",
4107
+ file_types=[".json"],
4108
+ file_count="single",
4109
+ )
4110
+ with gr.Column():
4111
+ profile_export_btn = gr.Button("export current settings", size="sm")
4112
+ profile_export_file = gr.File(
4113
+ label="download",
4114
+ interactive=False,
4115
+ visible=False,
4116
+ )
4117
+ profile_status = gr.Textbox(
4118
+ label="",
4119
+ interactive=False,
4120
+ max_lines=1,
4121
+ visible=False,
4122
+ )
4123
  button = gr.Button("generate", variant="primary")
4124
  with gr.Column():
4125
  video = gr.Video(label="output")
 
4202
  audio_ref_guidance_scale,
4203
  audio_ref_stem_sep,
4204
  audio_ref_normalize,
4205
+ kf_last_image,
4206
+ kf_strength,
4207
+ kf_mid_enabled,
4208
+ kf_mid_1_image,
4209
+ kf_mid_1_pos,
4210
+ kf_mid_2_image,
4211
+ kf_mid_2_pos,
4212
+ kf_mid_3_image,
4213
+ kf_mid_3_pos,
4214
+ kf_mid_4_image,
4215
+ kf_mid_4_pos,
4216
+ kf_mid_5_image,
4217
+ kf_mid_5_pos,
4218
+ profile_name,
4219
+ skip_refine,
4220
  ],
4221
  outputs=[video, status, used_seed],
4222
  )
 
4270
  msr_settings_acc],
4271
  )
4272
 
4273
+ def _on_input_mode_skip_refine(m: str):
4274
+ is_msr = m in ("multi-reference (MSR)", "multi-reference (original)")
4275
+ return gr.update(value=is_msr, interactive=not is_msr)
4276
+
4277
+ input_mode.change(
4278
+ fn=_on_input_mode_skip_refine,
4279
+ inputs=[input_mode],
4280
+ outputs=[skip_refine],
4281
+ )
4282
+
4283
  def _on_prompt_relay_toggle(enabled: bool):
4284
  # Registered LAST so it takes the highest fn_index and doesn't shift
4285
  # /generate, /enhance_prompt, or any other handler the proxy depends
 
4301
  outputs=[custom_res_row],
4302
  )
4303
 
4304
+ # Keyframe intermediate slots: show/hide dynamically.
4305
+ # Slot N+1 becomes visible when slot N has an image AND the checkbox is on.
4306
+ def _update_kf_slots(enabled, img1, img2, img3, img4, img5):
4307
+ imgs = [img1, img2, img3, img4, img5]
4308
+ col_vis = gr.update(visible=bool(enabled))
4309
+ if not enabled:
4310
+ return [col_vis] + [gr.update(visible=False)] * 5
4311
+ slot_vis = []
4312
+ for i in range(5):
4313
+ show = (i == 0) or bool(imgs[i - 1])
4314
+ slot_vis.append(gr.update(visible=show))
4315
+ return [col_vis] + slot_vis
4316
+
4317
+ _kf_inputs = [kf_mid_enabled, kf_mid_1_image, kf_mid_2_image,
4318
+ kf_mid_3_image, kf_mid_4_image, kf_mid_5_image]
4319
+ _kf_outputs = [kf_mid_col, kf_slot_1_grp, kf_slot_2_grp,
4320
+ kf_slot_3_grp, kf_slot_4_grp, kf_slot_5_grp]
4321
+
4322
+ kf_mid_enabled.change(fn=_update_kf_slots, inputs=_kf_inputs, outputs=_kf_outputs)
4323
+ for _kf_img in [kf_mid_1_image, kf_mid_2_image, kf_mid_3_image,
4324
+ kf_mid_4_image, kf_mid_5_image]:
4325
+ _kf_img.change(fn=_update_kf_slots, inputs=_kf_inputs, outputs=_kf_outputs)
4326
+
4327
+ # -----------------------------------------------------------------------
4328
+ # Settings profile wiring - registered last so fn_indexes above stay stable
4329
+ # -----------------------------------------------------------------------
4330
+ _PROFILE_COMPONENT_LIST = [
4331
+ preset, mode, seconds,
4332
+ target_mp, snap_multiple, custom_res_enabled, max_width, max_height,
4333
+ sulphur_lora_strength, sulphur_v1_lora_strength, vbvr_lora_strength,
4334
+ dreamly_lora_strength, synth_lora_strength, plora_lora_strength,
4335
+ singularity_lora_strength, omninft_lora_strength, omninft_bf16_lora_strength,
4336
+ better_motion_lora_strength, physics_v2_lora_strength,
4337
+ hardcut_lora_strength, transition_lora_strength,
4338
+ sulphur_audio_strength, sulphur_v1_audio_strength, vbvr_audio_strength,
4339
+ dreamly_audio_strength, synth_audio_strength, plora_audio_strength,
4340
+ singularity_audio_strength, omninft_audio_strength, omninft_bf16_audio_strength,
4341
+ better_motion_audio_strength, physics_v2_audio_strength,
4342
+ hardcut_audio_strength, transition_audio_strength,
4343
+ likeness_strength, likeness_anchor_strength, latent_anchor_strength,
4344
+ first_frame_strength, face_bbox,
4345
+ kv_enabled, kv_strength,
4346
+ scene_chain_enabled, scene_chain_prompt, scene_chain_max_scenes,
4347
+ scene_chain_frame_overlap, scene_chain_mid_guide, scene_chain_mid_guide_strength,
4348
+ audio_ref_enabled, audio_ref_guidance_scale, audio_ref_stem_sep, audio_ref_normalize,
4349
+ anchor_similarity_threshold, cache_at_step, cache_warmup,
4350
+ energy_threshold, sigma_string,
4351
+ prompt_relay_enabled, prompt_segments,
4352
+ msr_frame_count, msr_guide_strength, msr_lora_strength,
4353
+ enhance_budget, gen_budget,
4354
+ seed, randomize,
4355
+ ]
4356
+
4357
+ _PROFILE_KF_COMPONENTS = [kf_strength, kf_mid_enabled]
4358
+
4359
+ profile_export_btn.click(
4360
+ fn=export_settings,
4361
+ inputs=_PROFILE_COMPONENT_LIST + _PROFILE_KF_COMPONENTS + [profile_name],
4362
+ outputs=[profile_export_file, profile_status],
4363
+ ).then(
4364
+ fn=lambda: (gr.update(visible=True), gr.update(visible=True)),
4365
+ outputs=[profile_export_file, profile_status],
4366
+ )
4367
+
4368
+ profile_import.change(
4369
+ fn=import_settings,
4370
+ inputs=[profile_import],
4371
+ outputs=_PROFILE_COMPONENT_LIST + _PROFILE_KF_COMPONENTS + [profile_name, profile_status],
4372
+ ).then(
4373
+ fn=lambda: gr.update(visible=True),
4374
+ outputs=[profile_status],
4375
+ )
4376
+
4377
  demo.queue()
4378
 
4379
  if __name__ == "__main__":