diff --git a/README.md b/README.md index e403e6c..e9e33d0 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,10 @@ widget, making saved workflows portable even when the optional browser panel is unavailable. The node can also accept up to nine optional reference-image inputs. Each -input has a fixed identity (`Reference Image 1` is always `@R1`, through -`@R9`); when an image is connected, the editor shows a button for inserting -that tag at the current caret position. The fourth output is the same typed +input has a fixed identity (`Reference Image 1` is always `@image1`, through +`@image9`; the backend also accepts the equivalent `@R1`–`@R9` tags). When an +image is connected, the editor shows a CSGlide-style pill with a thumbnail and +inserts that tag at the current caret position. The fourth output is the same typed `H3_CONTINUUM_REFERENCE_IMAGES_V39` bundle used by the V3.9 sampler. It is automatically set to `Per chunk`, and only references explicitly mentioned in each chunk's prompt are assigned to that chunk. References that are connected diff --git a/prompt_builder.py b/prompt_builder.py index e19e2a1..29a0db6 100644 --- a/prompt_builder.py +++ b/prompt_builder.py @@ -182,12 +182,13 @@ class DumasH3SequencePromptBuilder: ) 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 + rf"@(R{reference_index}|image{reference_index})(?![A-Za-z0-9_])", + text, + re.IGNORECASE, ): chunks.append(chunk_index) selectors.append(",".join(map(str, chunks)) or "off") diff --git a/tests/test_sequence_prompt_builder.py b/tests/test_sequence_prompt_builder.py index 49b1181..0390853 100644 --- a/tests/test_sequence_prompt_builder.py +++ b/tests/test_sequence_prompt_builder.py @@ -82,7 +82,7 @@ def test_builder_routes_connected_references_only_to_mentioning_chunks(): value = { "clips": [ {"slots": [{"start": 0, "end": 4, "text": "@R1 walks toward @R2."}]}, - {"slots": [{"start": 0, "end": 4, "text": "The camera follows @r2."}]}, + {"slots": [{"start": 0, "end": 4, "text": "The camera follows @image2."}]}, {"slots": [{"start": 0, "end": 4, "text": "A wide shot with no reference."}]}, ] } diff --git a/web/sequence_prompt_builder.js b/web/sequence_prompt_builder.js index c002cbe..e530fb7 100644 --- a/web/sequence_prompt_builder.js +++ b/web/sequence_prompt_builder.js @@ -241,21 +241,39 @@ function configure(node) { shotChips.append(chip); }); panel.append(shotChips); - const referenceRow = el("div"); referenceRow.style.cssText = "display:flex;gap:4px;overflow:hidden;margin:4px 0 7px;align-items:center"; + const referenceRow = el("div"); referenceRow.style.cssText = "display:flex;gap:8px;overflow:hidden;margin:7px 0 8px;align-items:center;flex-wrap:wrap"; const connectedReferences = Array.from({ length: 9 }, (_, offset) => offset + 1) .filter((index) => node.inputs?.some((input) => input.name === `reference_image_${index}` && input.link != null)); if (connectedReferences.length) { - const referenceLabel = el("span", "Refs:"); referenceLabel.style.cssText = "color:#8fa898;font:10px monospace;margin-right:2px"; referenceRow.append(referenceLabel); connectedReferences.forEach((index) => { - const button = el("button", `@R${index}`); button.type = "button"; - button.title = `Insert reference image ${index} as @R${index}`; - button.style.cssText = "padding:3px 8px;border:1px solid #4f9bb0;border-radius:4px;background:#172d33;color:#8bd5e7;font:11px monospace;cursor:pointer"; + const button = el("button"); button.type = "button"; + button.title = `Insert reference image ${index} as @image${index}`; + button.style.cssText = "display:inline-flex;align-items:center;gap:7px;height:31px;padding:2px 11px 2px 3px;border:2px solid #49c9f5;border-radius:18px;background:#202b31;color:#70d8ff;font:16px monospace;cursor:pointer;white-space:nowrap"; + const thumbnail = document.createElement("img"); + thumbnail.alt = ""; thumbnail.draggable = false; + thumbnail.style.cssText = "width:25px;height:25px;object-fit:cover;border-radius:50%;background:#68727a;display:block"; + const linkId = node.inputs?.find((input) => input.name === `reference_image_${index}`)?.link; + const link = linkId == null ? null : (app.graph?.links?.get?.(linkId) ?? app.graph?.links?.[linkId]); + const source = link?.origin_id == null ? null : app.graph?.getNodeById?.(link.origin_id); + const imageWidget = source?.widgets?.find((widget) => ["image", "filename", "file"].includes(widget.name)); + const imageValue = imageWidget?.value; + if (imageValue && typeof imageValue === "object" && imageValue.filename) { + const params = new URLSearchParams({ filename: imageValue.filename, type: imageValue.type || "input", subfolder: imageValue.subfolder || "" }); + thumbnail.src = `/view?${params.toString()}`; + } else if (typeof imageValue === "string" && imageValue) { + const params = new URLSearchParams({ filename: imageValue, type: "input", subfolder: "" }); + thumbnail.src = `/view?${params.toString()}`; + } else { + thumbnail.src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='25' height='25' viewBox='0 0 25 25'%3E%3Crect width='25' height='25' fill='%2368727a'/%3E%3Cpath d='M4 19l5-6 3 3 3-4 6 7' fill='none' stroke='%23dce8ed' stroke-width='2'/%3E%3Ccircle cx='17' cy='8' r='2' fill='%23dce8ed'/%3E%3C/svg%3E"; + } + thumbnail.onerror = () => { thumbnail.style.opacity = "0.35"; }; + button.append(thumbnail, el("span", `@image${index}`)); button.onclick = (event) => { event.preventDefault(); event.stopPropagation(); if (!prompt) return; const start = prompt.selectionStart ?? prompt.value.length; const end = prompt.selectionEnd ?? start; - const token = `@R${index} `; + const token = `@image${index} `; prompt.value = prompt.value.slice(0, start) + token + prompt.value.slice(end); const caret = start + token.length; prompt.focus(); prompt.setSelectionRange(caret, caret);