From 4ea26ed8de758de346a0c47baf8cc7ce61fb86a9 Mon Sep 17 00:00:00 2001 From: Doug White Date: Tue, 25 Jul 2023 20:03:32 +1000 Subject: [PATCH 01/56] Fix unclickable image gallery buttons in Firefox (#34) --- web/imageFeed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/imageFeed.js b/web/imageFeed.js index 18347e5..2c33d1c 100644 --- a/web/imageFeed.js +++ b/web/imageFeed.js @@ -34,7 +34,7 @@ const styles = { zIndex: 9999999, fontSize: '30px', cursor: 'pointer', - pointerEvents: 'bounding-box', + pointerEvents: 'auto', ...extra, }), img_list: { From be162a20477258627fa0d742c97a478bd085ff4f Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Tue, 25 Jul 2023 15:20:57 +0200 Subject: [PATCH 02/56] =?UTF-8?q?docs:=20=F0=9F=93=9D=20add=20readme=20for?= =?UTF-8?q?=20web=20extensions=20features?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 web/README.md diff --git a/web/README.md b/web/README.md new file mode 100644 index 0000000..9bb1c37 --- /dev/null +++ b/web/README.md @@ -0,0 +1,12 @@ +## Core +These 3 script should cannot be used independently and must all be present to work +- `comfy_shared`: library of methods used in `mtb_widgets` and `debug` + +## Standalone +These scripts can be taken and placed independently of `comfy_mtb` or any other files, mimicking what pythongosss did for their [Custom Scripts](https://github.com/pythongosssss/ComfyUI-Custom-Scripts/tree/main/js) + +- **imageFeed**: a fork of pythongosssss's image feed, it adds support for: a lightbox to see images bigger, a way to load the current session history (in case of a web page reload), and different icons, most of the work come from the original script. +- ![imagefeed](https://github.com/melMass/comfy_mtb/assets/7041726/c3acab4b-d28b-4432-a31b-248391aa2ee8) + +- **notify**: a basic toast notification system that I use in some places accross mtb, it can be used by simply calling `window.MTB.notify("Hello world!")` +![extract](https://github.com/melMass/comfy_mtb/assets/7041726/450c67fc-a7e9-4bea-ae49-b610d693098d) From 5d661b2509fecf3940c3c0fab25b16ec0eae7a2d Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Thu, 27 Jul 2023 01:30:13 +0200 Subject: [PATCH 03/56] =?UTF-8?q?fix:=20=F0=9F=93=9D=20narrow=20requiremen?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The protobuf issue is only valid on windows as we must use the old TF lib to get usable speeds for FILM interpolation. WSL, windows and mac don't need that trick. Fixes #28 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 462486e..5cf4d07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ tensorflow<2.11.0; platform_system == "Windows" tb-nightly==2.12.0a20230126; platform_system == "Windows" tensorflow; platform_system != "Windows" # the old tf version on windows comes with a breaking protobuf version -protobuf==3.19.6 +protobuf==3.19.6; platform_system != "Windows" gdown @ git+https://github.com/melMass/gdown@main mmdet==3.0.0 facexlib==0.3.0 From 889f08c08b721be8fdb4e4d7eacc47169d5692d6 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Fri, 28 Jul 2023 20:26:37 +0200 Subject: [PATCH 04/56] =?UTF-8?q?fix:=20=F0=9F=93=9D=20last=20release=20(#?= =?UTF-8?q?36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/package_wheels.yml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package_wheels.yml b/.github/workflows/package_wheels.yml index 4f7eba5..d8677c0 100644 --- a/.github/workflows/package_wheels.yml +++ b/.github/workflows/package_wheels.yml @@ -35,7 +35,7 @@ jobs: - name: 📦 Building and Bundling wheels shell: bash run: | - python -m pip wheel --no-cache-dir --no-deps -r requirements-wheels.txt -w ./wheels 2>&1 | tee build.log + python -m pip wheel --no-cache-dir -r requirements-wheels.txt -w ./wheels 2>&1 | tee build.log # find source wheels packages=$(cat build.log | awk -F 'Building wheels for collected packages: ' '{print $2}') diff --git a/requirements.txt b/requirements.txt index 5cf4d07..3fc5e65 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ tensorflow<2.11.0; platform_system == "Windows" tb-nightly==2.12.0a20230126; platform_system == "Windows" tensorflow; platform_system != "Windows" # the old tf version on windows comes with a breaking protobuf version -protobuf==3.19.6; platform_system != "Windows" +protobuf==3.20.2; platform_system == "Windows" gdown @ git+https://github.com/melMass/gdown@main mmdet==3.0.0 facexlib==0.3.0 From 0e311cf2c64cf2b4861d4cc612a3409390e3039a Mon Sep 17 00:00:00 2001 From: melMass Date: Fri, 28 Jul 2023 20:47:27 +0200 Subject: [PATCH 05/56] =?UTF-8?q?fix:=20=E2=9C=A8=20various=20small=20thin?= =?UTF-8?q?gs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - removed border on imagefeed images. - don't load mtb.imageFeed if the user has pythongoss's version already. - fix the promptserver issue when importing mtb from a jupyter notebook - fix: if the user doesn't have the facemodels downloaded it would crash - added an internal counter to batchfromhistory to invalidate it at each frame, which might not be a good idea. --- __init__.py | 212 ++++++++++++++++++++++--------------------- nodes/faceenhance.py | 4 + pyrightconfig.json | 2 +- web/imageFeed.js | 16 +++- web/mtb_widgets.js | 57 ++++++++++-- 5 files changed, 177 insertions(+), 114 deletions(-) diff --git a/__init__.py b/__init__.py index 11a713d..f5c0bb9 100644 --- a/__init__.py +++ b/__init__.py @@ -5,11 +5,13 @@ # Project: comfy_mtb # Author: Mel Massadian # Copyright (c) 2023 Mel Massadian -# +# ### import os +# todo: don't override this if the user has that setup already os.environ["TF_FORCE_GPU_ALLOW_GROWTH"] = "true" +os.environ["TF_GPU_ALLOCATOR"] = "cuda_malloc_async" import traceback from .log import log, blue_text, cyan_text, get_summary, get_label @@ -112,8 +114,16 @@ if web_mtb.exists(): elif web_extensions_root.exists(): web_tgt = here / "web" + src = web_tgt.as_posix() + dst = web_mtb.as_posix() try: - os.symlink(web_tgt.as_posix(), web_mtb.as_posix()) + if os.name == "nt": + import _winapi + + _winapi.CreateJunction(src, dst) + else: + os.symlink(web_tgt.as_posix(), web_mtb.as_posix()) + except OSError: log.warn(f"Failed to create symlink to {web_mtb}, trying to copy it") try: @@ -174,123 +184,121 @@ from importlib import reload import logging from .endpoint import endlog +if hasattr(PromptServer, "instance"): -@PromptServer.instance.routes.get("/mtb/status") -async def get_full_library(request): - from . import endpoint + @PromptServer.instance.routes.get("/mtb/status") + async def get_full_library(request): + from . import endpoint - reload(endpoint) + reload(endpoint) - endlog.debug("Getting node registration status") - # Check if the request prefers HTML content - if "text/html" in request.headers.get("Accept", ""): - # # Return an HTML page - html_response = endpoint.render_table( - NODE_CLASS_MAPPINGS_DEBUG, title="Registered" - ) - html_response += endpoint.render_table( - {k: "-" for k in failed}, title="Failed to load" + endlog.debug("Getting node registration status") + # Check if the request prefers HTML content + if "text/html" in request.headers.get("Accept", ""): + # # Return an HTML page + html_response = endpoint.render_table( + NODE_CLASS_MAPPINGS_DEBUG, title="Registered" + ) + html_response += endpoint.render_table( + {k: "-" for k in failed}, title="Failed to load" + ) + + return web.Response( + text=endpoint.render_base_template("MTB", html_response), + content_type="text/html", + ) + + return web.json_response( + { + "registered": NODE_CLASS_MAPPINGS_DEBUG, + "failed": failed, + } ) - return web.Response( - text=endpoint.render_base_template("MTB", html_response), - content_type="text/html", + @PromptServer.instance.routes.post("/mtb/debug") + async def set_debug(request): + json_data = await request.json() + enabled = json_data.get("enabled") + if enabled: + os.environ["MTB_DEBUG"] = "true" + log.setLevel(logging.DEBUG) + log.debug("Debug mode set from API (/mtb/debug POST route)") + + else: + if "MTB_DEBUG" in os.environ: + # del os.environ["MTB_DEBUG"] + os.environ.pop("MTB_DEBUG") + log.setLevel(logging.INFO) + + return web.json_response( + {"message": f"Debug mode {'set' if enabled else 'unset'}"} ) - return web.json_response( - { - "registered": NODE_CLASS_MAPPINGS_DEBUG, - "failed": failed, - } - ) + @PromptServer.instance.routes.get("/mtb") + async def get_home(request): + from . import endpoint + reload(endpoint) + # Check if the request prefers HTML content + if "text/html" in request.headers.get("Accept", ""): + # # Return an HTML page + html_response = f""" + + """ + return web.Response( + text=endpoint.render_base_template("MTB", html_response), + content_type="text/html", + ) -@PromptServer.instance.routes.post("/mtb/debug") -async def set_debug(request): - json_data = await request.json() - enabled = json_data.get("enabled") - if enabled: - os.environ["MTB_DEBUG"] = "true" - log.setLevel(logging.DEBUG) - log.debug("Debug mode set from API (/mtb/debug POST route)") + # Return JSON for other requests + return web.json_response({"message": "Welcome to MTB!"}) - else: + @PromptServer.instance.routes.get("/mtb/debug") + async def get_debug(request): + from . import endpoint + + reload(endpoint) + enabled = False if "MTB_DEBUG" in os.environ: - # del os.environ["MTB_DEBUG"] - os.environ.pop("MTB_DEBUG") - log.setLevel(logging.INFO) + enabled = True + # Check if the request prefers HTML content + if "text/html" in request.headers.get("Accept", ""): + # # Return an HTML page + html_response = f""" +

MTB Debug Status: {'Enabled' if enabled else 'Disabled'}

+ """ + return web.Response( + text=endpoint.render_base_template("Debug", html_response), + content_type="text/html", + ) - return web.json_response({"message": f"Debug mode {'set' if enabled else 'unset'}"}) + # Return JSON for other requests + return web.json_response({"enabled": enabled}) + @PromptServer.instance.routes.get("/mtb/actions") + async def no_route(request): + from . import endpoint -@PromptServer.instance.routes.get("/mtb") -async def get_home(request): - from . import endpoint + if "text/html" in request.headers.get("Accept", ""): + html_response = f""" +

Actions has no get for now...

+ """ + return web.Response( + text=endpoint.render_base_template("Actions", html_response), + content_type="text/html", + ) + return web.json_response({"message": "actions has no get for now"}) - reload(endpoint) - # Check if the request prefers HTML content - if "text/html" in request.headers.get("Accept", ""): - # # Return an HTML page - html_response = f""" - - """ - return web.Response( - text=endpoint.render_base_template("MTB", html_response), - content_type="text/html", - ) + @PromptServer.instance.routes.post("/mtb/actions") + async def do_action(request): + from . import endpoint - # Return JSON for other requests - return web.json_response({"message": "Welcome to MTB!"}) + reload(endpoint) - -@PromptServer.instance.routes.get("/mtb/debug") -async def get_debug(request): - from . import endpoint - - reload(endpoint) - enabled = False - if "MTB_DEBUG" in os.environ: - enabled = True - # Check if the request prefers HTML content - if "text/html" in request.headers.get("Accept", ""): - # # Return an HTML page - html_response = f""" -

MTB Debug Status: {'Enabled' if enabled else 'Disabled'}

- """ - return web.Response( - text=endpoint.render_base_template("Debug", html_response), - content_type="text/html", - ) - - # Return JSON for other requests - return web.json_response({"enabled": enabled}) - - -@PromptServer.instance.routes.get("/mtb/actions") -async def no_route(request): - from . import endpoint - - if "text/html" in request.headers.get("Accept", ""): - html_response = f""" -

Actions has no get for now...

- """ - return web.Response( - text=endpoint.render_base_template("Actions", html_response), - content_type="text/html", - ) - return web.json_response({"message": "actions has no get for now"}) - - -@PromptServer.instance.routes.post("/mtb/actions") -async def do_action(request): - from . import endpoint - - reload(endpoint) - - return await endpoint.do_action(request) + return await endpoint.do_action(request) # - WAS Dictionary diff --git a/nodes/faceenhance.py b/nodes/faceenhance.py index 45d4fde..e922559 100644 --- a/nodes/faceenhance.py +++ b/nodes/faceenhance.py @@ -28,6 +28,10 @@ class LoadFaceEnhanceModel: @classmethod def get_models(cls): models_path = cls.get_models_root() + + if not models_path.exists(): + log.warning(f"No models found at {models_path}") + return [] return [ x diff --git a/pyrightconfig.json b/pyrightconfig.json index 2d041e3..4d820f5 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -13,6 +13,6 @@ "reportMissingImports": true, "reportMissingTypeStubs": false, "pythonVersion": "3.10", - "pythonPlatform": "Windows", + "pythonPlatform": "All", "reportOptionalMemberAccess": "none" } \ No newline at end of file diff --git a/web/imageFeed.js b/web/imageFeed.js index 2c33d1c..824d1ea 100644 --- a/web/imageFeed.js +++ b/web/imageFeed.js @@ -53,10 +53,21 @@ let currentImageIndex = 0 const imageUrls = [] let image_menu = null +let activated = true app.registerExtension({ name: 'mtb.ImageFeed', - setup: async () => { + init: async () => { + const pythongossFeed = app.extensions.find( + (e) => e.name == 'pysssss.ImageFeed' + ) + if (pythongossFeed) { + console.warn( + "[mtb] - Aborting the loading of mtb's imageFeed in favor of pysssss.ImageFeed" + ) + activated = false // just in case other methods are added later on + return + } // - HTML & CSS //- lightbox const lightboxContainer = document.createElement('div') @@ -209,6 +220,9 @@ app.registerExtension({ Object.assign(but.style, { height: '120px', width: '120px', + border: 'none', + padding: 0, + margin: 0, }) Object.assign(img.style, { width: '100%', diff --git a/web/mtb_widgets.js b/web/mtb_widgets.js index 4ea2136..c5f36b4 100644 --- a/web/mtb_widgets.js +++ b/web/mtb_widgets.js @@ -688,7 +688,34 @@ const mtb_widgets = { } break } - case 'Save Gif (mtb)': { + //TODO: remove this non sense + case 'Get Batch From History (mtb)': { + const onNodeCreated = nodeType.prototype.onNodeCreated + nodeType.prototype.onNodeCreated = function () { + const r = onNodeCreated + ? onNodeCreated.apply(this, arguments) + : undefined + const internal_count = this.widgets.find( + (w) => w.name === 'internal_count' + ) + shared.hideWidgetForGood(this, internal_count) + internal_count.afterQueued = function () { + this.value++ + } + + return r + } + + const onExecuted = nodeType.prototype.onExecuted + nodeType.prototype.onExecuted = function (message) { + const r = onExecuted ? onExecuted.apply(this, message) : undefined + return r + } + + break + } + case 'Save Gif (mtb)': + case 'Save Animated Image (mtb)': { const onExecuted = nodeType.prototype.onExecuted nodeType.prototype.onExecuted = function (message) { const prefix = 'anything_' @@ -704,15 +731,25 @@ const mtb_widgets = { } let imgURLs = [] - if (message && message.gif) { - imgURLs = imgURLs.concat( - message.gif.map((params) => { - return api.apiURL( - '/view?' + new URLSearchParams(params).toString() - ) - }) - ) - + if (message) { + if (message.gif) { + imgURLs = imgURLs.concat( + message.gif.map((params) => { + return api.apiURL( + '/view?' + new URLSearchParams(params).toString() + ) + }) + ) + } + if (message.apng) { + imgURLs = imgURLs.concat( + message.apng.map((params) => { + return api.apiURL( + '/view?' + new URLSearchParams(params).toString() + ) + }) + ) + } let i = 0 for (const img of imgURLs) { const w = this.addCustomWidget( From 9e751a242f4e9afee3dc5c871c414b29b9706ff6 Mon Sep 17 00:00:00 2001 From: melMass Date: Fri, 28 Jul 2023 20:54:44 +0200 Subject: [PATCH 06/56] =?UTF-8?q?chore:=20=F0=9F=8E=89=20bump=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index f5c0bb9..de37f06 100644 --- a/__init__.py +++ b/__init__.py @@ -26,7 +26,7 @@ NODE_CLASS_MAPPINGS = {} NODE_DISPLAY_NAME_MAPPINGS = {} NODE_CLASS_MAPPINGS_DEBUG = {} -__version__ = "0.1.1" +__version__ = "0.1.2" def extract_nodes_from_source(filename): From 7c020bab288aa7d17dc937b5f102319d43c3ebb3 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Fri, 28 Jul 2023 21:33:39 +0200 Subject: [PATCH 07/56] =?UTF-8?q?docs:=20=F0=9F=93=9D=20fix=20typo=20and?= =?UTF-8?q?=20add=20more=20details?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/README.md | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/web/README.md b/web/README.md index 9bb1c37..9b222e3 100644 --- a/web/README.md +++ b/web/README.md @@ -1,11 +1,29 @@ ## Core -These 3 script should cannot be used independently and must all be present to work +These 3 scripts cannot be used independently and must all be present to work, they are mostly enhancing the frontend of python nodes - `comfy_shared`: library of methods used in `mtb_widgets` and `debug` -## Standalone -These scripts can be taken and placed independently of `comfy_mtb` or any other files, mimicking what pythongosss did for their [Custom Scripts](https://github.com/pythongosssss/ComfyUI-Custom-Scripts/tree/main/js) +**mtb_widgets** define ui callbacks, and various widgets like the `COLOR` type: + -- **imageFeed**: a fork of pythongosssss's image feed, it adds support for: a lightbox to see images bigger, a way to load the current session history (in case of a web page reload), and different icons, most of the work come from the original script. +or the `BOOL` type: + + +There is also `Debug` which is a node that should be able to display any data input, it handle a few cases and fallback to the string representation of the +data otherwise: +![debug](https://github.com/melMass/comfy_mtb/assets/7041726/1f4393e4-1c3d-4807-9501-fe8888bfae25) + + + +## Standalone +These scripts can be taken and placed independently of `comfy_mtb` or any other files, mimicking what pythongosss did for their + +- **imageFeed**: a fork of @pythongosssss ' s [image feed](https://github.com/pythongosssss/ComfyUI-Custom-Scripts/tree/main/js), it adds support for: a lightbox to see images bigger, a way to load the current session history (in case of a web page reload), and different icons, most of the work come from the original script. + + +> **NOTE** +> +> The original imagefeed got updated since and offer more options, ideally I would clean my lightbox thing and PR it to pythongoss later but in the meantime the script will detect if you already use the original one and not load this fork + - ![imagefeed](https://github.com/melMass/comfy_mtb/assets/7041726/c3acab4b-d28b-4432-a31b-248391aa2ee8) - **notify**: a basic toast notification system that I use in some places accross mtb, it can be used by simply calling `window.MTB.notify("Hello world!")` From cbcacbe3c92ebb5f74d046b83504c3723710f130 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Fri, 28 Jul 2023 22:12:43 +0200 Subject: [PATCH 08/56] =?UTF-8?q?docs:=20=F0=9F=93=9D=20update=20imagefeed?= =?UTF-8?q?=20preview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/README.md b/web/README.md index 9b222e3..83c79f3 100644 --- a/web/README.md +++ b/web/README.md @@ -23,8 +23,10 @@ These scripts can be taken and placed independently of `comfy_mtb` or any other > **NOTE** > > The original imagefeed got updated since and offer more options, ideally I would clean my lightbox thing and PR it to pythongoss later but in the meantime the script will detect if you already use the original one and not load this fork - -- ![imagefeed](https://github.com/melMass/comfy_mtb/assets/7041726/c3acab4b-d28b-4432-a31b-248391aa2ee8) + + +- ![imagefeed2-hd](https://github.com/melMass/comfy_mtb/assets/7041726/8539f46f-78e1-459a-a11c-fddd44e63ca9) + - **notify**: a basic toast notification system that I use in some places accross mtb, it can be used by simply calling `window.MTB.notify("Hello world!")` ![extract](https://github.com/melMass/comfy_mtb/assets/7041726/450c67fc-a7e9-4bea-ae49-b610d693098d) From f5cd56ce861c8c0a931744ae6cf2b96e9c8bca06 Mon Sep 17 00:00:00 2001 From: melMass Date: Fri, 28 Jul 2023 22:14:22 +0200 Subject: [PATCH 09/56] =?UTF-8?q?fix:=20=F0=9F=8E=A8=20use=20image=20ratio?= =?UTF-8?q?=20for=20imagefeed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/imageFeed.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/web/imageFeed.js b/web/imageFeed.js index 824d1ea..4a2cf4b 100644 --- a/web/imageFeed.js +++ b/web/imageFeed.js @@ -227,7 +227,7 @@ app.registerExtension({ Object.assign(img.style, { width: '100%', height: '100%', - objectFit: 'scale-down', + objectFit: 'cover', }) img.src = `/view?filename=${encodeURIComponent(src.filename)}&type=${ @@ -238,6 +238,10 @@ app.registerExtension({ console.debug(img.src) + img.onload = () => { + but.style.width = `${120 * (img.naturalWidth / img.naturalHeight)}px` + } + but.onclick = () => { lightboxContainer.style.display = 'flex' // add the same image to the lightbox @@ -284,9 +288,11 @@ app.registerExtension({ if (history.outputs) { for (const key of Object.keys(history.outputs)) { console.debug(key) - for (const im of history.outputs[key].images) { - console.debug(im) - createImageBtn(im) + if (history.outputs[key].images) { + for (const im of history.outputs[key].images) { + console.debug(im) + createImageBtn(im) + } } } // for (const src of outputs.outputs.images) { From 505314294f02e7c19ac95e4d0ed37fd397a54b46 Mon Sep 17 00:00:00 2001 From: melMass Date: Sat, 29 Jul 2023 00:25:24 +0200 Subject: [PATCH 10/56] =?UTF-8?q?ci:=20=E2=9C=A8=20store=20order=20of=20in?= =?UTF-8?q?stall=20for=20wheels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/package_wheels.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package_wheels.yml b/.github/workflows/package_wheels.yml index d8677c0..0044829 100644 --- a/.github/workflows/package_wheels.yml +++ b/.github/workflows/package_wheels.yml @@ -27,10 +27,10 @@ jobs: steps: - name: ♻️ Checking out the repository uses: actions/checkout@v3 - - name: "🐍 Setting up Python" + - name: '🐍 Setting up Python' uses: actions/setup-python@v4 with: - python-version: "3.10.9" + python-version: '3.10.9' - name: 📦 Building and Bundling wheels shell: bash @@ -43,6 +43,13 @@ jobs: IFS=', ' read -r -a package_array <<< "$packages" + # Save reversed package_array to wheel_order.txt + reversed_array=() + for ((idx=${#package_array[@]}-1; idx>=0; idx--)); do + reversed_array+=("${package_array[idx]}") + done + printf '%s\n' "${reversed_array[@]}" > ./wheels/wheel_order.txt + printf "Autodetect this source package: \e[32m%s\e[0m\n" "${package_array[@]}" # Iterate through the wheel files and remove those that are not source built From 9b24eddd9c51004af08d7ac6ff2b6473dd3ee161 Mon Sep 17 00:00:00 2001 From: melMass Date: Sat, 29 Jul 2023 00:55:10 +0200 Subject: [PATCH 11/56] =?UTF-8?q?chore:=20=E2=9C=A8=20use=20wheel=20order?= =?UTF-8?q?=20if=20present?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/install.py b/install.py index 06aefcd..de08916 100644 --- a/install.py +++ b/install.py @@ -418,6 +418,7 @@ if __name__ == "__main__": # - Unzip to wheels dir whl_files = [] + whl_order = None with zipfile.ZipFile(asset_dest, "r") as zip_ref: for item in tqdm(zip_ref.namelist(), desc="Extracting", unit="file"): if item.endswith(".whl"): @@ -428,6 +429,14 @@ if __name__ == "__main__": ) as target: whl_files.append(target_path) shutil.copyfileobj(source, target) + elif item.endswith("order.txt"): + item_basename = os.path.basename(item) + target_path = wheels_directory / item_basename + with zip_ref.open(item) as source, open( + target_path, "wb" + ) as target: + whl_order = target_path + shutil.copyfileobj(source, target) print_formatted( f"Wheels extracted for {current_platform} to the '{wheels_directory}' directory.", @@ -436,6 +445,14 @@ if __name__ == "__main__": ) if whl_files: + if whl_order: + with open(whl_order, "r") as order: + wheel_order_lines = [line.strip() for line in order] + whl_files = sorted( + whl_files, + key=lambda x: wheel_order_lines.index(x.split("-")[0]), + ) + for whl_file in tqdm(whl_files, desc="Installing", unit="package"): whl_path = wheels_directory / whl_file From 247fbfbc216b8259d607e0699d5b990b6a06ca71 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Sun, 30 Jul 2023 01:20:05 +0200 Subject: [PATCH 12/56] =?UTF-8?q?fix:=20=F0=9F=94=A5=20manage=20pip=20from?= =?UTF-8?q?=20install=20only,=20remove=20requirements.txt=20(#38)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/package_wheels.yml | 2 +- INSTALL-CN.md | 4 ++-- INSTALL-JP.md | 4 ++-- INSTALL.md | 4 ++-- install.py | 23 ++++++++++------------- requirements.txt => reqs.txt | 3 +++ requirements-wheels.txt | 3 --- 7 files changed, 20 insertions(+), 23 deletions(-) rename requirements.txt => reqs.txt (91%) delete mode 100644 requirements-wheels.txt diff --git a/.github/workflows/package_wheels.yml b/.github/workflows/package_wheels.yml index 0044829..9f68138 100644 --- a/.github/workflows/package_wheels.yml +++ b/.github/workflows/package_wheels.yml @@ -35,7 +35,7 @@ jobs: - name: 📦 Building and Bundling wheels shell: bash run: | - python -m pip wheel --no-cache-dir -r requirements-wheels.txt -w ./wheels 2>&1 | tee build.log + python -m pip wheel --no-cache-dir -r reqs.txt -w ./wheels 2>&1 | tee build.log # find source wheels packages=$(cat build.log | awk -F 'Building wheels for collected packages: ' '{print $2}') diff --git a/INSTALL-CN.md b/INSTALL-CN.md index 934e540..32ef707 100644 --- a/INSTALL-CN.md +++ b/INSTALL-CN.md @@ -49,7 +49,7 @@ python scripts/download_models.py 1. 确保您处于用于 ComfyUI 的 Python 环境中。 2. 运行以下命令安装所需的依赖项: ```bash - pip install -r comfy_mtb/requirements.txt + pip install -r comfy_mtb/reqs.txt ``` @@ -77,7 +77,7 @@ python scripts/download_models.py !python custom_nodes/comfy_mtb/scripts/download_models.py -y # install the dependencies -!pip install -r custom_nodes/comfy_mtb/requirements.txt -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html +!pip install -r custom_nodes/comfy_mtb/reqs.txt -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html ``` 如果运行后 colab 抱怨需要重新启动运行时,请重新启动,然后不要重新运行之前的单元格,只运行运行本地隧道的单元格。(可能需要先添加一个包含 `%cd ComfyUI` 的单元格) diff --git a/INSTALL-JP.md b/INSTALL-JP.md index f06dc6f..c7c3f52 100644 --- a/INSTALL-JP.md +++ b/INSTALL-JP.md @@ -52,7 +52,7 @@ python scripts/download_models.py 1. ComfyUIで使用しているPython環境であることを確認してください。 2. 以下のコマンドを実行して、必要な依存関係をインストールします: ```bash - pip install -r comfy_mtb/requirements.txt + pip install -r comfy_mtb/reqs.txt ``` @@ -78,7 +78,7 @@ ComfyUI with localtunnel (Recommended Way)**ヘッダーのすぐ後(コード !python custom_nodes/comfy_mtb/scripts/download_models.py -y # install the dependencies -!pip install -r custom_nodes/comfy_mtb/requirements.txt -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html +!pip install -r custom_nodes/comfy_mtb/reqs.txt -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html ``` これを実行した後、colabがランタイムを再起動する必要があると文句を言ったら、それを実行し、それ以前のセルは再実行せず、localtunnelを実行するセルだけを再実行してください。(最初に`%cd ComfyUI`のセルを追加する必要があるかもしれません...) diff --git a/INSTALL.md b/INSTALL.md index 2bf392d..e3f7d65 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -48,7 +48,7 @@ On first run the script [tries to symlink](https://github.com/melMass/comfy_mtb/ 1. Make sure you are in the Python environment you use for ComfyUI. 2. Install the required dependencies by running the following command: ```bash - pip install -r comfy_mtb/requirements.txt + pip install -r comfy_mtb/reqs.txt ``` @@ -76,7 +76,7 @@ Add a new code cell just after the **Run ComfyUI with localtunnel (Recommended W !python custom_nodes/comfy_mtb/scripts/download_models.py -y # install the dependencies -!pip install -r custom_nodes/comfy_mtb/requirements.txt -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html +!pip install -r custom_nodes/comfy_mtb/reqs.txt -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html ``` If after running this, colab complains about needing to restart runtime, do it, and then do not rerun earlier cells, just the one to run the localtunnel. (you might have to add a cell with `%cd ComfyUI` first...) diff --git a/install.py b/install.py index de08916..04108e4 100644 --- a/install.py +++ b/install.py @@ -258,23 +258,16 @@ def import_or_install(requirement, dry=False): # Install dependencies from requirements.txt def install_dependencies(dry=False): - parsed_requirements = get_requirements(here / "requirements.txt") + parsed_requirements = get_requirements(here / "reqs.txt") if not parsed_requirements: return print_formatted( - "Installing dependencies from requirements.txt...", "italic", color="yellow" + "Installing dependencies from reqs.txt...", "italic", color="yellow" ) for requirement in parsed_requirements: import_or_install(requirement, dry=dry) - if mode == "venv": - parsed_requirements = get_requirements(here / "requirements-wheels.txt") - if not parsed_requirements: - return - for requirement in parsed_requirements: - import_or_install(requirement, dry=dry) - if __name__ == "__main__": full = False @@ -328,7 +321,6 @@ if __name__ == "__main__": # Install dependencies from requirements.txt # if args.requirements or mode == "venv": - install_dependencies(dry=args.dry) if (not args.wheels and mode not in ["colab", "embeded"]) and not full: print_formatted( @@ -336,6 +328,8 @@ if __name__ == "__main__": "italic", color="yellow", ) + + install_dependencies(dry=args.dry) sys.exit() if mode in ["colab", "embeded"]: @@ -349,7 +343,7 @@ if __name__ == "__main__": # - Check the env before proceeding. missing_wheels = False - parsed_requirements = get_requirements(here / "requirements-wheels.txt") + parsed_requirements = get_requirements(here / "reqs.txt") if parsed_requirements: for requirement in parsed_requirements: installed, pip_name, import_name = try_import(requirement) @@ -359,7 +353,7 @@ if __name__ == "__main__": if not missing_wheels: print_formatted( - f"All required wheels are already installed.", "italic", color="green" + f"All requirements are already installed.", "italic", color="green" ) sys.exit() @@ -408,7 +402,7 @@ if __name__ == "__main__": ) wheels_directory.mkdir(exist_ok=True) - + # - Install the wheels for asset in matching_assets: asset_name = asset["name"] asset_download_url = asset["browser_download_url"] @@ -487,3 +481,6 @@ if __name__ == "__main__": print_formatted("Wheels installation completed.", color="green") else: print_formatted("No .whl files found. Nothing to install.", color="yellow") + + # - Install all remainings + install_dependencies(dry=args.dry) diff --git a/requirements.txt b/reqs.txt similarity index 91% rename from requirements.txt rename to reqs.txt index 3fc5e65..2d60329 100644 --- a/requirements.txt +++ b/reqs.txt @@ -12,3 +12,6 @@ protobuf==3.20.2; platform_system == "Windows" gdown @ git+https://github.com/melMass/gdown@main mmdet==3.0.0 facexlib==0.3.0 +insightface==0.7.3 +mmcv==2.0.0 +basicsr==1.4.2 diff --git a/requirements-wheels.txt b/requirements-wheels.txt deleted file mode 100644 index af6449d..0000000 --- a/requirements-wheels.txt +++ /dev/null @@ -1,3 +0,0 @@ -insightface==0.7.3 -mmcv==2.0.0 -basicsr==1.4.2 From 346ff649d50c9f0286ad2243938406fefb62853b Mon Sep 17 00:00:00 2001 From: melMass Date: Sun, 30 Jul 2023 01:41:14 +0200 Subject: [PATCH 13/56] =?UTF-8?q?ci:=20=E2=9C=A8=20individual=20wheels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 36bdfb0..4dfb86d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -99,9 +99,15 @@ jobs: with: path: ${{ env.archive_name }}.zip key: ${{ env.archive_name }} + - name: 📦 Unzip wheels + shell: bash + run: | + mkdir -p wheels + unzip -j ${{ env.archive_name }}.zip "**/*.whl" -d wheels + if: success() - name: ✅ Add wheels to release uses: softprops/action-gh-release@v1 with: tag_name: ${{ inputs.name }} files: | - ${{ env.archive_name }}.zip + wheels/*.whl From ffa1a87b9184df5a3699a6118714b39d359bde4d Mon Sep 17 00:00:00 2001 From: melMass Date: Sun, 30 Jul 2023 02:06:41 +0200 Subject: [PATCH 14/56] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20install=20?= =?UTF-8?q?typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.py b/install.py index 04108e4..656304b 100644 --- a/install.py +++ b/install.py @@ -444,7 +444,7 @@ if __name__ == "__main__": wheel_order_lines = [line.strip() for line in order] whl_files = sorted( whl_files, - key=lambda x: wheel_order_lines.index(x.split("-")[0]), + key=lambda x: wheel_order_lines.index(x.name.split("-")[0]), ) for whl_file in tqdm(whl_files, desc="Installing", unit="package"): From 3dadc119f44fca1029ec4b349d71ce99fb20a4b6 Mon Sep 17 00:00:00 2001 From: melMass Date: Sun, 30 Jul 2023 02:16:12 +0200 Subject: [PATCH 15/56] =?UTF-8?q?chore:=20=F0=9F=9A=A7=20more=20info=20for?= =?UTF-8?q?=20bug=20reports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index de37f06..aec26e0 100644 --- a/__init__.py +++ b/__init__.py @@ -131,15 +131,17 @@ elif web_extensions_root.exists(): shutil.copytree(web_tgt, web_mtb) log.info(f"Successfully copied {web_tgt} to {web_mtb}") - except Exception: + except Exception as e: log.warn( f"Failed to symlink and copy {web_tgt} to {web_mtb}. Please copy the folder manually." ) + log.warn(e) - except Exception: # OSError + except Exception as e: log.warn( f"Failed to create symlink to {web_mtb}. Please copy the folder manually." ) + log.warn(e) else: log.warn( f"Comfy root probably not found automatically, please copy the folder {web_mtb} manually in the web/extensions folder of ComfyUI" From 36d8e6bdb06edab72ccfb686266d2e644a9f028c Mon Sep 17 00:00:00 2001 From: melMass Date: Sun, 30 Jul 2023 02:55:06 +0200 Subject: [PATCH 16/56] =?UTF-8?q?fix:=20=E2=9A=A1=EF=B8=8F=20colab=20insta?= =?UTF-8?q?ll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/install.py b/install.py index 656304b..a2af587 100644 --- a/install.py +++ b/install.py @@ -394,7 +394,9 @@ if __name__ == "__main__": # Download the assets for the given version matching_assets = [ - asset for asset in tag_data["assets"] if current_platform in asset["name"] + asset + for asset in tag_data["assets"] + if current_platform in asset["name"] and asset["name"].endswith("zip") ] if not matching_assets: print_formatted( @@ -474,7 +476,7 @@ if __name__ == "__main__": "-m", "pip", "install", - whl_path.resolve().as_posix(), + whl_path.as_posix(), ] ) From 8e5b7765cc0c6730bd5517ccfd56e817ea39bd3a Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Sun, 30 Jul 2023 17:56:39 +0200 Subject: [PATCH 17/56] =?UTF-8?q?ci:=20=F0=9F=8E=A8=20also=20push=20wheels?= =?UTF-8?q?=5Forder=20to=20releases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I will use it directly from the installer --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4dfb86d..58ce467 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -111,3 +111,4 @@ jobs: tag_name: ${{ inputs.name }} files: | wheels/*.whl + wheels/wheel_order.txt From a22fd01d664276e4cd833ae1326feeece1d1deaf Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Sun, 30 Jul 2023 18:06:34 +0200 Subject: [PATCH 18/56] =?UTF-8?q?ci:=20=F0=9F=8E=A8=20extract=20txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 58ce467..05430d6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -103,7 +103,7 @@ jobs: shell: bash run: | mkdir -p wheels - unzip -j ${{ env.archive_name }}.zip "**/*.whl" -d wheels + unzip -j ${{ env.archive_name }}.zip "**/*.{whl,txt}" -d wheels if: success() - name: ✅ Add wheels to release uses: softprops/action-gh-release@v1 From bbfcb62c398de39058bcb6e18161425059d53e8e Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Sun, 30 Jul 2023 18:09:24 +0200 Subject: [PATCH 19/56] =?UTF-8?q?ci:=20=F0=9F=8E=A8=20no=20brace=20glob?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 05430d6..438f2eb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -103,7 +103,8 @@ jobs: shell: bash run: | mkdir -p wheels - unzip -j ${{ env.archive_name }}.zip "**/*.{whl,txt}" -d wheels + unzip -j ${{ env.archive_name }}.zip "**/*.whl" -d wheels + unzip -j ${{ env.archive_name }}.zip "**/*.txt" -d wheels if: success() - name: ✅ Add wheels to release uses: softprops/action-gh-release@v1 From 7b3afca8179760e35e8a6fbf742080dee13e4fc7 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Mon, 31 Jul 2023 18:50:51 +0200 Subject: [PATCH 20/56] =?UTF-8?q?test:=20=F0=9F=A7=AA=20ci=20for=20comfy?= =?UTF-8?q?=20embedded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test_embedded.yml | 63 +++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/test_embedded.yml diff --git a/.github/workflows/test_embedded.yml b/.github/workflows/test_embedded.yml new file mode 100644 index 0000000..a0c8e44 --- /dev/null +++ b/.github/workflows/test_embedded.yml @@ -0,0 +1,63 @@ +name: 🧪 Test Comfy Portable + +on: + workflow_dispatch: + inputs: + commit_sha: + description: 'The SHA of the commit to checkout' + required: false + default: ${{ github.sha }} + invalidate_cache: + description: 'Whether to invalidate the cache or not' + required: false + default: 'false' +jobs: + install-comfy: + runs-on: windows-latest + env: + repo_name: ${{ github.event.repository.name }} + steps: + - name: ⚠️ Invalidate Cache if Needed + if: ${{ github.event.inputs.invalidate_cache == 'true' }} + run: | + echo "Invalidating Cache..." + rmdir /s /q C:\Users\runner\AppData\Local\Temp\caches + + - name: 🚡 Download and Extract Comfy + run: | + mkdir comfy_temp + curl -L -o comfy_temp/comfyui.7z https://github.com/comfyanonymous/ComfyUI/releases/download/latest/ComfyUI_windows_portable_nvidia_cu118_or_cpu.7z + 7z x comfy_temp/comfyui.7z -o./comfy_temp + + + # mv comfy_temp/ComfyUI_windows_portable/python_embeded . + # mv comfy_temp/ComfyUI_windows_portable/ComfyUI . + # mv comfy_temp/ComfyUI_windows_portable/update . + + mv comfy_temp/ComfyUI_windows_portable . + + - name: 📦 Cache Comfy Environment + id: cache-comfy + uses: actions/cache@v2 + with: + path: ComfyUI_windows_portable + key: ${{ runner.os }}-comfy-env + + - name: ♻️ Checking out comfy_mtb to custom_nodes + uses: actions/checkout@v3 + with: + submodules: 'recursive' + path: ComfyUI_windows_portable/ComfyUI/custom_nodes/${{ env.repo_name }} + ref: ${{ github.event.inputs.commit_sha }} + + - name: 📦 Install mtb nodes + shell: bash + run: | + # run install + export COMFY_PYTHON="ComfyUI_windows_portable/python_embeded/python.exe" + + $COMFY_PYTHON ComfyUI_windows_portable/ComfyUI/custom_nodes/${{ env.repo_name }}/install.py -w + + # check node loading state + cd ComfyUI_windows_portable/ComfyUI/custom_nodes + $COMFY_PYTHON -c "import ${{ env.repo_name }}" From c5bbe83008bb194cbd6ad5e3dc70cb3850b18985 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Mon, 31 Jul 2023 18:57:41 +0200 Subject: [PATCH 21/56] =?UTF-8?q?test:=20=F0=9F=A7=AA=20remove=20sha=20inp?= =?UTF-8?q?ut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test_embedded.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_embedded.yml b/.github/workflows/test_embedded.yml index a0c8e44..26982d5 100644 --- a/.github/workflows/test_embedded.yml +++ b/.github/workflows/test_embedded.yml @@ -3,10 +3,7 @@ name: 🧪 Test Comfy Portable on: workflow_dispatch: inputs: - commit_sha: - description: 'The SHA of the commit to checkout' - required: false - default: ${{ github.sha }} + invalidate_cache: description: 'Whether to invalidate the cache or not' required: false @@ -48,16 +45,15 @@ jobs: with: submodules: 'recursive' path: ComfyUI_windows_portable/ComfyUI/custom_nodes/${{ env.repo_name }} - ref: ${{ github.event.inputs.commit_sha }} - name: 📦 Install mtb nodes shell: bash run: | # run install export COMFY_PYTHON="ComfyUI_windows_portable/python_embeded/python.exe" - - $COMFY_PYTHON ComfyUI_windows_portable/ComfyUI/custom_nodes/${{ env.repo_name }}/install.py -w + cd ComfyUI_windows_portable/ComfyUI/ + $COMFY_PYTHON custom_nodes/${{ env.repo_name }}/install.py -w # check node loading state - cd ComfyUI_windows_portable/ComfyUI/custom_nodes + cd custom_nodes $COMFY_PYTHON -c "import ${{ env.repo_name }}" From 512de6023e55f2cc47516bf44436efe22157273f Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Tue, 1 Aug 2023 03:24:27 +0200 Subject: [PATCH 22/56] =?UTF-8?q?feat:=20=E2=9C=A8=20install=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - removed un-needed dependencies - added a ci to test comfy-embedded - fixed wheel order install --- .github/workflows/package_wheels.yml | 2 +- .github/workflows/release.yml | 10 +- .github/workflows/test_embedded.yml | 39 ++- __init__.py | 2 +- install.py | 393 ++++++++++++++++++--------- nodes/faceenhance.py | 7 +- nodes/faceswap.py | 27 +- reqs.txt | 10 +- scripts/download_models.py | 22 +- utils.py | 37 ++- 10 files changed, 380 insertions(+), 169 deletions(-) diff --git a/.github/workflows/package_wheels.yml b/.github/workflows/package_wheels.yml index 9f68138..3909865 100644 --- a/.github/workflows/package_wheels.yml +++ b/.github/workflows/package_wheels.yml @@ -76,4 +76,4 @@ jobs: uses: actions/cache/save@v3 with: path: ${{ env.archive_name }}.zip - key: ${{ env.archive_name }} + key: ${{ env.archive_name }}-${{ hashFiles('reqs.txt') }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 438f2eb..67d97ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ on: name: description: Release tag / name ? required: true - default: "latest" + default: 'latest' type: string environment: description: Environment to run tests against @@ -27,9 +27,9 @@ jobs: - name: ♻️ Checking out the repository uses: actions/checkout@v3 with: - submodules: "recursive" + submodules: 'recursive' path: ${{ env.repo_name }} - + # - name: 📝 Prepare file with paths to remove # run: | # find ${{ env.repo_name }} -type f -size +10M > .release_ignore @@ -56,7 +56,7 @@ jobs: else echo "No .release_ignore file found. Skipping removal of files and directories." fi - + - name: 📦 Building custom comfy nodes shell: bash run: | @@ -98,7 +98,7 @@ jobs: id: cache with: path: ${{ env.archive_name }}.zip - key: ${{ env.archive_name }} + key: ${{ env.archive_name }}-${{ hashFiles('reqs.txt') }} - name: 📦 Unzip wheels shell: bash run: | diff --git a/.github/workflows/test_embedded.yml b/.github/workflows/test_embedded.yml index 26982d5..31c4c61 100644 --- a/.github/workflows/test_embedded.yml +++ b/.github/workflows/test_embedded.yml @@ -3,7 +3,6 @@ name: 🧪 Test Comfy Portable on: workflow_dispatch: inputs: - invalidate_cache: description: 'Whether to invalidate the cache or not' required: false @@ -14,28 +13,33 @@ jobs: env: repo_name: ${{ github.event.repository.name }} steps: - - name: ⚠️ Invalidate Cache if Needed - if: ${{ github.event.inputs.invalidate_cache == 'true' }} - run: | - echo "Invalidating Cache..." - rmdir /s /q C:\Users\runner\AppData\Local\Temp\caches + - name: ⚡️ Restore Cache if Available + id: cache-comfy + uses: actions/cache/restore@v3 + with: + path: ComfyUI_windows_portable + key: ${{ runner.os }}-comfy-env - name: 🚡 Download and Extract Comfy + id: download-extract-comfy + if: steps.cache-comfy.outputs.cache-hit != 'true' + shell: bash run: | mkdir comfy_temp curl -L -o comfy_temp/comfyui.7z https://github.com/comfyanonymous/ComfyUI/releases/download/latest/ComfyUI_windows_portable_nvidia_cu118_or_cpu.7z + 7z x comfy_temp/comfyui.7z -o./comfy_temp # mv comfy_temp/ComfyUI_windows_portable/python_embeded . # mv comfy_temp/ComfyUI_windows_portable/ComfyUI . # mv comfy_temp/ComfyUI_windows_portable/update . - + ls mv comfy_temp/ComfyUI_windows_portable . - - name: 📦 Cache Comfy Environment - id: cache-comfy - uses: actions/cache@v2 + - name: 💾 Store cache + uses: actions/cache/save@v3 + if: steps.cache-comfy.outputs.cache-hit != 'true' with: path: ComfyUI_windows_portable key: ${{ runner.os }}-comfy-env @@ -50,10 +54,15 @@ jobs: shell: bash run: | # run install - export COMFY_PYTHON="ComfyUI_windows_portable/python_embeded/python.exe" - cd ComfyUI_windows_portable/ComfyUI/ + export COMFY_PYTHON="${GITHUB_WORKSPACE}/ComfyUI_windows_portable/python_embeded/python.exe" + cd "${GITHUB_WORKSPACE}/ComfyUI_windows_portable/ComfyUI/" $COMFY_PYTHON custom_nodes/${{ env.repo_name }}/install.py -w - # check node loading state - cd custom_nodes - $COMFY_PYTHON -c "import ${{ env.repo_name }}" + - name: ⏬ Import mtb_nodes + shell: bash + run: | + export COMFY_PYTHON="${GITHUB_WORKSPACE}/ComfyUI_windows_portable/python_embeded/python.exe" + cd "${GITHUB_WORKSPACE}/ComfyUI_windows_portable/ComfyUI" + $COMFY_PYTHON -s main.py --quick-test-for-ci --cpu + + $COMFY_PYTHON -m pip freeze diff --git a/__init__.py b/__init__.py index aec26e0..0439ac0 100644 --- a/__init__.py +++ b/__init__.py @@ -26,7 +26,7 @@ NODE_CLASS_MAPPINGS = {} NODE_DISPLAY_NAME_MAPPINGS = {} NODE_CLASS_MAPPINGS_DEBUG = {} -__version__ = "0.1.2" +__version__ = "0.1.4" def extract_nodes_from_source(filename): diff --git a/install.py b/install.py index a2af587..604ca65 100644 --- a/install.py +++ b/install.py @@ -1,7 +1,6 @@ import requests import os import ast -import re import argparse import sys import subprocess @@ -9,10 +8,12 @@ from importlib import import_module import platform from pathlib import Path import sys -import zipfile -import shutil import stat - +import threading +import signal +from contextlib import suppress +from queue import Queue, Empty +from contextlib import contextmanager here = Path(__file__).parent executable = sys.executable @@ -27,7 +28,7 @@ elif ".venv" in executable: mode = "venv" -if mode == None: +if mode is None: mode = "unknown" # region ansi @@ -102,12 +103,104 @@ def print_formatted(text, *formats, color=None, background=None, **kwargs): formatted_text = apply_format(text, *formats) formatted_text = apply_color(formatted_text, color, background) file = kwargs.get("file", sys.stdout) - print( - apply_color(apply_format("[mtb install] ", "bold"), color="yellow"), - formatted_text, - file=file, + header = "[mtb install] " + + # Handle console encoding for Unicode characters (utf-8) + encoded_header = header.encode("utf-8", errors="replace").decode("utf-8") + encoded_text = formatted_text.encode("utf-8", errors="replace").decode("utf-8") + + if sys.platform == "win32": + output_text = ( + " " * len(encoded_header) + if kwargs.get("no_header") + else apply_color(apply_format(encoded_header, "bold"), color="yellow") + ) + output_text += encoded_text + "\n" + sys.stdout.buffer.write(output_text.encode("utf-8")) + else: + print( + " " * len(encoded_header) + if kwargs.get("no_header") + else apply_color(apply_format(encoded_header, "bold"), color="yellow"), + encoded_text, + file=file, + ) + + +# endregion + + +# region utils +def enqueue_output(out, queue): + for line in iter(out.readline, b""): + queue.put(line) + out.close() + + +def run_command(cmd): + if isinstance(cmd, str): + shell_cmd = cmd + shell = True + elif isinstance(cmd, list): + shell_cmd = " ".join(cmd) + shell = False + else: + raise ValueError( + "Invalid 'cmd' argument. It must be a string or a list of arguments." + ) + + process = subprocess.Popen( + shell_cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + shell=shell, ) + # Create separate threads to read standard output and standard error streams + stdout_queue = Queue() + stderr_queue = Queue() + stdout_thread = threading.Thread( + target=enqueue_output, args=(process.stdout, stdout_queue) + ) + stderr_thread = threading.Thread( + target=enqueue_output, args=(process.stderr, stderr_queue) + ) + stdout_thread.daemon = True + stderr_thread.daemon = True + stdout_thread.start() + stderr_thread.start() + + interrupted = False + + def signal_handler(signum, frame): + nonlocal interrupted + interrupted = True + print("Command execution interrupted.") + + # Register the signal handler for keyboard interrupts (SIGINT) + signal.signal(signal.SIGINT, signal_handler) + + # Process output from both streams until the process completes or interrupted + while not interrupted and ( + process.poll() is None or not stdout_queue.empty() or not stderr_queue.empty() + ): + with suppress(Empty): + stdout_line = stdout_queue.get_nowait() + if stdout_line.strip() != "": + print(stdout_line.strip()) + with suppress(Empty): + stderr_line = stderr_queue.get_nowait() + if stderr_line.strip() != "": + print(stderr_line.strip()) + return_code = process.returncode + + if return_code == 0 and not interrupted: + print("Command executed successfully!") + else: + if not interrupted: + print(f"Command failed with return code: {return_code}") + # endregion @@ -115,9 +208,7 @@ try: import requirements except ImportError: print_formatted("Installing requirements-parser...", "italic", color="yellow") - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "requirements-parser"] - ) + run_command([sys.executable, "-m", "pip", "install", "requirements-parser"]) import requirements print_formatted("Done.", "italic", color="green") @@ -126,7 +217,7 @@ try: from tqdm import tqdm except ImportError: print_formatted("Installing tqdm...", "italic", color="yellow") - subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "tqdm"]) + run_command([sys.executable, "-m", "pip", "install", "--upgrade", "tqdm"]) from tqdm import tqdm import importlib @@ -141,16 +232,41 @@ pip_map = { def is_pipe(): - try: - mode = os.fstat(0).st_mode - return ( - stat.S_ISFIFO(mode) - or stat.S_ISREG(mode) - or stat.S_ISBLK(mode) - or stat.S_ISSOCK(mode) - ) - except OSError: + if not sys.stdin.isatty(): return False + if sys.platform == "win32": + try: + import msvcrt + + return msvcrt.get_osfhandle(0) != -1 + except ImportError: + return False + else: + try: + mode = os.fstat(0).st_mode + return ( + stat.S_ISFIFO(mode) + or stat.S_ISREG(mode) + or stat.S_ISBLK(mode) + or stat.S_ISSOCK(mode) + ) + except OSError: + return False + + +@contextmanager +def suppress_std(): + with open(os.devnull, "w") as devnull: + old_stdout = sys.stdout + old_stderr = sys.stderr + sys.stdout = devnull + sys.stderr = devnull + + try: + yield + finally: + sys.stdout = old_stdout + sys.stderr = old_stderr # Get the version from __init__.py @@ -211,46 +327,51 @@ def try_import(requirement): installed = False pip_name = dependency - if specs := requirement.specs: - pip_name += "".join(specs[0]) - + pip_spec = "".join(specs[0]) if (specs := requirement.specs) else "" try: - import_module(import_name) + with suppress_std(): + import_module(import_name) print_formatted( - f"Package {pip_name} already installed (import name: '{import_name}').", + f"\t✅ Package {pip_name} already installed (import name: '{import_name}').", "bold", color="green", + no_header=True, ) installed = True except ImportError: - pass + print_formatted( + f"\t⛔ Package {pip_name} is missing (import name: '{import_name}').", + "bold", + color="red", + no_header=True, + ) - return (installed, pip_name, import_name) + return (installed, pip_name, pip_spec, import_name) def import_or_install(requirement, dry=False): - installed, pip_name, import_name = try_import(requirement) + installed, pip_name, pip_spec, import_name = try_import(requirement) + + pip_install_name = pip_name + pip_spec if not installed: print_formatted(f"Installing package {pip_name}...", "italic", color="yellow") if dry: print_formatted( - f"Dry-run: Package {pip_name} would be installed (import name: '{import_name}').", + f"Dry-run: Package {pip_install_name} would be installed (import name: '{import_name}').", color="yellow", ) else: try: - subprocess.check_call( - [sys.executable, "-m", "pip", "install", pip_name] - ) + run_command([sys.executable, "-m", "pip", "install", pip_install_name]) print_formatted( - f"Package {pip_name} installed successfully using pip package name (import name: '{import_name}')", + f"Package {pip_install_name} installed successfully using pip package name (import name: '{import_name}')", "bold", color="green", ) except subprocess.CalledProcessError as e: print_formatted( - f"Failed to install package {pip_name} using pip package name (import name: '{import_name}'). Error: {str(e)}", + f"Failed to install package {pip_install_name} using pip package name (import name: '{import_name}'). Error: {str(e)}", "bold", color="red", ) @@ -279,7 +400,7 @@ if __name__ == "__main__": if not clone_dir.exists(): clone_dir.parent.mkdir(parents=True, exist_ok=True) print_formatted(f"Cloning {url} to {clone_dir}", "italic", color="yellow") - subprocess.check_call(["git", "clone", "--recursive", url, clone_dir]) + run_command(["git", "clone", "--recursive", url, clone_dir.as_posix()]) # os.chdir(clone_dir) here = clone_dir @@ -316,7 +437,7 @@ if __name__ == "__main__": args = parser.parse_args() - wheels_directory = here / "wheels" + # wheels_directory = here / "wheels" print_formatted(f"Detected environment: {apply_color(mode,'cyan')}") # Install dependencies from requirements.txt @@ -335,23 +456,26 @@ if __name__ == "__main__": if mode in ["colab", "embeded"]: print_formatted( f"Downloading and installing release wheels since we are in a Comfy {apply_color(mode,'cyan')} environment", + "italic", + color="yellow", ) if full: print_formatted( - f"Downloading and installing release wheels since no arguments where provided" + f"Downloading and installing release wheels since no arguments where provided", + "italic", + color="yellow", ) # - Check the env before proceeding. - missing_wheels = False + missing_deps = [] parsed_requirements = get_requirements(here / "reqs.txt") if parsed_requirements: for requirement in parsed_requirements: - installed, pip_name, import_name = try_import(requirement) + installed, pip_name, pip_spec, import_name = try_import(requirement) if not installed: - missing_wheels = True - break + missing_deps.append(pip_name.split("-")[0]) - if not missing_wheels: + if len(missing_deps) == 0: print_formatted( f"All requirements are already installed.", "italic", color="green" ) @@ -392,97 +516,120 @@ if __name__ == "__main__": # ) # sys.exit() - # Download the assets for the given version + short_platform = { + "windows": "win_amd64", + "linux": "linux_x86_64", + } matching_assets = [ asset for asset in tag_data["assets"] - if current_platform in asset["name"] and asset["name"].endswith("zip") + if asset["name"].endswith(".whl") + and ( + "any" in asset["name"] or short_platform[current_platform] in asset["name"] + ) ] if not matching_assets: print_formatted( f"Unsupported operating system: {current_platform}", color="yellow" ) - - wheels_directory.mkdir(exist_ok=True) - # - Install the wheels - for asset in matching_assets: - asset_name = asset["name"] - asset_download_url = asset["browser_download_url"] - print_formatted(f"Downloading asset: {asset_name}", color="yellow") - asset_dest = wheels_directory / asset_name - download_file(asset_download_url, asset_dest) - - # - Unzip to wheels dir - whl_files = [] - whl_order = None - with zipfile.ZipFile(asset_dest, "r") as zip_ref: - for item in tqdm(zip_ref.namelist(), desc="Extracting", unit="file"): - if item.endswith(".whl"): - item_basename = os.path.basename(item) - target_path = wheels_directory / item_basename - with zip_ref.open(item) as source, open( - target_path, "wb" - ) as target: - whl_files.append(target_path) - shutil.copyfileobj(source, target) - elif item.endswith("order.txt"): - item_basename = os.path.basename(item) - target_path = wheels_directory / item_basename - with zip_ref.open(item) as source, open( - target_path, "wb" - ) as target: - whl_order = target_path - shutil.copyfileobj(source, target) - + wheel_order_asset = next( + (asset for asset in tag_data["assets"] if asset["name"] == "wheel_order.txt"), + None, + ) + if wheel_order_asset is not None: print_formatted( - f"Wheels extracted for {current_platform} to the '{wheels_directory}' directory.", - "bold", - color="green", + "⚙️ Sorting the release wheels using wheels order", "italic", color="yellow" ) + response = requests.get(wheel_order_asset["browser_download_url"]) + if response.status_code == 200: + wheel_order = [line.strip() for line in response.text.splitlines()] - if whl_files: - if whl_order: - with open(whl_order, "r") as order: - wheel_order_lines = [line.strip() for line in order] - whl_files = sorted( - whl_files, - key=lambda x: wheel_order_lines.index(x.name.split("-")[0]), - ) - - for whl_file in tqdm(whl_files, desc="Installing", unit="package"): - whl_path = wheels_directory / whl_file - - # check if installed + def get_order_index(val): try: - whl_dep = whl_path.name.split("-")[0] - import_name = pip_map.get(whl_dep, whl_dep) - import_module(import_name) - tqdm.write( - f"Package {import_name} already installed, skipping wheel installation.", - ) - continue - except ImportError: - if args.dry: - tqdm.write( - f"Dry-run: Package {whl_path.name} would be installed.", - ) - continue + return wheel_order.index(val) + except ValueError: + return len(wheel_order) - tqdm.write("Installing wheel: " + whl_path.name) - - subprocess.check_call( - [ - sys.executable, - "-m", - "pip", - "install", - whl_path.as_posix(), - ] - ) - - print_formatted("Wheels installation completed.", color="green") + matching_assets = sorted( + matching_assets, + key=lambda x: get_order_index(x["name"].split("-")[0]), + ) else: - print_formatted("No .whl files found. Nothing to install.", color="yellow") + print("Failed to fetch wheel_order.txt. Status code:", response.status_code) - # - Install all remainings - install_dependencies(dry=args.dry) + missing_deps_urls = [] + for whl_file in matching_assets: + # check if installed + whl_dep = whl_file["name"].split("-")[0] + missing_deps_urls.append(whl_file["browser_download_url"]) + + # run_command( + # [ + # sys.executable, + # "-m", + # "pip", + # "install", + # whl_path.as_posix(), + # ] + # ) + # # - Install the wheels + # for asset in matching_assets: + # asset_name = asset["name"] + # asset_download_url = asset["browser_download_url"] + # print_formatted(f"Downloading asset: {asset_name}", color="yellow") + # asset_dest = wheels_directory / asset_name + # download_file(asset_download_url, asset_dest) + + # # - Unzip to wheels dir + # whl_files = [] + # whl_order = None + # with zipfile.ZipFile(asset_dest, "r") as zip_ref: + # for item in tqdm(zip_ref.namelist(), desc="Extracting", unit="file"): + # if item.endswith(".whl"): + # item_basename = os.path.basename(item) + # target_path = wheels_directory / item_basename + # with zip_ref.open(item) as source, open( + # target_path, "wb" + # ) as target: + # whl_files.append(target_path) + # shutil.copyfileobj(source, target) + # elif item.endswith("order.txt"): + # item_basename = os.path.basename(item) + # target_path = wheels_directory / item_basename + # with zip_ref.open(item) as source, open( + # target_path, "wb" + # ) as target: + # whl_order = target_path + # shutil.copyfileobj(source, target) + + # print_formatted( + # f"Wheels extracted for {current_platform} to the '{wheels_directory}' directory.", + # "bold", + # color="green", + # ) + + # print_formatted( + # "\tFound those missing wheels from the release:\n\t\t -" + # + "\n\t\t - ".join(missing_deps_urls), + # "italic", + # color="yellow", + # no_header=True, + # ) + + install_cmd = [sys.executable, "-m", "pip", "install"] + + wheel_cmd = install_cmd + missing_deps_urls + + # - Install all deps + if not args.dry: + run_command(wheel_cmd) + run_command(install_cmd + ["-r", (here / "reqs.txt").as_posix()]) + print_formatted( + "Successfully installed all dependencies.", "italic", color="green" + ) + else: + print_formatted( + f"Would have run the following command:\n\t{apply_color(' '.join(install_cmd),'cyan')}", + "italic", + color="yellow", + ) diff --git a/nodes/faceenhance.py b/nodes/faceenhance.py index e922559..4dafd39 100644 --- a/nodes/faceenhance.py +++ b/nodes/faceenhance.py @@ -4,9 +4,12 @@ import numpy as np import os from pathlib import Path import folder_paths +from ..utils import pil2tensor, np2tensor, tensor2np + from basicsr.utils import imwrite + + from PIL import Image -from ..utils import pil2tensor, tensor2pil, np2tensor, tensor2np import torch from ..log import NullWriter, log from comfy import model_management @@ -28,7 +31,7 @@ class LoadFaceEnhanceModel: @classmethod def get_models(cls): models_path = cls.get_models_root() - + if not models_path.exists(): log.warning(f"No models found at {models_path}") return [] diff --git a/nodes/faceswap.py b/nodes/faceswap.py index bf8c2db..4f0eba9 100644 --- a/nodes/faceswap.py +++ b/nodes/faceswap.py @@ -22,15 +22,19 @@ import comfy.model_management as model_management log = mklog(__name__) + class LoadFaceAnalysisModel: """Loads a face analysis model""" models = [] + @staticmethod def get_models() -> List[str]: models_path = os.path.join(folder_paths.models_dir, "insightface/*") models = glob.glob(models_path) - models = [Path(x).name for x in models if x.endswith(".onnx") or x.endswith(".pth")] + models = [ + Path(x).name for x in models if x.endswith(".onnx") or x.endswith(".pth") + ] return models @classmethod @@ -50,10 +54,12 @@ class LoadFaceAnalysisModel: def load_model(self, faceswap_model: str): face_analyser = insightface.app.FaceAnalysis( - name=faceswap_model, root=os.path.join(folder_paths.models_dir, "insightface") + name=faceswap_model, + root=os.path.join(folder_paths.models_dir, "insightface"), ) return (face_analyser,) + class LoadFaceSwapModel: """Loads a faceswap model""" @@ -140,7 +146,7 @@ class FaceSwap: int(x) for x in faces_index.strip(",").split(",") if x.isnumeric() } sys.stdout = NullWriter() - swapped = swap_face(faceanalysis_model,ref, img, faceswap_model, face_ids) + swapped = swap_face(faceanalysis_model, ref, img, faceswap_model, face_ids) sys.stdout = sys.__stdout__ return pil2tensor(swapped) @@ -164,15 +170,18 @@ class FaceSwap: # region face swap utils -def get_face_single(face_analyser,img_data: np.ndarray, face_index=0, det_size=(640, 640)): - +def get_face_single( + face_analyser, img_data: np.ndarray, face_index=0, det_size=(640, 640) +): face_analyser.prepare(ctx_id=0, det_size=det_size) face = face_analyser.get(img_data) if len(face) == 0 and det_size[0] > 320 and det_size[1] > 320: log.debug("No face ed, trying again with smaller image") det_size_half = (det_size[0] // 2, det_size[1] // 2) - return get_face_single(face_analyser,img_data, face_index=face_index, det_size=det_size_half) + return get_face_single( + face_analyser, img_data, face_index=face_index, det_size=det_size_half + ) try: return sorted(face, key=lambda x: x.bbox[0])[face_index] @@ -195,12 +204,14 @@ def swap_face( if face_swapper_model is not None: cv_source_img = cv2.cvtColor(np.array(source_img), cv2.COLOR_RGB2BGR) cv_target_img = cv2.cvtColor(np.array(target_img), cv2.COLOR_RGB2BGR) - source_face = get_face_single(face_analyser,cv_source_img, face_index=0) + source_face = get_face_single(face_analyser, cv_source_img, face_index=0) if source_face is not None: result = cv_target_img for face_num in faces_index: - target_face = get_face_single(face_analyser,cv_target_img, face_index=face_num) + target_face = get_face_single( + face_analyser, cv_target_img, face_index=face_num + ) if target_face is not None: sys.stdout = NullWriter() result = face_swapper_model.get(result, target_face, source_face) diff --git a/reqs.txt b/reqs.txt index 2d60329..b0c986f 100644 --- a/reqs.txt +++ b/reqs.txt @@ -1,17 +1,11 @@ onnxruntime-gpu==1.15.1 -imageio===2.28.1 qrcode[pil] -numpy==1.23.5 -rembg==2.0.37 +rembg==2.0.50 # on windows non WSL 2.10 is the last version with GPU support -tensorflow<2.11.0; platform_system == "Windows" +tensorflow==2.10.1; platform_system == "Windows" tb-nightly==2.12.0a20230126; platform_system == "Windows" tensorflow; platform_system != "Windows" # the old tf version on windows comes with a breaking protobuf version -protobuf==3.20.2; platform_system == "Windows" -gdown @ git+https://github.com/melMass/gdown@main -mmdet==3.0.0 facexlib==0.3.0 insightface==0.7.3 -mmcv==2.0.0 basicsr==1.4.2 diff --git a/scripts/download_models.py b/scripts/download_models.py index 505ff9c..171bdbd 100644 --- a/scripts/download_models.py +++ b/scripts/download_models.py @@ -2,6 +2,8 @@ import os import requests from rich.console import Console from tqdm import tqdm +import subprocess +import sys try: import folder_paths @@ -30,13 +32,13 @@ models_to_download = { "size": 332, "download_url": [ "https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth", + "https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth" # TODO: provide a way to selectively download models from "packs" # https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth # https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth - # https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth # https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/RestoreFormer.pth ], - "destination": "upscale_models", + "destination": "face_restore", }, "FILM: Frame Interpolation for Large Motion": { "size": 402, @@ -51,7 +53,6 @@ console = Console() from urllib.parse import urlparse from pathlib import Path -import gdown def download_model(download_url, destination): @@ -63,6 +64,21 @@ def download_model(download_url, destination): filename = os.path.basename(urlparse(download_url).path) response = None if "drive.google.com" in download_url: + try: + import gdown + except ImportError: + print("Installing gdown") + subprocess.check_call( + [ + sys.executable, + "-m", + "pip", + "install", + "git+https://github.com/melMass/gdown@main", + ] + ) + import gdown + if "/folders/" in download_url: # download folder try: diff --git a/utils.py b/utils.py index 9bc7788..1152504 100644 --- a/utils.py +++ b/utils.py @@ -3,11 +3,10 @@ import numpy as np import torch from pathlib import Path import sys - -from typing import Union, List -from .log import log +from typing import List +# region MISC Utilities def add_path(path, prepend=False): if isinstance(path, list): for p in path: @@ -24,6 +23,33 @@ def add_path(path, prepend=False): sys.path.append(path) +# todo use the requirements library +reqs_map = { + "onnxruntime": "onnxruntime-gpu==1.15.1", + "basicsr": "basicsr==1.4.2", + "rembg": "rembg==2.0.50", + "qrcode": "qrcode[pil]", +} + + +def import_install(package_name): + from pip._internal import main as pip_main + + try: + __import__(package_name) + except ImportError: + package_spec = reqs_map.get(package_name) + if package_spec is None: + print(f"Installing {package_name}") + package_spec = package_name + + pip_main(["install", package_spec]) + __import__(package_name) + + +# endregion + +# region GLOBAL VARIABLES # Get the absolute path of the parent directory of the current script here = Path(__file__).parent.resolve() @@ -44,8 +70,10 @@ for pth in extern_root.iterdir(): # Add the ComfyUI directory and custom nodes path to the sys.path list add_path(comfy_dir) add_path((comfy_dir / "custom_nodes")) +# endregion +# region TENSOR UTILITIES def tensor2pil(image: torch.Tensor) -> List[Image.Image]: batch_count = 1 if len(image.shape) > 3: @@ -89,3 +117,6 @@ def tensor2np(tensor: torch.Tensor) -> List[np.ndarray]: return out return [np.clip(255.0 * tensor.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)] + + +# endregion From b854a302ce4708d2ad2dac249860308dbdcae5a6 Mon Sep 17 00:00:00 2001 From: melMass Date: Thu, 3 Aug 2023 13:12:56 +0200 Subject: [PATCH 23/56] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20remove=20p?= =?UTF-8?q?ipe=20mode=20from=20the=20install.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I added a `path` argument to mimic what pipe did. --- install.py | 172 ++++++++++++++++++++++++----------------------------- 1 file changed, 77 insertions(+), 95 deletions(-) diff --git a/install.py b/install.py index 604ca65..d994dd8 100644 --- a/install.py +++ b/install.py @@ -31,6 +31,16 @@ elif ".venv" in executable: if mode is None: mode = "unknown" +# - Constants +repo_url = "https://github.com/melmass/comfy_mtb.git" +repo_owner = "melmass" +repo_name = "comfy_mtb" +short_platform = { + "windows": "win_amd64", + "linux": "linux_x86_64", +} +current_platform = platform.system().lower() + # region ansi # ANSI escape sequences for text styling ANSI_FORMATS = { @@ -142,7 +152,11 @@ def run_command(cmd): shell_cmd = cmd shell = True elif isinstance(cmd, list): - shell_cmd = " ".join(cmd) + shell_cmd = "" + for arg in cmd: + if isinstance(arg, Path): + arg = arg.as_posix() + shell_cmd += f"{arg} " shell = False else: raise ValueError( @@ -377,6 +391,29 @@ def import_or_install(requirement, dry=False): ) +def get_github_assets(tag=None): + if tag: + tag_url = ( + f"https://api.github.com/repos/{repo_owner}/{repo_name}/releases/tags/{tag}" + ) + else: + tag_url = ( + f"https://api.github.com/repos/{repo_owner}/{repo_name}/releases/latest" + ) + response = requests.get(tag_url) + if response.status_code == 404: + # print_formatted( + # f"Tag version '{apply_color(version,'cyan')}' not found for {owner}/{repo} repository." + # ) + print_formatted("Error retrieving the release assets.", color="red") + sys.exit() + + tag_data = response.json() + tag_name = tag_data["name"] + + return tag_data, tag_name + + # Install dependencies from requirements.txt def install_dependencies(dry=False): parsed_requirements = get_requirements(here / "reqs.txt") @@ -392,20 +429,6 @@ def install_dependencies(dry=False): if __name__ == "__main__": full = False - if is_pipe(): - print_formatted("Pipe detected, full install...", color="green") - # we clone our repo - url = "https://github.com/melmass/comfy_mtb.git" - clone_dir = here / "custom_nodes" / "comfy_mtb" - if not clone_dir.exists(): - clone_dir.parent.mkdir(parents=True, exist_ok=True) - print_formatted(f"Cloning {url} to {clone_dir}", "italic", color="yellow") - run_command(["git", "clone", "--recursive", url, clone_dir.as_posix()]) - - # os.chdir(clone_dir) - here = clone_dir - full = True - if len(sys.argv) == 1: print_formatted( "No arguments provided, doing a full install/update...", @@ -416,7 +439,13 @@ if __name__ == "__main__": full = True # Parse command-line arguments - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser(description="Comfy_mtb install script") + parser.add_argument( + "--path", + "-p", + type=str, + help="Path to clone the repository to (i.e the absolute path to ComfyUI/custom_nodes)", + ) parser.add_argument( "--wheels", "-w", action="store_true", help="Install wheel dependencies" ) @@ -429,6 +458,7 @@ if __name__ == "__main__": help="Print what will happen without doing it (still making requests to the GH Api)", ) + # - keep # parser.add_argument( # "--version", # default=get_local_version(), @@ -440,6 +470,28 @@ if __name__ == "__main__": # wheels_directory = here / "wheels" print_formatted(f"Detected environment: {apply_color(mode,'cyan')}") + if args.path: + clone_dir = Path(args.path) + if not clone_dir.exists(): + print_formatted( + f"The path provided does not exist on disk... It must be pointing to ComfyUI's custom_nodes directory" + ) + sys.exit() + + else: + repo_dir = clone_dir / repo_name + if not repo_dir.exists(): + print_formatted(f"Cloning to {repo_dir}...", "italic", color="yellow") + run_command(["git", "clone", "--recursive", repo_url, repo_dir]) + else: + print_formatted( + f"Directory {repo_dir} already exists, we will update it..." + ) + run_command(["git", "pull", "-C", repo_dir]) + # os.chdir(clone_dir) + here = clone_dir + full = True + # Install dependencies from requirements.txt # if args.requirements or mode == "venv": @@ -477,29 +529,15 @@ if __name__ == "__main__": if len(missing_deps) == 0: print_formatted( - f"All requirements are already installed.", "italic", color="green" + f"All requirements are already installed. Enjoy 🚀", "italic", color="green" ) sys.exit() - # Fetch the JSON data from the GitHub API URL - owner = "melmass" - repo = "comfy_mtb" + # - Get the tag version from the GitHub API + tag_data, tag_name = get_github_assets(tag=None) + + # - keep # version = args.version - current_platform = platform.system().lower() - - # Get the tag version from the GitHub API - tag_url = f"https://api.github.com/repos/{owner}/{repo}/releases/latest" - response = requests.get(tag_url) - if response.status_code == 404: - # print_formatted( - # f"Tag version '{apply_color(version,'cyan')}' not found for {owner}/{repo} repository." - # ) - print_formatted("Error retrieving the release assets.", color="red") - sys.exit() - - tag_data = response.json() - tag_name = tag_data["name"] - # # Compare the local and tag versions # if version and tag_name: # if re.match(r"v?(\d+(\.\d+)+)", version) and re.match( @@ -516,10 +554,6 @@ if __name__ == "__main__": # ) # sys.exit() - short_platform = { - "windows": "win_amd64", - "linux": "linux_x86_64", - } matching_assets = [ asset for asset in tag_data["assets"] @@ -560,72 +594,20 @@ if __name__ == "__main__": missing_deps_urls = [] for whl_file in matching_assets: # check if installed - whl_dep = whl_file["name"].split("-")[0] missing_deps_urls.append(whl_file["browser_download_url"]) - # run_command( - # [ - # sys.executable, - # "-m", - # "pip", - # "install", - # whl_path.as_posix(), - # ] - # ) - # # - Install the wheels - # for asset in matching_assets: - # asset_name = asset["name"] - # asset_download_url = asset["browser_download_url"] - # print_formatted(f"Downloading asset: {asset_name}", color="yellow") - # asset_dest = wheels_directory / asset_name - # download_file(asset_download_url, asset_dest) - - # # - Unzip to wheels dir - # whl_files = [] - # whl_order = None - # with zipfile.ZipFile(asset_dest, "r") as zip_ref: - # for item in tqdm(zip_ref.namelist(), desc="Extracting", unit="file"): - # if item.endswith(".whl"): - # item_basename = os.path.basename(item) - # target_path = wheels_directory / item_basename - # with zip_ref.open(item) as source, open( - # target_path, "wb" - # ) as target: - # whl_files.append(target_path) - # shutil.copyfileobj(source, target) - # elif item.endswith("order.txt"): - # item_basename = os.path.basename(item) - # target_path = wheels_directory / item_basename - # with zip_ref.open(item) as source, open( - # target_path, "wb" - # ) as target: - # whl_order = target_path - # shutil.copyfileobj(source, target) - - # print_formatted( - # f"Wheels extracted for {current_platform} to the '{wheels_directory}' directory.", - # "bold", - # color="green", - # ) - - # print_formatted( - # "\tFound those missing wheels from the release:\n\t\t -" - # + "\n\t\t - ".join(missing_deps_urls), - # "italic", - # color="yellow", - # no_header=True, - # ) - install_cmd = [sys.executable, "-m", "pip", "install"] wheel_cmd = install_cmd + missing_deps_urls # - Install all deps if not args.dry: + # - first install the ordered wheel files run_command(wheel_cmd) - run_command(install_cmd + ["-r", (here / "reqs.txt").as_posix()]) + # - then install the rest of the deps + run_command(install_cmd + ["-r", (here / "reqs.txt")]) print_formatted( - "Successfully installed all dependencies.", "italic", color="green" + "✅ Successfully installed all dependencies.", "italic", color="green" ) else: print_formatted( From 2ff04672daff773d52e1552dca1bf616bc32daa6 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Thu, 3 Aug 2023 14:22:26 +0200 Subject: [PATCH 24/56] =?UTF-8?q?ci:=20=E2=9C=A8=20use=20the=20same=20cwd?= =?UTF-8?q?=20as=20manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test_embedded.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_embedded.yml b/.github/workflows/test_embedded.yml index 31c4c61..781c5ca 100644 --- a/.github/workflows/test_embedded.yml +++ b/.github/workflows/test_embedded.yml @@ -55,8 +55,8 @@ jobs: run: | # run install export COMFY_PYTHON="${GITHUB_WORKSPACE}/ComfyUI_windows_portable/python_embeded/python.exe" - cd "${GITHUB_WORKSPACE}/ComfyUI_windows_portable/ComfyUI/" - $COMFY_PYTHON custom_nodes/${{ env.repo_name }}/install.py -w + cd "${GITHUB_WORKSPACE}/ComfyUI_windows_portable/ComfyUI/custom_nodes" + $COMFY_PYTHON ${{ env.repo_name }}/install.py -w - name: ⏬ Import mtb_nodes shell: bash From d4f791d7a14ba9cb8abd7c95ba70b081fee5fb7c Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Thu, 3 Aug 2023 14:26:02 +0200 Subject: [PATCH 25/56] =?UTF-8?q?ci:=20=E2=9C=A8=20remove=20unused=20input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test_embedded.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/test_embedded.yml b/.github/workflows/test_embedded.yml index 781c5ca..c28f3d4 100644 --- a/.github/workflows/test_embedded.yml +++ b/.github/workflows/test_embedded.yml @@ -1,12 +1,6 @@ name: 🧪 Test Comfy Portable -on: - workflow_dispatch: - inputs: - invalidate_cache: - description: 'Whether to invalidate the cache or not' - required: false - default: 'false' +on: workflow_dispatch jobs: install-comfy: runs-on: windows-latest From e74314b04eb218c140482ccf704b61af06db3f4d Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Thu, 3 Aug 2023 14:28:38 +0200 Subject: [PATCH 26/56] =?UTF-8?q?docs:=20=F0=9F=93=9D=20add=20action=20bad?= =?UTF-8?q?ge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 2dc6e55..6449202 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # MTB Nodes + +![embedded test](https://github.com/melMass/comfy_mtb/actions/workflows/test_embedded.yml/badge.svg) + **Translated Readme (using DeepTranslate, PRs are welcome)**: From 098d74a3cd8449d836569a074995e20d775c6728 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Thu, 3 Aug 2023 14:33:15 +0200 Subject: [PATCH 27/56] =?UTF-8?q?docs:=20=F0=9F=93=9D=20link=20the=20actua?= =?UTF-8?q?l=20action=20instead=20of=20badge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6449202..aa444b7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MTB Nodes -![embedded test](https://github.com/melMass/comfy_mtb/actions/workflows/test_embedded.yml/badge.svg) +[![embedded test](https://github.com/melMass/comfy_mtb/actions/workflows/test_embedded.yml/badge.svg)](https://github.com/melMass/comfy_mtb/actions/workflows/test_embedded.yml) From 3d5075fea2e219a179271c9810017c7e38bff6cc Mon Sep 17 00:00:00 2001 From: melMass Date: Fri, 4 Aug 2023 14:44:52 +0200 Subject: [PATCH 28/56] =?UTF-8?q?fix:=20=F0=9F=90=9B=20shell=20command=20b?= =?UTF-8?q?ug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we always build a string shell should always be true --- install.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/install.py b/install.py index d994dd8..cc756dd 100644 --- a/install.py +++ b/install.py @@ -150,14 +150,12 @@ def enqueue_output(out, queue): def run_command(cmd): if isinstance(cmd, str): shell_cmd = cmd - shell = True elif isinstance(cmd, list): shell_cmd = "" for arg in cmd: if isinstance(arg, Path): arg = arg.as_posix() shell_cmd += f"{arg} " - shell = False else: raise ValueError( "Invalid 'cmd' argument. It must be a string or a list of arguments." @@ -168,7 +166,7 @@ def run_command(cmd): stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, - shell=shell, + shell=True, ) # Create separate threads to read standard output and standard error streams From cfb3b237cf64b512414a17f71e6d89c3355aa8ef Mon Sep 17 00:00:00 2001 From: melMass Date: Sat, 5 Aug 2023 13:08:18 +0200 Subject: [PATCH 29/56] =?UTF-8?q?revertible:=20=F0=9F=92=84=20use=20BOOLEA?= =?UTF-8?q?N=20instead=20of=20BOOL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since this commit: https://github.com/comfyanonymous/ComfyUI/commit/9534f0f8a5a026654492da378f84d2cdc589ed01 Input <-> widget is possible on booleans. Locally I edited it but forgot about it not being in comfy This commit is reversable since I'm not yet sure of all the impacts --- .../03-animation_builder-condition-lerp.json | 1249 +---------------- examples/04-animation_builder-deforum.json | 1190 +--------------- nodes/animation.py | 2 +- nodes/deep_bump.py | 2 +- nodes/faceenhance.py | 6 +- nodes/faceswap.py | 5 +- nodes/fun.py | 2 +- nodes/graph_utils.py | 2 +- nodes/image_interpolation.py | 4 +- nodes/image_processing.py | 6 +- nodes/io.py | 3 +- nodes/mask.py | 4 +- nodes/number.py | 2 +- web/mtb_widgets.js | 111 +- 14 files changed, 21 insertions(+), 2567 deletions(-) diff --git a/examples/03-animation_builder-condition-lerp.json b/examples/03-animation_builder-condition-lerp.json index 7262e17..531e312 100644 --- a/examples/03-animation_builder-condition-lerp.json +++ b/examples/03-animation_builder-condition-lerp.json @@ -1,1248 +1 @@ -{ - "last_node_id": 82, - "last_link_id": 171, - "nodes": [ - { - "id": 59, - "type": "Reroute", - "pos": [ - -150.35178124999982, - 644.4360633544919 - ], - "size": [ - 75, - 26 - ], - "flags": {}, - "order": 13, - "mode": 0, - "inputs": [ - { - "name": "", - "type": "*", - "link": 124 - } - ], - "outputs": [ - { - "name": "", - "type": "VAE", - "links": [ - 139 - ], - "slot_index": 0 - } - ], - "properties": { - "showOutputText": false, - "horizontal": false - } - }, - { - "id": 56, - "type": "Reroute", - "pos": [ - -1580.8297949218763, - 644.7740239257807 - ], - "size": [ - 75, - 26 - ], - "flags": {}, - "order": 7, - "mode": 0, - "inputs": [ - { - "name": "", - "type": "*", - "link": 117 - } - ], - "outputs": [ - { - "name": "", - "type": "VAE", - "links": [ - 124 - ] - } - ], - "properties": { - "showOutputText": false, - "horizontal": false - } - }, - { - "id": 57, - "type": "Reroute", - "pos": [ - -673.8297949218747, - -185.22597607421872 - ], - "size": [ - 75, - 26 - ], - "flags": {}, - "order": 10, - "mode": 0, - "inputs": [ - { - "name": "", - "type": "*", - "link": 135 - } - ], - "outputs": [ - { - "name": "", - "type": "MODEL", - "links": [ - 120 - ], - "slot_index": 0 - } - ], - "properties": { - "showOutputText": false, - "horizontal": false - } - }, - { - "id": 65, - "type": "Reroute", - "pos": [ - -1512.8297949218763, - -181.22597607421872 - ], - "size": [ - 75, - 26 - ], - "flags": {}, - "order": 5, - "mode": 0, - "inputs": [ - { - "name": "", - "type": "*", - "link": 134 - } - ], - "outputs": [ - { - "name": "", - "type": "MODEL", - "links": [ - 135 - ] - } - ], - "properties": { - "showOutputText": false, - "horizontal": false - } - }, - { - "id": 16, - "type": "CheckpointLoaderSimple", - "pos": [ - -2000.8297949218756, - 192.77402392578128 - ], - "size": [ - 315, - 98 - ], - "flags": {}, - "order": 0, - "mode": 0, - "outputs": [ - { - "name": "MODEL", - "type": "MODEL", - "links": [ - 134 - ], - "slot_index": 0 - }, - { - "name": "CLIP", - "type": "CLIP", - "links": [ - 116 - ], - "slot_index": 1 - }, - { - "name": "VAE", - "type": "VAE", - "links": [ - 117 - ], - "slot_index": 2 - } - ], - "properties": { - "Node name for S&R": "CheckpointLoaderSimple" - }, - "widgets_values": [ - "revAnimated_v122.safetensors" - ] - }, - { - "id": 19, - "type": "CLIPSetLastLayer", - "pos": [ - -1597, - 209 - ], - "size": [ - 315, - 58 - ], - "flags": {}, - "order": 6, - "mode": 0, - "inputs": [ - { - "name": "clip", - "type": "CLIP", - "link": 116 - } - ], - "outputs": [ - { - "name": "CLIP", - "type": "CLIP", - "links": [ - 28, - 29, - 149 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "CLIPSetLastLayer" - }, - "widgets_values": [ - -2 - ] - }, - { - "id": 7, - "type": "CLIPTextEncode", - "pos": [ - -839, - 335 - ], - "size": [ - 210, - 54 - ], - "flags": {}, - "order": 11, - "mode": 0, - "inputs": [ - { - "name": "clip", - "type": "CLIP", - "link": 29 - }, - { - "name": "text", - "type": "STRING", - "link": 163, - "widget": { - "name": "text", - "config": [ - "STRING", - { - "multiline": true - } - ] - }, - "slot_index": 1 - } - ], - "outputs": [ - { - "name": "CONDITIONING", - "type": "CONDITIONING", - "links": [ - 6 - ], - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "CLIPTextEncode" - }, - "widgets_values": [ - "worst quality, hands, embedding:EasyNegative," - ] - }, - { - "id": 5, - "type": "EmptyLatentImage", - "pos": [ - -969, - 484 - ], - "size": [ - 315, - 106 - ], - "flags": {}, - "order": 1, - "mode": 0, - "outputs": [ - { - "name": "LATENT", - "type": "LATENT", - "links": [ - 2 - ], - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "EmptyLatentImage" - }, - "widgets_values": [ - 768, - 512, - 1 - ] - }, - { - "id": 80, - "type": "Text box", - "pos": [ - -1397, - 356 - ], - "size": [ - 294, - 93.11674499511719 - ], - "flags": {}, - "order": 2, - "mode": 0, - "outputs": [ - { - "name": "STRING", - "type": "STRING", - "links": [ - 163 - ], - "shape": 3, - "slot_index": 0 - } - ], - "title": "❌Mel Negatives (general) (Negative)", - "properties": { - "Node name for S&R": "Text box" - }, - "widgets_values": [ - "embedding:EasyNegative, embedding:EasyNegativeV2, watermark, text, deformed" - ] - }, - { - "id": 72, - "type": "ConditioningAverage ", - "pos": [ - -960, - 2 - ], - "size": [ - 380.4000244140625, - 78 - ], - "flags": {}, - "order": 16, - "mode": 0, - "inputs": [ - { - "name": "conditioning_to", - "type": "CONDITIONING", - "link": 151 - }, - { - "name": "conditioning_from", - "type": "CONDITIONING", - "link": 152, - "slot_index": 1 - }, - { - "name": "conditioning_to_strength", - "type": "FLOAT", - "link": 154, - "widget": { - "name": "conditioning_to_strength", - "config": [ - "FLOAT", - { - "default": 1, - "min": 0, - "max": 1, - "step": 0.01 - } - ] - }, - "slot_index": 2 - } - ], - "outputs": [ - { - "name": "CONDITIONING", - "type": "CONDITIONING", - "links": [ - 153 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "ConditioningAverage " - }, - "widgets_values": [ - 1 - ] - }, - { - "id": 6, - "type": "CLIPTextEncode", - "pos": [ - -1261, - -46 - ], - "size": [ - 210, - 54 - ], - "flags": {}, - "order": 14, - "mode": 0, - "inputs": [ - { - "name": "clip", - "type": "CLIP", - "link": 28 - }, - { - "name": "text", - "type": "STRING", - "link": 145, - "widget": { - "name": "text", - "config": [ - "STRING", - { - "multiline": true - } - ] - }, - "slot_index": 1 - } - ], - "outputs": [ - { - "name": "CONDITIONING", - "type": "CONDITIONING", - "links": [ - 151 - ], - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "CLIPTextEncode" - }, - "widgets_values": [ - "A majestic Lion, fur in the wind, (smirk smile)" - ] - }, - { - "id": 70, - "type": "CLIPTextEncode", - "pos": [ - -1245, - 87 - ], - "size": [ - 210, - 54 - ], - "flags": {}, - "order": 12, - "mode": 0, - "inputs": [ - { - "name": "clip", - "type": "CLIP", - "link": 149, - "slot_index": 0 - }, - { - "name": "text", - "type": "STRING", - "link": 150, - "widget": { - "name": "text", - "config": [ - "STRING", - { - "multiline": true - } - ] - }, - "slot_index": 1 - } - ], - "outputs": [ - { - "name": "CONDITIONING", - "type": "CONDITIONING", - "links": [ - 152 - ], - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "CLIPTextEncode" - }, - "widgets_values": [ - "A majestic Lion, fur in the wind, (smirk smile)" - ] - }, - { - "id": 69, - "type": "String Replace (mtb)", - "pos": [ - -1560, - -70 - ], - "size": [ - 210, - 82 - ], - "flags": {}, - "order": 8, - "mode": 0, - "inputs": [ - { - "name": "string", - "type": "STRING", - "link": 141 - } - ], - "outputs": [ - { - "name": "STRING", - "type": "STRING", - "links": [ - 145 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "String Replace (mtb)" - }, - "widgets_values": [ - "blue", - "yellow" - ], - "color": "#432", - "bgcolor": "#653" - }, - { - "id": 68, - "type": "Text box", - "pos": [ - -1950, - 10 - ], - "size": [ - 217.2119140625, - 122.18632507324219 - ], - "flags": {}, - "order": 3, - "mode": 0, - "outputs": [ - { - "name": "STRING", - "type": "STRING", - "links": [ - 141, - 150 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "Text box" - }, - "widgets_values": [ - "A cinematic shot of a blue car, high speed, smoke whisps in the air, (at night), blue neon lighting" - ], - "color": "#432", - "bgcolor": "#653" - }, - { - "id": 3, - "type": "KSampler", - "pos": [ - -483, - -21 - ], - "size": [ - 315, - 474 - ], - "flags": {}, - "order": 19, - "mode": 0, - "inputs": [ - { - "name": "model", - "type": "MODEL", - "link": 120 - }, - { - "name": "positive", - "type": "CONDITIONING", - "link": 153 - }, - { - "name": "negative", - "type": "CONDITIONING", - "link": 6 - }, - { - "name": "latent_image", - "type": "LATENT", - "link": 2 - } - ], - "outputs": [ - { - "name": "LATENT", - "type": "LATENT", - "links": [ - 138 - ], - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "KSampler" - }, - "widgets_values": [ - 5428233522, - "fixed", - 45, - 8, - "euler_ancestral", - "simple", - 1 - ] - }, - { - "id": 66, - "type": "VAEDecodeTiled", - "pos": [ - 197, - -20 - ], - "size": [ - 210, - 46 - ], - "flags": { - "collapsed": false - }, - "order": 20, - "mode": 0, - "inputs": [ - { - "name": "samples", - "type": "LATENT", - "link": 138 - }, - { - "name": "vae", - "type": "VAE", - "link": 139, - "slot_index": 1 - } - ], - "outputs": [ - { - "name": "IMAGE", - "type": "IMAGE", - "links": [ - 161 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "VAEDecodeTiled" - } - }, - { - "id": 78, - "type": "SaveImage", - "pos": [ - 565, - -18 - ], - "size": [ - 315, - 270 - ], - "flags": {}, - "order": 21, - "mode": 0, - "inputs": [ - { - "name": "images", - "type": "IMAGE", - "link": 161 - } - ], - "properties": {}, - "widgets_values": [ - "mtb_demo-conditional_blend" - ] - }, - { - "id": 81, - "type": "Get Batch From History (mtb)", - "pos": [ - -625, - 848 - ], - "size": [ - 235.1999969482422, - 118 - ], - "flags": {}, - "order": 15, - "mode": 0, - "inputs": [ - { - "name": "passthrough_image", - "type": "IMAGE", - "link": null - }, - { - "name": "count", - "type": "INT", - "link": 171, - "widget": { - "name": "count", - "config": [ - "INT", - { - "default": 1, - "min": 0 - } - ] - }, - "slot_index": 2 - }, - { - "name": "enable", - "type": "BOOL", - "link": 168, - "widget": { - "name": "enable", - "config": [ - "BOOL", - { - "default": true - } - ] - }, - "slot_index": 2 - } - ], - "outputs": [ - { - "name": "i", - "type": "IMAGE", - "links": [ - 166, - 167 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "Get Batch From History (mtb)" - }, - "widgets_values": [ - true, - 24, - 0 - ] - }, - { - "id": 77, - "type": "Export To Prores (mtb)", - "pos": [ - -111, - 849 - ], - "size": [ - 315, - 82 - ], - "flags": {}, - "order": 17, - "mode": 0, - "inputs": [ - { - "name": "images", - "type": "IMAGE", - "link": 166, - "slot_index": 0 - } - ], - "outputs": [ - { - "name": "VIDEO", - "type": "VIDEO", - "links": null, - "shape": 3 - } - ], - "properties": { - "Node name for S&R": "Export To Prores (mtb)" - }, - "widgets_values": [ - 12, - "export" - ] - }, - { - "id": 79, - "type": "Save Gif (mtb)", - "pos": [ - -104, - 1000 - ], - "size": [ - 210, - 356 - ], - "flags": {}, - "order": 18, - "mode": 0, - "inputs": [ - { - "name": "image", - "type": "IMAGE", - "link": 167 - }, - { - "name": "pingpong", - "type": "BOOL", - "link": null - } - ], - "properties": { - "Node name for S&R": "Save Gif (mtb)" - }, - "widgets_values": [ - 12, - 1, - true, - "/view?filename=03031ebda0.gif&subfolder=&type=output" - ] - }, - { - "id": 73, - "type": "Animation Builder (mtb)", - "pos": [ - -1285, - 831 - ], - "size": [ - 211.60000610351562, - 294 - ], - "flags": {}, - "order": 9, - "mode": 0, - "inputs": [ - { - "name": "total_frames", - "type": "INT", - "link": 170, - "widget": { - "name": "total_frames", - "config": [ - "INT", - { - "default": 100, - "min": 0 - } - ] - }, - "slot_index": 0 - } - ], - "outputs": [ - { - "name": "frame", - "type": "INT", - "links": null, - "shape": 3, - "slot_index": 0 - }, - { - "name": "0-1 (scaled)", - "type": "FLOAT", - "links": [ - 154 - ], - "shape": 3, - "slot_index": 1 - }, - { - "name": "count", - "type": "INT", - "links": null, - "shape": 3 - }, - { - "name": "loop_ended", - "type": "BOOL", - "links": [ - 168 - ], - "shape": 3, - "slot_index": 3 - } - ], - "properties": { - "Node name for S&R": "Animation Builder (mtb)" - }, - "widgets_values": [ - 24, - 1, - 1, - 0, - 0, - "Idle", - "Iteration: Idle", - "reset", - "queue" - ], - "color": "#232", - "bgcolor": "#353", - "shape": 1 - }, - { - "id": 82, - "type": "PrimitiveNode", - "pos": [ - -1663, - 1205 - ], - "size": [ - 210, - 82 - ], - "flags": {}, - "order": 4, - "mode": 0, - "outputs": [ - { - "name": "INT", - "type": "INT", - "links": [ - 170, - 171 - ], - "widget": { - "name": "total_frames", - "config": [ - "INT", - { - "default": 100, - "min": 0 - } - ] - }, - "slot_index": 0 - } - ], - "title": "total_frames", - "properties": {}, - "widgets_values": [ - 24, - "fixed" - ] - } - ], - "links": [ - [ - 2, - 5, - 0, - 3, - 3, - "LATENT" - ], - [ - 6, - 7, - 0, - 3, - 2, - "CONDITIONING" - ], - [ - 28, - 19, - 0, - 6, - 0, - "CLIP" - ], - [ - 29, - 19, - 0, - 7, - 0, - "CLIP" - ], - [ - 116, - 16, - 1, - 19, - 0, - "CLIP" - ], - [ - 117, - 16, - 2, - 56, - 0, - "*" - ], - [ - 120, - 57, - 0, - 3, - 0, - "MODEL" - ], - [ - 124, - 56, - 0, - 59, - 0, - "*" - ], - [ - 134, - 16, - 0, - 65, - 0, - "*" - ], - [ - 135, - 65, - 0, - 57, - 0, - "*" - ], - [ - 138, - 3, - 0, - 66, - 0, - "LATENT" - ], - [ - 139, - 59, - 0, - 66, - 1, - "VAE" - ], - [ - 141, - 68, - 0, - 69, - 0, - "STRING" - ], - [ - 145, - 69, - 0, - 6, - 1, - "STRING" - ], - [ - 149, - 19, - 0, - 70, - 0, - "CLIP" - ], - [ - 150, - 68, - 0, - 70, - 1, - "STRING" - ], - [ - 151, - 6, - 0, - 72, - 0, - "CONDITIONING" - ], - [ - 152, - 70, - 0, - 72, - 1, - "CONDITIONING" - ], - [ - 153, - 72, - 0, - 3, - 1, - "CONDITIONING" - ], - [ - 154, - 73, - 1, - 72, - 2, - "FLOAT" - ], - [ - 161, - 66, - 0, - 78, - 0, - "IMAGE" - ], - [ - 163, - 80, - 0, - 7, - 1, - "STRING" - ], - [ - 166, - 81, - 0, - 77, - 0, - "IMAGE" - ], - [ - 167, - 81, - 0, - 79, - 0, - "IMAGE" - ], - [ - 168, - 73, - 3, - 81, - 2, - "BOOL" - ], - [ - 170, - 82, - 0, - 73, - 0, - "INT" - ], - [ - 171, - 82, - 0, - 81, - 1, - "INT" - ] - ], - "groups": [ - { - "title": "Txt2Img", - "bounding": [ - -2061, - -234, - 1932, - 973 - ], - "color": "#a1309b", - "locked": false - }, - { - "title": "Save Intermediate Image", - "bounding": [ - 150, - -116, - 303, - 213 - ], - "color": "#3f789e", - "locked": false - } - ], - "config": {}, - "extra": {}, - "version": 0.4 -} \ No newline at end of file +{"last_node_id":82,"last_link_id":171,"nodes":[{"id":59,"type":"Reroute","pos":[-150.35178124999982,644.4360633544919],"size":[75,26],"flags":{},"order":13,"mode":0,"inputs":[{"name":"","type":"*","link":124}],"outputs":[{"name":"","type":"VAE","links":[139],"slot_index":0}],"properties":{"showOutputText":false,"horizontal":false}},{"id":56,"type":"Reroute","pos":[-1580.8297949218763,644.7740239257807],"size":[75,26],"flags":{},"order":7,"mode":0,"inputs":[{"name":"","type":"*","link":117}],"outputs":[{"name":"","type":"VAE","links":[124]}],"properties":{"showOutputText":false,"horizontal":false}},{"id":57,"type":"Reroute","pos":[-673.8297949218747,-185.22597607421872],"size":[75,26],"flags":{},"order":10,"mode":0,"inputs":[{"name":"","type":"*","link":135}],"outputs":[{"name":"","type":"MODEL","links":[120],"slot_index":0}],"properties":{"showOutputText":false,"horizontal":false}},{"id":65,"type":"Reroute","pos":[-1512.8297949218763,-181.22597607421872],"size":[75,26],"flags":{},"order":5,"mode":0,"inputs":[{"name":"","type":"*","link":134}],"outputs":[{"name":"","type":"MODEL","links":[135]}],"properties":{"showOutputText":false,"horizontal":false}},{"id":16,"type":"CheckpointLoaderSimple","pos":[-2000.8297949218756,192.77402392578128],"size":[315,98],"flags":{},"order":0,"mode":0,"outputs":[{"name":"MODEL","type":"MODEL","links":[134],"slot_index":0},{"name":"CLIP","type":"CLIP","links":[116],"slot_index":1},{"name":"VAE","type":"VAE","links":[117],"slot_index":2}],"properties":{"Node name for S&R":"CheckpointLoaderSimple"},"widgets_values":["revAnimated_v122.safetensors"]},{"id":19,"type":"CLIPSetLastLayer","pos":[-1597,209],"size":[315,58],"flags":{},"order":6,"mode":0,"inputs":[{"name":"clip","type":"CLIP","link":116}],"outputs":[{"name":"CLIP","type":"CLIP","links":[28,29,149],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"CLIPSetLastLayer"},"widgets_values":[-2]},{"id":7,"type":"CLIPTextEncode","pos":[-839,335],"size":[210,54],"flags":{},"order":11,"mode":0,"inputs":[{"name":"clip","type":"CLIP","link":29},{"name":"text","type":"STRING","link":163,"widget":{"name":"text","config":["STRING",{"multiline":true}]},"slot_index":1}],"outputs":[{"name":"CONDITIONING","type":"CONDITIONING","links":[6],"slot_index":0}],"properties":{"Node name for S&R":"CLIPTextEncode"},"widgets_values":["worst quality, hands, embedding:EasyNegative,"]},{"id":5,"type":"EmptyLatentImage","pos":[-969,484],"size":[315,106],"flags":{},"order":1,"mode":0,"outputs":[{"name":"LATENT","type":"LATENT","links":[2],"slot_index":0}],"properties":{"Node name for S&R":"EmptyLatentImage"},"widgets_values":[768,512,1]},{"id":80,"type":"Text box","pos":[-1397,356],"size":[294,93.11674499511719],"flags":{},"order":2,"mode":0,"outputs":[{"name":"STRING","type":"STRING","links":[163],"shape":3,"slot_index":0}],"title":"❌Mel Negatives (general) (Negative)","properties":{"Node name for S&R":"Text box"},"widgets_values":["embedding:EasyNegative, embedding:EasyNegativeV2, watermark, text, deformed"]},{"id":72,"type":"ConditioningAverage ","pos":[-960,2],"size":[380.4000244140625,78],"flags":{},"order":16,"mode":0,"inputs":[{"name":"conditioning_to","type":"CONDITIONING","link":151},{"name":"conditioning_from","type":"CONDITIONING","link":152,"slot_index":1},{"name":"conditioning_to_strength","type":"FLOAT","link":154,"widget":{"name":"conditioning_to_strength","config":["FLOAT",{"default":1,"min":0,"max":1,"step":0.01}]},"slot_index":2}],"outputs":[{"name":"CONDITIONING","type":"CONDITIONING","links":[153],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"ConditioningAverage "},"widgets_values":[1]},{"id":6,"type":"CLIPTextEncode","pos":[-1261,-46],"size":[210,54],"flags":{},"order":14,"mode":0,"inputs":[{"name":"clip","type":"CLIP","link":28},{"name":"text","type":"STRING","link":145,"widget":{"name":"text","config":["STRING",{"multiline":true}]},"slot_index":1}],"outputs":[{"name":"CONDITIONING","type":"CONDITIONING","links":[151],"slot_index":0}],"properties":{"Node name for S&R":"CLIPTextEncode"},"widgets_values":["A majestic Lion, fur in the wind, (smirk smile)"]},{"id":70,"type":"CLIPTextEncode","pos":[-1245,87],"size":[210,54],"flags":{},"order":12,"mode":0,"inputs":[{"name":"clip","type":"CLIP","link":149,"slot_index":0},{"name":"text","type":"STRING","link":150,"widget":{"name":"text","config":["STRING",{"multiline":true}]},"slot_index":1}],"outputs":[{"name":"CONDITIONING","type":"CONDITIONING","links":[152],"slot_index":0}],"properties":{"Node name for S&R":"CLIPTextEncode"},"widgets_values":["A majestic Lion, fur in the wind, (smirk smile)"]},{"id":69,"type":"String Replace (mtb)","pos":[-1560,-70],"size":[210,82],"flags":{},"order":8,"mode":0,"inputs":[{"name":"string","type":"STRING","link":141}],"outputs":[{"name":"STRING","type":"STRING","links":[145],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"String Replace (mtb)"},"widgets_values":["blue","yellow"],"color":"#432","bgcolor":"#653"},{"id":68,"type":"Text box","pos":[-1950,10],"size":[217.2119140625,122.18632507324219],"flags":{},"order":3,"mode":0,"outputs":[{"name":"STRING","type":"STRING","links":[141,150],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"Text box"},"widgets_values":["A cinematic shot of a blue car, high speed, smoke whisps in the air, (at night), blue neon lighting"],"color":"#432","bgcolor":"#653"},{"id":3,"type":"KSampler","pos":[-483,-21],"size":[315,474],"flags":{},"order":19,"mode":0,"inputs":[{"name":"model","type":"MODEL","link":120},{"name":"positive","type":"CONDITIONING","link":153},{"name":"negative","type":"CONDITIONING","link":6},{"name":"latent_image","type":"LATENT","link":2}],"outputs":[{"name":"LATENT","type":"LATENT","links":[138],"slot_index":0}],"properties":{"Node name for S&R":"KSampler"},"widgets_values":[5428233522,"fixed",45,8,"euler_ancestral","simple",1]},{"id":66,"type":"VAEDecodeTiled","pos":[197,-20],"size":[210,46],"flags":{"collapsed":false},"order":20,"mode":0,"inputs":[{"name":"samples","type":"LATENT","link":138},{"name":"vae","type":"VAE","link":139,"slot_index":1}],"outputs":[{"name":"IMAGE","type":"IMAGE","links":[161],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"VAEDecodeTiled"}},{"id":78,"type":"SaveImage","pos":[565,-18],"size":[315,270],"flags":{},"order":21,"mode":0,"inputs":[{"name":"images","type":"IMAGE","link":161}],"properties":{},"widgets_values":["mtb_demo-conditional_blend"]},{"id":81,"type":"Get Batch From History (mtb)","pos":[-625,848],"size":[235.1999969482422,118],"flags":{},"order":15,"mode":0,"inputs":[{"name":"passthrough_image","type":"IMAGE","link":null},{"name":"count","type":"INT","link":171,"widget":{"name":"count","config":["INT",{"default":1,"min":0}]},"slot_index":2},{"name":"enable","type":"BOOLEAN","link":168,"widget":{"name":"enable","config":["BOOLEAN",{"default":true}]},"slot_index":2}],"outputs":[{"name":"i","type":"IMAGE","links":[166,167],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"Get Batch From History (mtb)"},"widgets_values":[true,24,0]},{"id":77,"type":"Export To Prores (mtb)","pos":[-111,849],"size":[315,82],"flags":{},"order":17,"mode":0,"inputs":[{"name":"images","type":"IMAGE","link":166,"slot_index":0}],"outputs":[{"name":"VIDEO","type":"VIDEO","links":null,"shape":3}],"properties":{"Node name for S&R":"Export To Prores (mtb)"},"widgets_values":[12,"export"]},{"id":79,"type":"Save Gif (mtb)","pos":[-104,1000],"size":[210,356],"flags":{},"order":18,"mode":0,"inputs":[{"name":"image","type":"IMAGE","link":167},{"name":"pingpong","type":"BOOLEAN","link":null}],"properties":{"Node name for S&R":"Save Gif (mtb)"},"widgets_values":[12,1,true,"/view?filename=03031ebda0.gif&subfolder=&type=output"]},{"id":73,"type":"Animation Builder (mtb)","pos":[-1285,831],"size":[211.60000610351562,294],"flags":{},"order":9,"mode":0,"inputs":[{"name":"total_frames","type":"INT","link":170,"widget":{"name":"total_frames","config":["INT",{"default":100,"min":0}]},"slot_index":0}],"outputs":[{"name":"frame","type":"INT","links":null,"shape":3,"slot_index":0},{"name":"0-1 (scaled)","type":"FLOAT","links":[154],"shape":3,"slot_index":1},{"name":"count","type":"INT","links":null,"shape":3},{"name":"loop_ended","type":"BOOLEAN","links":[168],"shape":3,"slot_index":3}],"properties":{"Node name for S&R":"Animation Builder (mtb)"},"widgets_values":[24,1,1,0,0,"Idle","Iteration: Idle","reset","queue"],"color":"#232","bgcolor":"#353","shape":1},{"id":82,"type":"PrimitiveNode","pos":[-1663,1205],"size":[210,82],"flags":{},"order":4,"mode":0,"outputs":[{"name":"INT","type":"INT","links":[170,171],"widget":{"name":"total_frames","config":["INT",{"default":100,"min":0}]},"slot_index":0}],"title":"total_frames","properties":{},"widgets_values":[24,"fixed"]}],"links":[[2,5,0,3,3,"LATENT"],[6,7,0,3,2,"CONDITIONING"],[28,19,0,6,0,"CLIP"],[29,19,0,7,0,"CLIP"],[116,16,1,19,0,"CLIP"],[117,16,2,56,0,"*"],[120,57,0,3,0,"MODEL"],[124,56,0,59,0,"*"],[134,16,0,65,0,"*"],[135,65,0,57,0,"*"],[138,3,0,66,0,"LATENT"],[139,59,0,66,1,"VAE"],[141,68,0,69,0,"STRING"],[145,69,0,6,1,"STRING"],[149,19,0,70,0,"CLIP"],[150,68,0,70,1,"STRING"],[151,6,0,72,0,"CONDITIONING"],[152,70,0,72,1,"CONDITIONING"],[153,72,0,3,1,"CONDITIONING"],[154,73,1,72,2,"FLOAT"],[161,66,0,78,0,"IMAGE"],[163,80,0,7,1,"STRING"],[166,81,0,77,0,"IMAGE"],[167,81,0,79,0,"IMAGE"],[168,73,3,81,2,"BOOLEAN"],[170,82,0,73,0,"INT"],[171,82,0,81,1,"INT"]],"groups":[{"title":"Txt2Img","bounding":[-2061,-234,1932,973],"color":"#a1309b","locked":false},{"title":"Save Intermediate Image","bounding":[150,-116,303,213],"color":"#3f789e","locked":false}],"config":{},"extra":{},"version":0.4} \ No newline at end of file diff --git a/examples/04-animation_builder-deforum.json b/examples/04-animation_builder-deforum.json index 99d3d0b..bd1ba9b 100644 --- a/examples/04-animation_builder-deforum.json +++ b/examples/04-animation_builder-deforum.json @@ -1,1189 +1 @@ -{ - "last_node_id": 42, - "last_link_id": 69, - "nodes": [ - { - "id": 11, - "type": "Get Batch From History (mtb)", - "pos": [ - -828, - 522 - ], - "size": [ - 235.1999969482422, - 118 - ], - "flags": {}, - "order": 12, - "mode": 0, - "inputs": [ - { - "name": "passthrough_image", - "type": "IMAGE", - "link": 10 - }, - { - "name": "enable", - "type": "BOOL", - "link": 9, - "widget": { - "name": "enable", - "config": [ - "BOOL", - { - "default": true - } - ] - }, - "slot_index": 1 - } - ], - "outputs": [ - { - "name": "i", - "type": "IMAGE", - "links": [ - 26 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "Get Batch From History (mtb)" - }, - "widgets_values": [ - false, - 1, - 0 - ], - "color": "#223", - "bgcolor": "#335" - }, - { - "id": 24, - "type": "Note", - "pos": [ - -827, - 406 - ], - "size": [ - 233.25148010253906, - 82.53218841552734 - ], - "flags": {}, - "order": 0, - "mode": 0, - "properties": { - "text": "" - }, - "widgets_values": [ - "On first frame we get the init image, on all subsequent ones the feedback from the previous queue item" - ], - "color": "#223", - "bgcolor": "#335", - "shape": 1 - }, - { - "id": 12, - "type": "Int To Bool (mtb)", - "pos": [ - -1057, - 583 - ], - "size": [ - 210, - 36.366058349609375 - ], - "flags": {}, - "order": 8, - "mode": 0, - "inputs": [ - { - "name": "int", - "type": "INT", - "link": 34, - "widget": { - "name": "int", - "config": [ - "INT", - { - "default": 0 - } - ] - }, - "slot_index": 0 - } - ], - "outputs": [ - { - "name": "BOOL", - "type": "BOOL", - "links": [ - 9 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "Int To Bool (mtb)" - }, - "widgets_values": [ - 29 - ], - "color": "#222", - "bgcolor": "#000" - }, - { - "id": 10, - "type": "LoadImage", - "pos": [ - -1409, - 524 - ], - "size": [ - 315, - 314 - ], - "flags": {}, - "order": 1, - "mode": 0, - "outputs": [ - { - "name": "IMAGE", - "type": "IMAGE", - "links": [ - 10 - ], - "shape": 3, - "slot_index": 0 - }, - { - "name": "MASK", - "type": "MASK", - "links": null, - "shape": 3 - } - ], - "properties": { - "Node name for S&R": "LoadImage" - }, - "widgets_values": [ - "example.png", - "image" - ], - "color": "#432", - "bgcolor": "#653", - "shape": 1 - }, - { - "id": 18, - "type": "Get Batch From History (mtb)", - "pos": [ - -960, - 1257 - ], - "size": [ - 235.1999969482422, - 118 - ], - "flags": {}, - "order": 11, - "mode": 0, - "inputs": [ - { - "name": "passthrough_image", - "type": "IMAGE", - "link": null - }, - { - "name": "enable", - "type": "BOOL", - "link": 31, - "widget": { - "name": "enable", - "config": [ - "BOOL", - { - "default": true - } - ] - }, - "slot_index": 1 - }, - { - "name": "count", - "type": "INT", - "link": 44, - "widget": { - "name": "count", - "config": [ - "INT", - { - "default": 1, - "min": 0 - } - ] - } - } - ], - "outputs": [ - { - "name": "i", - "type": "IMAGE", - "links": [ - 17, - 18 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "Get Batch From History (mtb)" - }, - "widgets_values": [ - true, - 30, - 0 - ] - }, - { - "id": 20, - "type": "Export To Prores (mtb)", - "pos": [ - -612, - 1818 - ], - "size": [ - 292.4239807128906, - 93.884033203125 - ], - "flags": {}, - "order": 13, - "mode": 0, - "inputs": [ - { - "name": "images", - "type": "IMAGE", - "link": 17 - } - ], - "outputs": [ - { - "name": "VIDEO", - "type": "VIDEO", - "links": null, - "shape": 3 - } - ], - "properties": { - "Node name for S&R": "Export To Prores (mtb)" - }, - "widgets_values": [ - 12, - "export" - ] - }, - { - "id": 35, - "type": "CLIPTextEncode", - "pos": [ - -118, - 331 - ], - "size": [ - 210, - 54 - ], - "flags": {}, - "order": 6, - "mode": 0, - "inputs": [ - { - "name": "clip", - "type": "CLIP", - "link": 60 - }, - { - "name": "text", - "type": "STRING", - "link": 66, - "widget": { - "name": "text", - "config": [ - "STRING", - { - "multiline": true - } - ] - } - } - ], - "outputs": [ - { - "name": "CONDITIONING", - "type": "CONDITIONING", - "links": [ - 54 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "CLIPTextEncode" - }, - "widgets_values": [ - "" - ] - }, - { - "id": 9, - "type": "CheckpointLoaderSimple", - "pos": [ - -558, - 114 - ], - "size": [ - 301.2330322265625, - 98 - ], - "flags": {}, - "order": 2, - "mode": 0, - "outputs": [ - { - "name": "MODEL", - "type": "MODEL", - "links": [ - 62 - ], - "shape": 3, - "slot_index": 0 - }, - { - "name": "CLIP", - "type": "CLIP", - "links": [ - 59, - 60 - ], - "shape": 3, - "slot_index": 1 - }, - { - "name": "VAE", - "type": "VAE", - "links": [ - 58, - 69 - ], - "shape": 3, - "slot_index": 2 - } - ], - "properties": { - "Node name for S&R": "CheckpointLoaderSimple" - }, - "widgets_values": [ - "revAnimated_v122.safetensors" - ] - }, - { - "id": 37, - "type": "VAEEncode", - "pos": [ - -125, - 236 - ], - "size": [ - 210, - 46 - ], - "flags": {}, - "order": 16, - "mode": 0, - "inputs": [ - { - "name": "pixels", - "type": "IMAGE", - "link": 57 - }, - { - "name": "vae", - "type": "VAE", - "link": 58, - "slot_index": 1 - } - ], - "outputs": [ - { - "name": "LATENT", - "type": "LATENT", - "links": [ - 55 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "VAEEncode" - } - }, - { - "id": 34, - "type": "CLIPTextEncode", - "pos": [ - -124, - 84 - ], - "size": [ - 210, - 96 - ], - "flags": {}, - "order": 5, - "mode": 0, - "inputs": [ - { - "name": "clip", - "type": "CLIP", - "link": 59 - } - ], - "outputs": [ - { - "name": "CONDITIONING", - "type": "CONDITIONING", - "links": [ - 53 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "CLIPTextEncode" - }, - "widgets_values": [ - "A plastic Barbie doll with a pink dress sleeping, draping, wrinkles, shiny" - ] - }, - { - "id": 33, - "type": "Text box", - "pos": [ - -497, - 349 - ], - "size": [ - 294, - 95.1284408569336 - ], - "flags": {}, - "order": 3, - "mode": 0, - "outputs": [ - { - "name": "STRING", - "type": "STRING", - "links": [ - 66 - ], - "shape": 3, - "slot_index": 0 - } - ], - "title": "❌Mel Negatives (general) (Negative)", - "properties": { - "Node name for S&R": "Text box" - }, - "widgets_values": [ - "embedding:EasyNegative, embedding:EasyNegativeV2, watermark, text, deformed, NSFW, Cleavage, Pubic Hair, Nudity, Naked, censored" - ] - }, - { - "id": 39, - "type": "Reroute", - "pos": [ - -156, - 908 - ], - "size": [ - 75, - 26 - ], - "flags": {}, - "order": 10, - "mode": 0, - "inputs": [ - { - "name": "", - "type": "*", - "link": 67 - } - ], - "outputs": [ - { - "name": "", - "type": "INT", - "links": [ - 68 - ] - } - ], - "properties": { - "showOutputText": false, - "horizontal": false - } - }, - { - "id": 14, - "type": "Transform Image (mtb)", - "pos": [ - -527, - 520 - ], - "size": [ - 315, - 178 - ], - "flags": {}, - "order": 15, - "mode": 0, - "inputs": [ - { - "name": "image", - "type": "IMAGE", - "link": 26 - } - ], - "outputs": [ - { - "name": "IMAGE", - "type": "IMAGE", - "links": [ - 57 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "Transform Image (mtb)" - }, - "widgets_values": [ - 0, - 5, - 1.03, - 1, - 0, - "reflect" - ], - "color": "#223", - "bgcolor": "#335" - }, - { - "id": 36, - "type": "KSampler", - "pos": [ - 223, - 262 - ], - "size": [ - 315, - 442 - ], - "flags": {}, - "order": 17, - "mode": 0, - "inputs": [ - { - "name": "model", - "type": "MODEL", - "link": 62, - "slot_index": 0 - }, - { - "name": "positive", - "type": "CONDITIONING", - "link": 53 - }, - { - "name": "negative", - "type": "CONDITIONING", - "link": 54 - }, - { - "name": "latent_image", - "type": "LATENT", - "link": 55 - }, - { - "name": "denoise", - "type": "FLOAT", - "link": 63, - "widget": { - "name": "denoise", - "config": [ - "FLOAT", - { - "default": 1, - "min": 0, - "max": 1, - "step": 0.01 - } - ] - }, - "slot_index": 4 - }, - { - "name": "seed", - "type": "INT", - "link": 68, - "widget": { - "name": "seed", - "config": [ - "INT", - { - "default": 0, - "min": 0, - "max": 18446744073709552000 - } - ] - } - } - ], - "outputs": [ - { - "name": "LATENT", - "type": "LATENT", - "links": [ - 56 - ], - "shape": 3, - "slot_index": 0, - "color": "#FF9CF9" - } - ], - "properties": { - "Node name for S&R": "KSampler" - }, - "widgets_values": [ - 61876307854624, - "randomize", - 15, - 8, - "euler_ancestral", - "normal", - 0.6 - ] - }, - { - "id": 15, - "type": "SaveImage", - "pos": [ - 782, - 259 - ], - "size": [ - 330.1112365722656, - 378.1239929199219 - ], - "flags": {}, - "order": 19, - "mode": 0, - "inputs": [ - { - "name": "images", - "type": "IMAGE", - "link": 65 - } - ], - "properties": {}, - "widgets_values": [ - "ComfyUI" - ] - }, - { - "id": 19, - "type": "Save Gif (mtb)", - "pos": [ - -613, - 1256 - ], - "size": [ - 356.1775817871094, - 471.8785705566406 - ], - "flags": {}, - "order": 14, - "mode": 0, - "inputs": [ - { - "name": "image", - "type": "IMAGE", - "link": 18 - } - ], - "properties": { - "Node name for S&R": "Save Gif (mtb)" - }, - "widgets_values": [ - 12, - 1, - true - ] - }, - { - "id": 31, - "type": "PrimitiveNode", - "pos": [ - -2060, - 1291 - ], - "size": [ - 210, - 82 - ], - "flags": {}, - "order": 4, - "mode": 0, - "outputs": [ - { - "name": "INT", - "type": "INT", - "links": [ - 43, - 44 - ], - "widget": { - "name": "total_frames", - "config": [ - "INT", - { - "default": 100, - "min": 0 - } - ] - }, - "slot_index": 0 - } - ], - "title": "total_frames", - "properties": {}, - "widgets_values": [ - 30, - "fixed" - ], - "color": "#432", - "bgcolor": "#653" - }, - { - "id": 38, - "type": "VAEDecode", - "pos": [ - 556, - 260 - ], - "size": [ - 210, - 46 - ], - "flags": {}, - "order": 18, - "mode": 0, - "inputs": [ - { - "name": "samples", - "type": "LATENT", - "link": 56 - }, - { - "name": "vae", - "type": "VAE", - "link": 69, - "slot_index": 1 - } - ], - "outputs": [ - { - "name": "IMAGE", - "type": "IMAGE", - "links": [ - 65 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "VAEDecode" - } - }, - { - "id": 22, - "type": "Fit Number (mtb)", - "pos": [ - -647, - 882 - ], - "size": [ - 232.28509521484375, - 166 - ], - "flags": {}, - "order": 9, - "mode": 0, - "inputs": [ - { - "name": "value", - "type": "FLOAT", - "link": 27 - } - ], - "outputs": [ - { - "name": "FLOAT", - "type": "FLOAT", - "links": [ - 63 - ], - "shape": 3, - "slot_index": 0 - } - ], - "title": "Fit Number (mtb) - Denoise", - "properties": { - "Node name for S&R": "Fit Number (mtb)" - }, - "widgets_values": [ - true, - 0, - 1, - 0.3, - 0.6 - ] - }, - { - "id": 17, - "type": "Animation Builder (mtb)", - "pos": [ - -1310, - 883 - ], - "size": [ - 211.60000610351562, - 318 - ], - "flags": {}, - "order": 7, - "mode": 0, - "inputs": [ - { - "name": "total_frames", - "type": "INT", - "link": 43, - "widget": { - "name": "total_frames", - "config": [ - "INT", - { - "default": 100, - "min": 0 - } - ] - }, - "slot_index": 0 - } - ], - "outputs": [ - { - "name": "frame", - "type": "INT", - "links": [ - 34 - ], - "shape": 3, - "slot_index": 0 - }, - { - "name": "0-1 (scaled)", - "type": "FLOAT", - "links": [ - 27 - ], - "shape": 3, - "slot_index": 1 - }, - { - "name": "count", - "type": "INT", - "links": [ - 67 - ], - "shape": 3, - "slot_index": 2 - }, - { - "name": "loop_ended", - "type": "BOOL", - "links": [ - 31 - ], - "shape": 3, - "slot_index": 3 - } - ], - "properties": { - "Node name for S&R": "Animation Builder (mtb)" - }, - "widgets_values": [ - 30, - 1, - 1, - 0, - 0, - "Idle", - "Iteration: Idle", - "reset", - "queue" - ], - "color": "#232", - "bgcolor": "#353", - "shape": 1 - } - ], - "links": [ - [ - 9, - 12, - 0, - 11, - 1, - "BOOL" - ], - [ - 10, - 10, - 0, - 11, - 0, - "IMAGE" - ], - [ - 17, - 18, - 0, - 20, - 0, - "IMAGE" - ], - [ - 18, - 18, - 0, - 19, - 0, - "IMAGE" - ], - [ - 26, - 11, - 0, - 14, - 0, - "IMAGE" - ], - [ - 27, - 17, - 1, - 22, - 0, - "FLOAT" - ], - [ - 31, - 17, - 3, - 18, - 1, - "BOOL" - ], - [ - 34, - 17, - 0, - 12, - 0, - "INT" - ], - [ - 43, - 31, - 0, - 17, - 0, - "INT" - ], - [ - 44, - 31, - 0, - 18, - 2, - "INT" - ], - [ - 53, - 34, - 0, - 36, - 1, - "CONDITIONING" - ], - [ - 54, - 35, - 0, - 36, - 2, - "CONDITIONING" - ], - [ - 55, - 37, - 0, - 36, - 3, - "LATENT" - ], - [ - 56, - 36, - 0, - 38, - 0, - "LATENT" - ], - [ - 57, - 14, - 0, - 37, - 0, - "IMAGE" - ], - [ - 58, - 9, - 2, - 37, - 1, - "VAE" - ], - [ - 59, - 9, - 1, - 34, - 0, - "CLIP" - ], - [ - 60, - 9, - 1, - 35, - 0, - "CLIP" - ], - [ - 62, - 9, - 0, - 36, - 0, - "MODEL" - ], - [ - 63, - 22, - 0, - 36, - 4, - "FLOAT" - ], - [ - 65, - 38, - 0, - 15, - 0, - "IMAGE" - ], - [ - 66, - 33, - 0, - 35, - 1, - "STRING" - ], - [ - 67, - 17, - 2, - 39, - 0, - "*" - ], - [ - 68, - 39, - 0, - 36, - 5, - "INT" - ], - [ - 69, - 9, - 2, - 38, - 1, - "VAE" - ] - ], - "groups": [ - { - "title": "Video Output", - "bounding": [ - -702, - 1161, - 516, - 773 - ], - "color": "#3f789e", - "locked": false - }, - { - "title": "START THE QUEUE BY CLICKLING HERE 👆", - "bounding": [ - -1612, - 1219, - 521, - 80 - ], - "color": "#8A8", - "locked": false - } - ], - "config": {}, - "extra": {}, - "version": 0.4 -} \ No newline at end of file +{"last_node_id":42,"last_link_id":69,"nodes":[{"id":11,"type":"Get Batch From History (mtb)","pos":[-828,522],"size":[235.1999969482422,118],"flags":{},"order":12,"mode":0,"inputs":[{"name":"passthrough_image","type":"IMAGE","link":10},{"name":"enable","type":"BOOLEAN","link":9,"widget":{"name":"enable","config":["BOOLEAN",{"default":true}]},"slot_index":1}],"outputs":[{"name":"i","type":"IMAGE","links":[26],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"Get Batch From History (mtb)"},"widgets_values":[false,1,0],"color":"#223","bgcolor":"#335"},{"id":24,"type":"Note","pos":[-827,406],"size":[233.25148010253906,82.53218841552734],"flags":{},"order":0,"mode":0,"properties":{"text":""},"widgets_values":["On first frame we get the init image, on all subsequent ones the feedback from the previous queue item"],"color":"#223","bgcolor":"#335","shape":1},{"id":12,"type":"Int To Bool (mtb)","pos":[-1057,583],"size":[210,36.366058349609375],"flags":{},"order":8,"mode":0,"inputs":[{"name":"int","type":"INT","link":34,"widget":{"name":"int","config":["INT",{"default":0}]},"slot_index":0}],"outputs":[{"name":"BOOLEAN","type":"BOOLEAN","links":[9],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"Int To Bool (mtb)"},"widgets_values":[29],"color":"#222","bgcolor":"#000"},{"id":10,"type":"LoadImage","pos":[-1409,524],"size":[315,314],"flags":{},"order":1,"mode":0,"outputs":[{"name":"IMAGE","type":"IMAGE","links":[10],"shape":3,"slot_index":0},{"name":"MASK","type":"MASK","links":null,"shape":3}],"properties":{"Node name for S&R":"LoadImage"},"widgets_values":["example.png","image"],"color":"#432","bgcolor":"#653","shape":1},{"id":18,"type":"Get Batch From History (mtb)","pos":[-960,1257],"size":[235.1999969482422,118],"flags":{},"order":11,"mode":0,"inputs":[{"name":"passthrough_image","type":"IMAGE","link":null},{"name":"enable","type":"BOOLEAN","link":31,"widget":{"name":"enable","config":["BOOLEAN",{"default":true}]},"slot_index":1},{"name":"count","type":"INT","link":44,"widget":{"name":"count","config":["INT",{"default":1,"min":0}]}}],"outputs":[{"name":"i","type":"IMAGE","links":[17,18],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"Get Batch From History (mtb)"},"widgets_values":[true,30,0]},{"id":20,"type":"Export To Prores (mtb)","pos":[-612,1818],"size":[292.4239807128906,93.884033203125],"flags":{},"order":13,"mode":0,"inputs":[{"name":"images","type":"IMAGE","link":17}],"outputs":[{"name":"VIDEO","type":"VIDEO","links":null,"shape":3}],"properties":{"Node name for S&R":"Export To Prores (mtb)"},"widgets_values":[12,"export"]},{"id":35,"type":"CLIPTextEncode","pos":[-118,331],"size":[210,54],"flags":{},"order":6,"mode":0,"inputs":[{"name":"clip","type":"CLIP","link":60},{"name":"text","type":"STRING","link":66,"widget":{"name":"text","config":["STRING",{"multiline":true}]}}],"outputs":[{"name":"CONDITIONING","type":"CONDITIONING","links":[54],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"CLIPTextEncode"},"widgets_values":[""]},{"id":9,"type":"CheckpointLoaderSimple","pos":[-558,114],"size":[301.2330322265625,98],"flags":{},"order":2,"mode":0,"outputs":[{"name":"MODEL","type":"MODEL","links":[62],"shape":3,"slot_index":0},{"name":"CLIP","type":"CLIP","links":[59,60],"shape":3,"slot_index":1},{"name":"VAE","type":"VAE","links":[58,69],"shape":3,"slot_index":2}],"properties":{"Node name for S&R":"CheckpointLoaderSimple"},"widgets_values":["revAnimated_v122.safetensors"]},{"id":37,"type":"VAEEncode","pos":[-125,236],"size":[210,46],"flags":{},"order":16,"mode":0,"inputs":[{"name":"pixels","type":"IMAGE","link":57},{"name":"vae","type":"VAE","link":58,"slot_index":1}],"outputs":[{"name":"LATENT","type":"LATENT","links":[55],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"VAEEncode"}},{"id":34,"type":"CLIPTextEncode","pos":[-124,84],"size":[210,96],"flags":{},"order":5,"mode":0,"inputs":[{"name":"clip","type":"CLIP","link":59}],"outputs":[{"name":"CONDITIONING","type":"CONDITIONING","links":[53],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"CLIPTextEncode"},"widgets_values":["A plastic Barbie doll with a pink dress sleeping, draping, wrinkles, shiny"]},{"id":33,"type":"Text box","pos":[-497,349],"size":[294,95.1284408569336],"flags":{},"order":3,"mode":0,"outputs":[{"name":"STRING","type":"STRING","links":[66],"shape":3,"slot_index":0}],"title":"❌Mel Negatives (general) (Negative)","properties":{"Node name for S&R":"Text box"},"widgets_values":["embedding:EasyNegative, embedding:EasyNegativeV2, watermark, text, deformed, NSFW, Cleavage, Pubic Hair, Nudity, Naked, censored"]},{"id":39,"type":"Reroute","pos":[-156,908],"size":[75,26],"flags":{},"order":10,"mode":0,"inputs":[{"name":"","type":"*","link":67}],"outputs":[{"name":"","type":"INT","links":[68]}],"properties":{"showOutputText":false,"horizontal":false}},{"id":14,"type":"Transform Image (mtb)","pos":[-527,520],"size":[315,178],"flags":{},"order":15,"mode":0,"inputs":[{"name":"image","type":"IMAGE","link":26}],"outputs":[{"name":"IMAGE","type":"IMAGE","links":[57],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"Transform Image (mtb)"},"widgets_values":[0,5,1.03,1,0,"reflect"],"color":"#223","bgcolor":"#335"},{"id":36,"type":"KSampler","pos":[223,262],"size":[315,442],"flags":{},"order":17,"mode":0,"inputs":[{"name":"model","type":"MODEL","link":62,"slot_index":0},{"name":"positive","type":"CONDITIONING","link":53},{"name":"negative","type":"CONDITIONING","link":54},{"name":"latent_image","type":"LATENT","link":55},{"name":"denoise","type":"FLOAT","link":63,"widget":{"name":"denoise","config":["FLOAT",{"default":1,"min":0,"max":1,"step":0.01}]},"slot_index":4},{"name":"seed","type":"INT","link":68,"widget":{"name":"seed","config":["INT",{"default":0,"min":0,"max":18446744073709552000}]}}],"outputs":[{"name":"LATENT","type":"LATENT","links":[56],"shape":3,"slot_index":0,"color":"#FF9CF9"}],"properties":{"Node name for S&R":"KSampler"},"widgets_values":[61876307854624,"randomize",15,8,"euler_ancestral","normal",0.6]},{"id":15,"type":"SaveImage","pos":[782,259],"size":[330.1112365722656,378.1239929199219],"flags":{},"order":19,"mode":0,"inputs":[{"name":"images","type":"IMAGE","link":65}],"properties":{},"widgets_values":["ComfyUI"]},{"id":19,"type":"Save Gif (mtb)","pos":[-613,1256],"size":[356.1775817871094,471.8785705566406],"flags":{},"order":14,"mode":0,"inputs":[{"name":"image","type":"IMAGE","link":18}],"properties":{"Node name for S&R":"Save Gif (mtb)"},"widgets_values":[12,1,true]},{"id":31,"type":"PrimitiveNode","pos":[-2060,1291],"size":[210,82],"flags":{},"order":4,"mode":0,"outputs":[{"name":"INT","type":"INT","links":[43,44],"widget":{"name":"total_frames","config":["INT",{"default":100,"min":0}]},"slot_index":0}],"title":"total_frames","properties":{},"widgets_values":[30,"fixed"],"color":"#432","bgcolor":"#653"},{"id":38,"type":"VAEDecode","pos":[556,260],"size":[210,46],"flags":{},"order":18,"mode":0,"inputs":[{"name":"samples","type":"LATENT","link":56},{"name":"vae","type":"VAE","link":69,"slot_index":1}],"outputs":[{"name":"IMAGE","type":"IMAGE","links":[65],"shape":3,"slot_index":0}],"properties":{"Node name for S&R":"VAEDecode"}},{"id":22,"type":"Fit Number (mtb)","pos":[-647,882],"size":[232.28509521484375,166],"flags":{},"order":9,"mode":0,"inputs":[{"name":"value","type":"FLOAT","link":27}],"outputs":[{"name":"FLOAT","type":"FLOAT","links":[63],"shape":3,"slot_index":0}],"title":"Fit Number (mtb) - Denoise","properties":{"Node name for S&R":"Fit Number (mtb)"},"widgets_values":[true,0,1,0.3,0.6]},{"id":17,"type":"Animation Builder (mtb)","pos":[-1310,883],"size":[211.60000610351562,318],"flags":{},"order":7,"mode":0,"inputs":[{"name":"total_frames","type":"INT","link":43,"widget":{"name":"total_frames","config":["INT",{"default":100,"min":0}]},"slot_index":0}],"outputs":[{"name":"frame","type":"INT","links":[34],"shape":3,"slot_index":0},{"name":"0-1 (scaled)","type":"FLOAT","links":[27],"shape":3,"slot_index":1},{"name":"count","type":"INT","links":[67],"shape":3,"slot_index":2},{"name":"loop_ended","type":"BOOLEAN","links":[31],"shape":3,"slot_index":3}],"properties":{"Node name for S&R":"Animation Builder (mtb)"},"widgets_values":[30,1,1,0,0,"Idle","Iteration: Idle","reset","queue"],"color":"#232","bgcolor":"#353","shape":1}],"links":[[9,12,0,11,1,"BOOLEAN"],[10,10,0,11,0,"IMAGE"],[17,18,0,20,0,"IMAGE"],[18,18,0,19,0,"IMAGE"],[26,11,0,14,0,"IMAGE"],[27,17,1,22,0,"FLOAT"],[31,17,3,18,1,"BOOLEAN"],[34,17,0,12,0,"INT"],[43,31,0,17,0,"INT"],[44,31,0,18,2,"INT"],[53,34,0,36,1,"CONDITIONING"],[54,35,0,36,2,"CONDITIONING"],[55,37,0,36,3,"LATENT"],[56,36,0,38,0,"LATENT"],[57,14,0,37,0,"IMAGE"],[58,9,2,37,1,"VAE"],[59,9,1,34,0,"CLIP"],[60,9,1,35,0,"CLIP"],[62,9,0,36,0,"MODEL"],[63,22,0,36,4,"FLOAT"],[65,38,0,15,0,"IMAGE"],[66,33,0,35,1,"STRING"],[67,17,2,39,0,"*"],[68,39,0,36,5,"INT"],[69,9,2,38,1,"VAE"]],"groups":[{"title":"Video Output","bounding":[-702,1161,516,773],"color":"#3f789e","locked":false},{"title":"START THE QUEUE BY CLICKLING HERE 👆","bounding":[-1612,1219,521,80],"color":"#8A8","locked":false}],"config":{},"extra":{},"version":0.4} \ No newline at end of file diff --git a/nodes/animation.py b/nodes/animation.py index da22df1..9822685 100644 --- a/nodes/animation.py +++ b/nodes/animation.py @@ -17,7 +17,7 @@ class AnimationBuilder: }, } - RETURN_TYPES = ("INT", "FLOAT", "INT", "BOOL") + RETURN_TYPES = ("INT", "FLOAT", "INT", "BOOLEAN") RETURN_NAMES = ("frame", "0-1 (scaled)", "count", "loop_ended") CATEGORY = "mtb/animation" FUNCTION = "build_animation" diff --git a/nodes/deep_bump.py b/nodes/deep_bump.py index 1444d35..47a4d26 100644 --- a/nodes/deep_bump.py +++ b/nodes/deep_bump.py @@ -261,7 +261,7 @@ class DeepBump: "LARGEST", ], ), - "normals_to_height_seamless": ("BOOL", {"default": False}), + "normals_to_height_seamless": ("BOOLEAN", {"default": False}), }, } diff --git a/nodes/faceenhance.py b/nodes/faceenhance.py index 4dafd39..0155514 100644 --- a/nodes/faceenhance.py +++ b/nodes/faceenhance.py @@ -143,12 +143,12 @@ class RestoreFace: "image": ("IMAGE",), "model": ("FACEENHANCE_MODEL",), # Input are aligned faces - "aligned": ("BOOL", {"default": False}), + "aligned": ("BOOLEAN", {"default": False}), # Only restore the center face - "only_center_face": ("BOOL", {"default": False}), + "only_center_face": ("BOOLEAN", {"default": False}), # Adjustable weights "weight": ("FLOAT", {"default": 0.5}), - "save_tmp_steps": ("BOOL", {"default": True}), + "save_tmp_steps": ("BOOLEAN", {"default": True}), } } diff --git a/nodes/faceswap.py b/nodes/faceswap.py index 4f0eba9..83074d7 100644 --- a/nodes/faceswap.py +++ b/nodes/faceswap.py @@ -2,14 +2,13 @@ import onnxruntime from pathlib import Path from PIL import Image -from typing import List, Set, Tuple, Union, Optional +from typing import List, Set, Union, Optional import cv2 import folder_paths import glob import insightface import numpy as np import os -import tempfile import torch from insightface.model_zoo.inswapper import INSwapper from ..utils import pil2tensor, tensor2pil @@ -120,7 +119,6 @@ class FaceSwap: "faces_index": ("STRING", {"default": "0"}), "faceanalysis_model": ("FACE_ANALYSIS_MODEL", {"default": "None"}), "faceswap_model": ("FACESWAP_MODEL", {"default": "None"}), - "debug": ("BOOL", {"default": False}), }, "optional": {}, } @@ -136,7 +134,6 @@ class FaceSwap: faces_index: str, faceanalysis_model, faceswap_model, - debug=False, ): def do_swap(img): model_management.throw_exception_if_processing_interrupted() diff --git a/nodes/fun.py b/nodes/fun.py index d12af8f..332e11a 100644 --- a/nodes/fun.py +++ b/nodes/fun.py @@ -121,7 +121,7 @@ class QrCode: "error_correct": (("L", "M", "Q", "H"), {"default": "L"}), "box_size": ("INT", {"default": 10, "max": 8096, "min": 0, "step": 1}), "border": ("INT", {"default": 4, "max": 8096, "min": 0, "step": 1}), - "invert": (("BOOL",), {"default": False}), + "invert": (("BOOLEAN",), {"default": False}), } } diff --git a/nodes/graph_utils.py b/nodes/graph_utils.py index e191fbc..0288a99 100644 --- a/nodes/graph_utils.py +++ b/nodes/graph_utils.py @@ -38,7 +38,7 @@ class FitNumber: return { "required": { "value": ("FLOAT", {"default": 0, "forceInput": True}), - "clamp": ("BOOL", {"default": False}), + "clamp": ("BOOLEAN", {"default": False}), "source_min": ("FLOAT", {"default": 0.0}), "source_max": ("FLOAT", {"default": 1.0}), "target_min": ("FLOAT", {"default": 0.0}), diff --git a/nodes/image_interpolation.py b/nodes/image_interpolation.py index 2fcb3f7..b8e71ef 100644 --- a/nodes/image_interpolation.py +++ b/nodes/image_interpolation.py @@ -6,9 +6,9 @@ import folder_paths from ..log import log import torch from frame_interpolation.eval import util, interpolator -from ..utils import tensor2np import numpy as np import comfy +import comfy.utils from PIL import Image import urllib.request import urllib.parse @@ -39,7 +39,7 @@ class GetBatchFromHistory: def INPUT_TYPES(cls): return { "required": { - "enable": ("BOOL", {"default": True}), + "enable": ("BOOLEAN", {"default": True}), "count": ("INT", {"default": 1, "min": 0}), "offset": ("INT", {"default": 0, "min": -1e9, "max": 1e9}), }, diff --git a/nodes/image_processing.py b/nodes/image_processing.py index 04f04e1..de43c9a 100644 --- a/nodes/image_processing.py +++ b/nodes/image_processing.py @@ -377,7 +377,7 @@ class ImagePremultiply: "required": { "image": ("IMAGE",), "mask": ("MASK",), - "invert": ("BOOL", {"default": False}), + "invert": ("BOOLEAN", {"default": False}), } } @@ -425,7 +425,7 @@ class ImageResizeFactor: "FLOAT", {"default": 2, "min": 0.01, "max": 16.0, "step": 0.01}, ), - "supersample": ("BOOL", {"default": True}), + "supersample": ("BOOLEAN", {"default": True}), "resampling": ( ["lanczos", "nearest", "bilinear", "bicubic"], {"default": "lanczos"}, @@ -546,7 +546,7 @@ class SaveImageGrid: "required": { "images": ("IMAGE",), "filename_prefix": ("STRING", {"default": "ComfyUI"}), - "save_intermediate": ("BOOL", {"default": False}), + "save_intermediate": ("BOOLEAN", {"default": False}), }, "hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"}, } diff --git a/nodes/io.py b/nodes/io.py index d31d27e..e8a07bd 100644 --- a/nodes/io.py +++ b/nodes/io.py @@ -101,7 +101,8 @@ class SaveGif: "image": ("IMAGE",), "fps": ("INT", {"default": 12, "min": 1, "max": 120}), "resize_by": ("FLOAT", {"default": 1.0, "min": 0.1}), - "pingpong": ("BOOL", {"default": False}), + "optimize": ("BOOLEAN", {"default": False}), + "pingpong": ("BOOLEAN", {"default": False}), } } diff --git a/nodes/mask.py b/nodes/mask.py index 64e5119..fe80fc4 100644 --- a/nodes/mask.py +++ b/nodes/mask.py @@ -13,7 +13,7 @@ class ImageRemoveBackgroundRembg: "required": { "image": ("IMAGE",), "alpha_matting": ( - "BOOL", + "BOOLEAN", {"default": False}, ), "alpha_matting_foreground_threshold": ( @@ -29,7 +29,7 @@ class ImageRemoveBackgroundRembg: {"default": 10, "min": 0, "max": 255}, ), "post_process_mask": ( - "BOOL", + "BOOLEAN", {"default": False}, ), "bgcolor": ( diff --git a/nodes/number.py b/nodes/number.py index dc1be4b..6881194 100644 --- a/nodes/number.py +++ b/nodes/number.py @@ -14,7 +14,7 @@ class IntToBool: } } - RETURN_TYPES = ("BOOL",) + RETURN_TYPES = ("BOOLEAN",) FUNCTION = "int_to_bool" CATEGORY = "mtb/number" diff --git a/web/mtb_widgets.js b/web/mtb_widgets.js index c5f36b4..30283b5 100644 --- a/web/mtb_widgets.js +++ b/web/mtb_widgets.js @@ -13,7 +13,7 @@ import * as shared from '/extensions/mtb/comfy_shared.js' import { log } from '/extensions/mtb/comfy_shared.js' import { api } from '/scripts/api.js' -const newTypes = ['BOOL', 'COLOR', 'BBOX'] +const newTypes = [, /*'BOOL'*/ 'COLOR', 'BBOX'] export const MtbWidgets = { BBOX: (key, val) => { @@ -204,116 +204,7 @@ export const MtbWidgets = { widget.desc = 'Represents a Bounding Box with x, y, width, and height.' return widget }, - BOOL: (key, val, compute = false) => { - /** @type {import("/types/litegraph").IWidget} */ - const widget = { - name: key, - type: 'BOOL', - options: { default: false }, - y: 0, - draw: function (ctx, node, widget_width, widgetY, height) { - const hide = this.type !== 'BOOL' && app.canvas.ds.scale > 0.5 - if (hide) { - return - } - const outline_color = LiteGraph.WIDGET_OUTLINE_COLOR - const background_color = LiteGraph.WIDGET_BGCOLOR - const text_color = LiteGraph.WIDGET_TEXT_COLOR - const H = LiteGraph.NODE_WIDGET_HEIGHT - // const arrowSize = 8 - - let margin = 15 - if (hide) return - - let currentY = widgetY - - ctx.textAlign = 'left' - ctx.strokeStyle = outline_color - ctx.fillStyle = background_color - ctx.beginPath() - // ctx.roundRect(margin, currentY, widget_width - margin * 2, H, [H * 0.5]); - ctx.rect(margin, currentY, H, H) // Draw checkbox square - - ctx.fill() - ctx.stroke() - - ctx.fillStyle = text_color - // ctx.fillText(this.label || this.name, margin * 2 + 5, currentY + H * 0.7); - ctx.fillText( - this.label || this.name, - H + margin * 2, - currentY + H * 0.7 - ) - - // Draw arrow if the value is true - // Draw checkmark if the value is true - if (this.value) { - ctx.fillStyle = text_color - ctx.beginPath() - ctx.moveTo(margin + H * 0.15, currentY + H * 0.5) - ctx.lineTo(margin + H * 0.4, currentY + H * 0.8) - ctx.lineTo(margin + H * 0.85, currentY + H * 0.2) - ctx.stroke() - } - }, - get value() { - return this.inputEl.value === 'true' - }, - set value(x) { - this.inputEl.value = x - }, - computeSize: function (width) { - return [width, 32] - }, - mouse: function (event, pos, node) { - // let x = pos[0] - node.pos[0]; - // let y = pos[1] - node.pos[1]; - // let width = node.size[0]; - // let H = LiteGraph.NODE_WIDGET_HEIGHT; - // let margin = 15; - - // if (event.type == LiteGraph.pointerevents_method + "down") { - // if (x > margin && x < widget_width - margin && y > widgetY && y < widgetY + H) { - // this.value = !this.value; // Toggle checkbox value - // shared.inner_value_change(this, this.value, event); - // app.canvas.setDirty(true); - // } - // } - if (event.type === 'pointerdown') { - // get widgets of type type : "COLOR" - const widgets = node.widgets.filter((w) => w.type === 'BOOL') - - for (const w of widgets) { - // color picker - const rect = [w.last_y, w.last_y + 32] - if (pos[1] > rect[0] && pos[1] < rect[1]) { - // picker.style.position = "absolute"; - // picker.style.left = ( pos[0]) + "px"; - // picker.style.top = ( pos[1]) + "px"; - - // place at screen center - // picker.style.position = "absolute"; - // picker.style.left = (window.innerWidth / 2) + "px"; - // picker.style.top = (window.innerHeight / 2) + "px"; - // picker.style.transform = "translate(-50%, -50%)"; - // picker.style.zIndex = 1000; - - this.value = this.value ? false : true - } - } - } - }, - } - - // create a checkbox - widget.inputEl = document.createElement('input') - widget.inputEl.type = 'checkbox' - widget.value = val || false - - document.body.appendChild(widget.inputEl) - return widget - }, COLOR: (key, val, compute = false) => { /** @type {import("/types/litegraph").IWidget} */ const widget = {} From 0fb2d4da90a7e65f82b3f9c8942a68e360456cf7 Mon Sep 17 00:00:00 2001 From: melMass Date: Sat, 5 Aug 2023 13:28:01 +0200 Subject: [PATCH 30/56] =?UTF-8?q?fix:=20=F0=9F=90=9B=20image=20feed=20zord?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/imageFeed.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/imageFeed.js b/web/imageFeed.js index 4a2cf4b..45c4973 100644 --- a/web/imageFeed.js +++ b/web/imageFeed.js @@ -31,7 +31,7 @@ const styles = { background: 'none', border: 'none', color: '#fff', - zIndex: 9999999, + zIndex: 1000, fontSize: '30px', cursor: 'pointer', pointerEvents: 'auto', @@ -43,7 +43,7 @@ const styles = { width: '100vw', position: 'absolute', bottom: 0, - zIndex: 9999999, + zIndex: 10, background: '#333', overflow: 'auto', }, From 2bc7ae88bf4cdfa575d11233c0e6f7b07f9dfd23 Mon Sep 17 00:00:00 2001 From: melMass Date: Sat, 5 Aug 2023 13:31:30 +0200 Subject: [PATCH 31/56] =?UTF-8?q?feat:=20=E2=9C=A8=20use=20PIL=20for=20gif?= =?UTF-8?q?=20saving?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodes/io.py | 113 +++++++++++++++++++++++++++++++--------------------- utils.py | 31 ++++++++------ 2 files changed, 85 insertions(+), 59 deletions(-) diff --git a/nodes/io.py b/nodes/io.py index e8a07bd..5bca95b 100644 --- a/nodes/io.py +++ b/nodes/io.py @@ -1,4 +1,4 @@ -from ..utils import tensor2np +from ..utils import tensor2np, PIL_FILTER_MAP import uuid import folder_paths from ..log import log @@ -7,6 +7,8 @@ import subprocess import torch from pathlib import Path import numpy as np +from PIL import Image +from typing import Optional, List class ExportToProres: @@ -37,9 +39,9 @@ class ExportToProres: if images.size(0) == 0: return ("",) output_dir = Path(folder_paths.get_output_directory()) - id = f"{prefix}_{uuid.uuid4()}.mov" + file_id = f"{prefix}_{uuid.uuid4()}.mov" - log.debug(f"Exporting to {output_dir / id}") + log.debug(f"Exporting to {output_dir / file_id}") frames = tensor2np(images) log.debug(f"Frames type {type(frames[0])}") @@ -49,7 +51,7 @@ class ExportToProres: height, width, _ = frames[0].shape - out_path = (output_dir / id).as_posix() + out_path = (output_dir / file_id).as_posix() # Prepare the FFmpeg command command = [ @@ -91,6 +93,37 @@ class ExportToProres: return (out_path,) +def prepare_animated_batch( + batch: torch.Tensor, + pingpong=False, + resize_by=1.0, + resample_filter: Optional[Image.Resampling] = None, + image_type=np.uint8, +) -> List[Image.Image]: + images = tensor2np(batch) + images = [frame.astype(image_type) for frame in images] + + height, width, _ = batch[0].shape + + if pingpong: + reversed_frames = images[::-1] + images.extend(reversed_frames) + pil_images = [Image.fromarray(frame) for frame in images] + + # Resize frames if necessary + if abs(resize_by - 1.0) > 1e-6: + new_width = int(width * resize_by) + new_height = int(height * resize_by) + pil_images_resized = [ + frame.resize((new_width, new_height), resample=resample_filter) + for frame in pil_images + ] + pil_images = pil_images_resized + + return pil_images + + +# todo: deprecate for apng class SaveGif: """Save the images from the batch as a GIF""" @@ -103,7 +136,10 @@ class SaveGif: "resize_by": ("FLOAT", {"default": 1.0, "min": 0.1}), "optimize": ("BOOLEAN", {"default": False}), "pingpong": ("BOOLEAN", {"default": False}), - } + }, + "optional": { + "resample_filter": (list(PIL_FILTER_MAP.keys()),), + }, } RETURN_TYPES = () @@ -111,58 +147,43 @@ class SaveGif: CATEGORY = "mtb/IO" FUNCTION = "save_gif" - def save_gif(self, image, fps=12, resize_by=1.0, pingpong=False): + def save_gif( + self, + image, + fps=12, + resize_by=1.0, + optimize=False, + pingpong=False, + resample_filter=None, + ): if image.size(0) == 0: return ("",) - images = tensor2np(image) - images = [frame.astype(np.uint8) for frame in images] - if pingpong: - reversed_frames = images[::-1] - images.extend(reversed_frames) + if resample_filter is not None: + resample_filter = PIL_FILTER_MAP.get(resample_filter) - height, width, _ = image[0].shape + pil_images = prepare_animated_batch( + image, + pingpong, + resize_by, + resample_filter, + ) ruuid = uuid.uuid4() - ruuid = ruuid.hex[:10] - out_path = f"{folder_paths.output_directory}/{ruuid}.gif" - log.debug(f"Saving a gif file {width}x{height} as {ruuid}.gif") - - # Prepare the FFmpeg command - command = [ - "ffmpeg", - "-y", - "-f", - "rawvideo", - "-vcodec", - "rawvideo", - "-s", - f"{width}x{height}", - "-pix_fmt", - "rgb24", # GIF only supports rgb24 - "-r", - str(fps), - "-i", - "-", - "-vf", - f"fps={fps},scale={width * resize_by}:-1", # Set frame rate and resize if necessary - "-y", + # Create the GIF from PIL images + pil_images[0].save( out_path, - ] + save_all=True, + append_images=pil_images[1:], + optimize=optimize, + duration=int(1000 / fps), + loop=0, + ) - process = subprocess.Popen(command, stdin=subprocess.PIPE) - - for frame in images: - model_management.throw_exception_if_processing_interrupted() - process.stdin.write(frame.tobytes()) - - process.stdin.close() - process.wait() - results = [] - results.append({"filename": f"{ruuid}.gif", "subfolder": "", "type": "output"}) + results = [{"filename": f"{ruuid}.gif", "subfolder": "", "type": "output"}] return {"ui": {"gif": results}} diff --git a/utils.py b/utils.py index 1152504..ccfdfea 100644 --- a/utils.py +++ b/utils.py @@ -50,35 +50,42 @@ def import_install(package_name): # endregion # region GLOBAL VARIABLES -# Get the absolute path of the parent directory of the current script +# - Get the absolute path of the parent directory of the current script here = Path(__file__).parent.resolve() -# Construct the absolute path to the ComfyUI directory +# - Construct the absolute path to the ComfyUI directory comfy_dir = here.parent.parent -# Construct the path to the font file +# - Construct the path to the font file font_path = here / "font.ttf" -# Add extern folder to path +# - Add extern folder to path extern_root = here / "extern" add_path(extern_root) for pth in extern_root.iterdir(): if pth.is_dir(): add_path(pth) - -# Add the ComfyUI directory and custom nodes path to the sys.path list +# - Add the ComfyUI directory and custom nodes path to the sys.path list add_path(comfy_dir) add_path((comfy_dir / "custom_nodes")) + +PIL_FILTER_MAP = { + "nearest": Image.Resampling.NEAREST, + "box": Image.Resampling.BOX, + "bilinear": Image.Resampling.BILINEAR, + "hamming": Image.Resampling.HAMMING, + "bicubic": Image.Resampling.BICUBIC, + "lanczos": Image.Resampling.LANCZOS, +} + + # endregion # region TENSOR UTILITIES def tensor2pil(image: torch.Tensor) -> List[Image.Image]: - batch_count = 1 - if len(image.shape) > 3: - batch_count = image.size(0) - + batch_count = image.size(0) if len(image.shape) > 3 else 1 if batch_count > 1: out = [] for i in range(batch_count): @@ -107,9 +114,7 @@ def np2tensor(img_np: np.ndarray | List[np.ndarray]) -> torch.Tensor: def tensor2np(tensor: torch.Tensor) -> List[np.ndarray]: - batch_count = 1 - if len(tensor.shape) > 3: - batch_count = tensor.size(0) + batch_count = tensor.size(0) if len(tensor.shape) > 3 else 1 if batch_count > 1: out = [] for i in range(batch_count): From 13d255a730b08c4903647875350b9b3dcd61b4a6 Mon Sep 17 00:00:00 2001 From: melMass Date: Sat, 5 Aug 2023 13:31:54 +0200 Subject: [PATCH 32/56] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20get=20ba?= =?UTF-8?q?tch=20from=20history?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodes/image_interpolation.py | 83 ++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/nodes/image_interpolation.py b/nodes/image_interpolation.py index b8e71ef..8b1e013 100644 --- a/nodes/image_interpolation.py +++ b/nodes/image_interpolation.py @@ -25,7 +25,7 @@ def get_image(filename, subfolder, folder_type): data = {"filename": filename, "subfolder": subfolder, "type": folder_type} url_values = urllib.parse.urlencode(data) with urllib.request.urlopen( - "http://{}:{}/view?{}".format(args.listen, args.port, url_values) + f"http://{args.listen}:{args.port}/view?{url_values}" ) as response: return io.BytesIO(response.read()) @@ -33,7 +33,7 @@ def get_image(filename, subfolder, folder_type): class GetBatchFromHistory: """Very experimental node to load images from the history of the server. - Queue items without output are ignore in the count.""" + Queue items without output are ignored in the count.""" @classmethod def INPUT_TYPES(cls): @@ -42,8 +42,11 @@ class GetBatchFromHistory: "enable": ("BOOLEAN", {"default": True}), "count": ("INT", {"default": 1, "min": 0}), "offset": ("INT", {"default": 0, "min": -1e9, "max": 1e9}), + "internal_count": ("INT", {"default": 0}), + }, + "optional": { + "passthrough_image": ("IMAGE",), }, - "optional": {"passthrough_image": ("IMAGE",)}, } RETURN_TYPES = ("IMAGE",) @@ -56,55 +59,63 @@ class GetBatchFromHistory: enable=True, count=0, offset=0, + internal_count=0, # hacky way to invalidate the node passthrough_image=None, ): if not enable or count == 0: if passthrough_image is not None: + log.debug("Using passthrough image") return (passthrough_image,) log.debug("Load from history is disabled for this iteration") return (torch.zeros(0),) frames = [] with urllib.request.urlopen( - "http://{}:{}/history".format(args.listen, args.port) + f"http://{args.listen}:{args.port}/history" ) as response: - history = json.loads(response.read()) + return self.load_batch_frames(response, offset, count, frames) - output_images = [] - for k, run in history.items(): - for o in run["outputs"]: - for node_id in run["outputs"]: - node_output = run["outputs"][node_id] - if "images" in node_output: - images_output = [] - for image in node_output["images"]: - image_data = get_image( - image["filename"], image["subfolder"], image["type"] - ) - images_output.append(image_data) - output_images.extend(images_output) - if len(output_images) == 0: - return (torch.zeros(0),) - for i, image in enumerate(list(reversed(output_images))): - if i < offset: - continue - if i >= offset + count: - break - # Decode image as tensor - img = Image.open(image) - log.debug(f"Image from history {i} of shape {img.size}") - frames.append(img) + def load_batch_frames(self, response, offset, count, frames): + history = json.loads(response.read()) - # Display the shape of the tensor - # print("Tensor shape:", image_tensor.shape) + output_images = [] + for k, run in history.items(): + for o in run["outputs"]: + for node_id in run["outputs"]: + node_output = run["outputs"][node_id] + if "images" in node_output: + images_output = [] + for image in node_output["images"]: + image_data = get_image( + image["filename"], image["subfolder"], image["type"] + ) + images_output.append(image_data) + output_images.extend(images_output) + if not output_images: + return (torch.zeros(0),) + for i, image in enumerate(list(reversed(output_images))): + if i < offset: + continue + if i >= offset + count: + break + # Decode image as tensor + img = Image.open(image) + log.debug(f"Image from history {i} of shape {img.size}") + frames.append(img) + + # Display the shape of the tensor + # print("Tensor shape:", image_tensor.shape) # return (output_images,) + if not frames: + return (torch.zeros(0),) + elif len(frames) != count: + log.warning(f"Expected {count} images, got {len(frames)} instead") + output = pil2tensor( + list(reversed(frames)), + ) - output = pil2tensor( - list(reversed(frames)), - ) - - return (output,) + return (output,) class LoadFilmModel: From a54d7d5346c272898dd4e67c65495de7325ab3a0 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Sun, 6 Aug 2023 00:34:42 +0200 Subject: [PATCH 33/56] =?UTF-8?q?feat:=20=F0=9F=8E=A8=20update=20node=20li?= =?UTF-8?q?st?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_list.json | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/node_list.json b/node_list.json index 42dc354..7ddc03e 100644 --- a/node_list.json +++ b/node_list.json @@ -14,7 +14,7 @@ "Film Interpolation (mtb)": "Google Research FILM frame interpolation for large motion", "Fit Number (mtb)": "Fit the input float using a source and target range", "Float To Number (mtb)": "Node addon for the WAS Suite. Converts a \"comfy\" FLOAT to a NUMBER.", - "Get Batch From History (mtb)": "Very experimental node to load images from the history of the server.\n\n Queue items without output are ignore in the count.", + "Get Batch From History (mtb)": "Very experimental node to load images from the history of the server.\n\n Queue items without output are ignored in the count.", "Image Compare (mtb)": "Compare two images and return a difference image", "Image Premultiply (mtb)": "Premultiply image with mask", "Image Remove Background Rembg (mtb)": "Removes the background from the input using Rembg.", @@ -22,8 +22,7 @@ "Int To Bool (mtb)": "Basic int to bool conversion", "Int To Number (mtb)": "Node addon for the WAS Suite. Converts a \"comfy\" INT to a NUMBER.", "Latent Lerp (mtb)": "Linear interpolation (blend) between two latent vectors", - "Latent Noise (mtb)": "Inject noise into latent space", - "Latent Transform (mtb)": "Dumb attempt at reproducing some deforum like motion", + "Load Face Analysis Model (mtb)": "Loads a face analysis model", "Load Face Enhance Model (mtb)": "Loads a GFPGan or RestoreFormer model for face enhancement.", "Load Face Swap Model (mtb)": "Loads a faceswap model", "Load Film Model (mtb)": "Loads a FILM model", @@ -35,9 +34,12 @@ "Save Gif (mtb)": "Save the images from the batch as a GIF", "Save Image Grid (mtb)": "Save all the images in the input batch as a grid of images.", "Save Image Sequence (mtb)": "Save an image sequence to a folder. The current frame is used to determine which image to save.\n\n This is merely a wrapper around the `save_images` function with formatting for the output folder and filename.\n ", + "Save Tensors (mtb)": "Save torch tensors (image, mask or latent) to disk, useful to debug things outside comfy", "Smart Step (mtb)": "Utils to control the steps start/stop of the KAdvancedSampler in percentage", "String Replace (mtb)": "Basic string replacement", "Styles Loader (mtb)": "Load csv files and populate a dropdown from the rows (\u00e0 la A111)", "Text To Image (mtb)": "Utils to convert text to image using a font\n\n\n The tool looks for any .ttf file in the Comfy folder hierarchy.\n ", - "Uncrop (mtb)": "Uncrops an image to a given bounding box\n\n The bounding box can be given as a tuple of (x, y, width, height) or as a BBOX type\n The BBOX input takes precedence over the tuple input" -} \ No newline at end of file + "Transform Image (mtb)": "Save torch tensors (image, mask or latent) to disk, useful to debug things outside comfy\n\n\n it return a tensor representing the transformed images with the same shape as the input tensor\n ", + "Uncrop (mtb)": "Uncrops an image to a given bounding box\n\n The bounding box can be given as a tuple of (x, y, width, height) or as a BBOX type\n The BBOX input takes precedence over the tuple input", + "Unsplash Image (mtb)": "Unsplash Image given a keyword and a size" +} From 63b3aece2ba05adc2b655afeb41e3d47e7887b33 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Mon, 7 Aug 2023 00:39:32 +0200 Subject: [PATCH 34/56] =?UTF-8?q?ci:=20=F0=9F=9A=80=20add=20controlnetprep?= =?UTF-8?q?rocessors=20to=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test_embedded.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/test_embedded.yml b/.github/workflows/test_embedded.yml index c28f3d4..c62fd1b 100644 --- a/.github/workflows/test_embedded.yml +++ b/.github/workflows/test_embedded.yml @@ -37,7 +37,16 @@ jobs: with: path: ComfyUI_windows_portable key: ${{ runner.os }}-comfy-env + - name: ⏬ Install other extensions + shell: bash + run: | + export COMFY_PYTHON="${GITHUB_WORKSPACE}/ComfyUI_windows_portable/python_embeded/python.exe" + cd "${GITHUB_WORKSPACE}/ComfyUI_windows_portable/ComfyUI/custom_nodes" + git clone https://github.com/Fannovel16/comfy_controlnet_preprocessors + cd comfy_controlnet_preprocessors + $COMFY_PYTHON install.py + - name: ♻️ Checking out comfy_mtb to custom_nodes uses: actions/checkout@v3 with: From 84ac8ac852aeb962029bfd8369fe5ed59a203977 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Mon, 7 Aug 2023 02:59:16 +0200 Subject: [PATCH 35/56] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20missing=20?= =?UTF-8?q?input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodes/image_interpolation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nodes/image_interpolation.py b/nodes/image_interpolation.py index 2fcb3f7..60541cc 100644 --- a/nodes/image_interpolation.py +++ b/nodes/image_interpolation.py @@ -42,6 +42,7 @@ class GetBatchFromHistory: "enable": ("BOOL", {"default": True}), "count": ("INT", {"default": 1, "min": 0}), "offset": ("INT", {"default": 0, "min": -1e9, "max": 1e9}), + "internal_count": ("INT", {"default": 0}), }, "optional": {"passthrough_image": ("IMAGE",)}, } @@ -56,6 +57,7 @@ class GetBatchFromHistory: enable=True, count=0, offset=0, + internal_count=0, # hacky way to invalidate the node passthrough_image=None, ): if not enable or count == 0: From fb644847ca434123e8e8e4991d33949fd31e3cbe Mon Sep 17 00:00:00 2001 From: melMass Date: Mon, 7 Aug 2023 20:49:47 +0200 Subject: [PATCH 36/56] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20border=20extens?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The maths are still not correct I need to debug it in isolation --- nodes/transform.py | 38 ++++++++++++++++++++++++++++++++------ web/comfy_shared.js | 2 +- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/nodes/transform.py b/nodes/transform.py index 71d6580..c0b9be9 100644 --- a/nodes/transform.py +++ b/nodes/transform.py @@ -19,6 +19,10 @@ class TransformImage: "zoom": ("FLOAT", {"default": 1.0, "min": 0.001}), "angle": ("FLOAT", {"default": 0}), "shear": ("FLOAT", {"default": 0}), + "border_handling": ( + ["edge", "constant", "reflect", "symmetric"], + {"default": "edge"}, + ), }, } @@ -34,19 +38,41 @@ class TransformImage: zoom: float, angle: int, shear, + border_handling="edge", ): if image.size(0) == 0: return (torch.zeros(0),) transformed_images = [] - for img in image: - img = img.transpose(0, 2) + frames_count, frame_height, frame_width, frame_channel_count = image.size() - transformed_image = F.affine( - img, angle=angle, scale=zoom, translate=[int(y), int(x)], shear=shear + new_height, new_width = int(frame_height * zoom), int(frame_width * zoom) + + pw = int(frame_width - new_width) + ph = int(frame_height - new_height) + padding = [max(0, pw + x), max(0, ph + y), max(0, pw - x), max(0, ph - y)] + + for img in image: + img = img.permute(2, 0, 1) + new_height, new_width = int(frame_height * zoom), int(frame_width * zoom) + pw = int(frame_width - new_width) + ph = int(frame_height - new_height) + + padding = [int(i) for i in padding] + + img = F.pad( + img, # transformed_frame, + padding=padding, + padding_mode=border_handling, ) - transformed_image = transformed_image.transpose(2, 0) - transformed_images.append(transformed_image.unsqueeze(0)) + img = F.affine(img, angle=angle, scale=zoom, translate=[x, y], shear=shear) + + crop = [ph + y, -(ph - y), x + pw, -(pw - x)] + + img = img[:, crop[0] : crop[1], crop[2] : crop[3]] + + img = img.permute(1, 2, 0) + transformed_images.append(img.unsqueeze(0)) return (torch.cat(transformed_images, dim=0),) diff --git a/web/comfy_shared.js b/web/comfy_shared.js index 57850ac..3f34b54 100644 --- a/web/comfy_shared.js +++ b/web/comfy_shared.js @@ -49,7 +49,7 @@ export function offsetDOMWidget( position: 'absolute', background: !node.color ? '' : node.color, color: !node.color ? '' : 'white', - zIndex: app.graph._nodes.indexOf(node), + zIndex: 5, //app.graph._nodes.indexOf(node), }) } From 91f60d4c463c474ac10e868e8e73e13fa019856b Mon Sep 17 00:00:00 2001 From: melMass Date: Mon, 7 Aug 2023 21:24:23 +0200 Subject: [PATCH 37/56] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20frontend?= =?UTF-8?q?=20pushed=20too=20early?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since I mistakenly pushed some js code from a PR some nodes weren't working anymore... This fix that and the model path for face_restore nodes if installed using the manager, with a fallback for now.. --- nodes/faceenhance.py | 36 +++++++++++++++++++++++++++++------- nodes/faceswap.py | 2 -- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/nodes/faceenhance.py b/nodes/faceenhance.py index 4dafd39..0c97db4 100644 --- a/nodes/faceenhance.py +++ b/nodes/faceenhance.py @@ -26,19 +26,39 @@ class LoadFaceEnhanceModel: @classmethod def get_models_root(cls): - return Path(folder_paths.models_dir) / "upscale_models" + fr = Path(folder_paths.models_dir) / "face_restore" + if fr.exists(): + return (fr, None) + + um = Path(folder_paths.models_dir) / "upscale_models" + return (fr, um) if um.exists() else (None, None) @classmethod def get_models(cls): - models_path = cls.get_models_root() + fr_models_path, um_models_path = cls.get_models_root() - if not models_path.exists(): - log.warning(f"No models found at {models_path}") + if fr_models_path is None and um_models_path is None: + log.warning("Face restoration models not found.") + return [] + if not fr_models_path.exists(): + log.warning( + f"No Face Restore checkpoints found at {fr_models_path} (if you've used mtb before these checkpoints were saved in upscale_models before)" + ) + log.warning( + "For now we fallback to upscale_models but this will be removed in a future version" + ) + if um_models_path.exists(): + return [ + x + for x in um_models_path.iterdir() + if x.name.endswith(".pth") + and ("GFPGAN" in x.name or "RestoreFormer" in x.name) + ] return [] return [ x - for x in models_path.iterdir() + for x in fr_models_path.iterdir() if x.name.endswith(".pth") and ("GFPGAN" in x.name or "RestoreFormer" in x.name) ] @@ -64,7 +84,7 @@ class LoadFaceEnhanceModel: def load_model(self, model_name, upscale=2, bg_upsampler=None): basic = "RestoreFormer" not in model_name - root = self.get_models_root() + fr_root, um_root = self.get_models_root() if bg_upsampler is not None: log.warning( @@ -75,7 +95,9 @@ class LoadFaceEnhanceModel: sys.stdout = NullWriter() model = GFPGANer( - model_path=(root / model_name).as_posix(), + model_path=( + (fr_root if fr_root.exists() else um_root) / model_name + ).as_posix(), upscale=upscale, arch="clean" if basic else "RestoreFormer", # or original for v1.0 only channel_multiplier=2, # 1 for v1.0 only diff --git a/nodes/faceswap.py b/nodes/faceswap.py index 4f0eba9..faf433d 100644 --- a/nodes/faceswap.py +++ b/nodes/faceswap.py @@ -120,7 +120,6 @@ class FaceSwap: "faces_index": ("STRING", {"default": "0"}), "faceanalysis_model": ("FACE_ANALYSIS_MODEL", {"default": "None"}), "faceswap_model": ("FACESWAP_MODEL", {"default": "None"}), - "debug": ("BOOL", {"default": False}), }, "optional": {}, } @@ -136,7 +135,6 @@ class FaceSwap: faces_index: str, faceanalysis_model, faceswap_model, - debug=False, ): def do_swap(img): model_management.throw_exception_if_processing_interrupted() From 4dd532185223a1fa5978446e7bb75d32d77ebdb5 Mon Sep 17 00:00:00 2001 From: melMass Date: Mon, 7 Aug 2023 23:53:34 +0200 Subject: [PATCH 38/56] =?UTF-8?q?fix:=20=E2=AC=87=EF=B8=8F=20download=5Fan?= =?UTF-8?q?telopev2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the url used in insightface returns 404. fixes #55 --- nodes/faceswap.py | 5 ++++- utils.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/nodes/faceswap.py b/nodes/faceswap.py index faf433d..b21396b 100644 --- a/nodes/faceswap.py +++ b/nodes/faceswap.py @@ -12,7 +12,7 @@ import os import tempfile import torch from insightface.model_zoo.inswapper import INSwapper -from ..utils import pil2tensor, tensor2pil +from ..utils import pil2tensor, tensor2pil, download_antelopev2 from ..log import mklog, NullWriter import sys import comfy.model_management as model_management @@ -53,6 +53,9 @@ class LoadFaceAnalysisModel: CATEGORY = "mtb/facetools" def load_model(self, faceswap_model: str): + if faceswap_model == "antelopev2": + download_antelopev2() + face_analyser = insightface.app.FaceAnalysis( name=faceswap_model, root=os.path.join(folder_paths.models_dir, "insightface"), diff --git a/utils.py b/utils.py index 1152504..4068c6b 100644 --- a/utils.py +++ b/utils.py @@ -4,6 +4,7 @@ import torch from pathlib import Path import sys from typing import List +from .log import log # region MISC Utilities @@ -120,3 +121,43 @@ def tensor2np(tensor: torch.Tensor) -> List[np.ndarray]: # endregion + +# region MODEL Utilities +def download_antelopev2(): + antelopev2_url = "https://drive.google.com/uc?id=18wEUfMNohBJ4K3Ly5wpTejPfDzp-8fI8" + + try: + import gdown + + import folder_paths + + log.debug("Loading antelopev2 model") + + dest = Path(folder_paths.models_dir) / "insightface" + archive = dest / "antelopev2.zip" + final_path = dest / "models" / "antelopev2" + if not final_path.exists(): + log.info(f"antelopev2 not found, downloading to {dest}") + gdown.download( + antelopev2_url, + archive.as_posix(), + resume=True, + ) + + log.info(f"Unzipping antelopev2 to {final_path}") + + if archive.exists(): + # we unzip it + import zipfile + + with zipfile.ZipFile(archive.as_posix(), "r") as zip_ref: + zip_ref.extractall(final_path.parent.as_posix()) + + except Exception as e: + log.error( + f"Could not load or download antelopev2 model, download it manually from {antelopev2_url}" + ) + raise e + + +# endregion From 3f14b1676d28f5ffa1f47fda00b9bc244951045c Mon Sep 17 00:00:00 2001 From: melMass Date: Tue, 8 Aug 2023 21:29:28 +0200 Subject: [PATCH 39/56] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20portable=20reqs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reqs_portable.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 reqs_portable.txt diff --git a/reqs_portable.txt b/reqs_portable.txt new file mode 100644 index 0000000..a29f000 --- /dev/null +++ b/reqs_portable.txt @@ -0,0 +1,14 @@ +https://github.com/melMass/comfy_mtb/releases/download/v0.1.3/pycocotools-2.0.6-cp310-cp310-win_amd64.whl +https://github.com/melMass/comfy_mtb/releases/download/v0.1.3/future-0.18.3-py3-none-any.whl +https://github.com/melMass/comfy_mtb/releases/download/v0.1.3/filterpy-1.4.5-py3-none-any.whl +https://github.com/melMass/comfy_mtb/releases/download/v0.1.3/easydict-1.10-py3-none-any.whl +https://github.com/melMass/comfy_mtb/releases/download/v0.1.3/gdown-4.7.1-py3-none-any.whl +https://github.com/melMass/comfy_mtb/releases/download/v0.1.3/basicsr-1.4.2-py3-none-any.whl +https://github.com/melMass/comfy_mtb/releases/download/v0.1.3/mmcv-2.0.0-py2.py3-none-any.whl +https://github.com/melMass/comfy_mtb/releases/download/v0.1.3/insightface-0.7.3-cp310-cp310-win_amd64.whl + +onnxruntime-gpu==1.15.1 +qrcode[pil] +rembg==2.0.50 +tensorflow==2.10.1; platform_system == "Windows" +facexlib==0.3.0 From 414beb99a1f9bf719eca6ac139c9b2ccdfd6d743 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Tue, 8 Aug 2023 22:40:53 +0200 Subject: [PATCH 40/56] =?UTF-8?q?ci:=20=F0=9F=9A=80=20only=20fetch=20contr?= =?UTF-8?q?olnet=5Fpreprocessor=20deps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A true install seems to requires CUDA, I can probably change the image too. --- .github/workflows/test_embedded.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_embedded.yml b/.github/workflows/test_embedded.yml index c62fd1b..ac4daef 100644 --- a/.github/workflows/test_embedded.yml +++ b/.github/workflows/test_embedded.yml @@ -45,7 +45,7 @@ jobs: git clone https://github.com/Fannovel16/comfy_controlnet_preprocessors cd comfy_controlnet_preprocessors - $COMFY_PYTHON install.py + $COMFY_PYTHON -m pip install -r requirements.txt - name: ♻️ Checking out comfy_mtb to custom_nodes uses: actions/checkout@v3 From 4f30829e06c41b3685644bfe7bece07e0bcfb70e Mon Sep 17 00:00:00 2001 From: melMass Date: Tue, 8 Aug 2023 23:16:29 +0200 Subject: [PATCH 41/56] =?UTF-8?q?refactor:=20=F0=9F=9A=A7=20tidy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reqs.txt | 1 + reqs_portable.txt | 1 + .../interpolate_frames.py | 0 utils.py | 89 +++++++++++++++++++ 4 files changed, 91 insertions(+) rename interpolate_frames.py => scripts/interpolate_frames.py (100%) diff --git a/reqs.txt b/reqs.txt index b0c986f..9049834 100644 --- a/reqs.txt +++ b/reqs.txt @@ -9,3 +9,4 @@ tensorflow; platform_system != "Windows" facexlib==0.3.0 insightface==0.7.3 basicsr==1.4.2 +protobuf==3.19.6 \ No newline at end of file diff --git a/reqs_portable.txt b/reqs_portable.txt index a29f000..ddec4c0 100644 --- a/reqs_portable.txt +++ b/reqs_portable.txt @@ -12,3 +12,4 @@ qrcode[pil] rembg==2.0.50 tensorflow==2.10.1; platform_system == "Windows" facexlib==0.3.0 +protobuf==3.19.6 \ No newline at end of file diff --git a/interpolate_frames.py b/scripts/interpolate_frames.py similarity index 100% rename from interpolate_frames.py rename to scripts/interpolate_frames.py diff --git a/utils.py b/utils.py index e8aa4d3..d6ab36f 100644 --- a/utils.py +++ b/utils.py @@ -5,6 +5,21 @@ from pathlib import Path import sys from typing import List from .log import log +import signal +from contextlib import suppress +from queue import Queue, Empty +import subprocess +import threading +import os + +# - detect mode +comfy_mode = None +if os.environ.get("COLAB_GPU"): + comfy_mode = "colab" +elif "python_embeded" in sys.executable: + comfy_mode = "embeded" +elif ".venv" in sys.executable: + comfy_mode = "venv" # region MISC Utilities @@ -24,6 +39,79 @@ def add_path(path, prepend=False): sys.path.append(path) +def enqueue_output(out, queue): + for line in iter(out.readline, b""): + queue.put(line) + out.close() + + +def run_command(cmd): + if isinstance(cmd, str): + shell_cmd = cmd + elif isinstance(cmd, list): + shell_cmd = "" + for arg in cmd: + if isinstance(arg, Path): + arg = arg.as_posix() + shell_cmd += f"{arg} " + else: + raise ValueError( + "Invalid 'cmd' argument. It must be a string or a list of arguments." + ) + + process = subprocess.Popen( + shell_cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + shell=True, + ) + + # Create separate threads to read standard output and standard error streams + stdout_queue = Queue() + stderr_queue = Queue() + stdout_thread = threading.Thread( + target=enqueue_output, args=(process.stdout, stdout_queue) + ) + stderr_thread = threading.Thread( + target=enqueue_output, args=(process.stderr, stderr_queue) + ) + stdout_thread.daemon = True + stderr_thread.daemon = True + stdout_thread.start() + stderr_thread.start() + + interrupted = False + + def signal_handler(signum, frame): + nonlocal interrupted + interrupted = True + print("Command execution interrupted.") + + # Register the signal handler for keyboard interrupts (SIGINT) + signal.signal(signal.SIGINT, signal_handler) + + # Process output from both streams until the process completes or interrupted + while not interrupted and ( + process.poll() is None or not stdout_queue.empty() or not stderr_queue.empty() + ): + with suppress(Empty): + stdout_line = stdout_queue.get_nowait() + if stdout_line.strip() != "": + print(stdout_line.strip()) + with suppress(Empty): + stderr_line = stderr_queue.get_nowait() + if stderr_line.strip() != "": + print(stderr_line.strip()) + return_code = process.returncode + + if return_code == 0 and not interrupted: + print("Command executed successfully!") + else: + if not interrupted: + print(f"Command failed with return code: {return_code}") + + # todo use the requirements library reqs_map = { "onnxruntime": "onnxruntime-gpu==1.15.1", @@ -127,6 +215,7 @@ def tensor2np(tensor: torch.Tensor) -> List[np.ndarray]: # endregion + # region MODEL Utilities def download_antelopev2(): antelopev2_url = "https://drive.google.com/uc?id=18wEUfMNohBJ4K3Ly5wpTejPfDzp-8fI8" From 630b492347f75d7308b31a000061b41d7dfa4a10 Mon Sep 17 00:00:00 2001 From: melMass Date: Wed, 9 Aug 2023 14:33:58 +0200 Subject: [PATCH 42/56] =?UTF-8?q?fix:=20=F0=9F=9A=A7=20wip=20dependency=20?= =?UTF-8?q?installer=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Will allow to install missing deps/models from the endpoint: /mtb/status --- __init__.py | 16 +++++++++- endpoint.py | 90 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 92 insertions(+), 14 deletions(-) diff --git a/__init__.py b/__init__.py index 0439ac0..90e764d 100644 --- a/__init__.py +++ b/__init__.py @@ -187,6 +187,14 @@ import logging from .endpoint import endlog if hasattr(PromptServer, "instance"): + restore_deps = ["basicsr"] + swap_deps = ["insightface", "onnxruntime"] + + node_dependency_mapping = { + "FaceSwap": swap_deps, + "LoadFaceSwapModel": swap_deps, + "LoadFaceAnalysisModel": restore_deps, + } @PromptServer.instance.routes.get("/mtb/status") async def get_full_library(request): @@ -202,7 +210,13 @@ if hasattr(PromptServer, "instance"): NODE_CLASS_MAPPINGS_DEBUG, title="Registered" ) html_response += endpoint.render_table( - {k: "-" for k in failed}, title="Failed to load" + { + k: {"dependencies": node_dependency_mapping.get(k)} + if node_dependency_mapping.get(k) + else "-" + for k in failed + }, + title="Failed to load", ) return web.Response( diff --git a/endpoint.py b/endpoint.py index d2030e0..9d137f7 100644 --- a/endpoint.py +++ b/endpoint.py @@ -1,11 +1,35 @@ -from .utils import here +from .utils import here, run_command, comfy_mode from aiohttp import web from .log import mklog -import os +import sys endlog = mklog("mtb endpoint") -#- ACTIONS +# - ACTIONS +import requirements + + + +def ACTIONS_installDependency(dependency_names=None): + if dependency_names is None: + return {"error": "No dependency name provided"} + endlog.debug(f"Received Install Dependency request for {dependency_names}") + reqs = [] + if comfy_mode == "embeded": + reqs = list(requirements.parse((here / "reqs_portable.txt").read_text())) + else: + reqs = list(requirements.parse((here / "reqs.txt").read_text())) + print([x.specs for x in reqs]) + print( + "\n".join([f"{x.line} {''.join(x.specs[0] if x.specs else '')}" for x in reqs]) + ) + for dependency_name in dependency_names: + for req in reqs: + if req.name == dependency_name: + endlog.debug(f"Dependency {dependency_name} installed") + break + return {"success": True} + def ACTIONS_getStyles(style_name=None): from .nodes.conditions import StylesLoader @@ -19,10 +43,7 @@ def ACTIONS_getStyles(style_name=None): if not key.startswith("__") and key not in match_list } if style_name: - if style_name in filtered_styles: - return filtered_styles[style_name] - else: - return {"error": "Style not found"} + return filtered_styles.get(style_name, {"error": "Style not found"}) return filtered_styles return {"error": "No styles found"} @@ -35,7 +56,7 @@ async def do_action(request) -> web.Response: endlog.debug(f"Received action request: {name} {args}") - method_name = "ACTIONS_" + name + method_name = f"ACTIONS_{name}" method = globals().get(method_name) if callable(method): @@ -53,16 +74,36 @@ async def do_action(request) -> web.Response: # - HTML UTILS + + +def dependencies_button(name, dependencies): + deps = ",".join([f"'{x}'" for x in dependencies]) + return f""" + + """ + + def render_table(table_dict, sort=True, title=None): - table_rows = "" table_dict = sorted( table_dict.items(), key=lambda item: item[0] ) # Sort the dictionary by keys - for name, description in table_dict: - table_rows += f"{name}{description}" + table_rows = "" + for name, item in table_dict: + if isinstance(item, dict): + if "dependencies" in item: + table_rows += f"{name}" + table_rows += f"{dependencies_button(name,item['dependencies'])}" - html_response = f""" + table_rows += "" + else: + table_rows += f"{name}{render_table(item)}" + # elif isinstance(item, str): + # table_rows += f"{name}{item}" + else: + table_rows += f"{name}{item}" + + return f"""
{"" if title is None else f"

{title}

"} @@ -78,7 +119,6 @@ def render_table(table_dict, sort=True, title=None):
""" - return html_response def render_base_template(title, content): @@ -98,6 +138,29 @@ def render_base_template(title, content): {css_content} +
Back to Comfy @@ -117,5 +180,6 @@ def render_base_template(title, content): + """ From 5ec551143302b2a94ca82e477f684ecee23f1459 Mon Sep 17 00:00:00 2001 From: melMass Date: Wed, 9 Aug 2023 21:59:46 +0200 Subject: [PATCH 43/56] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20UI=20for=20inte?= =?UTF-8?q?rpolate=20clip=20sequential?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/mtb_widgets.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/web/mtb_widgets.js b/web/mtb_widgets.js index 30283b5..803d1a4 100644 --- a/web/mtb_widgets.js +++ b/web/mtb_widgets.js @@ -781,6 +781,40 @@ const mtb_widgets = { } break } + case 'Interpolate Clip Sequential (mtb)': { + const onNodeCreated = nodeType.prototype.onNodeCreated + nodeType.prototype.onNodeCreated = function () { + const r = onNodeCreated + ? onNodeCreated.apply(this, arguments) + : undefined + const addReplacement = () => { + const input = this.addInput( + `replacement_${this.widgets.length}`, + 'STRING', + '' + ) + console.log(input) + this.addWidget('STRING', `replacement_${this.widgets.length}`, '') + } + //- add + this.addWidget('button', '+', 'add', function (value, widget, node) { + console.log('Button clicked', value, widget, node) + addReplacement() + }) + //- remove + this.addWidget( + 'button', + '-', + 'remove', + function (value, widget, node) { + console.log(`Button clicked: ${value}`, widget, node) + } + ) + + return r + } + break + } case 'Styles Loader (mtb)': { const origGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions nodeType.prototype.getExtraMenuOptions = function (_, options) { From 2eccba4e33b21d1d080cb2f415f76a93488120f0 Mon Sep 17 00:00:00 2001 From: melMass Date: Thu, 10 Aug 2023 16:34:36 +0200 Subject: [PATCH 44/56] =?UTF-8?q?fix:=20=E2=9A=A1=EF=B8=8F=20move=20getbat?= =?UTF-8?q?chfromhistory=20to=20graphutils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #59 --- nodes/graph_utils.py | 107 ++++++++++++++++++++++++++++++++- nodes/image_interpolation.py | 112 +---------------------------------- 2 files changed, 107 insertions(+), 112 deletions(-) diff --git a/nodes/graph_utils.py b/nodes/graph_utils.py index 0288a99..3704a2d 100644 --- a/nodes/graph_utils.py +++ b/nodes/graph_utils.py @@ -1,4 +1,109 @@ from ..log import log +from PIL import Image +import urllib.request +import urllib.parse +import torch +import json +from comfy.cli_args import args +from ..utils import pil2tensor +import io + + +def get_image(filename, subfolder, folder_type): + data = {"filename": filename, "subfolder": subfolder, "type": folder_type} + url_values = urllib.parse.urlencode(data) + with urllib.request.urlopen( + f"http://{args.listen}:{args.port}/view?{url_values}" + ) as response: + return io.BytesIO(response.read()) + + +class GetBatchFromHistory: + """Very experimental node to load images from the history of the server. + + Queue items without output are ignored in the count.""" + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "enable": ("BOOLEAN", {"default": True}), + "count": ("INT", {"default": 1, "min": 0}), + "offset": ("INT", {"default": 0, "min": -1e9, "max": 1e9}), + "internal_count": ("INT", {"default": 0}), + }, + "optional": { + "passthrough_image": ("IMAGE",), + }, + } + + RETURN_TYPES = ("IMAGE",) + RETURN_NAMES = "images" + CATEGORY = "mtb/animation" + FUNCTION = "load_from_history" + + def load_from_history( + self, + enable=True, + count=0, + offset=0, + internal_count=0, # hacky way to invalidate the node + passthrough_image=None, + ): + if not enable or count == 0: + if passthrough_image is not None: + log.debug("Using passthrough image") + return (passthrough_image,) + log.debug("Load from history is disabled for this iteration") + return (torch.zeros(0),) + frames = [] + + with urllib.request.urlopen( + f"http://{args.listen}:{args.port}/history" + ) as response: + return self.load_batch_frames(response, offset, count, frames) + + def load_batch_frames(self, response, offset, count, frames): + history = json.loads(response.read()) + + output_images = [] + for k, run in history.items(): + for o in run["outputs"]: + for node_id in run["outputs"]: + node_output = run["outputs"][node_id] + if "images" in node_output: + images_output = [] + for image in node_output["images"]: + image_data = get_image( + image["filename"], image["subfolder"], image["type"] + ) + images_output.append(image_data) + output_images.extend(images_output) + if not output_images: + return (torch.zeros(0),) + for i, image in enumerate(list(reversed(output_images))): + if i < offset: + continue + if i >= offset + count: + break + # Decode image as tensor + img = Image.open(image) + log.debug(f"Image from history {i} of shape {img.size}") + frames.append(img) + + # Display the shape of the tensor + # print("Tensor shape:", image_tensor.shape) + + # return (output_images,) + if not frames: + return (torch.zeros(0),) + elif len(frames) != count: + log.warning(f"Expected {count} images, got {len(frames)} instead") + output = pil2tensor( + list(reversed(frames)), + ) + + return (output,) class StringReplace: @@ -72,4 +177,4 @@ class FitNumber: return (res,) -__nodes__ = [StringReplace, FitNumber] +__nodes__ = [StringReplace, FitNumber, GetBatchFromHistory] diff --git a/nodes/image_interpolation.py b/nodes/image_interpolation.py index 8b1e013..6bd39ae 100644 --- a/nodes/image_interpolation.py +++ b/nodes/image_interpolation.py @@ -9,113 +9,8 @@ from frame_interpolation.eval import util, interpolator import numpy as np import comfy import comfy.utils -from PIL import Image -import urllib.request -import urllib.parse -import json import tensorflow as tf import comfy.model_management as model_management -import io - -from comfy.cli_args import args -from ..utils import pil2tensor - - -def get_image(filename, subfolder, folder_type): - data = {"filename": filename, "subfolder": subfolder, "type": folder_type} - url_values = urllib.parse.urlencode(data) - with urllib.request.urlopen( - f"http://{args.listen}:{args.port}/view?{url_values}" - ) as response: - return io.BytesIO(response.read()) - - -class GetBatchFromHistory: - """Very experimental node to load images from the history of the server. - - Queue items without output are ignored in the count.""" - - @classmethod - def INPUT_TYPES(cls): - return { - "required": { - "enable": ("BOOLEAN", {"default": True}), - "count": ("INT", {"default": 1, "min": 0}), - "offset": ("INT", {"default": 0, "min": -1e9, "max": 1e9}), - "internal_count": ("INT", {"default": 0}), - }, - "optional": { - "passthrough_image": ("IMAGE",), - }, - } - - RETURN_TYPES = ("IMAGE",) - RETURN_NAMES = "images" - CATEGORY = "mtb/animation" - FUNCTION = "load_from_history" - - def load_from_history( - self, - enable=True, - count=0, - offset=0, - internal_count=0, # hacky way to invalidate the node - passthrough_image=None, - ): - if not enable or count == 0: - if passthrough_image is not None: - log.debug("Using passthrough image") - return (passthrough_image,) - log.debug("Load from history is disabled for this iteration") - return (torch.zeros(0),) - frames = [] - - with urllib.request.urlopen( - f"http://{args.listen}:{args.port}/history" - ) as response: - return self.load_batch_frames(response, offset, count, frames) - - def load_batch_frames(self, response, offset, count, frames): - history = json.loads(response.read()) - - output_images = [] - for k, run in history.items(): - for o in run["outputs"]: - for node_id in run["outputs"]: - node_output = run["outputs"][node_id] - if "images" in node_output: - images_output = [] - for image in node_output["images"]: - image_data = get_image( - image["filename"], image["subfolder"], image["type"] - ) - images_output.append(image_data) - output_images.extend(images_output) - if not output_images: - return (torch.zeros(0),) - for i, image in enumerate(list(reversed(output_images))): - if i < offset: - continue - if i >= offset + count: - break - # Decode image as tensor - img = Image.open(image) - log.debug(f"Image from history {i} of shape {img.size}") - frames.append(img) - - # Display the shape of the tensor - # print("Tensor shape:", image_tensor.shape) - - # return (output_images,) - if not frames: - return (torch.zeros(0),) - elif len(frames) != count: - log.warning(f"Expected {count} images, got {len(frames)} instead") - output = pil2tensor( - list(reversed(frames)), - ) - - return (output,) class LoadFilmModel: @@ -256,9 +151,4 @@ class ConcatImages: return (self.concatenate_tensors(imageA, imageB),) -__nodes__ = [ - LoadFilmModel, - FilmInterpolation, - ConcatImages, - GetBatchFromHistory, -] +__nodes__ = [LoadFilmModel, FilmInterpolation, ConcatImages] From 11444662b9198861b62aff06a08b9c9ea01dd8bd Mon Sep 17 00:00:00 2001 From: melMass Date: Thu, 10 Aug 2023 22:54:19 +0200 Subject: [PATCH 45/56] =?UTF-8?q?fix:=20=E2=9C=A8=20refactor=20existing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodes/graph_utils.py | 1 + nodes/transform.py | 70 +++++++++++++++++++++++++++++++------------- utils.py | 5 ++++ 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/nodes/graph_utils.py b/nodes/graph_utils.py index 3704a2d..70c711b 100644 --- a/nodes/graph_utils.py +++ b/nodes/graph_utils.py @@ -10,6 +10,7 @@ import io def get_image(filename, subfolder, folder_type): + log.debug(f"Getting image {filename} from {subfolder} of {folder_type}") data = {"filename": filename, "subfolder": subfolder, "type": folder_type} url_values = urllib.parse.urlencode(data) with urllib.request.urlopen( diff --git a/nodes/transform.py b/nodes/transform.py index c0b9be9..858a489 100644 --- a/nodes/transform.py +++ b/nodes/transform.py @@ -1,5 +1,9 @@ import torch import torchvision.transforms.functional as F +from ..utils import log, hex_to_rgb, tensor2pil, pil2tensor +from math import sqrt, ceil +from typing import cast +from PIL import Image class TransformImage: @@ -14,15 +18,19 @@ class TransformImage: return { "required": { "image": ("IMAGE",), - "x": ("FLOAT", {"default": 0}), - "y": ("FLOAT", {"default": 0}), - "zoom": ("FLOAT", {"default": 1.0, "min": 0.001}), - "angle": ("FLOAT", {"default": 0}), - "shear": ("FLOAT", {"default": 0}), + "x": ("FLOAT", {"default": 0, "step": 1, "min": -4096, "max": 4096}), + "y": ("FLOAT", {"default": 0, "step": 1, "min": -4096, "max": 4096}), + "zoom": ("FLOAT", {"default": 1.0, "min": 0.001, "step": 0.01}), + "angle": ("FLOAT", {"default": 0, "step": 1, "min": -360, "max": 360}), + "shear": ( + "FLOAT", + {"default": 0, "step": 1, "min": -4096, "max": 4096}, + ), "border_handling": ( ["edge", "constant", "reflect", "symmetric"], {"default": "edge"}, ), + "constant_color": ("COLOR", {"default": "black"}), }, } @@ -36,10 +44,17 @@ class TransformImage: x: float, y: float, zoom: float, - angle: int, - shear, + angle: float, + shear: float, border_handling="edge", + constant_color=None, ): + x = int(x) + y = int(y) + angle = int(angle) + + log.debug(f"Zoom: {zoom} | x: {x}, y: {y}, angle: {angle}, shear: {shear}") + if image.size(0) == 0: return (torch.zeros(0),) transformed_images = [] @@ -47,34 +62,49 @@ class TransformImage: new_height, new_width = int(frame_height * zoom), int(frame_width * zoom) + log.debug(f"New height: {new_height}, New width: {new_width}") + + # - Calculate diagonal of the original image + diagonal = sqrt(frame_width**2 + frame_height**2) + max_padding = ceil(diagonal * zoom - min(frame_width, frame_height)) + # Calculate padding for zoom pw = int(frame_width - new_width) ph = int(frame_height - new_height) + + pw += max_padding + ph += max_padding + padding = [max(0, pw + x), max(0, ph + y), max(0, pw - x), max(0, ph - y)] - for img in image: - img = img.permute(2, 0, 1) - new_height, new_width = int(frame_height * zoom), int(frame_width * zoom) - pw = int(frame_width - new_width) - ph = int(frame_height - new_height) - - padding = [int(i) for i in padding] + constant_color = hex_to_rgb(constant_color) + log.debug(f"Fill Tuple: {constant_color}") + for img in tensor2pil(image): img = F.pad( img, # transformed_frame, padding=padding, padding_mode=border_handling, + fill=constant_color or 0, ) - img = F.affine(img, angle=angle, scale=zoom, translate=[x, y], shear=shear) + img = cast( + Image.Image, + F.affine(img, angle=angle, scale=zoom, translate=[x, y], shear=shear), + ) - crop = [ph + y, -(ph - y), x + pw, -(pw - x)] + left = abs(padding[0]) + upper = abs(padding[1]) + right = img.width - abs(padding[2]) + bottom = img.height - abs(padding[3]) - img = img[:, crop[0] : crop[1], crop[2] : crop[3]] + # log.debug("crop is [:,top:bottom, left:right] for tensors") + log.debug("crop is [left, top, right, bottom] for PIL") + log.debug(f"crop is {left}, {upper}, {right}, {bottom}") + img = img.crop((left, upper, right, bottom)) - img = img.permute(1, 2, 0) - transformed_images.append(img.unsqueeze(0)) + transformed_images.append(img) - return (torch.cat(transformed_images, dim=0),) + return (pil2tensor(transformed_images),) __nodes__ = [TransformImage] diff --git a/utils.py b/utils.py index d6ab36f..2005f18 100644 --- a/utils.py +++ b/utils.py @@ -22,6 +22,11 @@ elif ".venv" in sys.executable: comfy_mode = "venv" +def hex_to_rgb(hex_color): + hex_color = hex_color.lstrip("#") + return tuple(int(hex_color[i : i + 2], 16) for i in (0, 2, 4)) + + # region MISC Utilities def add_path(path, prepend=False): if isinstance(path, list): From e7f72f9825da58254e3084b4ba91f76e6cf2cf5f Mon Sep 17 00:00:00 2001 From: melMass Date: Thu, 10 Aug 2023 22:58:12 +0200 Subject: [PATCH 46/56] =?UTF-8?q?fix:=20=F0=9F=8E=A8=20rename=20fun=20to?= =?UTF-8?q?=20generate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodes/{fun.py => generate.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename nodes/{fun.py => generate.py} (100%) diff --git a/nodes/fun.py b/nodes/generate.py similarity index 100% rename from nodes/fun.py rename to nodes/generate.py From 40560f8154d3ddeabf708be4d111370648d466ac Mon Sep 17 00:00:00 2001 From: melMass Date: Thu, 10 Aug 2023 23:22:05 +0200 Subject: [PATCH 47/56] =?UTF-8?q?fix:=20=F0=9F=90=9B=20debug=20rgba?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodes/debug.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nodes/debug.py b/nodes/debug.py index 2ca0ff9..1aaf5f0 100644 --- a/nodes/debug.py +++ b/nodes/debug.py @@ -38,9 +38,9 @@ class Debug: b64_imgs = [] for im in image: buffered = io.BytesIO() - im.save(buffered, format="JPEG") + im.save(buffered, format="PNG") b64_imgs.append( - "data:image/jpeg;base64," + "data:image/png;base64," + base64.b64encode(buffered.getvalue()).decode("utf-8") ) From dbdb872b74e18c16feb44bd037abc3aafbb4700f Mon Sep 17 00:00:00 2001 From: melMass Date: Thu, 10 Aug 2023 23:31:46 +0200 Subject: [PATCH 48/56] =?UTF-8?q?feat:=20=F0=9F=94=A5=20add=20any=20to=20s?= =?UTF-8?q?tring=20&=20refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodes/conditions.py | 111 +-------------------------------------- nodes/generate.py | 122 ++++++++++++++++++++++++++++++++++++++++++- nodes/graph_utils.py | 34 +++++++++++- web/comfy_shared.js | 2 +- 4 files changed, 157 insertions(+), 112 deletions(-) diff --git a/nodes/conditions.py b/nodes/conditions.py index 71eeef0..33d50e9 100644 --- a/nodes/conditions.py +++ b/nodes/conditions.py @@ -1,5 +1,4 @@ -from ..utils import pil2tensor -from ..utils import here, comfy_dir +from ..utils import here from ..log import log import folder_paths from pathlib import Path @@ -97,110 +96,4 @@ class StylesLoader: return (self.options[style_name][0], self.options[style_name][1]) -class TextToImage: - """Utils to convert text to image using a font - - - The tool looks for any .ttf file in the Comfy folder hierarchy. - """ - - fonts = {} - - def __init__(self): - # - This is executed when the graph is executed, we could conditionaly reload fonts there - pass - - @classmethod - def CACHE_FONTS(cls): - font_extensions = ["*.ttf", "*.otf", "*.woff", "*.woff2", "*.eot"] - fonts = [] - - for extension in font_extensions: - fonts.extend(comfy_dir.glob(f"**/{extension}")) - - if not fonts: - log.warn( - "> No fonts found in the comfy folder, place at least one font file somewhere in ComfyUI's hierarchy" - ) - else: - log.debug(f"> Found {len(fonts)} fonts") - - for font in fonts: - log.debug(f"Adding font {font}") - cls.fonts[font.stem] = font.as_posix() - - @classmethod - def INPUT_TYPES(cls): - if not cls.fonts: - cls.CACHE_FONTS() - else: - log.debug(f"Using cached fonts (count: {len(cls.fonts)})") - return { - "required": { - "text": ( - "STRING", - {"default": "Hello world!"}, - ), - "font": ((sorted(cls.fonts.keys())),), - "wrap": ( - "INT", - {"default": 120, "min": 0, "max": 8096, "step": 1}, - ), - "font_size": ( - "INT", - {"default": 12, "min": 1, "max": 2500, "step": 1}, - ), - "width": ( - "INT", - {"default": 512, "min": 1, "max": 8096, "step": 1}, - ), - "height": ( - "INT", - {"default": 512, "min": 1, "max": 8096, "step": 1}, - ), - # "position": (["INT"], {"default": 0, "min": 0, "max": 100, "step": 1}), - "color": ( - "COLOR", - {"default": "black"}, - ), - "background": ( - "COLOR", - {"default": "white"}, - ), - } - } - - RETURN_TYPES = ("IMAGE",) - RETURN_NAMES = ("image",) - FUNCTION = "text_to_image" - CATEGORY = "mtb/generate" - - def text_to_image( - self, text, font, wrap, font_size, width, height, color, background - ): - from PIL import Image, ImageDraw, ImageFont - import textwrap - - font = self.fonts[font] - font = ImageFont.truetype(font, font_size) - if wrap == 0: - wrap = width / font_size - lines = textwrap.wrap(text, width=wrap) - log.debug(f"Lines: {lines}") - line_height = font.getsize("hg")[1] - img_height = height # line_height * len(lines) - img_width = width # max(font.getsize(line)[0] for line in lines) - - img = Image.new("RGBA", (img_width, img_height), background) - draw = ImageDraw.Draw(img) - y_text = 0 - for line in lines: - width, height = font.getsize(line) - draw.text((0, y_text), line, color, font=font) - y_text += height - - # img.save(os.path.join(folder_paths.base_path, f'{str(uuid.uuid4())}.png')) - return (pil2tensor(img),) - - -__nodes__ = [SmartStep, TextToImage, StylesLoader] +__nodes__ = [SmartStep, StylesLoader] diff --git a/nodes/generate.py b/nodes/generate.py index 332e11a..8fa55ee 100644 --- a/nodes/generate.py +++ b/nodes/generate.py @@ -1,5 +1,7 @@ import qrcode from ..utils import pil2tensor +from ..utils import comfy_dir +from typing import cast from PIL import Image from ..log import log @@ -130,6 +132,9 @@ class QrCode: CATEGORY = "mtb/generate" def do_qr(self, url, width, height, error_correct, box_size, border, invert): + log.warning( + "This node will soon be deprecated, there are much better alternatives like https://github.com/coreyryanhanson/comfy-qr" + ) if error_correct == "L" or error_correct not in ["M", "Q", "H"]: error_correct = qrcode.constants.ERROR_CORRECT_L elif error_correct == "M": @@ -159,8 +164,123 @@ class QrCode: return (pil2tensor(code),) +def bbox_dim(bbox): + left, upper, right, lower = bbox + width = right - left + height = lower - upper + return width, height + + +class TextToImage: + """Utils to convert text to image using a font + + + The tool looks for any .ttf file in the Comfy folder hierarchy. + """ + + fonts = {} + + def __init__(self): + # - This is executed when the graph is executed, we could conditionaly reload fonts there + pass + + @classmethod + def CACHE_FONTS(cls): + font_extensions = ["*.ttf", "*.otf", "*.woff", "*.woff2", "*.eot"] + fonts = [] + + for extension in font_extensions: + fonts.extend(comfy_dir.glob(f"**/{extension}")) + + if not fonts: + log.warn( + "> No fonts found in the comfy folder, place at least one font file somewhere in ComfyUI's hierarchy" + ) + else: + log.debug(f"> Found {len(fonts)} fonts") + + for font in fonts: + log.debug(f"Adding font {font}") + cls.fonts[font.stem] = font.as_posix() + + @classmethod + def INPUT_TYPES(cls): + if not cls.fonts: + cls.CACHE_FONTS() + else: + log.debug(f"Using cached fonts (count: {len(cls.fonts)})") + return { + "required": { + "text": ( + "STRING", + {"default": "Hello world!"}, + ), + "font": ((sorted(cls.fonts.keys())),), + "wrap": ( + "INT", + {"default": 120, "min": 0, "max": 8096, "step": 1}, + ), + "font_size": ( + "INT", + {"default": 12, "min": 1, "max": 2500, "step": 1}, + ), + "width": ( + "INT", + {"default": 512, "min": 1, "max": 8096, "step": 1}, + ), + "height": ( + "INT", + {"default": 512, "min": 1, "max": 8096, "step": 1}, + ), + # "position": (["INT"], {"default": 0, "min": 0, "max": 100, "step": 1}), + "color": ( + "COLOR", + {"default": "black"}, + ), + "background": ( + "COLOR", + {"default": "white"}, + ), + } + } + + RETURN_TYPES = ("IMAGE",) + RETURN_NAMES = ("image",) + FUNCTION = "text_to_image" + CATEGORY = "mtb/generate" + + def text_to_image( + self, text, font, wrap, font_size, width, height, color, background + ): + from PIL import Image, ImageDraw, ImageFont + import textwrap + + font = self.fonts[font] + font = cast(ImageFont.FreeTypeFont, ImageFont.truetype(font, font_size)) + if wrap == 0: + wrap = width / font_size + lines = textwrap.wrap(text, width=wrap) + log.debug(f"Lines: {lines}") + line_height = bbox_dim(font.getbbox("hg"))[1] + img_height = height # line_height * len(lines) + img_width = width # max(font.getsize(line)[0] for line in lines) + + img = Image.new("RGBA", (img_width, img_height), background) + draw = ImageDraw.Draw(img) + y_text = 0 + # - bbox is [left, upper, right, lower] + for line in lines: + width, height = bbox_dim(font.getbbox(line)) + draw.text((0, y_text), line, color, font=font) + y_text += height + + # img.save(os.path.join(folder_paths.base_path, f'{str(uuid.uuid4())}.png')) + return (pil2tensor(img),) + + __nodes__ = [ QrCode, - UnsplashImage + UnsplashImage, + TextToImage # MtbExamples, ] diff --git a/nodes/graph_utils.py b/nodes/graph_utils.py index 70c711b..a9ccc35 100644 --- a/nodes/graph_utils.py +++ b/nodes/graph_utils.py @@ -7,6 +7,7 @@ import json from comfy.cli_args import args from ..utils import pil2tensor import io +import numpy as np def get_image(filename, subfolder, folder_type): @@ -107,6 +108,37 @@ class GetBatchFromHistory: return (output,) +class AnyToString: + """Tries to take any input and convert it to a string""" + + @classmethod + def INPUT_TYPES(cls): + return { + "required": {"input": ("*")}, + } + + RETURN_TYPES = ("STRING",) + FUNCTION = "do_str" + CATEGORY = "mtb/converters" + + def do_str(self, input): + if isinstance(input, str): + return (input,) + elif isinstance(input, torch.Tensor): + return (f"Tensor of shape {input.shape} and dtype {input.dtype}",) + elif isinstance(input, Image.Image): + return (f"PIL Image of size {input.size} and mode {input.mode}",) + elif isinstance(input, np.ndarray): + return (f"Numpy array of shape {input.shape} and dtype {input.dtype}",) + + elif isinstance(input, dict): + return (f"Dictionary of {len(input)} items, with keys {input.keys()}",) + + else: + log.debug(f"Falling back to string conversion of {input}") + return (str(input),) + + class StringReplace: """Basic string replacement""" @@ -178,4 +210,4 @@ class FitNumber: return (res,) -__nodes__ = [StringReplace, FitNumber, GetBatchFromHistory] +__nodes__ = [StringReplace, FitNumber, GetBatchFromHistory, AnyToString] diff --git a/web/comfy_shared.js b/web/comfy_shared.js index 3f34b54..f570fac 100644 --- a/web/comfy_shared.js +++ b/web/comfy_shared.js @@ -60,7 +60,7 @@ export function offsetDOMWidget( */ export function getWidgetType(config) { // Special handling for COMBO so we restrict links based on the entries - let type = config[0] + let type = config?.[0] let linkType = type if (type instanceof Array) { type = 'COMBO' From 8523392df74c586dc940841ddbb5069943b16f7d Mon Sep 17 00:00:00 2001 From: melMass Date: Fri, 11 Aug 2023 22:22:07 +0200 Subject: [PATCH 49/56] =?UTF-8?q?fix:=20=E2=9C=A8=20refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 33 +++---- log.py | 1 - nodes/graph_utils.py | 86 ++++++++++------ utils.py | 227 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 282 insertions(+), 65 deletions(-) diff --git a/__init__.py b/__init__.py index 90e764d..4440b9f 100644 --- a/__init__.py +++ b/__init__.py @@ -45,19 +45,15 @@ def extract_nodes_from_source(filename): if isinstance(target, ast.Name) and target.id == "__nodes__": value = ast.get_source_segment(source_code, node.value) node_value = ast.parse(value).body[0].value - if isinstance(node_value, ast.List) or isinstance( - node_value, ast.Tuple - ): - for element in node_value.elts: - if isinstance(element, ast.Name): - print(element.id) - nodes.append(element.id) - + if isinstance(node_value, (ast.List, ast.Tuple)): + nodes.extend( + element.id + for element in node_value.elts + if isinstance(element, ast.Name) + ) break except SyntaxError: log.error("Failed to parse") - pass # File couldn't be parsed - return nodes @@ -240,11 +236,10 @@ if hasattr(PromptServer, "instance"): log.setLevel(logging.DEBUG) log.debug("Debug mode set from API (/mtb/debug POST route)") - else: - if "MTB_DEBUG" in os.environ: - # del os.environ["MTB_DEBUG"] - os.environ.pop("MTB_DEBUG") - log.setLevel(logging.INFO) + elif "MTB_DEBUG" in os.environ: + # del os.environ["MTB_DEBUG"] + os.environ.pop("MTB_DEBUG") + log.setLevel(logging.INFO) return web.json_response( {"message": f"Debug mode {'set' if enabled else 'unset'}"} @@ -258,7 +253,7 @@ if hasattr(PromptServer, "instance"): # Check if the request prefers HTML content if "text/html" in request.headers.get("Accept", ""): # # Return an HTML page - html_response = f""" + html_response = """