prompt_images_sample/ にサンプル画像を同梱し、tags_sample → tags と 同様に、prompt_images が空/未作成なら copy_if_empty で複製する。 髪色のサンプルプロンプト(tags_sample/人_髪.yml)を leaf-meta 形式に 更新し、各サンプル画像を参照させた。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""
|
|
@author: da2el
|
|
@title: D2 Prompt Selector
|
|
@description:
|
|
"""
|
|
|
|
from pathlib import Path
|
|
import os
|
|
import server
|
|
from server import PromptServer
|
|
from aiohttp import web
|
|
from .nodes import tags
|
|
from .nodes.utils import copy_if_empty
|
|
from .nodes.nodes import comfy_entrypoint
|
|
|
|
WEB_DIRECTORY = "./web"
|
|
|
|
# ノードは V3 スキーマ(comfy_entrypoint / ComfyExtension)で登録する。
|
|
# ComfyUI のローダーは NODE_CLASS_MAPPINGS 属性があるとそちらを優先し
|
|
# comfy_entrypoint を無視する(nodes.py の load 分岐は elif)ため、
|
|
# NODE_CLASS_MAPPINGS はあえて定義しない。
|
|
__all__ = ["WEB_DIRECTORY", "comfy_entrypoint"]
|
|
|
|
|
|
|
|
"""
|
|
# css読み取り用のパスを設定
|
|
"""
|
|
d2_ps_path = os.path.join(os.path.dirname(__file__))
|
|
d2_web_path = os.path.join(d2_ps_path, "web")
|
|
|
|
if os.path.exists(d2_web_path):
|
|
server.PromptServer.instance.app.add_routes([
|
|
web.static("/D2_prompt-selector/assets/", d2_web_path)
|
|
])
|
|
|
|
# サンプル画像の保存先(tags/ の外)。
|
|
# tags 同様、prompt_images が空/未作成なら prompt_images_sample を初期データとして複製する。
|
|
d2_images_path = os.path.join(d2_ps_path, "prompt_images")
|
|
copy_if_empty(os.path.join(d2_ps_path, "prompt_images_sample"), d2_images_path)
|
|
# サンプルが無い場合でも配信ディレクトリは必要(web.static は存在しないパスでエラーになりうる)
|
|
os.makedirs(d2_images_path, exist_ok=True)
|
|
server.PromptServer.instance.app.add_routes([
|
|
web.static("/D2_prompt-selector/images/", d2_images_path)
|
|
])
|
|
|
|
|
|
# タグファイルがなかったらサンプルをコピーする
|
|
# ファイルがあったら何もしない
|
|
current_dir = Path(__file__).parent
|
|
src = current_dir / 'tags_sample'
|
|
dist = current_dir / 'tags'
|
|
|
|
copy_if_empty(src, dist)
|
|
|
|
|