Nodes/ComfyUI_omost/Omost Load Canvas Python Code
ComfyUI Node

Omost Load Canvas Python Code

Paste in the original Omost demo's Canvas code

By huchenlei·Created 2 years ago·Updated about a year ago· 445
Omost Load Canvas Python Code
    • OMOST_CANVAS_CONDITIONING
    python_str

    Omost Load Canvas Python Code is the sibling of the JSON loader, and it answers a specific need: the original Omost project hands you Python code, not JSON. Copy a snippet out of lllyasviel's demo app, paste it into python_str, and you get the same OMOST_CANVAS_CONDITIONING out the other side. One input, one output, nothing else.

    The code it expects is the Canvas API. A canvas = Canvas() variable, a set_global_description(...) call for the whole image, then a series of add_local_description(...) calls - each with a location, offset, area, distance_to_viewer, the description itself, detailed_descriptions, tags, atmosphere, style, quality meta, and an HTML web color name. The node exec()s the string, checks you produced a valid canvas, converts the boxes into the 90×90 rect system, and processes the regions. distance_to_viewer is what sorts regions front-to-back, by the way - larger numbers end up as higher layers.

    Why use this instead of the JSON loader? Mostly migration and portability. Omost guides and older workflows from the original repo ship Python, and an LLM answering in the Canvas format is a real possibility too. When your source hands you code, this node saves the translation step; when it hands you JSON, use Omost Load Canvas Conditioning. They're interchangeable downstream, so pick whichever matches what you're copying.

    Two warnings, and one of them matters. First, exec() runs whatever code you paste. That's fine when the code came from a trusted Omost source, but the moment you start pasting from random tutorials or an unfiltered LLM reply, you are executing arbitrary Python in your ComfyUI process. Custom nodes already run with full user-level access - the ecosystem's own security history is a reminder of what that means - so stick to code you understand. Second, the loader is strict: the executed code must define a canvas variable (it asserts on it), and unlike the chat node it does not strip ```python fences - it expects bare code, so unwrap any markdown before pasting.

    Categoryomost

    Inputs (1)

    NameTypeDefaultDescription
    python_strSTRING

    Outputs (1)

    NameTypeDescription
    OMOST_CANVAS_CONDITIONINGOMOST_CANVAS_CONDITIONING