Add prompt-driven reference image routing
This commit is contained in:
+42
-3
@@ -3,8 +3,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
from typing import Any, Mapping
|
||||
|
||||
from .v3.reference_images_v39 import (
|
||||
REFERENCE_IMAGES_V39_TYPE,
|
||||
ReferenceImagesV39Bundle,
|
||||
)
|
||||
|
||||
|
||||
MAX_CLIPS = 16
|
||||
DEFAULT_CLIP_SECONDS = 4.0
|
||||
@@ -135,8 +141,8 @@ class DumasH3SequencePromptBuilder:
|
||||
"the node emits one absolute Timeline prompt for Sequence Prompt."
|
||||
)
|
||||
CATEGORY = "DUMAS H3/Prompt"
|
||||
RETURN_TYPES = ("STRING", "INT", "FLOAT")
|
||||
RETURN_NAMES = ("sequence_prompt", "chunk_count", "chunk_duration")
|
||||
RETURN_TYPES = ("STRING", "INT", "FLOAT", REFERENCE_IMAGES_V39_TYPE)
|
||||
RETURN_NAMES = ("sequence_prompt", "chunk_count", "chunk_duration", "reference_images")
|
||||
FUNCTION = "build"
|
||||
|
||||
@classmethod
|
||||
@@ -150,15 +156,47 @@ class DumasH3SequencePromptBuilder:
|
||||
"timeline_json": ("STRING", {"default": state, "multiline": True}),
|
||||
"soundscape": ("STRING", {"default": "", "multiline": True}),
|
||||
"music": ("STRING", {"default": "", "multiline": True}),
|
||||
},
|
||||
"optional": {
|
||||
f"reference_image_{index}": ("IMAGE", {
|
||||
"display_name": f"Reference Image {index} (@R{index})",
|
||||
"tooltip": f"Fixed Reference Image {index}; use @R{index} in a clip prompt.",
|
||||
}) for index in range(1, 10)
|
||||
}
|
||||
}
|
||||
|
||||
def build(self, clip_count, default_chunk_seconds, shared_directive, timeline_json, soundscape, music):
|
||||
def build(
|
||||
self,
|
||||
clip_count,
|
||||
default_chunk_seconds,
|
||||
shared_directive,
|
||||
timeline_json,
|
||||
soundscape,
|
||||
music,
|
||||
**kwargs,
|
||||
):
|
||||
sequence = normalize_sequence(
|
||||
timeline_json,
|
||||
clip_count=int(clip_count),
|
||||
default_seconds=float(default_chunk_seconds),
|
||||
)
|
||||
selectors = []
|
||||
for reference_index in range(1, 10):
|
||||
tag = f"R{reference_index}"
|
||||
chunks = []
|
||||
for chunk_index, clip in enumerate(sequence["clips"], start=1):
|
||||
text = "\n".join(str(slot.get("text", "")) for slot in clip["slots"])
|
||||
if kwargs.get(f"reference_image_{reference_index}") is not None and re.search(
|
||||
rf"@{tag}(?![A-Za-z0-9_])", text, re.IGNORECASE
|
||||
):
|
||||
chunks.append(chunk_index)
|
||||
selectors.append(",".join(map(str, chunks)) or "off")
|
||||
images = tuple(kwargs.get(f"reference_image_{index}") for index in range(1, 10))
|
||||
reference_bundle = ReferenceImagesV39Bundle(
|
||||
images=images,
|
||||
reference_use="Per chunk",
|
||||
selectors=tuple(selectors),
|
||||
)
|
||||
return (
|
||||
format_sequence_prompt(
|
||||
shared_directive=shared_directive,
|
||||
@@ -168,6 +206,7 @@ class DumasH3SequencePromptBuilder:
|
||||
),
|
||||
len(sequence["clips"]),
|
||||
float(default_chunk_seconds),
|
||||
reference_bundle,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user