Files
aigc-home/docs/hel-892/flux2-print-document-evidence/build_definition.py
T
2026-10-31 07:59:52 +08:00

581 lines
26 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"Source-bound print extraction editorial text; never construct an execution prompt."
import copy
import hashlib
import json
from pathlib import Path
REPO = Path(__file__).resolve().parents[3]
OUT = Path(__file__).resolve().parent
REF = OUT.parent / "flux2-print-reference"
PATHS = [("example_ComfyUI_workflows/3-图像生成/Flux/flux2_klein_图生图_印花提取.json")]
def canonical(v):
return json.dumps(v, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()
MEANING = {
76: (
"原始图片保存长哈希.png/image(精确原文见现值),IMA"
"GE经272→146缩放,也经284直接→147.image1。"
"MASK links=null未接。properties.ima"
"ge另保存clipspace/clipspace-painted"
"-masked-1778737197714.png [input"
"];它与控件文件名分开,不读取媒体,不证明MASK连接或实际图片"
"内容。"
),
144: (
"TT完整提交b69cf75c保存false、1080x1920 "
"(9:16) (竖屏)、1024、1024。准确假分支查预设,真"
"分支才用custom缓存;宽槽0经276→146.width、高"
"槽1经278→146.height,覆盖两处512缓存。仅静态参"
"考,不试算最终尺寸,TT许可未知。"
),
146: (
"76原图→146 ImageResizeKJv2(准确KJ1.3"
".9)。width/height保存512/512被TT外线覆盖"
",IMAGE槽0→149.pixels;准确宽slot1经300"
"→宿主空名输入索引7(label width),高slot2经2"
"99→_1索引8(label height)。MASK输入无外线"
"、mask出口links=[]未接,非局部遮罩编辑;不试算尺寸。"
),
147: (
"空间拼接:image1经284直接来自76原图,image2经2"
"90来自149生成;保存right/true,147→148临时"
"预览。原图在左、生成在右,非Comparer滑块。源两输入typ"
"e原拼IMAGE,MASK,准确KJ假设schema只声明IMA"
"GE;保留差异,不把逗号联合口当实际MASK已连接。无提供方/版"
"本,仅明确KJ1.3.9参考假设:批次不同重复较短批次最后图;r"
"ight/left按image1高度保比例缩放image2(la"
"nczos),上下按宽;通道不同时加全1通道后沿方向cat。未执"
"行,不保证原图内容、像素、尺寸或批次不变。"
),
9: (
"149生成→9正式SaveImage,保存前缀Flux2-Kle"
"in。源outputs=[]与准确core0.8.2 RETUR"
"N_TYPES=()一致,无IMAGE输出冲突。准确PNG、ou"
"tput目录/递增命名与ui.images描述仅静态说明,真实目"
"录/history/成功未知;此处保存生成图,147拼接只送14"
"8临时预览。"
),
102: (
"CFG保存JSON int1(schema FLOAT默认8.0"
"),接142模型、140正向和139负向→103.guider;"
"不改源JSON类型,不保证抽取或白底效果。"
),
105: (
"保存种子1035226012090220与randomize前端"
"辅助,105.NOISE→103;宿主只有代理没有具名保存。准确"
"frontend1.36.13生成后控制与后端seed/缓存分列"
",不运行种子、钩子或计算下一值,不承诺复现。"
),
100: ("保存euler,SAMPLER→103;动态枚举与构造仅读,不运行采样器,不保证质量/兼容/耗时。"),
111: (
"空latent才是103.latent_image采样起点;保存"
"1024/1024/1,宽高经135/136外线覆盖。141参考"
"latent仅进入条件,非采样起点、像素复合或遮罩编辑。"
),
101: (
"Flux2Scheduler保存steps4/width1024"
"/height1024;SIGMAS→103。135宽与136高"
"分别同时覆盖101和111共四处1024缓存;不推定空宿主中的实"
"际值,不求sigmas或最终尺寸。"
),
106: (
"UNET保存Flux反斜杠flux-2-klein-9b-fp8"
".safetensors/default,106→142活动Lo"
"RA→102.model;unet_name经边界291来自宿主"
"索引1,无外线与具名保存,内部缓存/代理未知分列。作者Note推"
"荐base不证明实际非base保存兼容或许可。"
),
142: (
"活动mode0小志LoRA,准确core0.21.1,保存Flu"
"x反斜杠Flux2-Klein-9B_lcs_consist_2"
"0260415_一致性小志版.safetensors/0.8。1"
"06→142→102;lora_name边界292对应宿主索引2"
"无外线/保存。继承只更新MODEL,零强度返回、文件名缓存和非零"
"读取条件仅读,不保证加载成功、一致性或印花效果。"
),
107: (
"CLIP保存qwen_3_8b_fp8mixed.safeten"
"sors/flux2/default,同时供108正向和109负"
"向;clip_name边界293对应宿主索引3无外线、保存[]。"
"模型元数据单列,不证明目标dtype/设备/模型许可或兼容。"
),
110: (
"VAE实际保存flux2-vae.safetensors,不能套"
"上批full_encoder_small_decoder。110"
"同时供141参考编码和104生成解码;vae_name边界294"
"对应宿主索引4无外线/保存。准确0.8.2动态枚举、解析文件、读"
"取后构造VAE并校验的条件仅读,不据名称证明模型家族、目录存在或"
"兼容。"
),
108: (
"完整英文正向的中文意图:提取衣服上的印花,移除衣服本体和人体,只"
"保留图案,以平整独立设计呈现在干净白底,特别要求不要擦除、模糊或"
"移除图案。108→140追加141参考→102.positive"
";text边界295对应宿主索引5无外线、空保存/代理与内部缓存"
"分列。全文原样保留,只是作者意图,不保证抽取、白底、透明PNG、"
"矢量、无缝、文字/logo准确或版权。"
),
109: (
"负向保存空字符串,不制造负向提示词。109→139同样追加141"
"参考→102.negative;text边界296对应宿主tex"
"t_1索引6无外线、空保存与代理恢复未知分列。空文本不等于负向条"
"件不存在,不保证消除人体或衣服。"
),
}
EMPTY = {
143: ("Label无提供方/版本,字体布局属性单列;不因名称继承rgthree身份,不下载字体。"),
148: (
"147拼接→148;无提供方/版本,仅core0.8.2 Pre"
"viewImage假设:继承SaveImage、temp目录/随"
"机前缀、压缩级别与ui.images;源outputs=[]与该"
"假设一致,无IMAGE返回。临时预览不是9正式PNG或本次已生成"
"证据。"
),
149: (
"宿主身份/版本未知;widgets_values=[]零位置、定"
"义widgets=[]分别保留。10代理与9输入分开,不制造pr"
"omoted/具名值。pixels/宽高有外线,其余无外线,UE"
"/tab/宿主恢复未知。"
),
141: (
"149.pixels→边界281→141"
".VAEEncode,110.VAE供编"
"码;参考latent同时经256→140"
"正向和255→139负向。"
),
140: (
"108正向经258→140,追加141参考latent后经261"
"→102.positive;reference_latents按"
"现列表append,非像素拼接。"
),
139: ("109空串编码经259→139,同样追加141参考latent后经262→102.negative,不能省略负向引用。"),
103: (
"111空latent是采样起点;103输出slot0经197→1"
"04解码,第二LATENT denoised_output li"
"nks=[]未接,不冒充已去噪产物。"
),
104: (
"103.slot0与110.VAE→104解码→定义201→14"
"9生成→9正式保存及147.image2;定义输出linkIds"
"=[201,201]重复两次,物理201仅一条;两者分别保留,不"
"去重或据此模拟恢复。"
),
135: (
"宿主输入空名、label width,经边界297→135,再经"
"244→101.width和253→111.width;来源14"
"6宽slot1经300,四处覆盖中的两处。Reroute缺保存键"
",不造值。"
),
136: (
"宿主输入_1、label height,经边界298→136,再"
"经246→101.height和254→111.height;来"
"源146高slot2经299,四处覆盖中的另两处。Reroute"
"缺保存键,不造值。"
),
}
def build(index=0):
raw = (REPO / PATHS[index]).read_bytes()
g = json.loads(raw)
sub = g["definitions"]["subgraphs"][0]
reviews = json.loads(
(REPO / ("calliope-backend/src/calliope/comfyui/source_reviews.json")).read_bytes()
)
common = {}
# Reuse schema descriptions only; values and identities belong to this graph.
for stem in ["双图像或视频合并显示", "2_flux2_klein_图生图"]:
matches = [r for p, r in reviews.items() if p.endswith("/" + stem + ".json")]
for f in matches[0]["fixed_version_document"]["fields"]:
common[f["class_type"], f["field"]] = f
manifest = json.loads((REF / "sources.json").read_bytes())["sources"]
sources = []
def cite(key, file, first, last, claim):
e = next(e for e in manifest if e["id"] == key and e["file"] == file)
data = (REF / e["local_file"]).read_bytes()
assert hashlib.sha256(data).hexdigest() == e["sha256"]
assert 1 <= first <= last <= len(data.decode().splitlines())
sources.append(
dict(
e,
local_file="../flux2-print-reference/" + e["local_file"],
lines=[first, last],
claim=claim,
)
)
return len(sources) - 1
enc = cite("core", "nodes.py", 57, 81, "准确0.8.2全文/空串编码")
vae = cite("core", "nodes.py", 281, 353, "准确参考编码及生成解码")
loader = cite("core", "nodes.py", 701, 804, "准确VAE动态枚举及读取/解析条件")
model = cite("core", "nodes.py", 920, 992, "准确UNET及CLIP schema")
load = cite("core", "nodes.py", 1647, 1723, "准确LoadImage IMAGE/MASK协议")
save = cite("core", "nodes.py", 1578, 1646, "9准确正式PNG;148仅core0.8.2临时Preview假设")
cfg = cite("core", "comfy_extras/nodes_custom_sampler.py", 801, 825, "准确CFG条件和默认")
noise = cite(
"core", "comfy_extras/nodes_custom_sampler.py", 898, 913, "准确seed schema,不执行"
)
sample = cite(
"core", "comfy_extras/nodes_custom_sampler.py", 915, 969, "准确采样双LATENT与x0条件"
)
sampler = cite("core", "comfy_extras/nodes_custom_sampler.py", 376, 395, "准确采样器枚举")
latent = cite("core", "comfy_extras/nodes_flux.py", 36, 57, "准确空latent尺寸批量")
sched = cite("core", "comfy_extras/nodes_flux.py", 182, 249, "准确调度器schema及条件")
ref = cite("core", "comfy_extras/nodes_edit_model.py", 1, 38, "参考latent追加条件,非采样起点")
lora = cite("lora", "nodes.py", 670, 732, "准确0.21.1继承、强度、文件缓存/读取条件")
tt = cite(
"tt", "nodes/resolution_selector.py", 1, 80, "准确完整TT提交的预设和真假分支;许可未知"
)
kj = cite("kj", "nodes/image_nodes.py", 2784, 3074, "146准确KJ1.3.9缩放schema/设备/尺寸/出口")
concat = cite(
"kj", "nodes/image_nodes.py", 334, 429, "147缺提供方版本,仅KJ1.3.9空间拼接参考假设"
)
front = cite(
"frontend", "src/scripts/widgets.ts", 1, 270, "准确1.36.13种子辅助,非后端实际seed"
)
host = cite(
"frontend",
("src/lib/litegraph/src/subgraph/SubgraphNode.ts"),
1,
400,
"准确1.36.13子图边界恢复参考;目标宿主/UE/tab组合未知",
)
cite(
"frontend",
("src/lib/litegraph/src/subgraph/SubgraphNode.ts"),
605,
638,
"准确1.36.13序列化前边界同步条件;不回填空宿主",
)
for e in manifest:
if not any(s["id"] == e["id"] and s["file"] == e["file"] for s in sources):
cite(
e["id"],
e["file"],
1,
len((REF / e["local_file"]).read_bytes().decode().splitlines()),
"同树注册/helper/依赖锁/许可闭包;不证明安装或执行",
)
names = {
76: ["image", "upload"],
144: ["use_custom_resolution", "resolution", "custom_width", "custom_height"],
9: ["filename_prefix"],
147: ["direction", "match_image_size"],
146: [
"width",
"height",
"upscale_method",
"keep_proportion",
"pad_color",
"crop_position",
"divisible_by",
"device",
],
102: ["cfg"],
105: ["noise_seed", "control_after_generate"],
100: ["sampler_name"],
111: ["width", "height", "batch_size"],
101: ["steps", "width", "height"],
106: ["unet_name", "weight_dtype"],
142: ["lora_name", "strength_model"],
107: ["clip_name", "type", "device"],
110: ["vae_name"],
108: ["text"],
109: ["text"],
}
evidence = {
76: [load, front],
144: [tt],
9: [save],
147: [concat],
146: [kj],
102: [cfg],
105: [noise, front],
100: [sampler],
111: [latent, sample],
101: [sched],
106: [model, host],
142: [lora, host],
107: [model, host],
110: [loader, vae, host],
108: [enc, ref, host],
109: [enc, ref, host],
}
extra = {
"width": "保存512为外线覆盖缓存,不等于有效宽。",
"height": "保存512为外线覆盖缓存,不等于有效高。",
"upscale_method": "保存nearest-exact,按准确实现插值分支仅读。",
"keep_proportion": (
"保存crop,参考按目标比例裁切分支;schema字面False与枚举分列,不保证保留全部图案。"
),
"pad_color": "保存字符串0, 0, 0(黑色),非JSON数组;crop不证明已填黑边。",
"crop_position": "保存center,裁切居中意图,不处理图片。",
"divisible_by": "保存JSON int8,实现仅>1时向下整除对齐,不试算最终尺寸。",
"device": ("保存cpu,函数默认cpu;gpu与lanczos组合抛错仅参考,不执行CPU/GPU处理。"),
}
fields, comments, empty = [], [], []
for prefix, graph in [("", g), ("/definitions/subgraphs/0", sub)]:
for i, n in enumerate(graph["nodes"]):
nid = n["id"]
ptr = f"{prefix}/nodes/{i}"
display = str(nid) if not prefix else f"149:{nid}"
if n["type"] == "MarkdownNote":
comments.append(
dict(
node_id=display,
pointer=ptr + "/widgets_values/0",
text=n["widgets_values"][0],
meaning=(
"完整1396字符作者指南;下载协议、模型链接、推"
"荐目录/更新及报错建议只是原文,不证明目标事实,"
"不打开链接、代接受协议或执行文字。"
),
)
)
continue
if not n.get("widgets_values"):
state = "missing" if "widgets_values" not in n else "empty_list"
empty.append(
dict(
node_id=display,
class_type=n["type"],
pointer=ptr,
scope="root" if not prefix else prefix,
state=state,
effect=(
"源缺widgets_values键;"
if state == "missing"
else "源widgets_values=[]零位置;"
)
+ EMPTY[nid],
)
)
continue
for j, (name, v) in enumerate(zip(names[nid], n["widgets_values"], strict=True)):
f = copy.deepcopy(
common.get(
(n["type"], name),
{"label": "拼接方向" if name == "direction" else "匹配图像尺寸"},
)
)
inp = next(
(k for k, x in enumerate(n.get("inputs", [])) if x["name"] == name), None
)
aux = name in ["upload", "control_after_generate"]
linked = not aux and inp is not None and n["inputs"][inp].get("link") is not None
f.update(
node_id=display,
definition_node_id=str(nid),
scope="root" if not prefix else prefix,
class_type=n["type"],
field=name,
pointer=f"{ptr}/widgets_values/{j}",
value=v,
json_type=type(v).__name__,
named_pointer="源无widgets_values_named,不构造具名保存指针",
input_pointer=f"{ptr}/inputs/{inp}"
if inp is not None
else "无独立后端输入:前端辅助",
input_name=n["inputs"][inp]["name"] if inp is not None else None,
type=n["inputs"][inp]["type"] if inp is not None else "前端辅助",
role="frontend_reference_only"
if aux
else "linked_saved_cache"
if linked
else "saved_layout_reference",
effect=MEANING[nid],
evidence=evidence[nid],
execution_note=(
"保存现值、准确参考默认、外线覆盖、宿主代理与实际"
"运行值分列;目标安装/恢复/许可/目录/模型素材"
"兼容与效果未知,保持停用,不新增转换或执行资格。"
),
)
if nid == 146:
f["effect"] += " " + extra[name]
if nid in [108, 109]:
f.update(
label="完整印花提取正向缓存" if nid == 108 else "空串负向缓存",
unit="编码文本",
schema_default="无显式default;不以保存文本冒充默认",
limits=(
"准确core0.8.2 STRING multiline/dynamicPrompts;全文只读,不执行指令"
),
)
if nid == 105 and name == "noise_seed":
f["schema_default"] = "0"
if nid == 147:
f.update(
schema_default="right" if name == "direction" else "true",
unit="方向枚举" if name == "direction" else "布尔",
limits="仅KJ1.3.9假设:right/down/left/up"
if name == "direction"
else ("仅KJ1.3.9假设:BOOLEAN,匹配image2到image1对应边,不保证像素不变"),
)
fields.append(f)
assert len(fields) == 37 and len(comments) == 1 and len(empty) == 10
overview = (
"这张图希望把衣服上的印花单独提取为白底平面设计:先按竖屏选择缩放"
"参考,再用小志LoRA与参考特征从空latent生成,正式保存生"
"成图,并临时预览原图在左、生成在右的拼接。提取、去衣服人体和保留"
"图案只是作者意图,实际效果尚未验证。"
)
boundaries = [
dict(
scope="/definitions/subgraphs/0",
**{
k: sub[k] for k in ["id", "inputNode", "outputNode", "inputs", "outputs", "widgets"]
},
),
dict(
host_pointer="/nodes/6",
host_saved=g["nodes"][6]["widgets_values"],
proxyWidgets=g["nodes"][6]["properties"]["proxyWidgets"],
inputs=g["nodes"][6]["inputs"],
effect=(
"10代理与9输入分开;宿主无具名保存,定义wid"
"gets=[];输出linkIds=[201,2"
"01]重复两次与一条物理201分开核验,不继承旧"
"图计数。"
),
),
]
assert g["nodes"][6]["id"] == 149
flow = [
overview,
(
"根9节点10边,定义18节点32含边界记录,全mode0;根17"
"+内部20=37非注释标量位置,完整MarkdownNote97"
"另计1396字符,无具名保存。Label143、内部135/13"
"6缺键;宿主149、148与五内部[]各零位置,定义widget"
"s=[]分开。"
),
]
flow += [
MEANING[k] for k in [76, 144, 146, 106, 142, 107, 110, 108, 109, 102, 105, 100, 101, 111]
]
flow += [EMPTY[k] for k in [149, 135, 136, 141, 140, 139, 103, 104]]
flow += [
MEANING[9],
MEANING[147],
EMPTY[148],
EMPTY[143],
(
"完整英文正向要求不要擦除、模糊或移除图案;白底不等于透明PNG,"
"更不证明矢量、无缝或版权许可。没有MASK编辑链,未读取媒体,不"
"能据clipspace属性推定衣服/人体内容。"
),
(
"准确frontend1.36.13的SubgraphNode.c"
"onfigure按定义恢复边界、按linkId寻找可得widge"
"t;序列化前同步相连内部widget,再受serialize_w"
"idgets和serialize=false控制。源空宿主与10"
"代理只是线索,UE7.5.2/7.7/7.8、tab/宿主恢复未"
"知,不模拟回填。"
),
(
"准确前端randomize辅助与后端Noise_RandomNo"
"ise保存seed分开;generate_noise才调用pre"
"pare_noise,Sampler传noise.seed给gu"
"ider。不运行钩子、种子、状态或缓存,不保证复现。"
),
(
"身份分层:多数core0.8.2、142 LoRA0.21.1、"
"frontend1.36.13、TT完整提交、146明确KJ1."
"3.9。147与148缺身份,仅显式KJ1.3.9/core0."
"8.2假设;149宿主和Label未知。无Primitive0."
"28.3、LayerUtility、rgthreeCompare"
"r或Impact适用证据。TT许可仍未知,KJ必要成员SHA/C"
"RC不是完整包SHA或Git绑定;安装/目录/许可适用性/模型素"
"材兼容与效果未知。"
),
(
"常见问题:宽高先受TT覆盖146两处512,再由146实际尺寸槽"
"覆盖内部调度器/空latent四处1024;不按控件位置猜最终值"
"、不试算尺寸。拼接图不是正式9保存图,临时预览不证明执行成功;源"
"SaveImage没有输出冲突,但整图转换/执行资格继续关闭。"
),
]
flow += ["根物理边 " + json.dumps(e, ensure_ascii=False) for e in g["links"]]
flow += ["定义物理边 " + json.dumps(e, ensure_ascii=False) for e in sub["links"]]
for prefix, graph in [("", g), ("/definitions/subgraphs/0", sub)]:
flow += [
f"{prefix or '根'}节点{n['id']}独立属性 "
+ json.dumps(n.get("properties", {}), ensure_ascii=False)
for n in graph["nodes"]
]
flow += ["原定义边界/宿主声明 " + json.dumps(b, ensure_ascii=False) for b in boundaries]
versions = []
for key in ["core", "lora", "frontend", "tt", "kj"]:
e = next(s for s in sources if s["id"] == key)
versions.append(
f"{key} {e['tag']} commit {e['commit']};tree {e['tree']};许可见{e['license_file']}"
)
versions += [
("local_file以docs/hel-892/flux2-print-document-evidence为基准;原字节SHA256 ")
+ hashlib.sha256(raw).hexdigest(),
(
"旧57块2201位置+65注释逐对象冻结"
";完整KJ包SHA/Git、TT许可未知"
"。仅静态文本,不执行上游/模型/表达式/"
"种子/媒体,不构造prompt。"
),
]
return dict(
source_path=PATHS[index],
source_sha1=hashlib.sha1(raw).hexdigest(),
source_sha256=hashlib.sha256(raw).hexdigest(),
canonical_sha256=hashlib.sha256(canonical(g)).hexdigest(),
notice=(
"仅参考:目标安装/恢复、模型/素材/许可与实际印花提取效果未核,保持停用和转换关闭。"
),
user_overview=overview,
versions=versions,
counts=dict(
saved_fields=37,
root_saved_fields=17,
internal_saved_fields=20,
linked_saved_fields=sum(f["role"] == "linked_saved_cache" for f in fields),
frontend_only=sum(f["role"] == "frontend_reference_only" for f in fields),
source_nodes=27,
root_nodes=9,
internal_nodes=18,
physical_edges=42,
source_notes=1,
history_objects=0,
final_scalars=0,
final_prompt_constructed=False,
),
fields=fields,
sources=sources,
comments=comments,
flow=flow,
flow_evidence=list(range(len(sources))),
zero_saved_nodes=empty,
boundaries=boundaries,
steps=[
overview,
(
"阅读1:逐原图文件名、独立clipspa"
"ce属性、完整英文正向/中文解释、空串负"
"向和完整Note,仅读文本,不打开媒体或"
"链接。"
),
(
"阅读2:核对TT/缩放六处尺寸覆盖、宽slot1/高slot2、"
"正负参考与空latent起点、10代理9输入、活动LoRA、正式"
"保存和左原图右生成的临时空间拼接;缓存不是实际运行值。"
),
(
"阅读3:安装/许可/目录/恢复与效果未知,保持停用,155全量完"
"成审核后才发布;不连接目标、不构造prompt、不执行上游/模型"
"/GPU/媒体/种子/缓存,不下载或代接受协议。"
),
],
)