dagloop5 commited on
Commit
e45689d
·
verified ·
1 Parent(s): eb2140a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -3
app.py CHANGED
@@ -572,9 +572,17 @@ def conditioner():
572
  return Client(CONDITIONER_SPACE)
573
 
574
 
575
- def encode_remote(prompt, image_path, last_image_path, canvas, num_frames, rewrite_prompt=False):
 
 
 
576
  """`/encode` on the conditioner Space: a safetensors file holding `prompt_embeds` + `text_token_tags`, with the
577
- resolved `height` / `width` / `num_frames` in its metadata, plus the plan. `canvas` is the label."""
 
 
 
 
 
578
  from gradio_client import handle_file
579
  from safetensors import safe_open
580
 
@@ -585,6 +593,9 @@ def encode_remote(prompt, image_path, last_image_path, canvas, num_frames, rewri
585
  canvas=canvas,
586
  num_frames=num_frames,
587
  rewrite_prompt=bool(rewrite_prompt),
 
 
 
588
  api_name="/encode",
589
  )
590
  with safe_open(path, framework="pt") as handle:
@@ -867,6 +878,9 @@ def generate(
867
  chunk_stop=DEFAULT_CHUNK_STOP,
868
  chunk_state=None,
869
  momentum=DEFAULT_MOMENTUM,
 
 
 
870
  progress=gr.Progress(track_tqdm=True),
871
  *,
872
  advance: bool = False,
@@ -972,7 +986,9 @@ def generate(
972
  )
973
  conditioned = time.time()
974
  prompt_embeds, text_token_tags, metadata, plan = encode_remote(
975
- prompt, effective_first_frame, effective_last_frame, canvas, num_frames, rewrite_prompt=upsample
 
 
976
  )
977
  condition_seconds = time.time() - conditioned
978
  height, width, num_frames = (int(metadata[key]) for key in ("height", "width", "num_frames"))
@@ -1049,6 +1065,8 @@ def generate(
1049
  *post,
1050
  f"seed {int(seed)}",
1051
  ]
 
 
1052
  if stage_enabled:
1053
  info.append(f"staged {steps_done_after}/{int(target_steps)} steps")
1054
  if lora_text:
@@ -1374,6 +1392,23 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
1374
  value=False,
1375
  info="Rewrite the prompt on the conditioner Space first, MiniMax's Context-IR style.",
1376
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1377
  maximize_gpu = gr.Checkbox(
1378
  label="Maximize Free Tier ZeroGPU (150 seconds)",
1379
  value=False,
@@ -1568,6 +1603,12 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
1568
  [chunk_start, chunk_stop, momentum, continue_btn],
1569
  api_name=False,
1570
  )
 
 
 
 
 
 
1571
 
1572
  controls = [
1573
  prompt,
@@ -1607,6 +1648,9 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
1607
  chunk_stop,
1608
  chunk_state,
1609
  momentum,
 
 
 
1610
  ]
1611
 
1612
  # `functools.partial` binds `advance`/`chunk_advance` by keyword regardless of their position in `generate`'s
 
572
  return Client(CONDITIONER_SPACE)
573
 
574
 
575
+ def encode_remote(
576
+ prompt, image_path, last_image_path, canvas, num_frames, rewrite_prompt=False,
577
+ semantic_bridge=False, semantic_bridge_alpha=0.10, semantic_bridge_magnitude_match="per_token",
578
+ ):
579
  """`/encode` on the conditioner Space: a safetensors file holding `prompt_embeds` + `text_token_tags`, with the
580
+ resolved `height` / `width` / `num_frames` in its metadata, plus the plan. `canvas` is the label.
581
+
582
+ `semantic_bridge*` are forwarded as-is to the conditioner's own `encode()` — this Space never sees the
583
+ adapter itself, only whichever `prompt_embeds` comes back, bridged or not per the plan's `semantic_bridge`
584
+ field.
585
+ """
586
  from gradio_client import handle_file
587
  from safetensors import safe_open
588
 
 
593
  canvas=canvas,
594
  num_frames=num_frames,
595
  rewrite_prompt=bool(rewrite_prompt),
596
+ semantic_bridge=bool(semantic_bridge),
597
+ semantic_bridge_alpha=float(semantic_bridge_alpha),
598
+ semantic_bridge_magnitude_match=semantic_bridge_magnitude_match,
599
  api_name="/encode",
600
  )
601
  with safe_open(path, framework="pt") as handle:
 
878
  chunk_stop=DEFAULT_CHUNK_STOP,
879
  chunk_state=None,
880
  momentum=DEFAULT_MOMENTUM,
881
+ semantic_bridge=False,
882
+ semantic_bridge_alpha=0.10,
883
+ semantic_bridge_magnitude_match="per_token",
884
  progress=gr.Progress(track_tqdm=True),
885
  *,
886
  advance: bool = False,
 
986
  )
987
  conditioned = time.time()
988
  prompt_embeds, text_token_tags, metadata, plan = encode_remote(
989
+ prompt, effective_first_frame, effective_last_frame, canvas, num_frames, rewrite_prompt=upsample,
990
+ semantic_bridge=semantic_bridge, semantic_bridge_alpha=semantic_bridge_alpha,
991
+ semantic_bridge_magnitude_match=semantic_bridge_magnitude_match,
992
  )
993
  condition_seconds = time.time() - conditioned
994
  height, width, num_frames = (int(metadata[key]) for key in ("height", "width", "num_frames"))
 
1065
  *post,
1066
  f"seed {int(seed)}",
1067
  ]
1068
+ if plan.get("semantic_bridge"):
1069
+ info.append(f"Semantic Bridge {float(semantic_bridge_alpha):.2f}")
1070
  if stage_enabled:
1071
  info.append(f"staged {steps_done_after}/{int(target_steps)} steps")
1072
  if lora_text:
 
1392
  value=False,
1393
  info="Rewrite the prompt on the conditioner Space first, MiniMax's Context-IR style.",
1394
  )
1395
+ with gr.Accordion("Semantic Bridge", open=False):
1396
+ gr.Markdown(
1397
+ "A small, independent adapter that nudges text conditioning toward better constraint "
1398
+ "adherence — left/right ordering, which hand holds what, material and reflection "
1399
+ "correctness — without touching the video transformer. Runs on the conditioner Space. "
1400
+ "Experimental; may help some prompts, do little on others."
1401
+ )
1402
+ semantic_bridge = gr.Checkbox(label="Enable Semantic Bridge", value=False)
1403
+ semantic_bridge_alpha = gr.Slider(
1404
+ label="alpha", minimum=0.0, maximum=1.0, step=0.01, value=0.10, visible=False
1405
+ )
1406
+ semantic_bridge_magnitude_match = gr.Dropdown(
1407
+ label="magnitude_match",
1408
+ choices=["per_token", "global", "none"],
1409
+ value="per_token",
1410
+ visible=False,
1411
+ )
1412
  maximize_gpu = gr.Checkbox(
1413
  label="Maximize Free Tier ZeroGPU (150 seconds)",
1414
  value=False,
 
1603
  [chunk_start, chunk_stop, momentum, continue_btn],
1604
  api_name=False,
1605
  )
1606
+ semantic_bridge.change(
1607
+ lambda enabled: tuple(gr.update(visible=enabled) for _ in range(2)),
1608
+ semantic_bridge,
1609
+ [semantic_bridge_alpha, semantic_bridge_magnitude_match],
1610
+ api_name=False,
1611
+ )
1612
 
1613
  controls = [
1614
  prompt,
 
1648
  chunk_stop,
1649
  chunk_state,
1650
  momentum,
1651
+ semantic_bridge,
1652
+ semantic_bridge_alpha,
1653
+ semantic_bridge_magnitude_match,
1654
  ]
1655
 
1656
  # `functools.partial` binds `advance`/`chunk_advance` by keyword regardless of their position in `generate`'s