- An answer past Antigravity's size is filed away unread (eight LoRA searches in the exam): search_models answers small (loaders once, four trigger words, a LoRA's author weight); describe_canvas gives a big canvas's last nodes a line each; mcp_fit.py keeps any other list answer within the size and names what it left out. - An empty canvas: run_workflow, describe_canvas and get_situation say to open a workflow first; get_image_info says a picture's workflow opens with open_workflow. - ask_user does not put a "test" question to the user; a task's picture count counts what its runs made. - AMB failed to load now and then: ComfyUI loads every file at once and ui_ai_workbench.js set ui_ai_toolbox.js's sideHost before it was made when the toolbox file ran first. Connected on first draw now; tests/load_order.mjs runs every file first. - input_facts moved to api/picture_mask.py to keep mcp_tools.py short. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.5 KiB
Python
28 lines
1.5 KiB
Python
"""What LoadImage gets from a picture in ComfyUI's input folder (or a run's preview in temp), for the
|
|
AI (get_image_info folder=input/temp): its size and, when it has an alpha, the area LoadImage gives as
|
|
MASK (1 - alpha), the part a repaint changes, said as a share and a box in percent of the picture."""
|
|
|
|
from PIL import Image
|
|
|
|
|
|
def input_facts(path):
|
|
"""Size of an input or preview picture and, when it has an alpha, the area LoadImage gives as MASK (1 - alpha)."""
|
|
try:
|
|
with Image.open(path) as picture:
|
|
facts = {"width": picture.width, "height": picture.height}
|
|
if "A" not in picture.getbands():
|
|
facts["mask"] = "none: no alpha, so LoadImage's MASK is empty"
|
|
return facts
|
|
area = picture.getchannel("A").point(lambda value: 255 if value < 128 else 0)
|
|
except (OSError, ValueError, Image.DecompressionBombError):
|
|
return {"note": "The picture cannot be read."}
|
|
box = area.getbbox()
|
|
if not box:
|
|
facts["mask"] = "none: fully opaque, so LoadImage's MASK is empty"
|
|
return facts
|
|
share = area.histogram()[255] / (facts["width"] * facts["height"])
|
|
left, top, right, bottom = (round(100 * value / size) for value, size in zip(box, (facts["width"], facts["height"]) * 2))
|
|
facts["mask"] = {"share": f"{round(100 * share, 1)}%", "area": f"x {left}-{right}%, y {top}-{bottom}% of the picture",
|
|
"meaning": "LoadImage gives this area as MASK: what to repaint"}
|
|
return facts
|