INNER CODE UNIT · Python
paper_metaphor_reference_context
ChenShuo2004/cs-board · webapp/server.py:406
def paper_metaphor_reference_context(scenes: list[dict[str, Any]]) -> tuple[list[Path], str]:
text = " ".join(
str(scene.get(key, ""))
for scene in scenes
for key in ("title", "concept", "text", "key_text", "metaphor")
)
structure = "定义"
filenames = ("01-cause-heart-vs-wound.png",)
for candidate, keywords, routed_files in PAPER_METAPHOR_ROUTES:
if any(keyword in text for keyword in keywords):
structure, filenames = candidate, routed_files
break
paths = [PAPER_METAPHOR_REFERENCE_DIR / filename for filename in filenames]
paths = [path for path in paths if valid_image_file(path)][:3]
if not paths:
raise RuntimeError("纸感隐喻拼贴风的本地参考图缺失")
instruction = (
f"这些输入图仅作为纸艺视觉语言与“{structure}”构图参考,不提供人物身份或具体故事。"