Spaces:
Running on Zero
Running on Zero
Fix image-to-video enhancement: render the <|image|> token by passing the user turn as content blocks, matching LTX2ImageToVideoPipeline._enhance_prompt
Browse files
app.py
CHANGED
|
@@ -57,9 +57,20 @@ def enhance(prompt, image=None, progress=gr.Progress()):
|
|
| 57 |
raise gr.Error("Please enter a prompt to enhance.")
|
| 58 |
# I2V (reference-image) system prompt when an image is supplied, else T2V.
|
| 59 |
system_prompt = LTX2_4_I2V_DEFAULT_SYSTEM_PROMPT if image is not None else LTX2_4_T2V_DEFAULT_SYSTEM_PROMPT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
messages = [
|
| 61 |
{"role": "system", "content": system_prompt},
|
| 62 |
-
{"role": "user", "content":
|
| 63 |
]
|
| 64 |
template = processor.tokenizer.apply_chat_template(
|
| 65 |
messages, tokenize=False, add_generation_prompt=True
|
|
|
|
| 57 |
raise gr.Error("Please enter a prompt to enhance.")
|
| 58 |
# I2V (reference-image) system prompt when an image is supplied, else T2V.
|
| 59 |
system_prompt = LTX2_4_I2V_DEFAULT_SYSTEM_PROMPT if image is not None else LTX2_4_T2V_DEFAULT_SYSTEM_PROMPT
|
| 60 |
+
user_text = f"{CFG.user_prompt_prefix}: {prompt}"
|
| 61 |
+
# Gemma-4's processor validates that the rendered template carries exactly one <|image|> token per
|
| 62 |
+
# image passed. A plain-string user turn renders none, so supplying an image raised
|
| 63 |
+
# ValueError: ... Found [0] <|image|> tokens and [1] images per sample
|
| 64 |
+
# on EVERY image-to-video enhancement, while text-only worked — which is why it went unnoticed.
|
| 65 |
+
# The two shapes below are exactly `LTX2Pipeline._enhance_prompt` (plain string, images=None) and
|
| 66 |
+
# `LTX2ImageToVideoPipeline._enhance_prompt` (content blocks, images=image), so this Space keeps
|
| 67 |
+
# returning what the pipelines' own enhancement returns. The text-only path is untouched.
|
| 68 |
+
user_content = (
|
| 69 |
+
[{"type": "image"}, {"type": "text", "text": user_text}] if image is not None else user_text
|
| 70 |
+
)
|
| 71 |
messages = [
|
| 72 |
{"role": "system", "content": system_prompt},
|
| 73 |
+
{"role": "user", "content": user_content},
|
| 74 |
]
|
| 75 |
template = processor.tokenizer.apply_chat_template(
|
| 76 |
messages, tokenize=False, add_generation_prompt=True
|