mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-07-05 17:01:16 -03:00
fix(agent): handle plain YAML scalar text in extract_gallery_images
Widget entries with unquoted multi-line YAML scalars (e.g. "text: two samurais...\n continuation") were not parsed, leaving gallery image prompts empty. Add a third branch for plain scalar format alongside the existing quoted and >- folded block handlers.
This commit is contained in:
@@ -65,26 +65,30 @@ def extract_gallery_images(
|
||||
|
||||
entry = entry.strip()
|
||||
|
||||
# Extract text (prompt)
|
||||
# Extract text (prompt) — handles three YAML scalar styles:
|
||||
# 1. "quoted inline"
|
||||
# 2. >- folded block
|
||||
# 3. plain (unquoted) multi-line
|
||||
text = ""
|
||||
# Quoted inline: `"some prompt"`
|
||||
qm = re.match(r'^"((?:[^"\\]|\\.)*)"', entry)
|
||||
if qm:
|
||||
text = qm.group(1)
|
||||
else:
|
||||
# Multi-line YAML scalar: `>-\n line1\n line2`
|
||||
mm = re.match(r"^>(?:-\s*)?\n((?:.+(?:\n|$))+)", entry, re.MULTILINE)
|
||||
if mm:
|
||||
raw = mm.group(1)
|
||||
# Take lines until a line starts with a YAML key (word + colon)
|
||||
else:
|
||||
# Plain YAML scalar — take lines until a YAML key
|
||||
raw = entry
|
||||
if raw:
|
||||
text_lines: list[str] = []
|
||||
for line in raw.split("\n"):
|
||||
if re.match(r"^\s*\w+:", line):
|
||||
break
|
||||
text_lines.append(line)
|
||||
text = " ".join(
|
||||
line.strip() for line in text_lines if line.strip()
|
||||
)
|
||||
stripped = line.strip()
|
||||
if stripped:
|
||||
text_lines.append(stripped)
|
||||
text = " ".join(text_lines)
|
||||
|
||||
# Extract output.url
|
||||
url = ""
|
||||
|
||||
@@ -566,3 +566,20 @@ base_model: flux
|
||||
) == "prithivMLmods/Flux-Long-Toon-LoRA"
|
||||
assert extract_repo_from_hf_url("") == ""
|
||||
assert extract_repo_from_hf_url("not a url") == ""
|
||||
|
||||
def test_plain_yaml_scalar_text(self):
|
||||
"""Unquoted multi-line YAML scalar (plain format) should extract prompt."""
|
||||
from py.services.agent.skills.enrich_hf_metadata.md_to_html import \
|
||||
extract_gallery_images
|
||||
|
||||
md = """---
|
||||
widget:
|
||||
- text: two samurais doing a muay thai fight
|
||||
while the other leans back. Textured abstract style
|
||||
output:
|
||||
url: images/00.png
|
||||
---"""
|
||||
images = extract_gallery_images(md, "user/repo")
|
||||
assert len(images) == 1
|
||||
assert "two samurais doing a muay thai fight" in images[0]["meta"]["prompt"]
|
||||
assert "Textured abstract style" in images[0]["meta"]["prompt"]
|
||||
|
||||
Reference in New Issue
Block a user