Chaoses-Ib / ComfyScript

A Python frontend and library for ComfyUI
https://discord.gg/arqJbtEg7w
MIT License
431 stars 24 forks source link

Am I doing this right? #5

Closed lingondricka2 closed 11 months ago

lingondricka2 commented 11 months ago

I might be missing some fundamental knowledge here, new to Python. I copied a script called test.py:

from script.runtime import *
load()
from script.runtime.nodes import *

with Workflow():
    model, clip, vae = CheckpointLoaderSimple('v1-5-pruned-emaonly.ckpt')
    conditioning = CLIPTextEncode('beautiful scenery nature glass bottle landscape, , purple galaxy bottle,', clip)
    conditioning2 = CLIPTextEncode('text, watermark', clip)
    latent = EmptyLatentImage(512, 512, 1)
    latent = KSampler(model, 156680208700286, 20, 8, 'euler', 'normal', conditioning, conditioning2, latent, 1)
    image = VAEDecode(latent, vae)
    SaveImage(image, 'ComfyUI')

Put it in ComfyScript folder, run it like "python test.py", result:

Nodes: 1018
Traceback (most recent call last):
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\test.py", line 2, in <module>
    load()
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\__init__.py", line 18, in load
    asyncio.run(_load(api_endpoint, vars, watch, save_script_source))
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages\nest_asyncio.py", line 31, in run
    return loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages\nest_asyncio.py", line 99, in run_until_complete
    return f.result()
           ^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\asyncio\futures.py", line 203, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py", line 267, in __step
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\__init__.py", line 29, in _load
    nodes.load(nodes_info, vars)
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\nodes.py", line 10, in load
    fact.add_node(node_info)
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 124, in add_node
    inputs.append(f'{name}: {type_and_hint(type_info, name, optional, config.get("default"))[1]}')
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 69, in type_and_hint
    enum_c, t = astutil.to_str_enum(name, { _remove_extension(s): s for s in type_info }, '    ')
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 69, in <dictcomp>
    enum_c, t = astutil.to_str_enum(name, { _remove_extension(s): s for s in type_info }, '    ')
                                            ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 14, in _remove_extension
    path = path.removesuffix(ext)
           ^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'removesuffix'

Using Python 3.11.

Also am I suppose to run some kind of IDE and feed it lines runtime, like the queue commands?

Chaoses-Ib commented 11 months ago

Probably due to some custom nodes. Can you post a list of the custom node packs you installed? Or access http://127.0.0.1:8188/object_info and upload the json here?

Also am I suppose to run some kind of IDE and feed it lines runtime, like the queue commands?

The usage in your test.py is valid, and it can run on my machine. That being said, normally one would use ComfyScript in a Jupyter Notebook, thus you can see the progress and preview the results. If you don't have an IDE, VS Code is recommended.

lingondricka2 commented 11 months ago

I realized both my custom_nodes folder and global python packages are a mess, custom_nodes contains nodes I have copied over from other ComfyUI installations, some nodes that failed to load and some failed custom ones I tried making myself. "pip list" showed me packages I have manually deleted, so need to clean this up first.

lingondricka2 commented 11 months ago

I tested to run the script with only one custom node besides ComfyScript and ComfyUI-Manager, not much luck, each custom node installed seems to give a different error. with was-node-suite-comfyui:

Nodes: 335
Traceback (most recent call last):
File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\test.py", line 2, in <module>
    load()
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\__init__.py", line 18, in load
    asyncio.run(_load(api_endpoint, vars, watch, save_script_source))
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages\nest_asyncio.py", line 31, in run
    return loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages\nest_asyncio.py", line 99, in run_until_complete
    return f.result()
           ^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\asyncio\futures.py", line 203, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py", line 267, in __step
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\__init__.py", line 29, in _load
    nodes.load(nodes_info, vars)
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\nodes.py", line 10, in load
    fact.add_node(node_info)
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 124, in add_node
    inputs.append(f'{name}: {type_and_hint(type_info, name, optional, config.get("default"))[1]}')
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 95, in type_and_hint
    c = t.__name__
        ^^^^^^^^^^
AttributeError: 'Node' object has no attribute '__name__'. Did you mean: '__ne__'?

with ComfyUI-Impact-Pack

Nodes: 292
Traceback (most recent call last):
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\test.py", line 2, in <module>
    load()
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\__init__.py", line 18, in load
    asyncio.run(_load(api_endpoint, vars, watch, save_script_source))
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages\nest_asyncio.py", line 31, in run
    return loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages\nest_asyncio.py", line 99, in run_until_complete
    return f.result()
           ^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\asyncio\futures.py", line 203, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py", line 267, in __step
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\__init__.py", line 29, in _load
    nodes.load(nodes_info, vars)
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\nodes.py", line 10, in load
    fact.add_node(node_info)
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 124, in add_node
    inputs.append(f'{name}: {type_and_hint(type_info, name, optional, config.get("default"))[1]}')
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 86, in type_and_hint
    type_id = astutil.str_to_class_id(type_info)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\astutil.py", line 61, in str_to_class_id
    return id_to_camel(str_to_raw_id(s))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\astutil.py", line 41, in id_to_camel
    id = id[0].upper() + id[1:]
         ~~^^^
IndexError: string index out of range

with comfyui_controlnet_aux: works fine

with efficiency-nodes-comfyui:

Nodes: 176
Traceback (most recent call last):
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\test.py", line 2, in <module>
    load()
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\__init__.py", line 18, in load
    asyncio.run(_load(api_endpoint, vars, watch, save_script_source))
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages\nest_asyncio.py", line 31, in run
    return loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages\nest_asyncio.py", line 99, in run_until_complete
    return f.result()
           ^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\asyncio\futures.py", line 203, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py", line 267, in __step
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\__init__.py", line 29, in _load
    nodes.load(nodes_info, vars)
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\nodes.py", line 10, in load
    fact.add_node(node_info)
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 124, in add_node
    inputs.append(f'{name}: {type_and_hint(type_info, name, optional, config.get("default"))[1]}')
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 69, in type_and_hint
    enum_c, t = astutil.to_str_enum(name, { _remove_extension(s): s for s in type_info }, '    ')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\astutil.py", line 115, in to_str_enum
    return c, StrEnum(id, members)
              ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\enum.py", line 697, in __call__
    return cls._create_(
           ^^^^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\enum.py", line 872, in _create_
    return metacls.__new__(metacls, class_name, bases, classdict, boundary=boundary)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\enum.py", line 487, in __new__
    raise ValueError('invalid enum member name(s) %s'  % (
ValueError: invalid enum member name(s) ''

All nodes are installed using comfy-manager. I post my package list here also for good measure.

absl-py                   2.0.0
accelerate                0.24.1
addict                    2.4.0
aiohttp                   3.9.1
aiosignal                 1.3.1
annotated-types           0.6.0
antlr4-python3-runtime    4.9.3
anyio                     4.2.0
appdirs                   1.4.4
arabic-reshaper           3.0.0
asttokens                 2.4.1
attrs                     23.1.0
audioread                 3.0.1
certifi                   2023.11.17
cffi                      1.16.0
chardet                   5.2.0
charset-normalizer        3.3.2
click                     8.1.7
clip                      1.0
clip-interrogator         0.6.0
clipseg                   0.0.1
cmake                     3.27.7
color-matcher             0.5.0
colorama                  0.4.6
coloredlogs               15.0.1
colorlog                  6.8.0
comm                      0.2.0
contourpy                 1.2.0
cssselect2                0.7.0
cstr                      0.1.0
cycler                    0.12.1
ddt                       1.7.0
debugpy                   1.8.0
decorator                 5.1.1
diffusers                 0.24.0
distro                    1.8.0
docutils                  0.20.1
einops                    0.7.0
embreex                   2.17.7.post4
executing                 2.0.1
fairscale                 0.4.4
ffmpy                     0.3.0
filelock                  3.13.1
flatbuffers               23.5.26
fonttools                 4.45.1
frozenlist                1.4.0
fsspec                    2023.10.0
ftfy                      6.1.3
fvcore                    0.1.5.post20221221
gitdb                     4.0.11
GitPython                 3.1.40
h11                       0.14.0
httpcore                  1.0.2
httpx                     0.25.2
huggingface-hub           0.19.4
humanfriendly             10.0
idna                      3.6
imageio                   2.33.0
img2texture               1.0.6
importlib-metadata        6.8.0
iopath                    0.1.10
ipykernel                 6.27.1
ipython                   8.18.1
ipywidgets                8.1.1
jedi                      0.19.1
Jinja2                    3.1.2
joblib                    1.3.2
jsonschema                4.20.0
jsonschema-specifications 2023.11.1
jupyter_client            8.6.0
jupyter_core              5.5.1
jupyterlab-widgets        3.0.9
kiwisolver                1.4.5
kornia                    0.7.0
lazy_loader               0.3
librosa                   0.10.1
lightning-utilities       0.10.0
litellm                   1.15.1
llvmlite                  0.41.1
lxml                      4.9.3
mapbox-earcut             1.0.1
MarkupSafe                2.1.3
matplotlib                3.8.2
matplotlib-inline         0.1.6
matrix-client             0.4.0
mediapipe                 0.10.8
mpmath                    1.3.0
msgpack                   1.0.7
multidict                 6.0.4
nest-asyncio              1.5.8
networkx                  3.2.1
ninja                     1.11.1.1
numba                     0.58.1
numpy                     1.24.4
omegaconf                 2.3.0
onnx                      1.15.0
onnxruntime               1.16.3
open-clip-torch           2.23.0
openai                    1.5.0
opencv-contrib-python     4.8.1.78
opencv-python             4.8.1.78
opencv-python-headless    4.7.0.72
packaging                 23.2
pandas                    2.1.3
parso                     0.8.3
piexif                    1.1.3
pilgram                   1.2.1
Pillow                    9.5.0
pip                       23.3.2
platformdirs              4.0.0
pooch                     1.8.0
portalocker               2.8.2
prompt-toolkit            3.0.43
protobuf                  3.20.3
psutil                    5.9.6
pure-eval                 0.2.2
py-cpuinfo                9.0.0
pycocoevalcap             1.2
pycocotools               2.0.7
pycollada                 0.7.2
pycparser                 2.21
pydantic                  2.5.2
pydantic_core             2.14.5
Pygments                  2.17.2
PyMatting                 1.1.11
pyparsing                 3.1.1
pypiwin32                 223
pypng                     0.20220715.0
pyreadline3               3.4.1
python-bidi               0.4.2
python-dateutil           2.8.2
python-dotenv             1.0.0
pytorch-lightning         2.1.2
pytz                      2023.3.post1
PyWavelets                1.5.0
pywin32                   306
PyYAML                    6.0.1
pyzmq                     25.1.2
qrcode                    7.4.2
referencing               0.31.0
regex                     2023.10.3
rembg                     2.0.52
reportlab                 4.0.7
requests                  2.31.0
rpds-py                   0.13.1
Rtree                     1.1.0
safetensors               0.4.1
scikit-image              0.20.0
scikit-learn              1.3.2
scipy                     1.11.4
seaborn                   0.13.0
segment-anything          1.0                  C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages
sentencepiece             0.1.99
setuptools                65.5.0
shapely                   2.0.2
simpleeval                0.9.13
six                       1.16.0
smmap                     5.0.1
sniffio                   1.3.0
sounddevice               0.4.6
soundfile                 0.12.1
soxr                      0.3.7
stack-data                0.6.3
supervision               0.17.1
svg.path                  6.3
svglib                    1.5.1
sympy                     1.12
tabulate                  0.9.0
termcolor                 2.4.0
thop                      0.1.1.post2209072238
threadpoolctl             3.2.0
tifffile                  2023.9.26
tiktoken                  0.5.2
timm                      0.4.12
tinycss2                  1.2.1
tokenizers                0.13.3
tomli                     2.0.1
torch                     2.1.1+cu121
torchaudio                2.1.1+cu121
torchmetrics              1.2.1
torchsde                  0.2.6
torchvision               0.16.1+cu121
tornado                   6.4
tqdm                      4.66.1
traitlets                 5.14.0
trampoline                0.1.2
transformers              4.26.1
trimesh                   4.0.8
typing_extensions         4.8.0
tzdata                    2023.3
ultralytics               8.0.219
urllib3                   1.26.18
wcwidth                   0.2.12
webencodings              0.5.1
wheel                     0.42.0
widgetsnbextension        4.0.9
xformers                  0.0.23.post1
xxhash                    3.4.1
yacs                      0.1.8
yapf                      0.40.2
yarl                      1.9.3
zipp                      3.17.0
Chaoses-Ib commented 11 months ago

Thanks very much for your test. All related bugs are fixed now.

image

lingondricka2 commented 11 months ago

It seems to be working with all my custom nodes except this one now, Derfuu_ComfyUI_ModdedNodes:

Nodes: 174
Traceback (most recent call last):
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\test.py", line 2, in <module>
    load()
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\__init__.py", line 18, in load
    asyncio.run(_load(api_endpoint, vars, watch, save_script_source))
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages\nest_asyncio.py", line 31, in run
    return loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\site-packages\nest_asyncio.py", line 99, in run_until_complete
    return f.result()
           ^^^^^^^^^^
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\asyncio\futures.py", line 203, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "C:\Users\lingo\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py", line 267, in __step
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\__init__.py", line 29, in _load
    nodes.load(nodes_info, vars)
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\nodes.py", line 10, in load
    fact.add_node(node_info)
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 178, in add_node
    inputs.append(f'{name}: {type_and_hint(type_info, name, optional, config.get("default"))[1]}')
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 80, in type_and_hint
    if is_bool_enum(type_info):
       ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 21, in is_bool_enum
    lower = [s.lower() for s in enum]
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lingo\Desktop\ComfyUI\custom_nodes\ComfyScript\script\runtime\factory.py", line 21, in <listcomp>
    lower = [s.lower() for s in enum]
             ^^^^^^^
AttributeError: 'bool' object has no attribute 'lower'
Chaoses-Ib commented 11 months ago

Fixed. ComfyUI's lack of docs plus Python's weak type is really a nightmare...