Compare commits

...
270 Commits
Author SHA1 Message Date
drbaph b35b5d8a17 fix: whisper transcription compatibility with newer transformers (#274)
- Use getattr for max_length to handle removed WhisperConfig attribute
- Cast input_features to model dtype to fix float16 mismatch
2026-07-04 21:40:35 +02:00
carlostsai 6d5fd74333 fix: typo on vitmatte torch script name (#276) 2026-06-27 21:15:11 +02:00
Anderson Yan b705a177d3 fix: add retry to LoadImageFromURL 2026-03-19 08:39:38 +01:00
Mel Massadian 00fbad37c5 docs: remove deprecation
Updated caution and note sections regarding recent changes and versioning.
2026-01-10 10:32:45 +01:00
Benjamin Gregg 6cbe294c1b Fix Deepcopy Error
Fix Deepcopy Error in new comfy versions
2026-01-10 10:30:32 +01:00
Mel Massadian eabe43db79 fix: 🐛 add missing widgetTypes for COLOR 2025-09-07 11:54:27 +00:00
Austin Mroz 1c99a1c63c Set widgetType for COLOR widgets 2025-09-06 16:56:35 +02:00
Mel Massadian 426cdf5f9f fix: 🐛 temporary fix for COLOR 2025-09-06 12:38:41 +00:00
Mel Massadian 5fa3791559 📚 docs: add caution about project status 2025-09-06 11:03:42 +02:00
Mel Massadian 5c0e020c73 fix: 🐛 use gpu for uncrop if available
image tensors are often offloaded to cpu which makes
the gaussian blur dead slow
2025-07-18 15:26:58 +02:00
Mel Massadian d00722e9ea fix: 🐛 remove numpy from bbox crop/uncrop 2025-07-17 20:54:44 +02:00
Mel Massadian 0106c13250 fix: 🐛 typo in clock 2025-07-07 21:05:04 +02:00
Mel Massadian 55226058d4 feat: ✨ add a simple clock system
StartClock and EndClock
2025-07-05 18:18:10 +02:00
Mel Massadian 50e0f7b357 wip: 🚧 generic GetItem node
For now pretty bare bones
2025-07-04 12:02:29 +02:00
Mel Massadian 71f601094a feat: ✨ simple not boolean node
requested and contributed by vallestutz
2025-06-28 13:49:54 +02:00
Mel Massadian ea750b5e8b fix: 🐛 use core toast
I made this long before it was a thing in comfy.
It now wraps the builtin toat system unless specificaly requested.

(notify css broke in recent ComfyUI updates anyway)
2025-06-26 17:33:38 +02:00
Mel Massadian ff2e99f73e fix(web): 🐛 allow cancelling queue of animation builder
fixes #246
2025-06-26 17:23:42 +02:00
Mel Massadian efc6855073 chore: 🧹 apply biome on missed files 2025-06-26 15:42:31 +02:00
Mel Massadian 0853b7fb6a chore: 🧹 update biome 2025-06-26 15:42:31 +02:00
Mel Massadian 10aa493dd8 docs(web): 📚 add markdown notice for sidebar settings 2025-06-26 15:42:31 +02:00
Mel Massadian f038d76748 fix(web): 🐛 make main settings appear first 2025-06-26 15:42:31 +02:00
Mel Massadian 940a781f29 feat: ✨ implement ipaq ideas for the I/O sidebar 2025-06-26 15:42:31 +02:00
Jared J c7248344cc Clarify mtb.io-sidebar.img-size name and tooltip 2025-06-26 15:42:31 +02:00
Mel Massadian fab33a40a2 chore: 🧹 add debug after esm load 2025-06-26 12:59:03 +02:00
Mel Massadian 8f83e8d4d7 chore(web): 🧹 remove API stuff
this is being rewritten in typescript
2025-06-26 12:52:44 +02:00
Mel Massadian 6c59d5c32d chore: 🧹 support hot reloading 2025-06-26 12:52:44 +02:00
Mel Massadian e98f3f626f fix: 🐛 add rgb/rgba toggle to stack images
now defaulting to rgb (too many nodes don't properly support rgba)
2025-06-24 17:02:41 +02:00
Mel Massadian 7e89e96e9d feat(web): ✨ use comfy text area fontsize for editors 2025-06-08 19:58:05 +02:00
Mel Massadian 177b6eeef3 fix(web): 🐛 don't break note+ on undo
Issuing undo will both undo the last note edit and the last graph
edit...
I asked upstream about it:
https://github.com/Comfy-Org/ComfyUI_frontend/issues/4108

this also fixes height calculation
2025-06-08 16:52:06 +02:00
Mel Massadian 502a583409 fix(web): 🐛 properly init after ace load 2025-06-07 17:17:05 +02:00
Mel Massadian a7966355c1 fix(web): 🐛 use natural widget/properties de/serialization 2025-06-07 16:39:19 +02:00
Mel Massadian 321abea51a fix(web): 🐛 use the new settings api 2025-06-07 15:00:05 +02:00
Mel Massadian 63be3f26fd fix(web): 🐛 note+
- reworked the internal logic to be simpler and more robust
- removed the dedicated HTML editing mode
  markdown is a superset of HTML in this context
- fixed layout of the css editor
- introduces a quick edit mode: double-clicking the note's preview area
now opens an inline Ace editor
2025-06-07 14:34:39 +02:00
Mel Massadian c4f40e299f fix(web): 🐛 always bind the load event 2025-06-07 12:20:51 +02:00
Mel Massadian b541670a5b fix: 🐛 improve startup times 2025-06-05 16:37:27 +02:00
Mel Massadian 4574c6451c ci: 🤖 disable ci 2025-05-23 02:11:22 +02:00
Mel Massadian 7fb27804e1 chore!: 🧹 bump version 2025-05-23 01:34:56 +02:00
Mel Massadian 9a7e022df1 chore!: 🧹 bump version 2025-05-22 23:00:01 +02:00
Mel Massadian 2c483fd1d2 ci: 🤖 finally fix the registry issue
The upstream action was overwritting the checkout: https://github.com/Comfy-Org/publish-node-action/blob/d2366e7abb6ab16f3bb03e3520ae25c8cf749bc9/action.yml#L16
2025-05-22 22:58:10 +02:00
Mel Massadian 0967d439f5 chore!: 🧹 bump version
closes #230
2025-05-22 22:02:39 +02:00
Mel Massadian 319c02d658 fix: 🐛 ascii encoding only for whisper chunks
fixes #251
2025-05-22 21:52:44 +02:00
Mel Massadian 265cb953ec feat: ✨ rework extract points
Make use of both inputs if provided, more efficient point drawing
2025-05-18 20:56:41 +02:00
Mel Massadian 7e36007933 docs: 📚 add contribution 2025-05-07 10:56:29 +02:00
Mel Massadian bc5b613490 chore: 🧹 bump version 2025-04-17 01:25:02 +02:00
Mel Massadian 01107c45f8 chore: 🧹 small adjustments 2025-04-17 01:17:52 +02:00
Mel Massadian 96185132b8 feat: ⚡ add BatchFromFolder 2025-04-17 01:05:47 +02:00
Mel Massadian d4a31bf19c feat: ⚡ add use_normalized to TransformBatch2D 2025-04-17 01:02:07 +02:00
Mel Massadian fc7ba084f6 feat!: ⚡ add support for masks in BatchFLoatMath 2025-04-17 01:00:07 +02:00
Mel Massadian 4516aa9cb4 feat: ✨ add use_normalized to TransformImage
this makes working with various input dimensions much easier
2025-04-16 22:38:54 +02:00
0e48aaa3e4 ci: 🤖 update publish action workflow with permissions and version constraints (#237)
Co-authored-by: snomiao <snomiao+comfy-pr@gmail.com>
Co-authored-by: Mel Massadian <mel@melmassadian.com>
2025-04-01 00:48:32 +02:00
诗无尽头iandMel Massadian 78946b0fa3 feat: ✨ add regex support for String Replace (#233)
---------

Co-authored-by: Mel Massadian <mel@melmassadian.com>
2025-04-01 00:45:52 +02:00
NumZ c30408f96d feat: ✨ update diarization to 3.1
And fix MTB_AudioIsolateSpeaker

Migrated from #241
2025-04-01 00:35:08 +02:00
Mel Massadian eb7cf89f17 feat: ✨ add "workflow" query to /mtb/view endpoint 2025-04-01 00:20:59 +02:00
Mel Massadian af42134028 fix: 🐛 note+ breaking wfs
Note+ itself still doesn't work (see #238) but this should at least
avoid issues like #239...
2025-03-22 19:33:35 +01:00
Mel Massadian a85e57b18c fix: 🐛 ColorCorrect clamp issue
Closes: #192
2025-03-10 12:15:16 +01:00
Mel Massadian 22fce6fdda feat: ✨ add stretch_x and stretch_y to TransformImage 2025-03-09 18:39:56 +01:00
Mel Massadian 147edcfcbc refactor: 📦 add model autodownload 2025-03-07 22:28:24 +01:00
Mel Massadian 8bf3545fec fix: 🐛 Whisper chunks processing
also add support for whisper chunks in TextToImage
2025-03-04 02:10:37 +01:00
Mel Massadian f47149746a feat: ✨ add AudioDuration node 2025-02-20 00:59:22 +01:00
Mel Massadian 83cfc5c723 feat: ✨ basic whisper nodes 2025-02-20 00:58:06 +01:00
Mel Massadian d87e52ea2c fix: 🐛 stackImages move to device 2025-02-16 02:52:26 +01:00
Mel Massadian 9405784764 feat: ✨ add BboxForDimensions
Useful for doing Crop/Uncrop with video models
2025-02-16 02:36:10 +01:00
Mel Massadian 55261bda7c fix: 🐛 bbox upscale from center 2025-02-16 02:01:41 +01:00
Mel Massadian cf7a9c41e8 feat: ✨ improve the debug node
- preserve input order
- new "as_detailed_type" option
- support mask preview
- improved styling a bit for readibility
2025-02-15 23:44:34 +01:00
Mel Massadian 3a25526e81 chore: 🧹 basic standalone detection 2025-02-14 23:53:01 +01:00
Mel Massadian 00173fa3fb feat: ✨ add BatchImageToSublist and counterpart
Basically like ImpactPack's BatchImageToList but you can specify the batch
count per item
2025-02-14 23:51:37 +01:00
Mel Massadian 0d264b90a7 fix: 🐛 add MASK support for PickFromBatch 2025-02-14 23:48:43 +01:00
Mel Massadian a8cf4650ff feat: ✨ add TensorOps
pretty rough for now, inspired by blender math nodes
2025-02-14 23:47:48 +01:00
Mel Massadian edcb3da08b chore: 🧹 rename type 2025-02-14 23:46:51 +01:00
christian-byrne 7f7a62f832 feat: ✨ live update outputs grid 2025-02-01 14:40:43 +01:00
Mel Massadian fc908ba0a5 chore: 🧹 update env file 2025-02-01 14:35:54 +01:00
Mel Massadian ead4b34e6d wip: 🚧 loop drawing 2025-01-01 05:10:45 +01:00
Mel Massadian 46af6027d6 fix: 🐛 use addDOMWidget for Debug node 2025-01-01 01:58:13 +01:00
Mel Massadian b7ca8ed1c6 fix: 🐛 use "modern" notation in toDevice 2024-12-30 21:36:35 +01:00
Mel Massadian 4aad5c3b9d ⬆️ Bump version: 0.2.0 → 0.2.1 2024-12-30 18:49:43 +01:00
Mel Massadian d61da30409 fix: 🐛 handle missing submodules
the nodes should never fail to load completely.
I still need to remove the few remaining side effects like this one.
2024-12-30 18:49:43 +01:00
Robin Huang 6851da6638 Checkout submodules before publishing. 2024-12-30 18:49:43 +01:00
Mel Massadian 0eeb707f34 feat: ✨ add SaveImage passthrough
Exactly like the native one but not as an OUTPUT_NODE,
primarly meant to "inline" image saving in upcoming mtb loops.
2024-12-30 18:29:28 +01:00
Mel Massadian 9a943714aa chore: 🧹 dev
dev files
2024-12-29 13:51:03 +01:00
Mel Massadian bae26a07fb feat: ✨ add filtering to TransformImage
fixes #209
2024-12-27 19:29:34 +01:00
Mel Massadian c92d99a8a3 feat: ✨ add support for video in I/O sidebar
slow if you have big videos, maybe it shouldn't use force_size
2024-12-22 05:43:19 +01:00
Mel Massadian 3f6d082940 feat: ✨ add an extra static input to Stack Images 2024-12-22 02:40:01 +01:00
Mel Massadian 58ae89f8e0 chore: 🧹 apply formatting 2024-12-22 02:40:01 +01:00
pak c9a26427a8 improve dynamic inputs: custom separator and start_index, preserve labels, ... 2024-12-22 02:40:01 +01:00
Mel Massadian 6608c0b6d1 fix: 🐛 add warnings about what each IO mode can do
VHS now has a Load Image Path node that could be used to solve all cases.
For this I'll need to get the full path of each images from the endpoint
2024-12-22 02:11:21 +01:00
Mel Massadian a757e1c98b fix: 🐛 soft deprecate compression h264 2024-12-22 01:30:03 +01:00
Mel Massadian 52bd76e19c feat: ✨ add support for subdirs (i/o sidebar)
fixes #221
2024-12-22 01:28:08 +01:00
Mel Massadian d6e004cce2 fix: 🐛 limit packages allowed to be installed from API
fixes #224

thanks @boy-hack for the report!
2024-12-22 00:22:24 +01:00
Mel Massadian ed17fa2ef4 fix: 🐛 ensure default settings (io sidebar)
fixes #225
2024-12-21 02:14:40 +01:00
Mel Massadian 827c64c43d feat: ✨ add Batch Sequence Nodes
- A regular one that just sequence batches
- A "plus" with transition support (POC + for now)
2024-12-16 01:44:01 +01:00
filtered e5482aee5e fix: 🐛 spawn colour picker at pointer location (#223) 2024-12-15 22:22:22 +01:00
Mel Massadian 62469a4dd9 fix: 🐛 i/o sidebar for custom paths
In utils I uses a constant for these which doesn't
update with the global... calling the getters should
solve that.

This issue is probably in other places where I use these
utils.

fixes #219
2024-12-11 00:09:43 +01:00
Mel Massadian 8c629bee18 feat: ✨ add support for more formats (I/O sidebar) 2024-12-08 23:13:07 +01:00
Mel Massadian 50cb6f5ed6 chore: 🧹 bump minor 2024-12-08 19:34:26 +01:00
Mel Massadian e32d1e02df feat: ✨ add h264 compression node
recommended for i2i in ltx.
original code by [mix](https://github.com/XmYx)
2024-12-08 19:12:28 +01:00
Mel Massadian b0d52f7305 fix: 🐛 remove mtb sidebar
- The source for this is not yet in main... this file slipped
  in an earlier commit

fixes https://github.com/Comfy-Org/ComfyUI_frontend/issues/1834
2024-12-07 15:45:43 +01:00
Mel Massadian e17c6e29f5 docs: 📚 update wiki
pull wiki for documentation
2024-12-04 02:11:02 +01:00
Mel Massadian 27e03fa23e feat: ✨ add postshot nodes
basic wrapper of the cli the idea is to
queue Cog + Rotating loras -> Postshot

needs testing
2024-12-03 23:17:54 +01:00
Mel Massadian ec1cb1ac17 fix: 🐛 always enable the I/O sidebar
closes #214
2024-12-03 22:11:48 +01:00
d8ahazard 64634104a2 Use local import for Rembg
Rembg can sometimes cause *very* long load times on import (like 40s). Moving it to local doesn't fix the long import entirely, but it does prevent it causing ComfyUI from loading slowly.
2024-12-03 04:55:55 +01:00
Mel Massadian ecbb220de6 fix: 🐛 ui shifts on animation builder
finally updated to addDOMWidget
2024-11-20 23:03:00 +01:00
Mel Massadian cd9e614b1a feat: ✨ improve the I/O sidebar
- better options (sort, count)
- uses the new toast api instead of MTB.notify
2024-11-20 22:42:32 +01:00
Mel Massadian 9ccf572a15 chore: 🧹 add worktree to gitignores
for the experimental doc site at:
https://melmass.github.io/comfy_mtb/
2024-11-20 22:42:32 +01:00
Mel Massadian 74af5c6499 feat: ✨ add UpscaleBBoxBy 2024-11-20 22:42:32 +01:00
Mel Massadian caf0b39d8a chore 🧹: add deprecations and experimental 2024-11-20 22:42:32 +01:00
Mel Massadian e099d581a7 chore: 🧹 remove dupe code 2024-11-20 22:42:32 +01:00
Mel Massadian 22f7c30373 feat: ✨ simplified sidebar and backend
If you have a LoadImage selected,
clicking on images in the "input" mode will set the image on the
selected nodes
2024-11-20 22:42:32 +01:00
Mel Massadian 0133fb93bc feat: ✨ add Interpolate Condition 2024-11-20 22:42:32 +01:00
Mel Massadian cf7d30507e feat: ✨ dump of wip things... 2024-11-20 22:42:32 +01:00
Mel Massadian b6fa571fd2 fix: 🐛 category for settings 2024-11-20 21:41:57 +01:00
Mel Massadian f272526bfc fix: 🐛 new UI issues
- Fixes the "edit icon cannot be clicked"
- Changed the parser to add support for more non std markdown
- Markdown links now always open a new tab instead of replacing current
- New optional shiki support for code blocks (check #211 for details)
2024-11-20 21:41:57 +01:00
Mel Massadian 4e593bb30b feat: ✨ use the new parser for documentations
- might also fix #210
2024-11-20 21:41:57 +01:00
Mel Massadian 097ca33b8e feat: ✨ add @mtb/markdown-parser bundles
- the standard one is half the size of showdown
- the enhanced one (add shiki with most of its features) is 1.5mb
2024-11-20 21:41:57 +01:00
Mel Massadian 784fb0145b chore: 🧹 update externs
- remove showdown
- update dompurify
2024-11-20 21:41:57 +01:00
Chenlei Hu dbcca15a21 fix 🐛: input type on MTB_AnyToString (#204) 2024-10-10 02:13:13 +02:00
Mel Massadian bc41576fac docs 📚: fix wiki link
closes #202
2024-09-29 00:57:44 +02:00
Mel Massadian 8596b8184e fix: 🐛 disable old BOOL widget (legacy)
This can break if a pack declares a BOOL type

fixes #201
2024-09-27 13:33:01 +02:00
Mel Massadian 896a025006 feat: ✨ add VitMatte nodes
Basic implementation hardcoded for cuda
https://huggingface.co/melmass/pytorch-scripts
2024-09-22 00:16:23 +02:00
Mel Massadian 43092e44a4 fix: 🐛 pass ONNX providers explicitely
see #199
2024-09-08 19:58:35 +02:00
bymyself 80b5a0ca74 fix: 🐛 typo in mtb_widgets error catch (#197) 2024-09-05 14:50:48 +02:00
Mel Massadian 81b3bc1651 fix: 🐛 doc widget sidebar offset in the new ui 2024-08-18 14:26:02 +02:00
Mel Massadian a825504bdd chore: 🧹 add pathlibed inputs to utils 2024-08-18 14:07:42 +02:00
Mel Massadian 22190cd25e chore: 🧹 disable Constant
Removing as this doesn't work without my PR
2024-08-16 00:03:25 +02:00
Mel Massadian a976adbb39 chore: 🧹 new ui is default, flag for old ui 2024-08-16 00:02:18 +02:00
Mel Massadian 997d2fb13a fix: 🐛 don't fallback to eval
addresses legitimate concerns raised in #190
This limits the use a bit, SimpleMath from:
https://github.com/cubiq/ComfyUI_essentials
Is a better alternative
2024-08-08 22:34:03 +02:00
Mel Massadian f8829fcb37 chore: 🧹 add methods to shared 2024-08-08 16:57:10 +02:00
Mel Massadian 9651a70341 feat: ✨ add ColorCorrectGPU
Alternative to my ColorCorrect using only torch.
Also added Mask input for both (optional so this is not a breaking change)
2024-08-01 19:33:13 +02:00
Mel Massadian 57683c3c7d feat: ✨ add Swap FG/BG colors to MaskToImage 2024-08-01 18:38:58 +02:00
Mel Massadian f99f92e8f7 feat: ✨ add Extract coordinates
wip meant mainly for SAM2
2024-08-01 18:36:12 +02:00
Mel Massadian 5bc125d2f0 docs: 📚 remove link
still in issues
2024-08-01 17:32:23 +02:00
Mel Massadian c99b0812ab fix: 🐛 rework main utils
A whole gymnastic because comfy masks are (B,H,W).
maybe unsqueezing first is better but some nodes seems to still output
(B,H,W,C), IIRC there is an upstream PR about that
2024-08-01 17:31:18 +02:00
Mel Massadian 333f646ab1 docs: 📚 clean readme 2024-08-01 17:28:33 +02:00
Mel Massadian dbdf27664c chore: 🧹 add an old_ui flag to my launcher
this is dev related to easily test both UIs
see: https://github.com/melMass/CosyVoice-ComfyUI/commit/29510c36f0f8c1e4e5209148d14fe038947728c1
2024-07-31 04:59:36 +02:00
Mel Massadian 7d5569e5c1 chore: 🧹 move qrcode to his own file
Each files in `./nodes` can fail, but this means all nodes in the
file are skipped... `Generate` has "too important" nodes to fail
and doesn't require any extra dependencies.

This change allow qrcode to fail on its own
2024-07-31 04:59:17 +02:00
Mel Massadian 5681b464ad feat: ✨ add AudioCut
and make AudioSequence able to get negative "silence"
which would effectively "overlap" the joining sections
2024-07-31 04:42:40 +02:00
Mel Massadian 8d0fcee2f3 feat: ✨ add AudioStack
To stack/overlay audios.
2024-07-28 20:11:31 +02:00
Mel Massadian 1078fc6f0f feat: ✨ add AudioSequence node 2024-07-28 17:20:01 +02:00
Mel Massadian 821a0ef427 fix: 🐛 MaskToImage
also remove style debug
2024-07-07 20:40:18 +02:00
Mel Massadian 9007a70aa0 feat: ✨ add Split Bbox node 2024-07-06 18:30:14 +02:00
Mel Massadian 1a0ebd5173 feat: ✨ update lerp example 2024-07-06 18:26:45 +02:00
Mel Massadian 59608320c8 ⬆️ Bump version: 0.1.5 → 0.1.6 2024-07-03 18:16:37 +02:00
Mel Massadian d64fac4b74 fix: 🐛 menu callback issue
`+` on arrays returns a string in js...
2024-07-03 18:11:07 +02:00
Mel Massadian d687497d80 chore: 🧹 better classname extraction
Allow for consecutive uppercase letters:
- MTB_BatchFromHistoryV2 -> Batch From History V2
- MTB_CLIPInterpolate -> CLIP Interpolate
2024-07-03 16:00:48 +02:00
Mel Massadian d6343e1860 feat: ✨ add alpha channel support for faceswap/restore
Fixes #187
2024-07-03 15:59:09 +02:00
Mel Massadian 4eebdd8b8b ci: 🤖 limit release only to tags
I regularly need to push to main without needing to update
the extension's code / registry.
2024-07-02 13:14:00 +02:00
Mel Massadian 372e035686 Merge branch 'main' of https://github.com/melMass/comfy_mtb 2024-07-02 13:09:05 +02:00
Mel Massadian fb34671ee6 chore: 🧹 runner 2024-07-02 13:08:57 +02:00
Elthariel f25f6bdcd1 docs: 📚 Update requirements file in INSTALL.md (#186) 2024-06-26 15:05:45 +02:00
Mel Massadian f1b484617a ci: 🤖 only publish on tag
I can still autotag easily but it avoids bumping too much
versions to quickly
2024-06-22 20:17:14 +02:00
Mel Massadian 4507842a70 chore: 🧹 small fixes
- Handle image dimension mismatch in ConcatImages (Error,Smallest,Largest)
- typing
2024-06-22 20:13:59 +02:00
Mel Massadian e10faab458 ⬆️ Bump version: 0.1.4 → 0.1.5 2024-06-21 20:54:30 +02:00
Mel Massadian bb5682aa6d chore: 🧹 add fields for the registry 2024-06-21 20:48:55 +02:00
Mel Massadian 59612fd811 chore: 🧹 add pre-commit 2024-06-21 20:44:46 +02:00
Mel Massadian 30eb5b0091 chore 🧹: prepare for auto versioning 2024-06-21 19:55:50 +02:00
Mel Massadian 1edc2cd10d fix: 🐛 keep the last model match instead of first
See #184 for details
2024-06-21 19:53:25 +02:00
Mel Massadian fa3199be2b docs: 📚 update the wiki 2024-06-09 19:19:55 +02:00
Mel Massadian 43d65ae68c feat: ✨ add ModelPruner (wip) 2024-06-09 19:13:46 +02:00
Mel Massadian dfd17f6d78 chore: 🧹 migrate from poetry to setuptools 2024-06-09 15:23:07 +02:00
Mel Massadian 1070edd024 chore: 🧹 remove logs 2024-05-27 22:28:53 +02:00
Mel Massadian 9f0ed85cc1 Merge branch 'main' of https://github.com/melMass/comfy_mtb 2024-05-27 22:25:45 +02:00
Mel Massadian 35622e3a5e fix: 🐛 properly initialize the curve value
Also restored the old sorting logic adapted for Object
Closes #183

note: the ux is still bad and will improve
2024-05-27 22:25:28 +02:00
Mel Massadian 644371e5b5 chore: 🧹 add more pyproject meta 2024-05-21 12:51:40 +02:00
Mel Massadian f3d468cfc2 ci: 🤖 move at the proper location 2024-05-21 12:45:22 +02:00
haohaocreatesandMel Massadian 6cd448b026 ci: 🤖 add CI to publish to ComfyUI Registry (#182)
* publish-action
* feat ⚡:  rename token and add icons

---------

Co-authored-by: Mel Massadian <melmassadian@gmail.com>
2024-05-21 12:40:16 +02:00
haohaocreatesandMel Massadian 5951c90b10 chore: 🧹 add ComfyUI registry to pyproject.toml (#181)
* Add pyproject.toml for Custom Node Registry
* feat ⚡: add publisher id

---------

Co-authored-by: Mel Massadian <melmassadian@gmail.com>
2024-05-21 12:37:54 +02:00
bymyself 6abac2e470 feat: ✨ Use dynamic contrast in Color Correct (#180)
* Change contrast_adjustment_tensor method to change contrast dynamically
* Switch to Adobe RGB color space
2024-05-20 23:32:15 +02:00
Mel Massadian 01c73e1c5e feat ⚡: add more options to load image sequence 2024-05-17 17:35:53 +02:00
Mel Massadian 5060c56135 feat: ✨ StackImages add support for batch mismatch
Useful for comparing a static image with a batch of images
for instance.
2024-05-15 12:21:10 +02:00
bymyselfandMel Massadian acc2d687d5 fix: 🐛 ImageCompare improvements (#176)
* avoid unnecessary numpy conversion for diff and blend
* add support for Batch
* add support for input mismatch (RGB/RGBA)
* fixes #175 

---------

Co-authored-by: Mel Massadian <mel@melmassadian.com>
2024-05-14 21:16:56 +02:00
vxkj1211andMel Massadian 780c52f03a fix: 🐛 repetitive warning (#177)
Co-authored-by: Mel Massadian <mel@melmassadian.com>
2024-05-14 16:09:10 +02:00
Mel Massadian 2fe0859476 docs 📚: update wiki 2024-05-14 15:36:43 +02:00
Mel Massadian 1186239751 chore 🧹: use sections properly 2024-05-14 15:36:29 +02:00
Mel Massadian 96a0da9dbd chore: 🧹 update types 2024-05-10 20:30:46 +02:00
Mel Massadian f9d2ebf91d feat: ✨ add BatchFloatMath
Simple math operations on FLOATS (list of floats)
2024-05-07 23:42:02 +02:00
Mel Massadian 1b7ae27cc1 feat: ✨ add FLOATS to INTS
For using it with FrameInterpolation's new multiplier
2024-05-07 19:22:23 +02:00
Mel Massadian e312b02ad2 wip: 🚧 curve widget logic fixed
Most of the logic is fixed, but it still needs some UI/UX tweaks.
2024-05-07 18:40:12 +02:00
Mel Massadian 63ee25d001 feat: ✨ debug dict
it was only working on conditions
2024-05-07 18:36:56 +02:00
Mel Massadian 1caf7c18c3 feat: ✨ add Swap BG/FG color menu item 2024-05-07 08:29:57 +02:00
Mel Massadian 349a8524c6 fix: 🐛 add back was conversion node
To avoid breaking other worklfows
I thought this was now builtin WAS suite.
Fixes #172
2024-05-02 07:58:37 +02:00
Mel Massadian 15330eab65 fix: 🐛 drag lag on documentation resize handle 2024-04-28 16:54:42 +02:00
Mel Massadian 1571782d01 fix: 🐛 kwarg typo
floats vs float
2024-04-28 15:51:24 +02:00
Mel Massadian 5b4030288d fix: 🐛 seed of PlotBatchFloat
Also using random colors instead of mapped to
colormap, the values weren't distinct enough
2024-04-28 15:18:27 +02:00
Mel Massadian ab58c36212 feat: ✨ BatchFloatFit the batch version of FitNumber 2024-04-28 15:18:27 +02:00
Mel Massadian 5a0ef0dadd fix: 🐛 forceInput for FLOAT <-> FLOATS converters 2024-04-28 13:10:36 +02:00
Mel Massadian 967e72fc66 fix: 🐛 FLOAT always need options to be set
Fixes #171
2024-04-28 13:04:38 +02:00
Mel Massadian 78a86daaf7 feat: ✨ add FloatToFloats (the counterpart) 2024-04-27 21:11:53 +02:00
Mel Massadian bee3f47a14 fix: 🐛 remove doc if opened on node delete 2024-04-27 20:25:54 +02:00
Mel Massadian 2159395389 feat: ✨ add some FLOATS batch nodes
* TimeWrap
* Normalize
2024-04-27 19:47:45 +02:00
Mel Massadian b11346aba8 fix: 🐛 for documentation on HiDPI
thanks @kijai
2024-04-27 19:46:25 +02:00
Mel Massadian 30982fa488 fix: 🐛 never remove input 0 of dynamic inputs
If you reloaded a graph containing a node with dynamic inputs
but none connected the node would end up input-less
2024-04-27 16:29:34 +02:00
Mel Massadian 92b79906cd fix: 🐛 use the same fix as dynamicInputs for debug
i.e we don't auto delete inputs on disconnect, only on connect of
inputs
2024-04-27 14:58:50 +02:00
Mel Massadian 76f365b5ee fix: 🐛 missing numberInput
This is the first iteration of the "multi" number inputs.
The behaviour is based on Houdini number inputs
2024-04-27 14:16:07 +02:00
Mel Massadian da67e766c2 fix: 🐛 better curve 2024-04-27 04:08:09 +02:00
Mel Massadian 49cea8d945 docs: 📚 update wiki submodule 2024-04-27 01:17:25 +02:00
Mel Massadian b1d74adb15 fix: 🐛 prepend MTB_ to all classes
to avoid any future clash.
2024-04-27 01:13:32 +02:00
Mel Massadian 652ac3f3b9 fix: 🐛 dynamic connections 2024-04-26 21:11:32 +02:00
Mel Massadian 060e733605 Merge branch 'main' into fix/js-refactor 2024-04-25 22:19:28 +02:00
Mel Massadian eedbb4bc65 wip: 🚧 dump3 2024-04-25 22:08:25 +02:00
Mel Massadian fa2397585f wip: 🚧 dump 2024-04-25 21:56:59 +02:00
Mel Massadian 77348c4adb Merge branch 'main' into fix/js-refactor 2024-04-25 21:42:12 +02:00
Mel Massadian 0d0fb8e13a wip: 🚧 dump
js refactor start
2024-04-25 21:41:40 +02:00
Mel Massadian eb48b7a277 Merge branch 'main' into dev/doc-widget 2024-04-25 20:57:01 +02:00
Mel Massadian dff5b2201d feat: ✨ add the backend node for Constant
This requires this PR to be merged:
https://github.com/comfyanonymous/ComfyUI/pull/3329

There is a trick to make it work without that PR but it
feels very hacky, the code for it is kept for reference but unused
2024-04-25 20:56:16 +02:00
Mel Massadian 100067a645 fix: 🐛 remaining issue before merge 2024-04-25 20:42:34 +02:00
Mel Massadian 5998924926 docs: 📚 add the wiki as a submodule 2024-04-25 03:21:49 +02:00
Mel Massadian c19aa007e6 Merge branch 'main' into dev/doc-widget 2024-04-25 02:27:29 +02:00
Mel Massadian cbb5dd2cf8 feat: ✨ add Constant node
For now supports:

- number (int/float)
- string
- vector (2, 3, 4)
- color (serialised as HEX)
2024-04-21 17:12:13 +02:00
Mel Massadian 64cc4e9649 chore: 🧹 cleanup js 2024-04-21 17:03:58 +02:00
Mel Massadian 7807449e6d fix: 🐛 debug issues
also properly print to console now...
2024-04-21 17:01:25 +02:00
Mel Massadian e838c04758 fix: 🐛 errors when insightface's folder missing
This would polute output
2024-04-18 14:38:29 +02:00
Mel Massadian e40ad7a574 fix: 🐛 typo 2024-04-18 14:37:22 +02:00
Mel Massadian 6ebecfd8cf feat: ✨ add FloatsToFloat
I just discovered how most commonly used extensions where dealing
with list of values... they mistype it. Not sure the reason this
was "standardized", probably to mimic image batches?

This node makes mtb FLOATS work with these.
2024-04-18 13:52:42 +02:00
Mel Massadian 1da483a8ba fix: 🐛 better defaults (cont)
:)
2024-04-08 21:33:19 +02:00
Mel Massadian 5eff38b387 fix: 🐛 better defaults for Autopan 2024-04-08 21:30:58 +02:00
Mel Massadian 35139371e8 feat: ✨ add AutoPanEquilateral 2024-04-08 15:54:14 +02:00
Mel Massadian 9ab20a0ab5 fix: 🐛 dynamic inputs
Not making them sequential introduces strange bugs
2024-04-07 00:33:39 +02:00
Mel Massadian 5db3ebedb9 feat: ✨ add MatchDimensions
simplifies mismatching tensors for comparaisons
2024-04-07 00:32:36 +02:00
Mel Massadian 8d65556c37 feat: ✨ add equilateral example 2024-04-06 20:54:40 +02:00
Mel Massadian ba73fc6af7 feat: ✨ enhance tiling tools
- Add a separate X & Y seamless model patch
- Add a separate X & Y tile offset check

This theorically allow to generate proper equilateral env
2024-04-06 20:06:48 +02:00
Mel Massadian 92c810c503 feat: ✨ add FLOATS support to blur 2024-04-02 21:56:52 +02:00
Mel Massadian 7c3558273b fix: 🐛 bundle ace editor
Bundles the Ace editor from ace-builds

ref build commit:
https://github.com/ajaxorg/ace-builds/tree/a6c99a08252c1e6f0dfb61c29bc20b79d9324143

closes #166 and #167
2024-04-02 17:23:49 +02:00
Mel Massadian c9836a87f6 docs: 📚 missing doc 2024-04-02 17:18:26 +02:00
Mel Massadian f658fc31e0 feat: ✨ add "tube" to Batch Shape 2024-04-02 05:34:34 +02:00
Mel Massadian f16d576f6f fix: 🐛 image to mask 2024-04-02 05:33:16 +02:00
Mel Massadian e56508c207 fix: 🐛 prepend MTB to classnames
Avoid clashing with other extensions/core nodes.
2024-04-01 21:17:26 +02:00
Mel Massadian edd7c3f5d0 chore: 🧹 add savedatabundle js part
wip
2024-04-01 14:09:21 +02:00
Mel Massadian 71bfdd61d7 chore: 🧹 wip dynamic multitype
This just allow to pass a list of types to
dynamic widgets. Not used yet.
The idea is to use "*" but then limit it to the
given types.

Used in SaveDataBundle
2024-04-01 13:59:20 +02:00
Mel Massadian 9a4b27d2e0 fix: 🐛 allow smaller values in BatchTransform
Using a smaller step to avoid 0 division on low values.
Also added some typing
2024-04-01 13:57:01 +02:00
Mel Massadian eeac8c002a fix: 🐛 add category for virtual note+
Should fix: https://github.com/Nuked88/ComfyUI-N-Sidebar/issues/19
2024-03-28 20:17:02 +01:00
Mel Massadian 991af4f45f docs: 📚 use flat icon 2024-03-25 01:01:14 +01:00
Mel Massadian 9ce34b47fd docs: 📚 add banodoco channel link 2024-03-25 00:57:10 +01:00
Mel Massadian df0a98b94a fix: 🐛 make image feed of by default
Still here, just reverting the default.
Local Storage on some context isn't perserved
so I will use some fallback but in the meantime
this is better off.
2024-03-23 22:04:05 +01:00
Mel Massadian 133da705c9 feat: ✨ note+ editor themes
Expose the ace themes from the editor dialog.
possible solution for #162
2024-03-22 20:08:01 +01:00
Mel Massadian a344cdcba9 chore: 🧹 use a gettattr fallback
to avoid B009 auto reformatting...
2024-03-22 08:04:01 +01:00
Mel Massadian 68184552dd Merge branch 'main' into dev/doc-widget 2024-03-22 07:59:28 +01:00
huanggou666andMel Massadian 1b29aad360 feat: ✨ add ffmpeg gif export (#159)
* reverts 2bc7ae88bf
* chore: 🧹 apply formatting
* fix: 🐛 indentation issue
* feat: ✨ conditionally use ffmpeg
* chore: 🧹 reorder inputs
  to avoid breaking existing workflows using
  this node.
---------

closes: #157

Co-authored-by: Mel Massadian <mel@melmassadian.com>
2024-03-22 07:54:28 +01:00
Mel Massadian fac7529d1f feat: ✨ poc of the doc widget idea 2024-03-22 06:35:16 +01:00
Mel Massadian 2465ffb0d3 fix: 🐛 support batch masks (colored image node)
Also replace ANTIALIAS with LANCZOS.

closes #156
2024-03-13 16:57:31 +01:00
Mel Massadian 48f91b74e2 fix: 🐛 support pillow < 10
It seems I did this after VLM nodes installed it.
This fix handle both cases.

closes #155
2024-03-13 01:20:14 +01:00
hongminpark 54ff6583de fix: 🐛 image rotation bug (#154) 2024-03-12 14:24:58 +01:00
Mel Massadian 8221c49942 docs: 📚 udpate changelog 2024-03-07 06:49:54 +01:00
Mel Massadian 9fccdee82d fix: 🐛 font fallback
since I scoped the location for fonts the fallback
was not being used.. This commit fixes that.

Closes #152
2024-03-07 06:12:04 +01:00
Mel Massadian af2175a1fc wip: 🚧 add text template node
Using dynamic inputs as template variables in strings.
Useful for slate on wedge tests to pipe values from the workflow.
2024-03-07 05:45:05 +01:00
Mel Massadian fe49312cbe chore: 🧹 applied some linting 2024-03-07 05:39:45 +01:00
melMass c28181f161 feat: ✨ add "To Device"
To send an image or mask tensor to an available device.
Supports "cpu", "cuda", and "mps"
2024-03-04 01:53:24 +01:00
melMass b7c8582458 ⚡ feat: add offset and coverage to text to image
BREAKING CHANGES: Changes the UI

fixes #150
2024-03-01 01:33:23 +01:00
melMass d202da0e92 fix 🐛: stack images
also update pillow min version
2024-03-01 00:28:11 +01:00
melMass 91fcdb1c61 🐛 fix: text to image
BREAKING CHANGES: the UI changed
2024-02-29 19:22:23 +01:00
melMass 8371867dea 📚 docs: add changelog script 2024-02-29 19:07:01 +01:00
melMass 514c0d2eda chore: 📝 header links not parsed 2024-02-04 17:18:11 +01:00
melMass 915b7444a9 chore: 📝 hardcode links in changelog
For some reason github doesn't autolink commit/PRs
I'm probably doing something wrong but for now
I just hardcode the repo url in the cliff template
2024-02-04 16:05:36 +01:00
melMass 0d817bf326 docs: 📝 add changelog 2024-02-04 15:28:23 +01:00
Scott Nealon cd32f26b16 fix: ✨ optional inputs of colored image
* fix: Re-enable ColoredImage generation when foreground_image is not provided.
* fix: convert new image to RGB
2024-01-31 01:32:03 +01:00
melMass 501c330105 fix: 📝 adds a way to not load the imagefeed
closes #136
2024-01-05 23:36:19 +01:00
melMass 30c4311b69 fix: 🐛 colored image mask input
- mask input was completely broken, now it works.
- size can now be different from the input images, it will crop or expand accordingly.
- the image and mask tensors still must be of the same size
2024-01-05 18:22:49 +01:00
melMass 6c5e5d3637 chore: 🔖 local updates
- black -> Ruff
- wip nodes (Curve, FilterZ, Plot Batch Floats)
2023-12-25 18:36:24 +01:00
melMass 90f3bc2d95 feat: ✨ add note+ example 2023-12-05 03:50:28 +01:00
melMass 4b29395000 feat: 💄 node+ improvements
- Mardown mode (now default as it support most html too)
- Added a CSS editor
- "Purify" input to avoid script embedding in notes...
2023-12-05 03:28:33 +01:00
melMass c43a661ba3 fix: 🐛 handle font cache errors
closes #132
2023-12-03 17:06:12 +01:00
Mel Massadian 90d96366c8 docs: 📄 add note+ screenshot 2023-12-02 19:16:35 +01:00
melMass 605c8db320 feat: 📝 add note plus
future ideas:

- add a markdown mode
- add a separate css tab on the edit dialog
2023-12-02 19:07:32 +01:00
melMass cf965727e8 feat: 🚧 add playlist nodes
very basic for now
2023-12-01 00:50:50 +01:00
melMass 12b134ab4c fix: 💄 register the COLOR type even for external extensions
Since I register the widgets, anyone using a COLOR type in their extension
and mixing it with mtb will end up with widgets, before this commit they would not have the
option to turn it back and forth between input <-> widgets.

related to:
https://github.com/melMass/comfy_mtb/discussions/131

draft pr in bmad here:
https://github.com/bmad4ever/comfyui_bmad_nodes/pull/6
2023-11-30 20:58:29 +01:00
melMass dd27f990c7 chore: 📝 update node list 2023-11-29 15:41:47 +01:00
melMass 16c1a59312 feat: 🚨 add missing node
- pickfrombatch: exctract X images from either ends of your batch
- added alignement to TextToImage
2023-11-29 15:40:57 +01:00
melMass 59a361af58 fix: ✨ mask crop output
Follow up of #124
Thanks to @Yurchikian
2023-11-14 21:39:09 +01:00
melMass e4da832b99 fix: 🚑️ thread font loading
This created a huge lag on first opening of the browser.
The small drawback is that the webpage needs a reload
for fonts to be available
2023-11-14 20:53:44 +01:00
Artem YurchenkoandmelMass 14ee9e23c0 fix: 📦 changed way of creating bbox from mask (#124)
* fix: changed way of creating bbox from mask

changed code according to
https://stackoverflow.com/questions/31400769/bounding-box-of-numpy-array
Also fixed processing of mask input

* fix: 🐛 ambigous check

---------

Co-authored-by: melMass <mel@melmassadian.com>
2023-11-14 20:46:26 +01:00
melMass 53cb503866 fix: ✨ expose invert of bboxfrommask
changes the default to false
related to #124
2023-11-14 18:02:04 +01:00
melMass d5c4c5f264 fix: ✨ less strict csv parsing
closes #122
2023-11-08 18:28:27 +01:00
182 changed files with 16586 additions and 2063 deletions
+2
View File
@@ -0,0 +1,2 @@
[*]
end_of_line = lf
+7
View File
@@ -0,0 +1,7 @@
**/GFPGAN/inputs/**
**/GFPGAN/tests/**
**/frame_interpolation/photos/*
moment.gif
node.zip
.DS_Store
+6 -4
View File
@@ -1,10 +1,10 @@
name: 🐞 Bug Report
title: "[bug] "
title: '[bug] '
description: Report a bug
labels: ["type: 🐛 bug", "status: 🧹 needs triage"]
labels: ['type: 🐛 bug', 'status: 🧹 needs triage']
assignees:
- melMass
body:
- type: markdown
attributes:
@@ -12,6 +12,8 @@ body:
## Before submiting an issue
- Make sure to read the README & INSTALL instructions.
- Please search for [existing issues](https://github.com/melMass/comfy_mtb/issues?q=is%3Aissue) around your problem before filing a report.
- Optionally check the `#mtb-nodes` channel on the Banodoco discord:
[![](https://dcbadge.vercel.app/api/server/AXhsabmDhn?style=flat)](https://discord.gg/IAXhsabmDhn)
### Try using the debug mode to get more info
@@ -54,7 +56,7 @@ body:
default: 0
validations:
required: true
- type: dropdown
id: comfy_mode
attributes:
+22
View File
@@ -0,0 +1,22 @@
name: 📦 Publish to Comfy registry
on:
workflow_dispatch:
permissions:
issues: write
jobs:
publish-node:
name: Publish Custom Node to registry
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'melMass' }}
steps:
- name: ♻️ Check out code
uses: actions/checkout@v4
with:
submodules: true
- name: 📦 Publish Custom Node
uses: Comfy-Org/publish-node-action@v1
with:
skip_checkout: 'true'
personal_access_token: ${{ secrets.COMFY_REGISTRY_TOKEN }}
+12 -1
View File
@@ -1,5 +1,16 @@
__pycache__
*.py[cod]
*.onnx
wheels/
node_modules/
node_modules/
compose.yaml
comfy_mtb.wsb
Dockerfile
.DS_Store
node.zip
# I store the gh-pages worktrees (src & build) there
.worktrees
comfy.lock
+3
View File
@@ -7,3 +7,6 @@
[submodule "extern/frame_interpolation"]
path = extern/frame_interpolation
url = https://github.com/google-research/frame-interpolation
[submodule "wiki"]
path = wiki
url = https://github.com/melMass/comfy_mtb.wiki.git
+10
View File
@@ -0,0 +1,10 @@
-- HACK: this should theorically not be needed since the lsp should read from the pyproject
-- tried: ruff-lsp or basedpyright
local comfyRoot = vim.fn.expand("%:p:h:h:h")
if not vim.env.PYTHONPATH or vim.env.PYTHONPATH == "" then
vim.env.PYTHONPATH = comfyRoot
else
vim.env.PYTHONPATH = vim.env.PYTHONPATH .. ";" .. comfyRoot
end
+8
View File
@@ -0,0 +1,8 @@
default_language_version:
python: python3.10
repos:
- repo: https://github.com/melmass/hooks
rev: e8c6c18175ed4f6e30f23991de7989411e09c73b
hooks:
- id: fix-trailing-whitespace
- id: bump-version
+638
View File
@@ -0,0 +1,638 @@
# Changelog
This is an automated changelog based on the commits in this repository.
Check the notes in the [releases](https://github.com/melMass/comfy_mtb/releases) for more information.
## [main] - 2025-04-16
### Bug Fixes
- 🐛 note+ breaking wfs ([af42134](https://github.com/melMass/comfy_mtb/commit/af421340286b234e4c0cfcd4143a9d8726ebf3d1))
- 🐛 ColorCorrect clamp issue ([a85e57b](https://github.com/melMass/comfy_mtb/commit/a85e57b18c7d3c765131873ffff523244ca9be73))
- 🐛 Whisper chunks processing ([8bf3545](https://github.com/melMass/comfy_mtb/commit/8bf3545fec5b2a180607d40394b025a1e09c14b6))
- 🐛 stackImages move to device ([d87e52e](https://github.com/melMass/comfy_mtb/commit/d87e52ea2c112fd95f257dcd6a54a5db77a34fc3))
- 🐛 bbox upscale from center ([55261bd](https://github.com/melMass/comfy_mtb/commit/55261bda7c33d088b62c5483e4483201e5a9ce77))
- 🐛 add MASK support for PickFromBatch ([0d264b9](https://github.com/melMass/comfy_mtb/commit/0d264b90a78d5a6719fb3ce71f4e9a642db4c950))
- 🐛 use addDOMWidget for Debug node ([46af602](https://github.com/melMass/comfy_mtb/commit/46af6027d6c87d0c29b8bb0fd1cc1dbdae993629))
- 🐛 use "modern" notation in toDevice ([b7ca8ed](https://github.com/melMass/comfy_mtb/commit/b7ca8ed1c6e117b71afd7696f55dcc3dbd5bad08))
- 🐛 handle missing submodules ([d61da30](https://github.com/melMass/comfy_mtb/commit/d61da304099ff5e4528e4beb1ecc2eb83cabaaa1))
- 🐛 add warnings about what each IO mode can do ([6608c0b](https://github.com/melMass/comfy_mtb/commit/6608c0b6d1cf8f7a9901214096f8c78bfe17056f))
- 🐛 soft deprecate compression h264 ([a757e1c](https://github.com/melMass/comfy_mtb/commit/a757e1c98b2abbd2221a15b77e89d772e02d1d82))
- 🐛 limit packages allowed to be installed from API ([d6e004c](https://github.com/melMass/comfy_mtb/commit/d6e004cce2c32f8e48b868e66b89f82da4887dc3))
- 🐛 ensure default settings (io sidebar) ([ed17fa2](https://github.com/melMass/comfy_mtb/commit/ed17fa2ef4688aadf305a6d51b32c13a0efd22d6))
- 🐛 spawn colour picker at pointer location ([e5482ae](https://github.com/melMass/comfy_mtb/commit/e5482aee5e3de07e8f055b3edc0fccc0e0f75c14)) by [@webfiltered](https://github.com/webfiltered) in [#223](https://github.com/melMass/comfy_mtb/pull/223)
- 🐛 i/o sidebar for custom paths ([62469a4](https://github.com/melMass/comfy_mtb/commit/62469a4dd96e32509171aad74fcae8d2bb0ec593))
### Features
- ⚡ add BatchFromFolder ([9618513](https://github.com/melMass/comfy_mtb/commit/96185132b83c182032e9f6e822561eb5699af517))
- ⚡ add use_normalized to TransformBatch2D ([d4a31bf](https://github.com/melMass/comfy_mtb/commit/d4a31bf19c2863df8dfc4cb9a3cd6683304949e4))
- [**breaking**] ⚡ add support for masks in BatchFLoatMath ([fc7ba08](https://github.com/melMass/comfy_mtb/commit/fc7ba084f6ed7880e88e28eb448ab0bd7d796824))
- ✨ add use_normalized to TransformImage ([4516aa9](https://github.com/melMass/comfy_mtb/commit/4516aa9cb4fcb12c946999d6dcc1501cc09011a3))
- ✨ add regex support for String Replace ([78946b0](https://github.com/melMass/comfy_mtb/commit/78946b0fa3c3cf5dfcee8c7c4c0921b722d09d1e)) by [@poetryiii](https://github.com/poetryiii) in [#233](https://github.com/melMass/comfy_mtb/pull/233)
- ✨ update diarization to 3.1 ([c30408f](https://github.com/melMass/comfy_mtb/commit/c30408f96d4df9c7d35545654401162090a74305)) by [@numz](https://github.com/numz)
- ✨ add "workflow" query to /mtb/view endpoint ([eb7cf89](https://github.com/melMass/comfy_mtb/commit/eb7cf89f173b2342b04e7b61dca3d12cfaf65bdb))
- ✨ add stretch_x and stretch_y to TransformImage ([22fce6f](https://github.com/melMass/comfy_mtb/commit/22fce6fdda135cbb1f1aad42c86aae166cba81b5))
- ✨ add AudioDuration node ([f471497](https://github.com/melMass/comfy_mtb/commit/f47149746ac1e418cda2007c38aafbb03946ce22))
- ✨ basic whisper nodes ([83cfc5c](https://github.com/melMass/comfy_mtb/commit/83cfc5c723d1a572af67ad14b52be4f8371a3c5f))
- ✨ add BboxForDimensions ([9405784](https://github.com/melMass/comfy_mtb/commit/940578476438eaa6a42e0056f1b7b319ee585334))
- ✨ improve the debug node ([cf7a9c4](https://github.com/melMass/comfy_mtb/commit/cf7a9c41e81e8dd461ab9dfa3c05bb8e2cdf2a67))
- ✨ add BatchImageToSublist and counterpart ([00173fa](https://github.com/melMass/comfy_mtb/commit/00173fa3fbca4c5b1ff3016cc5139705ce61ec20))
- ✨ add TensorOps ([a8cf465](https://github.com/melMass/comfy_mtb/commit/a8cf4650ff5cbd4975ef954b5829c772ee53250c))
- ✨ live update outputs grid ([7f7a62f](https://github.com/melMass/comfy_mtb/commit/7f7a62f832c865a13b9181daee79d3cfc21581e2)) by [@christian-byrne](https://github.com/christian-byrne) in [#229](https://github.com/melMass/comfy_mtb/pull/229)
- ✨ add SaveImage passthrough ([0eeb707](https://github.com/melMass/comfy_mtb/commit/0eeb707f34f51142def8e0ef7d351ee5028cb5e0))
- ✨ add filtering to TransformImage ([bae26a0](https://github.com/melMass/comfy_mtb/commit/bae26a07fb02dd518c621eba28986a51c5d086bc))
- ✨ add support for video in I/O sidebar ([c92d99a](https://github.com/melMass/comfy_mtb/commit/c92d99a8a37a64cfc285296f21452c4927a22774))
- ✨ add an extra static input to Stack Images ([3f6d082](https://github.com/melMass/comfy_mtb/commit/3f6d08294096918d50101a19083f9134305cc8c9)) in [#222](https://github.com/melMass/comfy_mtb/pull/222)
- ✨ add support for subdirs (i/o sidebar) ([52bd76e](https://github.com/melMass/comfy_mtb/commit/52bd76e19c8bd7e72986900e5dbfade0457ef7e0))
- ✨ add Batch Sequence Nodes ([827c64c](https://github.com/melMass/comfy_mtb/commit/827c64c43d52ebfb8acd2e5c4491c4b66e6b8f40))
- ✨ add support for more formats (I/O sidebar) ([8c629be](https://github.com/melMass/comfy_mtb/commit/8c629bee186b5ac991058018a788e4a836eef630))
### Miscellaneous Tasks
- 🧹 bump version ([d093d76](https://github.com/melMass/comfy_mtb/commit/d093d76efd87474a3ca82858147255038060ab17))
- 🧹 small adjustments ([01107c4](https://github.com/melMass/comfy_mtb/commit/01107c45f8539ff7c579e08e2a9075d93781b9a2))
- 🤖 update publish action workflow with permissions and version constraints ([0e48aaa](https://github.com/melMass/comfy_mtb/commit/0e48aaa3e4f1e440a5d7ab42df56b728ced03aca)) by [@robinjhuang](https://github.com/robinjhuang) in [#237](https://github.com/melMass/comfy_mtb/pull/237)
- 🧹 basic standalone detection ([3a25526](https://github.com/melMass/comfy_mtb/commit/3a25526e818a1af8f886d2ad5c27101c4a0caa8b))
- 🧹 rename type ([edcb3da](https://github.com/melMass/comfy_mtb/commit/edcb3da08bff66f9adcef8dcd37c3925e64d0135))
- 🧹 update env file ([fc908ba](https://github.com/melMass/comfy_mtb/commit/fc908ba0a528523b7c1e37e34fb32f430746de0d))
- 🧹 dev ([9a94371](https://github.com/melMass/comfy_mtb/commit/9a943714aada107bfd236e00fa1063872db7a834))
- 🧹 apply formatting ([58ae89f](https://github.com/melMass/comfy_mtb/commit/58ae89f8e0f0f8b42825722a6aebc04da39847b1))
### Refactor
- 📦 add model autodownload ([147edcf](https://github.com/melMass/comfy_mtb/commit/147edcfcbc09dd27a0c787f9da568fb850c3308a))
### Wip
- 🚧 loop drawing ([ead4b34](https://github.com/melMass/comfy_mtb/commit/ead4b34e6dd03ea4ed309b246ef31c995325aa08))
## New Contributors
* [@poetryiii](https://github.com/poetryiii) made their first contribution in [#233](https://github.com/melMass/comfy_mtb/pull/233)
* [@numz](https://github.com/numz) made their first contribution in [#](https://github.com/melMass/comfy_mtb/pull/)
* [@webfiltered](https://github.com/webfiltered) made their first contribution in [#223](https://github.com/melMass/comfy_mtb/pull/223)
## [0.2.0] - 2024-12-08
### Bug Fixes
- 🐛 remove mtb sidebar ([b0d52f7](https://github.com/melMass/comfy_mtb/commit/b0d52f73051368df6de2d1e10ad28ca56df72803))
- 🐛 always enable the I/O sidebar ([ec1cb1a](https://github.com/melMass/comfy_mtb/commit/ec1cb1ac17d14670aa756dfb1ae7542397b12559))
- 🐛 ui shifts on animation builder ([ecbb220](https://github.com/melMass/comfy_mtb/commit/ecbb220de6a05f2e506ec43f2b786be983166157))
- 🐛 category for settings ([b6fa571](https://github.com/melMass/comfy_mtb/commit/b6fa571fd2096ace60d03cab42dba9ca37d0cb27)) in [#211](https://github.com/melMass/comfy_mtb/pull/211)
- 🐛 new UI issues ([f272526](https://github.com/melMass/comfy_mtb/commit/f272526bfc5da95e95d42cb4c613a0b9585b2577))
- 🐛 disable old BOOL widget (legacy) ([8596b81](https://github.com/melMass/comfy_mtb/commit/8596b8184edb484c907475a77ac1dc9e4a5c92af))
- 🐛 pass ONNX providers explicitely ([43092e4](https://github.com/melMass/comfy_mtb/commit/43092e44a4ea17f90fcfb12372da634fe4b79557))
- 🐛 typo in mtb_widgets error catch ([80b5a0c](https://github.com/melMass/comfy_mtb/commit/80b5a0ca7459763e7662421bccd8636976eefddd)) by [@christian-byrne](https://github.com/christian-byrne) in [#197](https://github.com/melMass/comfy_mtb/pull/197)
- 🐛 doc widget sidebar offset in the new ui ([81b3bc1](https://github.com/melMass/comfy_mtb/commit/81b3bc1651f06ad2fa7938f810d3f406f5e7c41c))
- 🐛 don't fallback to eval ([997d2fb](https://github.com/melMass/comfy_mtb/commit/997d2fb13af6aadf36873ea2ea3317e56f405aef))
- 🐛 rework main utils ([c99b081](https://github.com/melMass/comfy_mtb/commit/c99b0812ab4a4183ef9298fb8a7c954bc7c858b2))
- 🐛 MaskToImage ([821a0ef](https://github.com/melMass/comfy_mtb/commit/821a0ef42735a0a97ab82be22a4fdc67c9cfc80e))
### Documentation
- 📚 update wiki ([e17c6e2](https://github.com/melMass/comfy_mtb/commit/e17c6e29f5111bf5085b1fe6f764cfd1aae709f2))
- 📚 remove link ([5bc125d](https://github.com/melMass/comfy_mtb/commit/5bc125d2f08470c8900dfd89deca721835848917))
- 📚 clean readme ([333f646](https://github.com/melMass/comfy_mtb/commit/333f646ab1959d2c944fb046275cc93a545d557c))
### Features
- ✨ add h264 compression node ([e32d1e0](https://github.com/melMass/comfy_mtb/commit/e32d1e02df5e3a9351f829513f7ee3ffb2934be4))
- ✨ add postshot nodes ([27e03fa](https://github.com/melMass/comfy_mtb/commit/27e03fa23efffda461c6975b15fe3964de476cb3))
- ✨ improve the I/O sidebar ([cd9e614](https://github.com/melMass/comfy_mtb/commit/cd9e614b1a385d6b06eacfaad62def1d69f09808)) in [#193](https://github.com/melMass/comfy_mtb/pull/193)
- ✨ add UpscaleBBoxBy ([74af5c6](https://github.com/melMass/comfy_mtb/commit/74af5c6499ef5dd73ce66c4c21b8c3507d69b037))
- ✨ simplified sidebar and backend ([22f7c30](https://github.com/melMass/comfy_mtb/commit/22f7c3037345a866c9ff0b06f6689748021cee63))
- ✨ add Interpolate Condition ([0133fb9](https://github.com/melMass/comfy_mtb/commit/0133fb93bc944d0dd7593b89b36e5b2676d9397a))
- ✨ dump of wip things... ([cf7d305](https://github.com/melMass/comfy_mtb/commit/cf7d30507e7e449c4489e6a1ca159d3d0486bc55))
- ✨ use the new parser for documentations ([4e593bb](https://github.com/melMass/comfy_mtb/commit/4e593bb30be561e39f1790e3514f60bb39e5a261))
- ✨ add @mtb/markdown-parser bundles ([097ca33](https://github.com/melMass/comfy_mtb/commit/097ca33b8e7b27148e183e91712dc34d98d1a69b))
- ✨ add VitMatte nodes ([896a025](https://github.com/melMass/comfy_mtb/commit/896a025006f9c7809c5e0776393a28f908be8950))
- ✨ add ColorCorrectGPU ([9651a70](https://github.com/melMass/comfy_mtb/commit/9651a7034120589b059329b21688708e42772453))
- ✨ add Swap FG/BG colors to MaskToImage ([57683c3](https://github.com/melMass/comfy_mtb/commit/57683c3c7d299a117a26526d52de4c26f2ec0f69))
- ✨ add Extract coordinates ([f99f92e](https://github.com/melMass/comfy_mtb/commit/f99f92e8f7b2d6fac56f7f40049715910e15cfee))
- ✨ add AudioCut ([5681b46](https://github.com/melMass/comfy_mtb/commit/5681b464adce395086712b61159b2694150b8027))
- ✨ add AudioStack ([8d0fcee](https://github.com/melMass/comfy_mtb/commit/8d0fcee2f3decc1cbbf3b850332e6b2a022e1377))
- ✨ add AudioSequence node ([1078fc6](https://github.com/melMass/comfy_mtb/commit/1078fc6f0fb225b52536f25ec6a9fa0456a90595))
- ✨ add Split Bbox node ([9007a70](https://github.com/melMass/comfy_mtb/commit/9007a70aa0d6b2ead0f68f7aff8ae8e3c4f3624f))
- ✨ update lerp example ([1a0ebd5](https://github.com/melMass/comfy_mtb/commit/1a0ebd5173687784f279a9c2184c89fb3be01dc5))
### Miscellaneous Tasks
- 🧹 bump minor ([50cb6f5](https://github.com/melMass/comfy_mtb/commit/50cb6f5ed6e5d9fecb9733ef3f7852b8500005e9))
- 🧹 add worktree to gitignores ([9ccf572](https://github.com/melMass/comfy_mtb/commit/9ccf572a158caeab9bff53853e8f6fb85b76776d))
- 🧹 remove dupe code ([e099d58](https://github.com/melMass/comfy_mtb/commit/e099d581a7627c3a66d2e3e6df3a701b0e5f31b7))
- 🧹 update externs ([784fb01](https://github.com/melMass/comfy_mtb/commit/784fb0145b7421e2730b52237ce6a8b63b189191))
- 🧹 add pathlibed inputs to utils ([a825504](https://github.com/melMass/comfy_mtb/commit/a825504bdd67e3461be8118119e0becc35f8af40))
- 🧹 disable Constant ([22190cd](https://github.com/melMass/comfy_mtb/commit/22190cd25ee590595f8f19e75a9a6c539699622b))
- 🧹 new ui is default, flag for old ui ([a976adb](https://github.com/melMass/comfy_mtb/commit/a976adbb39a13b4cd76f224ebba40c604900c862))
- 🧹 add methods to shared ([f8829fc](https://github.com/melMass/comfy_mtb/commit/f8829fcb373e0f9bc4f0ad36c939f372349943bf))
- 🧹 add an old_ui flag to my launcher ([dbdf276](https://github.com/melMass/comfy_mtb/commit/dbdf27664cd207dbbc69b8d635adcd59ed8d269a))
- 🧹 move qrcode to his own file ([7d5569e](https://github.com/melMass/comfy_mtb/commit/7d5569e5c1e0f0b6ccb505a02f74640139d6aaf9))
## [0.1.6] - 2024-07-03
### Bug Fixes
- 🐛 menu callback issue ([d64fac4](https://github.com/melMass/comfy_mtb/commit/d64fac4b74e0590acde5e3b8edd4a2f715448cf5))
### Documentation
- 📚 Update requirements file in INSTALL.md ([f25f6bd](https://github.com/melMass/comfy_mtb/commit/f25f6bdcd13d50f9d383065321320b0ce6a03214)) by [@elthariel](https://github.com/elthariel) in [#186](https://github.com/melMass/comfy_mtb/pull/186)
### Features
- ✨ add alpha channel support for faceswap/restore ([d6343e1](https://github.com/melMass/comfy_mtb/commit/d6343e1860f46947e93758f8bba03857c9326b38))
### Miscellaneous Tasks
- 🧹 better classname extraction ([d687497](https://github.com/melMass/comfy_mtb/commit/d687497d8041ab5d77bd31909592def6e4d0e7f6))
- 🤖 limit release only to tags ([4eebdd8](https://github.com/melMass/comfy_mtb/commit/4eebdd8b8bff73c3db4f0248da8dac7d67cb310b))
- 🧹 runner ([fb34671](https://github.com/melMass/comfy_mtb/commit/fb34671ee6fe80b965fe576c279ed1ff77a358f2))
- 🤖 only publish on tag ([f1b4846](https://github.com/melMass/comfy_mtb/commit/f1b484617a917d38d9b3658d8920aa7dec672a79))
- 🧹 small fixes ([4507842](https://github.com/melMass/comfy_mtb/commit/4507842a706141977a6a68945c36e977c358d91a))
## New Contributors
* [@elthariel](https://github.com/elthariel) made their first contribution in [#186](https://github.com/melMass/comfy_mtb/pull/186)
## [0.1.5] - 2024-06-21
### Bug Fixes
- 🐛 keep the last model match instead of first ([1edc2cd](https://github.com/melMass/comfy_mtb/commit/1edc2cd10de81297e7a895009d358813e79b70ba))
- 🐛 properly initialize the curve value ([35622e3](https://github.com/melMass/comfy_mtb/commit/35622e3a5e58103a8f5b150556b85e97e31555e1))
- 🐛 ImageCompare improvements ([acc2d68](https://github.com/melMass/comfy_mtb/commit/acc2d687d596bf82c2075f9a24003eacf18adfe7)) by [@christian-byrne](https://github.com/christian-byrne) in [#176](https://github.com/melMass/comfy_mtb/pull/176)
- 🐛 repetitive warning ([780c52f](https://github.com/melMass/comfy_mtb/commit/780c52f03aca3079a1b695510341486720004bec)) by [@vxkj1211](https://github.com/vxkj1211) in [#177](https://github.com/melMass/comfy_mtb/pull/177)
- 🐛 add back was conversion node ([349a852](https://github.com/melMass/comfy_mtb/commit/349a8524c6f7fcab4a124cacb60bfbef1463cf1b))
- 🐛 drag lag on documentation resize handle ([15330ea](https://github.com/melMass/comfy_mtb/commit/15330eab655f66214d3c25fd237679f090175c32))
- 🐛 kwarg typo ([1571782](https://github.com/melMass/comfy_mtb/commit/1571782d012b83bce32a065e700f9a587db234d2))
- 🐛 seed of PlotBatchFloat ([5b40302](https://github.com/melMass/comfy_mtb/commit/5b4030288d43c79859c9706a12aa0f8b7dea190f))
- 🐛 forceInput for FLOAT <-> FLOATS converters ([5a0ef0d](https://github.com/melMass/comfy_mtb/commit/5a0ef0dadd01fd5937ed0715d829d6a456f96318))
- 🐛 FLOAT always need options to be set ([967e72f](https://github.com/melMass/comfy_mtb/commit/967e72fc66780685f8192cb8fe13ba66b9326f63))
- 🐛 remove doc if opened on node delete ([bee3f47](https://github.com/melMass/comfy_mtb/commit/bee3f47a14ddb92b3760098666bf75dc7d37f1e4))
- 🐛 for documentation on HiDPI ([b11346a](https://github.com/melMass/comfy_mtb/commit/b11346aba88d9f1dac3b6b42c691979cc0978b6f))
- 🐛 never remove input 0 of dynamic inputs ([30982fa](https://github.com/melMass/comfy_mtb/commit/30982fa48829c3fc2a6745ce5a07537a3d94b2f9))
- 🐛 use the same fix as dynamicInputs for debug ([92b7990](https://github.com/melMass/comfy_mtb/commit/92b79906cd2ee1b4ca3ff25378d7786b5a47cb75))
- 🐛 missing numberInput ([76f365b](https://github.com/melMass/comfy_mtb/commit/76f365b5eee165c76f3da7d2e3950786685bc08b))
- 🐛 better curve ([da67e76](https://github.com/melMass/comfy_mtb/commit/da67e766c2f700dd9e2f51a5bafe07c612904f5d))
- 🐛 prepend MTB_ to all classes ([b1d74ad](https://github.com/melMass/comfy_mtb/commit/b1d74adb15166e3e5eb9cf92d6148e4644bed346))
- 🐛 dynamic connections ([652ac3f](https://github.com/melMass/comfy_mtb/commit/652ac3f3b971582b02115177fd6f7a9d3d7295df))
- 🐛 remaining issue before merge ([100067a](https://github.com/melMass/comfy_mtb/commit/100067a645194366426f29b085bf25d0623f4fac))
- 🐛 debug issues ([7807449](https://github.com/melMass/comfy_mtb/commit/7807449e6dcc01cfdb7f0eb818569184c8b41af2))
- 🐛 errors when insightface's folder missing ([e838c04](https://github.com/melMass/comfy_mtb/commit/e838c04758402250fd3464d6cd6a6f872e8cef29))
- 🐛 typo ([e40ad7a](https://github.com/melMass/comfy_mtb/commit/e40ad7a574f961ebe1f338b97214da5cbadcc529))
- 🐛 better defaults (cont) ([1da483a](https://github.com/melMass/comfy_mtb/commit/1da483a8baa6a893f1adb05ef79b90c4412c3834))
- 🐛 better defaults for Autopan ([5eff38b](https://github.com/melMass/comfy_mtb/commit/5eff38b387d22206d39c08e435806f9d03992feb))
- 🐛 dynamic inputs ([9ab20a0](https://github.com/melMass/comfy_mtb/commit/9ab20a0ab50b1656ded9a84c13769fd2d547f2d2))
- 🐛 bundle ace editor ([7c35582](https://github.com/melMass/comfy_mtb/commit/7c3558273bebc0754c802720e705232f220a0da4))
- 🐛 image to mask ([f16d576](https://github.com/melMass/comfy_mtb/commit/f16d576f6f0e83fc2fafd2d1f29b2edeb00d3197))
- 🐛 prepend MTB to classnames ([e56508c](https://github.com/melMass/comfy_mtb/commit/e56508c2078155f053e7f11d538a048df6a5b18b))
- 🐛 allow smaller values in BatchTransform ([9a4b27d](https://github.com/melMass/comfy_mtb/commit/9a4b27d2e05e8ebe31f58a21db94bd3a54ed23d9))
- 🐛 add category for virtual note+ ([eeac8c0](https://github.com/melMass/comfy_mtb/commit/eeac8c002ad1f9e461418fb66b9338e969259e58))
- 🐛 make image feed of by default ([df0a98b](https://github.com/melMass/comfy_mtb/commit/df0a98b94a4a9388811bc8786e820ec892919c1a))
- 🐛 support batch masks (colored image node) ([2465ffb](https://github.com/melMass/comfy_mtb/commit/2465ffb0d3b052fb78559394dbb550bba59b97a3))
- 🐛 support pillow < 10 ([48f91b7](https://github.com/melMass/comfy_mtb/commit/48f91b74e2c7ef6d31c094eafa5332784a275a8b))
- 🐛 image rotation bug ([54ff658](https://github.com/melMass/comfy_mtb/commit/54ff6583ded0ed4054f8e5d7fadf0b2350259dce)) by [@hongminpark](https://github.com/hongminpark) in [#154](https://github.com/melMass/comfy_mtb/pull/154)
- 🐛 font fallback ([9fccdee](https://github.com/melMass/comfy_mtb/commit/9fccdee82d721e88c64d2292c209fec869524dd2))
- ✨ optional inputs of colored image ([cd32f26](https://github.com/melMass/comfy_mtb/commit/cd32f26b167088d6b489e43b260c187ea5e4d223)) by [@ScottNealon](https://github.com/ScottNealon) in [#147](https://github.com/melMass/comfy_mtb/pull/147)
- 📝 adds a way to not load the imagefeed ([501c330](https://github.com/melMass/comfy_mtb/commit/501c3301056b2851555cccd75ab3ff15b1ab8e0c))
- 🐛 colored image mask input ([30c4311](https://github.com/melMass/comfy_mtb/commit/30c4311b69f6481a34f968cb67a9b5ce5d2e9fda))
- 🐛 handle font cache errors ([c43a661](https://github.com/melMass/comfy_mtb/commit/c43a661ba31dcd7720b4f32d8e96760e6191fbd9))
- 💄 register the COLOR type even for external extensions ([12b134a](https://github.com/melMass/comfy_mtb/commit/12b134ab4c937c192aaf4a3667d9885dd4fe43ca))
- ✨ mask crop output ([59a361a](https://github.com/melMass/comfy_mtb/commit/59a361af5870b8ffc984c6680dd3282d3553dcf9))
- 🚑️ thread font loading ([e4da832](https://github.com/melMass/comfy_mtb/commit/e4da832b99bd640b72c31b67178a3168e3238fa0))
- 📦 changed way of creating bbox from mask ([14ee9e2](https://github.com/melMass/comfy_mtb/commit/14ee9e23c009ab55fa3b2fc6ec60fb683c46d57d)) by [@Yurchikian](https://github.com/Yurchikian) in [#124](https://github.com/melMass/comfy_mtb/pull/124)
- ✨ expose invert of bboxfrommask ([53cb503](https://github.com/melMass/comfy_mtb/commit/53cb503866da6d83b47eaeb8073039ace2ae0a95))
- ✨ less strict csv parsing ([d5c4c5f](https://github.com/melMass/comfy_mtb/commit/d5c4c5f2649ecdb4bf7b517c5b33bbf8df753047))
- 🐛 fit number regression ([c8658df](https://github.com/melMass/comfy_mtb/commit/c8658dfbdd3a0ca8c3e88cd1adfddc55c7444045))
- 🐛 remove uneeded installs ([4e07450](https://github.com/melMass/comfy_mtb/commit/4e07450bcabb0105b5610e52f7d4692ea07f9c1d))
- 🐛 import issue ([255ac03](https://github.com/melMass/comfy_mtb/commit/255ac036bab1d776301857843d0e7a85e9a9dcb8))
- 🐛 wrong output for bbox ([8d12b59](https://github.com/melMass/comfy_mtb/commit/8d12b59844958fbc696d01d51162f97262664ae9))
- 🚑️ fallback when symlink detection fails ([278f22c](https://github.com/melMass/comfy_mtb/commit/278f22c2093b6eca63d2d00f7936774918707e4e))
- ✨ handle malformed styles.csv ([e6f6502](https://github.com/melMass/comfy_mtb/commit/e6f65026735770df8aced4a3acb75550ff1c84da))
- 🐛 encoding ([5af2840](https://github.com/melMass/comfy_mtb/commit/5af284067c65042bcdfff04a5d5a2360bf9e4af7))
- ⚡️ add the cli deps ([bb90e04](https://github.com/melMass/comfy_mtb/commit/bb90e0415f6a1ececbf468815dc0f5959d9a34e8))
- 🚑️ check for symlink ([25b933c](https://github.com/melMass/comfy_mtb/commit/25b933c698b250a411549d2600fae49bec225b7a))
- 🚑️ remove problematic dependencies ([5dfea51](https://github.com/melMass/comfy_mtb/commit/5dfea51dd8db2a4829e559eadeda22374b51c8a4))
- 🐛 batch support ([f1ff9fc](https://github.com/melMass/comfy_mtb/commit/f1ff9fc7c4684ad673c3178df3b8142dcf0b16ac))
- 🐛 automatically disable tiling if seamless is on ([4605f74](https://github.com/melMass/comfy_mtb/commit/4605f74f370d4d221ab1d50f21b72910fa6909c7))
- 🐛 debug node ([dc500b7](https://github.com/melMass/comfy_mtb/commit/dc500b788e885205f017956da6a71a677f822941))
- ⚡️ hack to handle prompt validation ([d49b257](https://github.com/melMass/comfy_mtb/commit/d49b2578c247dcba9b09b374d99f5cc45cac172d))
- ✨ deepbump update ([87b245c](https://github.com/melMass/comfy_mtb/commit/87b245c6a6895490e3612b235879fa90b62dea2b))
- 👷 user folder_paths to retrieve comfy root ([38df58a](https://github.com/melMass/comfy_mtb/commit/38df58a78c363ef2657011893d4d811676b1c664))
- 🐛 typo ([90aee83](https://github.com/melMass/comfy_mtb/commit/90aee83797a863cf4797cdbe187f949061cbd176))
- 🐛 do not resolve symlink for "here" ([a50b11b](https://github.com/melMass/comfy_mtb/commit/a50b11bdaa66f4e805811b1676c937ade11318c2))
- ✏️ use Union to allow support for <3.10 ([88a2779](https://github.com/melMass/comfy_mtb/commit/88a277968745ac990406b14d300a8ada9c575b11)) by [@M1kep](https://github.com/M1kep) in [#91](https://github.com/melMass/comfy_mtb/pull/91)
- ⚡️ simplify widgets cleanup ([cdd098e](https://github.com/melMass/comfy_mtb/commit/cdd098e10258401402b8023c9143532cfa4a1745))
- ✨ don't assume the install was ran ([cc43654](https://github.com/melMass/comfy_mtb/commit/cc43654af2987bc8860557caa99cde91e8309b21))
- 🐛 install ([616b2bf](https://github.com/melMass/comfy_mtb/commit/616b2bfc6c629cef1d30cb0d717bd805c3a086aa))
- 🐛 properly escape paths ([22cac9b](https://github.com/melMass/comfy_mtb/commit/22cac9b2d95910197941b73e7548735470bd3b17))
- 🐛 use relative paths in JS ([e2773ff](https://github.com/melMass/comfy_mtb/commit/e2773ff22e43e7756ad618344a03d661a576cf35))
- 💄 BatchFromHistory when "listening" ([3b07984](https://github.com/melMass/comfy_mtb/commit/3b07984716402fbbf5da41020bf73befd52e7ebf))
- ✨ save gif widget removal ([fe8f519](https://github.com/melMass/comfy_mtb/commit/fe8f519f8860b0610d8cafcd9b843b4171c2b3d4))
### Documentation
- 📚 update the wiki ([fa3199b](https://github.com/melMass/comfy_mtb/commit/fa3199be2b87bf3cb7484a0fee32a8ac099adc65))
- 📚 update wiki submodule ([49cea8d](https://github.com/melMass/comfy_mtb/commit/49cea8d94508b27781506e3b5509c65e1d84e80f))
- 📚 add the wiki as a submodule ([5998924](https://github.com/melMass/comfy_mtb/commit/59989249260a9c579ec851c50534b58f3f02cd61))
- 📚 missing doc ([c9836a8](https://github.com/melMass/comfy_mtb/commit/c9836a87f6823db1d53e56997417f3cbe8cc4727))
- 📚 use flat icon ([991af4f](https://github.com/melMass/comfy_mtb/commit/991af4f45ff8c660b2c45466bb219186699170ed))
- 📚 add banodoco channel link ([9ce34b4](https://github.com/melMass/comfy_mtb/commit/9ce34b47fd99b18db7997ccce44e6063f00b6801))
- 📚 udpate changelog ([8221c49](https://github.com/melMass/comfy_mtb/commit/8221c49942bd87c14d5063066315a449a1fee86e))
- 📝 add changelog ([0d817bf](https://github.com/melMass/comfy_mtb/commit/0d817bf326b4a22e2221264a414af50c3b7048b9))
- 📄 add note+ screenshot ([90d9636](https://github.com/melMass/comfy_mtb/commit/90d96366c8b7637b55d1b4f88cb9aca217c1414b))
- 📝 add cover image ([6b993b8](https://github.com/melMass/comfy_mtb/commit/6b993b84071bbb80ba1b8bd63576f31e35d05590))
- 📝 fix image size ([3e8c2fe](https://github.com/melMass/comfy_mtb/commit/3e8c2fe789925e7017c2f8c8d9164c139588aba4))
- 📝 add image ([3e93ea6](https://github.com/melMass/comfy_mtb/commit/3e93ea6f2c73353891b1a3f6223b5730bc69df37))
- 📝 explain optional nodes ([cea0b08](https://github.com/melMass/comfy_mtb/commit/cea0b08eb044756ab1b408f630435095b8969d36))
- 📝 add the example previews from the wiki ([8f90986](https://github.com/melMass/comfy_mtb/commit/8f909864bfaa9f2d0fbdcf3942eacb9d78ee8fb8))
- 📝 update node list ([4917e31](https://github.com/melMass/comfy_mtb/commit/4917e31c427c74d28c830fd7b2423cab393ba0f8))
- 📝 add some deprecation warnings and recommendations ([e11df9d](https://github.com/melMass/comfy_mtb/commit/e11df9d45c81d93f4334841de036b4aa3364375a))
- 📝 add a reference to SlickComfy for colab ([bb35098](https://github.com/melMass/comfy_mtb/commit/bb35098c656b0b2d30909b83df0a3b65c5975f78))
### Features
- ✨ add ModelPruner (wip) ([43d65ae](https://github.com/melMass/comfy_mtb/commit/43d65ae68c97e077117b17b7c9d1936583f965eb))
- ✨ Use dynamic contrast in Color Correct ([6abac2e](https://github.com/melMass/comfy_mtb/commit/6abac2e4706a3d937420213e01468bae10cc2017)) by [@christian-byrne](https://github.com/christian-byrne) in [#180](https://github.com/melMass/comfy_mtb/pull/180)
- ✨ StackImages add support for batch mismatch ([5060c56](https://github.com/melMass/comfy_mtb/commit/5060c561353e43624ec164cb73fce7d1d422f765))
- ✨ add BatchFloatMath ([f9d2ebf](https://github.com/melMass/comfy_mtb/commit/f9d2ebf91d09fc214fecf7501a5490b33c30aca2))
- ✨ add FLOATS to INTS ([1b7ae27](https://github.com/melMass/comfy_mtb/commit/1b7ae27cc1907bfba3c5166ec2c61547babd2e0a))
- ✨ debug dict ([63ee25d](https://github.com/melMass/comfy_mtb/commit/63ee25d001d4c94aa95dc8b39008f5d943f2ab45))
- ✨ add Swap BG/FG color menu item ([1caf7c1](https://github.com/melMass/comfy_mtb/commit/1caf7c18c372651b2be7227eb77e2251d963693d))
- ✨ BatchFloatFit the batch version of FitNumber ([ab58c36](https://github.com/melMass/comfy_mtb/commit/ab58c362124f0f4b3178534ca78cb924fb881534))
- ✨ add FloatToFloats (the counterpart) ([78a86da](https://github.com/melMass/comfy_mtb/commit/78a86daaf71dab5be34b90b13491460854718485))
- ✨ add some FLOATS batch nodes ([2159395](https://github.com/melMass/comfy_mtb/commit/2159395389429c5f7012e660b41fad48d376b39f))
- ✨ poc of the doc widget idea ([fac7529](https://github.com/melMass/comfy_mtb/commit/fac7529d1f7b6fc4b3b2e7f6022ebb23ec71169d))
- ✨ add the backend node for Constant ([dff5b22](https://github.com/melMass/comfy_mtb/commit/dff5b2201d73c1a91d4b5864e3b974e68846a011))
- ✨ add Constant node ([cbb5dd2](https://github.com/melMass/comfy_mtb/commit/cbb5dd2cf810d5648a64eae370dba610336b99d5))
- ✨ add FloatsToFloat ([6ebecfd](https://github.com/melMass/comfy_mtb/commit/6ebecfd8cf1dc3779384e565a65baa9dceb43660))
- ✨ add AutoPanEquilateral ([3513937](https://github.com/melMass/comfy_mtb/commit/35139371e84d715423015e05d1b4a6c1d88b0eb5))
- ✨ add MatchDimensions ([5db3ebe](https://github.com/melMass/comfy_mtb/commit/5db3ebedb9d38470c82544e45970775193add05c))
- ✨ add equilateral example ([8d65556](https://github.com/melMass/comfy_mtb/commit/8d65556c37f33d1c496504db92574805916dd613))
- ✨ enhance tiling tools ([ba73fc6](https://github.com/melMass/comfy_mtb/commit/ba73fc6af7039a4629a73cdc36a8c8736dc27c9d))
- ✨ add FLOATS support to blur ([92c810c](https://github.com/melMass/comfy_mtb/commit/92c810c5036f7a2b3f84a3fde8c81e6a2b046b07))
- ✨ add "tube" to Batch Shape ([f658fc3](https://github.com/melMass/comfy_mtb/commit/f658fc31e040141209384d98dfe84b766fe4ae11))
- ✨ note+ editor themes ([133da70](https://github.com/melMass/comfy_mtb/commit/133da705c94af2dfb3d2f38c0d9c2723c72cacf7))
- ✨ add ffmpeg gif export ([1b29aad](https://github.com/melMass/comfy_mtb/commit/1b29aad360116e631b7b4d34e98a5a631f134977)) by [@huanggou666](https://github.com/huanggou666) in [#159](https://github.com/melMass/comfy_mtb/pull/159)
- ✨ add "To Device" ([c28181f](https://github.com/melMass/comfy_mtb/commit/c28181f1615d2e183767aa76cc2350934330e546))
- ✨ add note+ example ([90f3bc2](https://github.com/melMass/comfy_mtb/commit/90f3bc2d953b299ea34e9e3a925f1a824b488855))
- 💄 node+ improvements ([4b29395](https://github.com/melMass/comfy_mtb/commit/4b29395000254382882c0d1be115b2ed80cd7c99))
- 📝 add note plus ([605c8db](https://github.com/melMass/comfy_mtb/commit/605c8db320e1531c6347f6888606fa50d8eb268b))
- 🚧 add playlist nodes ([cf96572](https://github.com/melMass/comfy_mtb/commit/cf965727e8e7064328704d88cd0410c61f1e686e))
- 🚨 add missing node ([16c1a59](https://github.com/melMass/comfy_mtb/commit/16c1a59312b1d9841f5f8a814eff93a1ddf04edb))
- ✨ Math Expression node ([142624e](https://github.com/melMass/comfy_mtb/commit/142624eea616a5622387b1b641c02605455ee6f1))
- 🚀 add optional inputs to colored image ([049983d](https://github.com/melMass/comfy_mtb/commit/049983dbe2dbce6b772908468c4042d2bfde5eb2))
- ✨ Add support for extra_model_paths.yaml ([d7b8ac8](https://github.com/melMass/comfy_mtb/commit/d7b8ac8e0c98b0d7a2e21889d35aad9f6b093560))
- ✨ add batch shake ([af94203](https://github.com/melMass/comfy_mtb/commit/af94203d1b461d934ca1c44211ca0f71a5d05d48))
- ✨ enhance concat images ([a798eb0](https://github.com/melMass/comfy_mtb/commit/a798eb07d0d891cfbd47013b442ef2fa3d7cc5bc))
- 💄 add a few more batch nodes ([c1d42de](https://github.com/melMass/comfy_mtb/commit/c1d42de0fcde86d2a167fb4b5e781ee987814da2))
- ✨ Batch node utilities ([cef5023](https://github.com/melMass/comfy_mtb/commit/cef5023efc17366a2e937ef43944de3587707fac))
- 🚨 Image Stack node (horizontal and vertical stack) ([bb3277d](https://github.com/melMass/comfy_mtb/commit/bb3277d85f4ca21735cb1f5237cb1430db88c183))
- 🚀 add seamless model hack ([21acc87](https://github.com/melMass/comfy_mtb/commit/21acc87ff0a84b7588f4b5aae0aeb5ae94bbbfbe))
- 🔧 debug handle a few more types ([638498c](https://github.com/melMass/comfy_mtb/commit/638498c6b47c2b2cab82f76aec1f3d46df67f263))
- 🎨 Add an editor for the styles loader ([2faa2f2](https://github.com/melMass/comfy_mtb/commit/2faa2f2a148a4dbf5525e4945f688a239f244546))
- ✨ add a static assets path ([6a00d1d](https://github.com/melMass/comfy_mtb/commit/6a00d1da5a8a5fa47af1bf1ab5d3cd206c599841))
- ✨ add Interpolate Clip Sequential ([a71c273](https://github.com/melMass/comfy_mtb/commit/a71c273baf450ad7e2a7e032451f015d3be3e9e9))
### Miscellaneous Tasks
- 🧹 add fields for the registry ([bb5682a](https://github.com/melMass/comfy_mtb/commit/bb5682aa6da923859db33830c2e46f24b19199a1))
- 🧹 add pre-commit ([59612fd](https://github.com/melMass/comfy_mtb/commit/59612fd8110a888f0081433242a2b5a5f7e46da6))
- 🧹 migrate from poetry to setuptools ([dfd17f6](https://github.com/melMass/comfy_mtb/commit/dfd17f6d783e784df7dab38d185c747b4c04d1d0))
- 🧹 remove logs ([1070edd](https://github.com/melMass/comfy_mtb/commit/1070edd0245fb235183d5f38cd1bebf6e0405f97))
- 🧹 add more pyproject meta ([644371e](https://github.com/melMass/comfy_mtb/commit/644371e5b5a2b8260fc5c6f699465b0bc1c81d57))
- 🤖 move at the proper location ([f3d468c](https://github.com/melMass/comfy_mtb/commit/f3d468cfc238f13905a13a7b2225e3711129c64d))
- 🤖 add CI to publish to ComfyUI Registry ([6cd448b](https://github.com/melMass/comfy_mtb/commit/6cd448b026956cdf3f1b81e93724b295316fbf09)) by [@haohaocreates](https://github.com/haohaocreates) in [#182](https://github.com/melMass/comfy_mtb/pull/182)
- 🧹 add ComfyUI registry to pyproject.toml ([5951c90](https://github.com/melMass/comfy_mtb/commit/5951c90b10f9b77b2b617e83efe0112f43c8daef)) by [@haohaocreates](https://github.com/haohaocreates) in [#181](https://github.com/melMass/comfy_mtb/pull/181)
- 🧹 update types ([96a0da9](https://github.com/melMass/comfy_mtb/commit/96a0da9dbd051d1fcf8b332c54ed2d307d8ae0dd))
- 🧹 use a gettattr fallback ([a344cdc](https://github.com/melMass/comfy_mtb/commit/a344cdcba9823ca1fb0762795068039b1e1cf0ab))
- 🧹 cleanup js ([64cc4e9](https://github.com/melMass/comfy_mtb/commit/64cc4e9649853023d645245bea1e1ceb11073f01))
- 🧹 add savedatabundle js part ([edd7c3f](https://github.com/melMass/comfy_mtb/commit/edd7c3f5d075b640e9cdb067ebfe51c42ff61791))
- 🧹 wip dynamic multitype ([71bfdd6](https://github.com/melMass/comfy_mtb/commit/71bfdd61d731ce15f9bd0bb19d65b5af208d5dcf))
- 🧹 applied some linting ([fe49312](https://github.com/melMass/comfy_mtb/commit/fe49312cbef03c6540304448fa88aa7a88391efa))
- 📝 header links not parsed ([514c0d2](https://github.com/melMass/comfy_mtb/commit/514c0d2eda9990435eb18258d4bbd1aa137feb3d))
- 📝 hardcode links in changelog ([915b744](https://github.com/melMass/comfy_mtb/commit/915b7444a9db83f349d83b636304af0d276f529f))
- 🔖 local updates ([6c5e5d3](https://github.com/melMass/comfy_mtb/commit/6c5e5d36379bdab223b4503e42b7956b55a82ab0))
- 📝 update node list ([dd27f99](https://github.com/melMass/comfy_mtb/commit/dd27f990c72fa94aff205eb314a8ea360f57479e))
- ✨ update node_list ([537a0d8](https://github.com/melMass/comfy_mtb/commit/537a0d8108d0caa3ab2daeafd1d25d680214ef26))
- ✨ local stuff ([9afad1a](https://github.com/melMass/comfy_mtb/commit/9afad1a1680073006d946be10f8c97b75ddfe253))
- 📝 fix update issue template ([da290db](https://github.com/melMass/comfy_mtb/commit/da290dbcf2952a56be9334f7bf9dc4d8fa64a21d))
- 📝 update issue template ([b949bb4](https://github.com/melMass/comfy_mtb/commit/b949bb406bc1929634600465ea389eaedefe6e6f))
### Refactor
- ⚡️ small local fixes ([bcac665](https://github.com/melMass/comfy_mtb/commit/bcac66508d2e788cc437da289d1ccede19465b8c))
- 🗑️ remove unused code in install script ([5b75436](https://github.com/melMass/comfy_mtb/commit/5b75436610c6312adf47c6baa3e9fe9cc7d56dcf))
### Merge
- 🔀 pull request #109 from melMass/dev/0.2.0 ([87e301d](https://github.com/melMass/comfy_mtb/commit/87e301d120a542d5aabe544bec10d38dbd19b2f6)) in [#109](https://github.com/melMass/comfy_mtb/pull/109)
- 🔀 pull request #86 from melMass/feature/styles-editor ([cbdb816](https://github.com/melMass/comfy_mtb/commit/cbdb816164900061ddaa1671f4287763d0b79ee1)) in [#86](https://github.com/melMass/comfy_mtb/pull/86)
### Wip
- 🚧 curve widget logic fixed ([e312b02](https://github.com/melMass/comfy_mtb/commit/e312b02ad2f8334e87654a20b0114837df229371))
- 🚧 dump3 ([eedbb4b](https://github.com/melMass/comfy_mtb/commit/eedbb4bc6581bef85c746307fe9d53360ea45bcf))
- 🚧 dump ([fa23975](https://github.com/melMass/comfy_mtb/commit/fa2397585fff4f54bcf17f0b0e0083c427b34fa8))
- 🚧 dump ([0d0fb8e](https://github.com/melMass/comfy_mtb/commit/0d0fb8e13a5da54a44a96a04607f7a349f8fdb03))
- 🚧 add text template node ([af2175a](https://github.com/melMass/comfy_mtb/commit/af2175a1fc0c2fb29ef3493f242fe45ec6fcabac))
## New Contributors
* [@haohaocreates](https://github.com/haohaocreates) made their first contribution in [#182](https://github.com/melMass/comfy_mtb/pull/182)
* [@vxkj1211](https://github.com/vxkj1211) made their first contribution in [#177](https://github.com/melMass/comfy_mtb/pull/177)
* [@huanggou666](https://github.com/huanggou666) made their first contribution in [#159](https://github.com/melMass/comfy_mtb/pull/159)
* [@hongminpark](https://github.com/hongminpark) made their first contribution in [#154](https://github.com/melMass/comfy_mtb/pull/154)
* [@ScottNealon](https://github.com/ScottNealon) made their first contribution in [#147](https://github.com/melMass/comfy_mtb/pull/147)
* [@Yurchikian](https://github.com/Yurchikian) made their first contribution in [#124](https://github.com/melMass/comfy_mtb/pull/124)
* [@M1kep](https://github.com/M1kep) made their first contribution in [#91](https://github.com/melMass/comfy_mtb/pull/91)
## [0.1.4] - 2023-08-12
### Bug Fixes
- 🚀 pending fixes ([ea5d73d](https://github.com/melMass/comfy_mtb/commit/ea5d73d48cfa4046f48a52609cff7f754d8364ed))
- 🚑️ image resize infinite loop ([30d6cfe](https://github.com/melMass/comfy_mtb/commit/30d6cfe81292d0f7702544b3c2cbad1820c4a926))
- ✨ update example files ([610afe0](https://github.com/melMass/comfy_mtb/commit/610afe031f21d737b2fd5128e4be7100b6666181))
- 🐛 simplify install steps ([4fc84d6](https://github.com/melMass/comfy_mtb/commit/4fc84d615dd0f546442c3537f00c52366db4ca9b))
- ✨ refactor ([8523392](https://github.com/melMass/comfy_mtb/commit/8523392df74c586dc940841ddbb5069943b16f7d))
- 🐛 debug rgba ([40560f8](https://github.com/melMass/comfy_mtb/commit/40560f8154d3ddeabf708be4d111370648d466ac))
- 🎨 rename fun to generate ([e7f72f9](https://github.com/melMass/comfy_mtb/commit/e7f72f9825da58254e3084b4ba91f76e6cf2cf5f))
- ✨ refactor existing ([1144466](https://github.com/melMass/comfy_mtb/commit/11444662b9198861b62aff06a08b9c9ea01dd8bd))
- ⚡️ move getbatchfromhistory to graphutils ([2eccba4](https://github.com/melMass/comfy_mtb/commit/2eccba4e33b21d1d080cb2f415f76a93488120f0))
- 🚧 wip dependency installer UI ([630b492](https://github.com/melMass/comfy_mtb/commit/630b492347f75d7308b31a000061b41d7dfa4a10))
- 🐛 image feed zorder ([0fb2d4d](https://github.com/melMass/comfy_mtb/commit/0fb2d4da90a7e65f82b3f9c8942a68e360456cf7))
- ⬇️ download_antelopev2 ([4dd5321](https://github.com/melMass/comfy_mtb/commit/4dd532185223a1fa5978446e7bb75d32d77ebdb5))
- 🚑️ frontend pushed too early ([91f60d4](https://github.com/melMass/comfy_mtb/commit/91f60d4c463c474ac10e868e8e73e13fa019856b))
- 🚑️ missing input ([84ac8ac](https://github.com/melMass/comfy_mtb/commit/84ac8ac852aeb962029bfd8369fe5ed59a203977))
- 🐛 shell command bug ([3d5075f](https://github.com/melMass/comfy_mtb/commit/3d5075fea2e219a179271c9810017c7e38bff6cc))
- 🚑️ remove pipe mode from the install.py ([b854a30](https://github.com/melMass/comfy_mtb/commit/b854a302ce4708d2ad2dac249860308dbdcae5a6))
- ⚡️ colab install ([36d8e6b](https://github.com/melMass/comfy_mtb/commit/36d8e6bdb06edab72ccfb686266d2e644a9f028c))
- 🚑️ install typo ([ffa1a87](https://github.com/melMass/comfy_mtb/commit/ffa1a87b9184df5a3699a6118714b39d359bde4d))
### Documentation
- 📝 link the actual action instead of badge ([098d74a](https://github.com/melMass/comfy_mtb/commit/098d74a3cd8449d836569a074995e20d775c6728))
- 📝 add action badge ([e74314b](https://github.com/melMass/comfy_mtb/commit/e74314b04eb218c140482ccf704b61af06db3f4d))
### Features
- 💫 export to prores -> export with ffmpeg ([a4d99d9](https://github.com/melMass/comfy_mtb/commit/a4d99d966b1207191243a9749385b998d1a9c6b1))
- 🔥 add any to string & refactor ([dbdb872](https://github.com/melMass/comfy_mtb/commit/dbdb872b74e18c16feb44bd037abc3aafbb4700f))
- ✨ add UI for interpolate clip sequential ([5ec5511](https://github.com/melMass/comfy_mtb/commit/5ec551143302b2a94ca82e477f684ecee23f1459))
- ✨ add portable reqs ([3f14b16](https://github.com/melMass/comfy_mtb/commit/3f14b1676d28f5ffa1f47fda00b9bc244951045c))
- ✨ add border extension ([fb64484](https://github.com/melMass/comfy_mtb/commit/fb644847ca434123e8e8e4991d33949fd31e3cbe))
- ✨ use PIL for gif saving ([2bc7ae8](https://github.com/melMass/comfy_mtb/commit/2bc7ae88bf4cdfa575d11233c0e6f7b07f9dfd23))
- 🎨 update node list ([a54d7d5](https://github.com/melMass/comfy_mtb/commit/a54d7d5346c272898dd4e67c65495de7325ab3a0))
- ✨ install fix ([512de60](https://github.com/melMass/comfy_mtb/commit/512de6023e55f2cc47516bf44436efe22157273f)) in [#41](https://github.com/melMass/comfy_mtb/pull/41)
### Miscellaneous Tasks
- 💄 encoding ([49c64c7](https://github.com/melMass/comfy_mtb/commit/49c64c74eb3e99f456b563bbd79e3fe47a85c70d))
- 🚀 only fetch controlnet_preprocessor deps ([414beb9](https://github.com/melMass/comfy_mtb/commit/414beb99a1f9bf719eca6ac139c9b2ccdfd6d743))
- 🚀 add controlnetpreprocessors to tests ([63b3aec](https://github.com/melMass/comfy_mtb/commit/63b3aece2ba05adc2b655afeb41e3d47e7887b33))
- ✨ remove unused input ([d4f791d](https://github.com/melMass/comfy_mtb/commit/d4f791d7a14ba9cb8abd7c95ba70b081fee5fb7c))
- ✨ use the same cwd as manager ([2ff0467](https://github.com/melMass/comfy_mtb/commit/2ff04672daff773d52e1552dca1bf616bc32daa6))
- 🎨 no brace glob ([bbfcb62](https://github.com/melMass/comfy_mtb/commit/bbfcb62c398de39058bcb6e18161425059d53e8e))
- 🎨 extract txt ([a22fd01](https://github.com/melMass/comfy_mtb/commit/a22fd01d664276e4cd833ae1326feeece1d1deaf))
- 🎨 also push wheels_order to releases ([8e5b776](https://github.com/melMass/comfy_mtb/commit/8e5b7765cc0c6730bd5517ccfd56e817ea39bd3a))
- 🚧 more info for bug reports ([3dadc11](https://github.com/melMass/comfy_mtb/commit/3dadc119f44fca1029ec4b349d71ce99fb20a4b6))
- ✨ individual wheels ([346ff64](https://github.com/melMass/comfy_mtb/commit/346ff649d50c9f0286ad2243938406fefb62853b))
### Refactor
- 🚧 tidy ([4f30829](https://github.com/melMass/comfy_mtb/commit/4f30829e06c41b3685644bfe7bece07e0bcfb70e))
- ♻️ get batch from history ([13d255a](https://github.com/melMass/comfy_mtb/commit/13d255a730b08c4903647875350b9b3dcd61b4a6))
### Revert
- 💄 use BOOLEAN instead of BOOL ([cfb3b23](https://github.com/melMass/comfy_mtb/commit/cfb3b237cf64b512414a17f71e6d89c3355aa8ef))
### Testing
- 🧪 remove sha input ([c5bbe83](https://github.com/melMass/comfy_mtb/commit/c5bbe83008bb194cbd6ad5e3dc70cb3850b18985))
- 🧪 ci for comfy embedded ([7b3afca](https://github.com/melMass/comfy_mtb/commit/7b3afca8179760e35e8a6fbf742080dee13e4fc7))
### Merge
- 🔀 pull request #50 from melMass/dev/august-refactor ([2ecd470](https://github.com/melMass/comfy_mtb/commit/2ecd4700d77c0727e6b5d2124e0a6ebd48ec96ed)) in [#50](https://github.com/melMass/comfy_mtb/pull/50)
## [0.1.3] - 2023-07-29
### Bug Fixes
- 🔥 manage pip from install only, remove requirements.txt ([247fbfb](https://github.com/melMass/comfy_mtb/commit/247fbfbc216b8259d607e0699d5b990b6a06ca71)) in [#38](https://github.com/melMass/comfy_mtb/pull/38)
- 🎨 use image ratio for imagefeed ([f5cd56c](https://github.com/melMass/comfy_mtb/commit/f5cd56ce861c8c0a931744ae6cf2b96e9c8bca06))
### Documentation
- 📝 update imagefeed preview ([cbcacbe](https://github.com/melMass/comfy_mtb/commit/cbcacbe3c92ebb5f74d046b83504c3723710f130))
- 📝 fix typo and add more details ([7c020ba](https://github.com/melMass/comfy_mtb/commit/7c020bab288aa7d17dc937b5f102319d43c3ebb3))
### Miscellaneous Tasks
- ✨ use wheel order if present ([9b24edd](https://github.com/melMass/comfy_mtb/commit/9b24eddd9c51004af08d7ac6ff2b6473dd3ee161))
- ✨ store order of install for wheels ([5053142](https://github.com/melMass/comfy_mtb/commit/505314294f02e7c19ac95e4d0ed37fd397a54b46))
## [0.1.2] - 2023-07-28
### Bug Fixes
- ✨ various small things ([0e311cf](https://github.com/melMass/comfy_mtb/commit/0e311cf2c64cf2b4861d4cc612a3409390e3039a))
- 📝 last release ([889f08c](https://github.com/melMass/comfy_mtb/commit/889f08c08b721be8fdb4e4d7eacc47169d5692d6)) in [#36](https://github.com/melMass/comfy_mtb/pull/36)
- 📝 narrow requirements ([5d661b2](https://github.com/melMass/comfy_mtb/commit/5d661b2509fecf3940c3c0fab25b16ec0eae7a2d))
- ✨ Separate FaceAnalysis model loading ([d143e83](https://github.com/melMass/comfy_mtb/commit/d143e83dba3bffa16e1b98d7ad1e9cf92dc94db2))
- ⚡️ update examples to match wiki ([3dfe98c](https://github.com/melMass/comfy_mtb/commit/3dfe98c7957df48723380de85e1242a424ec23de))
### Documentation
- 📝 add readme for web extensions features ([be162a2](https://github.com/melMass/comfy_mtb/commit/be162a20477258627fa0d742c97a478bd085ff4f))
- 📝 link to the proper lang instructions ([232cf89](https://github.com/melMass/comfy_mtb/commit/232cf8966cc20291b60c68f487dfd37bf6aa4dfa)) in [#33](https://github.com/melMass/comfy_mtb/pull/33)
- 📝 update readmes ([96a0618](https://github.com/melMass/comfy_mtb/commit/96a0618c5990a8559a9e2dd17c868d3465b8ca90))
### Miscellaneous Tasks
- 🎉 bump version ([9e751a2](https://github.com/melMass/comfy_mtb/commit/9e751a242f4e9afee3dc5c871c414b29b9706ff6))
- 👷 remove stale example ([c237737](https://github.com/melMass/comfy_mtb/commit/c2377374201fc34b107c8b7db1cdeb2f483d1e18))
- 🐛 fix size ([c0cc557](https://github.com/melMass/comfy_mtb/commit/c0cc5572d8c727568eca8a3d0f116a1f540c31ff))
## [0.1.1] - 2023-07-24
### Bug Fixes
- 🎨 improve a bit the HTML response of endpoints ([50d51c7](https://github.com/melMass/comfy_mtb/commit/50d51c70d04e49e9df524975c171288c0fc0b20f))
- 🐛 caching issues ([55c9736](https://github.com/melMass/comfy_mtb/commit/55c9736a9b2ca036926be4b06406121bfb9ebad2))
- 🔥 remove notice ([abf1e82](https://github.com/melMass/comfy_mtb/commit/abf1e82adb9fac8cd70d5c409baad55309ef6fe1))
- 🔥 use BOOL everywhere ([a393793](https://github.com/melMass/comfy_mtb/commit/a393793cfa93721eac46295723076a1dda940dcd))
### Documentation
- 📝 added lang links ([bbdac97](https://github.com/melMass/comfy_mtb/commit/bbdac97e49af4e90d22eeec3f63b96ecc126ffcf))
- 📝 add comfyforum example ([10d0503](https://github.com/melMass/comfy_mtb/commit/10d05031b1791ab3534cf838be6eb75df638dfb6))
### Features
- 🚧 jupyter seems to require an __init__ there ([9a4eda3](https://github.com/melMass/comfy_mtb/commit/9a4eda3ef573bf382c13515f67ae8a415bf61abd))
- ⚡️ use notify ([a2ecc11](https://github.com/melMass/comfy_mtb/commit/a2ecc11ebde79c2403959bf09c258f3a2465894a))
- ✨ first version of Notify ([7e9c97e](https://github.com/melMass/comfy_mtb/commit/7e9c97ecb48672b25e5ed17b9b35dba9208ac311))
- ⚡️ add an "actions" endpoint ([3de160a](https://github.com/melMass/comfy_mtb/commit/3de160af25b516c02aaa8cc32baec16e9ef358fb))
- ✨ add Unsplash Image node ([8d3cc39](https://github.com/melMass/comfy_mtb/commit/8d3cc39b72dff1b5eb61bf7e2e395753c138ec8a))
- ✨ add back Save Tensors ([7142b28](https://github.com/melMass/comfy_mtb/commit/7142b284adc7fba9a1bdafd1a52621bfc168bde1))
- ✨ add TransformImage node ([11128ff](https://github.com/melMass/comfy_mtb/commit/11128ff85a7e0b4a54f405548969c2478da26df6))
### Miscellaneous Tasks
- 🚀 bump version ([cf86552](https://github.com/melMass/comfy_mtb/commit/cf865529ab64b350cd7af964b41160e7d130d12d))
- 🚀 Remove large files from release ([3b9190a](https://github.com/melMass/comfy_mtb/commit/3b9190a69b002b8933c097fd6655bb4fe07264d2))
### Refactor
- ✨ cleaned up frontend code a bit ([3801a44](https://github.com/melMass/comfy_mtb/commit/3801a443bc1e89c70fdb35ce0b1724d86fa22928))
- ⚡️ remove empty inits ([21729b2](https://github.com/melMass/comfy_mtb/commit/21729b2784a50fcaf24a63ac283bdae475a53ce7))
### Merge
- 🔀 pull request #32 from melMass/dev/next ([8695cd3](https://github.com/melMass/comfy_mtb/commit/8695cd3f1b6d27b5cd6c616ed1215ea2f25c5304)) in [#32](https://github.com/melMass/comfy_mtb/pull/32)
## [0.1.0] - 2023-07-22
### Bug Fixes
- 🔥 properly match built wheels ([119b4d6](https://github.com/melMass/comfy_mtb/commit/119b4d6e16c2a90db1664ccaac748507feb73ea0)) in [#30](https://github.com/melMass/comfy_mtb/pull/30)
- ✨ also try to copy web if symlink fails ([0df55de](https://github.com/melMass/comfy_mtb/commit/0df55def29fb992751010f6b8a707699f230ff37))
- ✨ install process tested in comfy-manager (embed, colab) ([b40730d](https://github.com/melMass/comfy_mtb/commit/b40730ddbc3f8e3e7d5a17e9e9e4526ff37977fd))
- 🚀 try to support remote install too ([3c66de2](https://github.com/melMass/comfy_mtb/commit/3c66de2500a89efd2d2e3af88fc58429af725789))
- 💄 save gif issues ([7335003](https://github.com/melMass/comfy_mtb/commit/7335003346e83666c5dee631b8e6b15586d871e7))
- 🚑️ always use latest for now ([fccf313](https://github.com/melMass/comfy_mtb/commit/fccf31348994ab6e344a1ab00a8f9998309f9319))
- 🐛 install logic ([7e301e2](https://github.com/melMass/comfy_mtb/commit/7e301e2a067d41cba9b8ef357496dd1df94e4cdd))
- 🎉 remove tests & add missing docs ([4e6b877](https://github.com/melMass/comfy_mtb/commit/4e6b87719989aa144946c5c9a43b9398c20bf11e))
- ⚡️ update node_list ([c794d6a](https://github.com/melMass/comfy_mtb/commit/c794d6a071778220d654b526d2edfddcc79752fc))
- 🚑️ set debug level from endpoint ([18402e3](https://github.com/melMass/comfy_mtb/commit/18402e3be1ab47e10109cfd2dff18863a1ee56f7))
- 🐛 add base64 prefix to outputs ([0950f99](https://github.com/melMass/comfy_mtb/commit/0950f9914c9bbed7c89f3de33a967cb76f9d0bbb))
- 🎨 refactor and add Gif preview on node ([c2e8379](https://github.com/melMass/comfy_mtb/commit/c2e83794faeb8da708c98908882e38b2a42827bd))
- ✨ Various widgets issues ([27500ca](https://github.com/melMass/comfy_mtb/commit/27500ca432d686774b991045b7cffc58c0b67faf))
- 🔥 deprecate some nodes and fix image list ([9aa934f](https://github.com/melMass/comfy_mtb/commit/9aa934f70ff6adf91efb26aa8e5cb21ec575196a))
- 🐛 crop nodes ([67d3783](https://github.com/melMass/comfy_mtb/commit/67d3783ac9186da6bba4b7dc7e8dc3d5db5a1b0f))
- 🐛 tensor2pil ([8a59508](https://github.com/melMass/comfy_mtb/commit/8a59508ff91d6b2d9ca287ef1c054ec5755337a4))
- ⚡️ a few missing __doc__ ([ab09cca](https://github.com/melMass/comfy_mtb/commit/ab09ccadd905bebbf1b7b2d992e96e36fc60d68a))
- ⚡️ from tensor2np always returning a list ([6168b3a](https://github.com/melMass/comfy_mtb/commit/6168b3a2ac38b5eebed3daf9e52df5742abf6813))
- 🚑️ TF by default fills vram ([c225da5](https://github.com/melMass/comfy_mtb/commit/c225da5f298acb4cb2b39022382543c0c966d428))
- ✨ leftovers ([da3e6f4](https://github.com/melMass/comfy_mtb/commit/da3e6f47c6073e73cf9d3a3cd23ba5ccbe1fedce))
- ✨ handle non fork gdown in model dll ([95797e8](https://github.com/melMass/comfy_mtb/commit/95797e823e12e62ae8758753f60c34afbe19ec90))
- ✨ properly add the submodules ([00510ed](https://github.com/melMass/comfy_mtb/commit/00510ed0b8583dd64518daa67d963582f4f029d3))
- 📌 remove sad talker for now ([1622cbc](https://github.com/melMass/comfy_mtb/commit/1622cbcb9d51ddd0e1a8b4d87ba47b99327163eb))
- 🎨 narrow requirements ([1a92ef7](https://github.com/melMass/comfy_mtb/commit/1a92ef734dd4271efc875856038f9e3b6b9ded6c))
- 🚀 use the comfy util to handle graph interruption ([9752f3e](https://github.com/melMass/comfy_mtb/commit/9752f3e9dec9aa59cfa809aa14f0151594c03858))
- 🔥 much faster (using GPU) on windows ([2f455aa](https://github.com/melMass/comfy_mtb/commit/2f455aaca55c0a044735c768b295d077b2f5b8d6))
- 🐛 uint8 to uint16 ([be5a655](https://github.com/melMass/comfy_mtb/commit/be5a655cfaba1794f7b09c82d65de42e2b031720))
- ✨ add missing requirements ([b779bc3](https://github.com/melMass/comfy_mtb/commit/b779bc39ac19f779aeb73c98b916671d1d16806f))
- 📝 don't propagate base logs ([7fd99c2](https://github.com/melMass/comfy_mtb/commit/7fd99c25c4e50566def5c5166a9d9059b1febfa6))
- 🐛 bg upscaler in gfpgan ([fee48ad](https://github.com/melMass/comfy_mtb/commit/fee48adff3d66960cb17836f3f4efbfd0c8740c4))
- 📝 separate debug / info better ([e24863d](https://github.com/melMass/comfy_mtb/commit/e24863d1f9f63f367a2b392e6228ffa42927b71b))
- 🔥 change log level of the base logger ([7538c2c](https://github.com/melMass/comfy_mtb/commit/7538c2c4bad8390a32226dc0a5a6ef978b00d201))
- ✨ handle externs dynamicly ([6ef308a](https://github.com/melMass/comfy_mtb/commit/6ef308a87062c91e2d7249c05d96c6fb76e5a6c4))
- 🐛 separate faceswap model load ([8e267c0](https://github.com/melMass/comfy_mtb/commit/8e267c0204ce5abe8e113fd401234d49f377646a))
### Documentation
- 📝 fold each comfy mode ([3c3c438](https://github.com/melMass/comfy_mtb/commit/3c3c4380bd1a3f0eed5216b835e076c26fce2f88))
- 📝 add more description to examples ([46eab5c](https://github.com/melMass/comfy_mtb/commit/46eab5ca2f0e04d872d87c849b11551fd219bdb9))
- 📝 add model notice ([cbe67ed](https://github.com/melMass/comfy_mtb/commit/cbe67edd4befb7260be01fa09af8448e5bcf5680))
- 📝 add preview for examples ([b5176ca](https://github.com/melMass/comfy_mtb/commit/b5176ca0ee489ada52b6632f68b794b4f709d5ba))
- 📝 add jp and cn (using deep translation) ([da559b9](https://github.com/melMass/comfy_mtb/commit/da559b9eaf135a49c0ab9bfa45573baf0c18dfb2))
- 📝 update readme ([b0fb522](https://github.com/melMass/comfy_mtb/commit/b0fb5222cb19e4004533d3367863be5c9ce8e72b)) in [#15](https://github.com/melMass/comfy_mtb/pull/15)
- 📝 update README.md ([f8dc768](https://github.com/melMass/comfy_mtb/commit/f8dc768635a2d21f6ff81b42c418724c432159bf))
- 📝 updated instructions ([c3b9fd4](https://github.com/melMass/comfy_mtb/commit/c3b9fd4afedbb46748aef17b40e167a4cfad65f5))
### Features
- ✨ update install instructions ([7be37db](https://github.com/melMass/comfy_mtb/commit/7be37dbbfac45e8038f94ced8a2fa8ec2b06fb34))
- 🚀 add install script ([dad3966](https://github.com/melMass/comfy_mtb/commit/dad3966ba219c1998e4fc7f6e641864fb0e7c3e8))
- 🚧 add my CLIs ([44eaae5](https://github.com/melMass/comfy_mtb/commit/44eaae5c79f4dbec344053d945e7275be5c3c0a5))
- ✨comfy_widget shared utils ([91bb95d](https://github.com/melMass/comfy_mtb/commit/91bb95da914468de533b040324700c7f9707e4fb))
- 🚀 debug node ([b27b8ef](https://github.com/melMass/comfy_mtb/commit/b27b8ef91fe7335b1df3766547edaf4b9625ae4d))
- ✨ add FitNumber node ([aa551eb](https://github.com/melMass/comfy_mtb/commit/aa551ebe57801c69010815119fe21e19a858780c))
- 🔥 add API endpoints ([95afbdb](https://github.com/melMass/comfy_mtb/commit/95afbdbf76e66897e632252d876384ada9acf153))
- ✨ categorize ([d2b3962](https://github.com/melMass/comfy_mtb/commit/d2b396236a10fe620ebebabd5a22c36159921913))
- 🚀 add a few examples ([b9c1d3d](https://github.com/melMass/comfy_mtb/commit/b9c1d3df7a1460fe9ffa84f6f9ea0cfb5409de1a))
- ✨ added a way to export the node list ([5f5297f](https://github.com/melMass/comfy_mtb/commit/5f5297f80debc77f3fda2f0d37b3acff8419140d))
- ✨ WIP batch from history ([cde7293](https://github.com/melMass/comfy_mtb/commit/cde72938d5ffd09179f5974676e12d4599a8d6ff))
- ✨ extract node names using ast ([38f6147](https://github.com/melMass/comfy_mtb/commit/38f61473bc23b4c5d4efc5048d54c059565a6fa0))
- 🔥 add batch support for load image sequence ([3faadc4](https://github.com/melMass/comfy_mtb/commit/3faadc4b8a5049cb8c264b8a3d50565adec405f1))
- 🎨 add support for image.size(0) == 0 ([629e2b5](https://github.com/melMass/comfy_mtb/commit/629e2b5f5fbebe4e79e8b7a4cff2de6017e79225))
- ✨ image feed ([99eb5ae](https://github.com/melMass/comfy_mtb/commit/99eb5ae0c7413f6ab1f24cfc8337c9b1b2d9824c))
- ✨ FILM interpolation nodes ([e04e77e](https://github.com/melMass/comfy_mtb/commit/e04e77eb097735ec1369dec51238cdcc5abe39b7))
- ✨ add an headless option for model downloads ([217e8a1](https://github.com/melMass/comfy_mtb/commit/217e8a1546d06b97250d99612ac6bdb5ce89e155))
- 🐛 support batch count > 1 for restore face ([8ef48a0](https://github.com/melMass/comfy_mtb/commit/8ef48a013a8d6b832b8c0c7dcabc1b78c27ff207))
- 🚧 wrapper for GFPGAN bg upscaler ([88cdcc6](https://github.com/melMass/comfy_mtb/commit/88cdcc6a87dae452924e8915eccdadc69d7d136e))
- ✨ add GFPGAN (FaceRestore) ([3a6e545](https://github.com/melMass/comfy_mtb/commit/3a6e5450502f3b1d7c505178fc9ba337cd95c39e))
### Miscellaneous Tasks
- ✨ before categorize ([0cc54e5](https://github.com/melMass/comfy_mtb/commit/0cc54e58ec86c28354cae37e14f39e831c13ea02))
- ✨ add more issue templates ([710a638](https://github.com/melMass/comfy_mtb/commit/710a638a8187ef08254478f684307dccdebcded2)) in [#25](https://github.com/melMass/comfy_mtb/pull/25)
- ✨ add bug report template ([f927bc7](https://github.com/melMass/comfy_mtb/commit/f927bc7c9a82951e6df4763433732f20ea87e9cb))
- 🍻 create FUNDING.yml ([f634fe0](https://github.com/melMass/comfy_mtb/commit/f634fe0e6b2db28138e4bd7932fbfc8606a0f033))
- 🍻 add bmc to readme ([cd1b603](https://github.com/melMass/comfy_mtb/commit/cd1b603565464fe98a718e1fbaa8c7cd84057576))
- 📝 extra files from another branch ([b78be8f](https://github.com/melMass/comfy_mtb/commit/b78be8fd3cd36666fd94a3ab08eca11cce526043))
- 🚀 push leftovers ([4c41fe7](https://github.com/melMass/comfy_mtb/commit/4c41fe7af9f8e16d895eb06223349e1294dd4698))
### Refactor
- ♻️ removes a few nodes, moved other around ([4d8ddac](https://github.com/melMass/comfy_mtb/commit/4d8ddaca320ce483640d030618e70730b3453df2))
- ♻️ remove test ([68c250e](https://github.com/melMass/comfy_mtb/commit/68c250e890dacae9f627b0d266ad6dcab0fa0c8b))
- 🚧 remove color_widget ([e480d07](https://github.com/melMass/comfy_mtb/commit/e480d071171cffa789930620f1e7ccc76473bf93))
### Testing
- 🔧 pipe detection ([ee17d57](https://github.com/melMass/comfy_mtb/commit/ee17d57c3d6d71fda1a5acc2cf85f936c525bc87))
### Install
- 🚧 handle symlink errors ([d982b69](https://github.com/melMass/comfy_mtb/commit/d982b69a58c05ccead9c49370764beaa4549992a))
### Merge
- 🔀 pull request #22 from melMass/dev/next-release ([c34de0a](https://github.com/melMass/comfy_mtb/commit/c34de0ab351b2c95d7fa4fab4487155bee6bfa3a)) in [#22](https://github.com/melMass/comfy_mtb/pull/22)
- 🎉 pull request #11 from dev/frame_interpolation ([1e28606](https://github.com/melMass/comfy_mtb/commit/1e28606427bcc8d895b87eaa6cd4147ab6d9a11f)) in [#11](https://github.com/melMass/comfy_mtb/pull/11)
- 🎉 pull request #8 from dev/small-fixes ([7585624](https://github.com/melMass/comfy_mtb/commit/7585624de5895eb34c6a520d4dab18b47e64b6ca)) in [#8](https://github.com/melMass/comfy_mtb/pull/8)
## [0.0.1] - 2023-06-28
### Bug Fixes
- 🤦 add missing file ([e2c4561](https://github.com/melMass/comfy_mtb/commit/e2c456147c260b4e9d583662e3bb9d6d9a019a5e))
- ✨ small edits ([bcf55ca](https://github.com/melMass/comfy_mtb/commit/bcf55ca9a3a07067be3319182501f7b635e5d2ba))
- ⚡️ add support for batch in roop ([2dae020](https://github.com/melMass/comfy_mtb/commit/2dae02056a11ddfe1f84ee040818028177e404b5))
- 🔥 various preparing for the first tag ([793784a](https://github.com/melMass/comfy_mtb/commit/793784a5fd08e8a70d670fc8edbc3bb5b6e13e67))
- 🐛 various bugs ([afd0843](https://github.com/melMass/comfy_mtb/commit/afd08431458e3bbb14a25c84a87408113edf5db5))
- ⚡️ add missing controls to QRCode ([7e86b0e](https://github.com/melMass/comfy_mtb/commit/7e86b0ed4d300021517f6c5cf28a45012497b5c5))
### Documentation
- 📝 add rembg screenshot ([9a2d523](https://github.com/melMass/comfy_mtb/commit/9a2d52325f87ecf6342ef4897da919006755b9db))
- 📝 add a few screenshots ([e162336](https://github.com/melMass/comfy_mtb/commit/e162336cd366d39cd4b96f05b3c9c68eecec3dc4))
- 📝 update readme ([7f3070d](https://github.com/melMass/comfy_mtb/commit/7f3070debbc3330da50ff845621ce299894cf862))
### Features
- 💄 faceswap node using roop ([966a14b](https://github.com/melMass/comfy_mtb/commit/966a14b40d88f4fccfb2eaa5ff9b222f0eedd7cb))
- ✨ sync local changes ([647bf9e](https://github.com/melMass/comfy_mtb/commit/647bf9e94195c279a620c74c2253471b9c4b90f7))
- ✨ bbox from alpha ([37abf8a](https://github.com/melMass/comfy_mtb/commit/37abf8aad12f4711c6d82c6be4be6fa3578e7af5))
- ✨ a111 like style loader ([f59b68e](https://github.com/melMass/comfy_mtb/commit/f59b68e3ad92841a4d189d8dddf7b41e915c9b4e))
- ✨ add a color type and widget ([9a2e986](https://github.com/melMass/comfy_mtb/commit/9a2e986327c34227a707beab6d9929b0a05e41e6))
- ✨ add a few nodes ([811443b](https://github.com/melMass/comfy_mtb/commit/811443b92161815db1cdff81898e8834dcd6fbfa))
- ✨ add SadTalker as a submodule ([3fb8716](https://github.com/melMass/comfy_mtb/commit/3fb871651b12bce62d8e911bd3884f417f80c937))
- 🚨 push local changes ([6cac344](https://github.com/melMass/comfy_mtb/commit/6cac344f6fb15ebb902acee70ee71edc585ec4bc))
- ⚡️ initial commit ([1ae3bbc](https://github.com/melMass/comfy_mtb/commit/1ae3bbc89ae6e0d2e8c61122485bd0df837e17c2))
### Miscellaneous Tasks
- 🚀 add gh action ([572b4d5](https://github.com/melMass/comfy_mtb/commit/572b4d52bce1398660d4d7ca0c5c48c11e0128e3)) in [#4](https://github.com/melMass/comfy_mtb/pull/4)
[main]: https://github.com/melMass/comfy_mtb/compare/v0.2.0..main
[0.2.0]: https://github.com/melMass/comfy_mtb/compare/v0.1.6..v0.2.0
[0.1.6]: https://github.com/melMass/comfy_mtb/compare/v0.1.5..v0.1.6
[0.1.5]: https://github.com/melMass/comfy_mtb/compare/v0.1.4..v0.1.5
[0.1.4]: https://github.com/melMass/comfy_mtb/compare/v0.1.3..v0.1.4
[0.1.3]: https://github.com/melMass/comfy_mtb/compare/v0.1.2..v0.1.3
[0.1.2]: https://github.com/melMass/comfy_mtb/compare/v0.1.1..v0.1.2
[0.1.1]: https://github.com/melMass/comfy_mtb/compare/v0.1.0..v0.1.1
[0.1.0]: https://github.com/melMass/comfy_mtb/compare/v0.0.1..v0.1.0
+52
View File
@@ -0,0 +1,52 @@
# Code of Conduct
## Our Commitment
We are committed to creating a welcoming and inclusive community for everyone. We believe that a diverse and respectful community is essential for fostering creativity and innovation. We expect all members of our community to adhere to this Code of Conduct.
## Our Expectations
This Code of Conduct applies to all interactions within the mtb community, including:
* Public communication channels (e.g., GitHub issues, pull requests, discussions, social media)
* Private communication channels (e.g., direct messages, email)
* In-person events (if any)
We expect all members to:
* **Be respectful and considerate:** Treat others with kindness and empathy.
* **Be inclusive:** Welcome and respect people of all backgrounds, identities, and experiences.
* **Be constructive:** Focus on providing helpful and positive feedback.
* **Be mindful of your language:** Avoid using offensive, discriminatory, or harassing language.
* **Respect privacy:** Do not share personal information without consent.
## Unacceptable Behavior
The following behaviors are not tolerated:
* Offensive, discriminatory, or harassing language or conduct
* Personal attacks or insults
* Spamming or trolling
* Sharing of malicious or inappropriate content
* Disrupting the community or hindering collaboration
* Violating the privacy of others
## Reporting Violations
If you experience or witness a violation of this Code of Conduct, please report it to @melmass. All reports will be treated confidentially and investigated promptly.
## Enforcement
Violations of this Code of Conduct may result in the following actions:
* Warning
* Removal from the community
* Ban from the community
## License
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
## Contact
If you have any questions or concerns about this Code of Conduct, please contact @melmass.
+62
View File
@@ -0,0 +1,62 @@
# Contributing to mtb
Thank you for your interest in contributing to mtb! We appreciate your help in making this project better. This document outlines how you can contribute to the project.
## Project Overview
This project is a collection of custom nodes for ComfyUI, tailored specifically for animation workflows. It aims to provide a streamlined and user-friendly experience for creating animations within the ComfyUI environment.
## Ways to Contribute
We welcome all kinds of contributions! Here's how you can get involved:
* **Bug Reports:** If you encounter any issues, please create a new issue on GitHub. Please include clear steps to reproduce the bug, along with any relevant error messages, workflows or screenshots.
* **Feature Requests:** Have an idea for a new node or feature? Create a new issue to discuss it! Please describe the feature in detail, and explain how it would benefit the project.
* **Documentation Improvements:** Help us improve the documentation by fixing errors, adding examples, or clarifying explanations.
* **Code Contributions:** We welcome contributions to the codebase! Please see the "Development Setup" and "File Structure" sections below for more information.
* **Testing:** Help us ensure the stability and reliability of the project by testing new features and bug fixes.
* **Refactoring:** Help us improve the codebase by refactoring existing code to improve readability, maintainability, and performance.
## Development Setup
```sh
git clone --recursive https://github.com/melmass/comfy_mtb
```
## File Structure
Understanding the project structure is crucial for making effective contributions.
* **`./nodes/*.py`:** This directory contains the definitions for all custom nodes. Nodes are automatically registered when a file defines an array named `__nodes__` containing the node classes. Make sure your node follows the ComfyUI node definition structure.
* **`./web/*.js`:** This directory contains all the frontend JavaScript code for the extension's user interface.
* **`./wiki`:** This directory is a Git submodule that contains the project's Wiki documentation, written in Markdown. Node documentation should be created or updated in the corresponding Markdown files within this submodule. This is then referenced by the UI for in-GUI help
## Coding Style
We use **Ruff** for code formatting to ensure consistency. Please run Ruff on your code before submitting a pull request. No specific configuration is required, so the default Ruff settings will be used.
## Contribution Workflow
1. **Create a Branch:** Create a new branch for your feature or fix. Use a descriptive branch name (e.g., `feature/new-node`, `fix/bug-in-ui`). **Do not fork the main branch directly.**
2. **Make Changes:** Implement your changes in your branch.
3. **Run Tests:** (Add instructions on how to run tests if available.)
4. **Format Code:** Run Ruff on your code to ensure it is properly formatted.
5. **Create a Pull Request:** Submit a pull request to the `main` branch. Please provide a clear and concise description of your changes.
## Code of Conduct
We are committed to creating a welcoming and inclusive community. We expect all contributors to adhere to a respectful and professional code of conduct. (Consider adding a link to a CODE_OF_CONDUCT.md file or a standard code of conduct.)
## Tools and Libraries
* **Python:** The primary programming language for this project.
* **ComfyUI:** The underlying framework for the custom nodes.
## Current Focus
We are currently focused on a major refactor to clean up the project's codebase. Contributions related to this effort are particularly welcome!
## Thank You!
Thank you for considering contributing to mtb! Your contributions are greatly appreciated. We look forward to reviewing your pull requests!
-93
View File
@@ -1,93 +0,0 @@
# 安装
- [安装](#安装)
- [自动安装(推荐)](#自动安装推荐)
- [ComfyUI 管理器](#comfyui-管理器)
- [虚拟环境](#虚拟环境)
- [模型下载](#模型下载)
- [网络扩展](#网络扩展)
- [旧的安装方法 (MANUAL)](#旧的安装方法-manual)
- [依赖关系](#依赖关系)
### 自动安装(推荐)
### ComfyUI 管理器
从 0.1.0 版开始,该扩展将使用 [ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager) 进行安装,这对处理各种环境下的各种安装问题大有帮助。
### 虚拟环境
还有一种试验性的单行安装方法,即在 ComfyUI 根目录下使用以下命令进行安装。它将下载代码、安装依赖项并运行安装脚本:
```bash
curl -sSL "https://raw.githubusercontent.com/username/repo/main/install.py" | python3 -
```
## 模型下载
某些节点需要下载额外的模型,您可以使用与上述相同的 python 环境以交互方式完成下载:
```bash
python scripts/download_models.py
```
然后根据提示或直接按回车键下载每个模型。
> **Note**
> 您可以使用以下方法下载所有型号,无需提示:
```bash
python scripts/download_models.py -y
```
#### 网络扩展
首次运行时,脚本会尝试将 [网络扩展](https://github.com/melMass/comfy_mtb/tree/main/web)链接到你的 "web/extensions "文件夹,[请参阅](https://github.com/melMass/comfy_mtb/blob/d982b69a58c05ccead9c49370764beaa4549992a/__init__.py#L45-L61)。
<img alt="color widget preview" src="https://github.com/melMass/comfy_mtb/assets/7041726/cff7e66a-4cc4-4866-b35b-10af0bb2d110" width=450>
### 旧的安装方法 (MANUAL)
### 依赖关系
<details><summary><h4>Custom Virtualenv(我主要用这个)</h4></summary
1. 确保您处于用于 ComfyUI 的 Python 环境中。
2. 运行以下命令安装所需的依赖项:
```bash
pip install -r comfy_mtb/reqs.txt
```
</details>
<details><summary><h4>Comfy 便携式/单机版(来自 ComfyUI 版本)</h4></summary>
如果您使用 ComfyUI 单机版中的 `python-embeded `,那么当二进制文件没有轮子时,您就无法使用 pip 安装二进制文件的依赖项,在这种情况下,请查看最近的 [发布](https://github.com/melMass/comfy_mtb/releases),那里有一个预编译轮子的 linux 和 windows 捆绑包(只有那些需要从源代码编译的轮子),请查看 [此问题 (#1)](https://github.com/melMass/comfy_mtb/issues/1) 以获取更多信息。
![image](https://github.com/melMass/comfy_mtb/assets/7041726/2934fa14-3725-427c-8b9e-2b4f60ba1b7b)
</details>
<details><summary><h4>Google Colab</h4></summary>
在 **Run ComfyUI with localtunnel (Recommended Way)** 标题之后(代码单元格之前)添加一个新的代码单元格
![preview of where to add it on colab](https://github.com/melMass/comfy_mtb/assets/7041726/35df2ef1-14f9-44cd-aa65-353829188cd7)
```python
# download the nodes
!git clone --recursive https://github.com/melMass/comfy_mtb.git custom_nodes/comfy_mtb
# download all models
!python custom_nodes/comfy_mtb/scripts/download_models.py -y
# install the dependencies
!pip install -r custom_nodes/comfy_mtb/reqs.txt -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html
```
如果运行后 colab 抱怨需要重新启动运行时,请重新启动,然后不要重新运行之前的单元格,只运行运行本地隧道的单元格。(可能需要先添加一个包含 `%cd ComfyUI` 的单元格)
> **Note**:
> If you don't need all models, remove the `-y` as collab actually supports user input: ![image](https://github.com/melMass/comfy_mtb/assets/7041726/40fc3602-f1d4-432a-98fd-ce2240f5ad06)
> **Preview**
> ![image](https://github.com/melMass/comfy_mtb/assets/7041726/b5b2b2d9-f1e8-4c43-b1db-7dfc5e07be86)
</details>
-93
View File
@@ -1,93 +0,0 @@
# インストール
- [インストール](#インストール)
- [自動インストール (推奨)](#自動インストール-推奨)
- [ComfyUI マネージャ](#comfyui-マネージャ)
- [仮想環境](#仮想環境)
- [モデルのダウンロード](#モデルのダウンロード)
- [ウェブ拡張機能](#ウェブ拡張機能)
- [旧インストール方法 (MANUAL)](#旧インストール方法-manual)
- [依存関係](#依存関係)
## 自動インストール (推奨)
### ComfyUI マネージャ
バージョン0.1.0では、この拡張機能は[ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager)と一緒にインストールすることを想定しています。これは、様々な環境で直面する様々なインストール問題を処理するのに非常に役立ちます。
### 仮想環境
また、ComfyUIのルートから以下のコマンドを使用する実験的なワンライナー・インストールもあります。これはコードをダウンロードし、依存関係をインストールし、インストールスクリプトを実行します:
```bash
curl -sSL "https://raw.githubusercontent.com/username/repo/main/install.py" | python3 -
```
## モデルのダウンロード
ノードによっては、追加モデルのダウンロードが必要な場合があるので、上記と同じ python 環境を使って対話的に行うことができる:
```bash
python scripts/download_models.py
```
プロンプトに従うか、Enterを押すだけで全てのモデルをダウンロードできます。
> **Note**
> プロンプトを出さずに全てのモデルをダウンロードするには、以下のようにします:
```bash
python scripts/download_models.py -y
```
### ウェブ拡張機能
初回実行時にスクリプトは[web extensions](https://github.com/melMass/comfy_mtb/tree/main/web)をあなたの快適な `web/extensions` フォルダに[シンボリックリンク](https://github.com/melMass/comfy_mtb/blob/d982b69a58c05ccead9c49370764beaa4549992a/__init__.py#L45-L61)しようとします。万が一失敗した場合は、mtbフォルダを手動で`ComfyUI/web/extensions`にコピーしてください:
<img alt="color widget preview" src="https://github.com/melMass/comfy_mtb/assets/7041726/cff7e66a-4cc4-4866-b35b-10af0bb2d110" width=450>
## 旧インストール方法 (MANUAL)
### 依存関係
<details><summary><h4>カスタム Virtualenv (私は主にこれを使っています)</h4></summary>
1. ComfyUIで使用しているPython環境であることを確認してください。
2. 以下のコマンドを実行して、必要な依存関係をインストールします:
```bash
pip install -r comfy_mtb/reqs.txt
```
</details>
<details><summary><h4>Comfy-portable / standalone (ComfyUI リリースより)</h4></summary>。
もしあなたがComfyUIスタンドアロンから`python-embeded`を使用している場合、バイナリがホイールを持っていない場合、依存関係をpipでインストールすることができません。この場合、最後の[リリース](https://github.com/melMass/comfy_mtb/releases)をチェックしてください。(ソースからのビルドが必要なもののみ)あらかじめビルドされたホイールがあるlinuxとwindows用のバンドルがあります。詳細は[この問題(#1)](https://github.com/melMass/comfy_mtb/issues/1)をチェックしてください。
![image](https://github.com/melMass/comfy_mtb/assets/7041726/2934fa14-3725-427c-8b9e-2b4f60ba1b7b)
</details>
<details><summary><h4>Google Colab</h4></summary>
ComfyUI with localtunnel (Recommended Way)**ヘッダーのすぐ後(コードセルの前)に、新しいコードセルを追加してください。
![colabに追加する場所のプレビュー](https://github.com/melMass/comfy_mtb/assets/7041726/35df2ef1-14f9-44cd-aa65-353829188cd7)
```python
# download the nodes
!git clone --recursive https://github.com/melMass/comfy_mtb.git custom_nodes/comfy_mtb
# download all models
!python custom_nodes/comfy_mtb/scripts/download_models.py -y
# install the dependencies
!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`のセルを追加する必要があるかもしれません...)
> **Note**:
> すべてのモデルが必要でない場合は、`-y`を削除してください : ![image](https://github.com/melMass/comfy_mtb/assets/7041726/40fc3602-f1d4-432a-98fd-ce2240f5ad06)
> **プレビュー**
> ![image](https://github.com/melMass/comfy_mtb/assets/7041726/b5b2b2d9-f1e8-4c43-b1db-7dfc5e07be86)
</details>
+1 -1
View File
@@ -42,7 +42,7 @@ then follow the prompt or just press enter to download every models.
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/reqs.txt
pip install -r comfy_mtb/requirements.txt
```
</details>
-99
View File
@@ -1,99 +0,0 @@
# MTB Nodes
<a href="https://www.buymeacoffee.com/melmass" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 32px !important;width: 140px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
[** 安装指南**](./INSTALL-CN.md) | [** 示例**](https://github.com/melMass/comfy_mtb/wiki/Examples)
欢迎使用 MTB Nodes 项目!这个代码库是开放的,您可以自由地探索和利用。它的主要目的是构建用于 [MLOPs](https://github.com/Bismuth-Consultancy-BV/MLOPs) 中的概念验证(POCs)。该项目中的许多节点都是受到现有社区贡献或内置功能的启发而创建的。
在继续之前,请注意与此项目中使用的某些库相关的许可证。例如,`deepbump` 库采用 [GPLv3](https://github.com/HugoTini/DeepBump/blob/master/LICENSE) 许可证。
- [节点列表](#节点列表)
- [bbox](#bbox)
- [colors](#colors)
- [人脸检测/交换](#人脸检测交换)
- [图像插值(动画)](#图像插值动画)
- [图像操作](#图像操作)
- [潜在变量工具](#潜在变量工具)
- [其他工具](#其他工具)
- [纹理](#纹理)
- [Comfy 资源](#comfy-资源)
# 节点列表
## bbox
- `Bounding Box`: BBox 构造函数(自定义类型)
- `BBox From Mask`: 从遮罩中提取边界框
- `Crop`: 根据边界框裁剪图像
- `Uncrop`: 根据边界框还原图像
## colors
- `Colored Image`: 给定尺寸的纯色图像
- `RGB to HSV`: -
- `HSV to RGB`: -
- `Color Correct`: 基本颜色校正工具
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/7c20ac83-31ff-40ea-a1a0-06c2acefb2ef" width=345/>
## 人脸检测/交换
- `Face Swap`: 使用 deepinsight/insightface 模型进行人脸交换(该节点在早期版本中称为 `Roop`,功能相同,`Roop` 只是使用这些模型的应用程序)
> **注意**
> 人脸索引允许您选择要替换的人脸,如下所示:
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/2e9d6066-c466-4a01-bd6c-315f7f1e8b42" width=320/>
- `Load Face Swap Model`: 加载 insightface 模型用于人脸交换
- `Restore Face`: 使用 [GFPGan](https://github.com/TencentARC/GFPGAN) 还原人脸,与 `Face Swap` 配合使用效果很好,并支持 `bg_upscaler` 的 Comfy 原生放大器
## 图像插值(动画)
- `Load Film Model`: 加载 [FILM](https://github.com/google-research/frame-interpolation) 模型
- `Film Interpolation`: 使用 [FILM](https://github.com/google-research/frame-interpolation) 处理输入帧
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/3afd1647-6634-4b92-a34b-51432e6a9834" width=400/>
- `Export to Prores (experimental)`: 将输入帧导出为 ProRes 4444 mov 文件。这使用 ffmpeg stdin 发送原始的 NumPy 数组,与 `Film Interpolation` 一起使用,目前很简单,但可以进一步扩展。
## 图像操作
- `Blur`: 使用高斯滤波器对图像进行模糊处理。
- `Deglaze Image`: 从 [FN16](https://github.com/Fannovel16/FN16-ComfyUI-nodes/blob/main/DeglazeImage.py) 中提取
- `Denoise`: 对输入图像进行降噪处理
- `Image Compare`: 比较两个图像并返回差异图像
- `Image Premultiply`: 使用掩码对图像进行预乘处理
- `Image Remove Background Rembg`: 使用 [RemBG](https://github.com/danielgatis/rembg) 进行背景去除
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/e69253b4-c03c-45e9-92b5-aa46fb887be8" width=320/>
- `Image Resize Factor`: 大部分提取自 [WAS Node Suite](https://github.com/WASasquatch/was-node-suite-comfyui),经过一些编辑(特别是支持多个图像)和较少的功能。
- `Mask To Image`: 将遮罩(Alpha)转换为带有颜色和背景的 RGB 图像
- `Save Image Grid`: 将输入批次中的所有图像保存为图像网格。
## 潜在变量工具
- `Latent Lerp`: 两个潜在变量之间的线性插值(混合)
## 其他工具
- `Concat Images`: 接受两个图像流,并将它们合并为其他 Comfy 管道支持的图像批次。
- `Image Resize Factor`: **已弃用**,因为我后来发现了内
置的图像调整大小功能。
- `Text To Image`: 使用字体将文本转换为图像的工具
- `Styles Loader`: 加载 csv 文件并从行中填充下拉列表(类似于 A111)
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/02fe3211-18ee-4e54-a029-931388f5fde8" width=320/>
- `Smart Step`: 一个非常基本的节点,用于获取在 KSampler 高级中使用的步骤百分比
- `Qr Code`: 基本的 QR Code 生成器
- `Save Tensors`: 调试节点,将来可能会被删除
- `Int to Number`: 用于 WASSuite 数字节点的补充
- `Smart Step`: 使用百分比来控制 `KAdvancedSampler` 的步骤(开始/停止)
## 纹理
- `DeepBump`: 从单张图片生成法线图和高度图
# Comfy 资源
**指南**:
- [官方示例(英文)](https://comfyanonymous.github.io/ComfyUI_examples/)
- @BlenderNeko 的[ComfyUI 社区手册(英文)](https://blenderneko.github.io/ComfyUI-docs/)
- @tjhayasaka 的[Tomoaki 个人 Wiki(日文)](https://comfyui.creamlab.net/guides/)
**扩展和自定义节点**:
- @WASasquatch 的[Comfy 列表插件(英文)](https://github.com/WASasquatch/comfyui-plugins)
- [CivitAI 上的 ComfyUI 标签(英文)](https://civitai.com/tag/comfyui)
-96
View File
@@ -1,96 +0,0 @@
# MTB Nodes
<a href="https://www.buymeacoffee.com/melmass" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 32px !important;width: 140px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
[**インストールガイド**](./INSTALL-JP.md) | [**サンプル**](https://github.com/melMass/comfy_mtb/wiki/Examples)
MTB Nodesプロジェクトへようこそ!このコードベースは、自由に探索し、利用することができます。主な目的は、[MLOPs](https://github.com/Bismuth-Consultancy-BV/MLOPs)の実装のための概念実証(POC)を構築することです。このプロジェクトの多くのノードは、既存のコミュニティの貢献や組み込みの機能に触発されています。
続行する前に、このプロジェクトで使用されている特定のライブラリに関連するライセンスに注意してください。たとえば、「deepbump」ライブラリは、[GPLv3](https://github.com/HugoTini/DeepBump/blob/master/LICENSE)の下でライセンスされています。
- [ノードリスト](#ノードリスト)
- [bbox](#bbox)
- [colors](#colors)
- [顔検出 / スワッピング](#顔検出--スワッピング)
- [画像補間(アニメーション)](#画像補間アニメーション)
- [画像操作](#画像操作)
- [潜在的なユーティリティ](#潜在的なユーティリティ)
- [その他のユーティリティ](#その他のユーティリティ)
- [テクスチャ](#テクスチャ)
- [Comfyリソース](#comfyリソース)
# ノードリスト
## bbox
- `Bounding Box`: BBoxコンストラクタ(カスタムタイプ)
- `BBox From Mask`: マスクからバウンディングボックスを抽出
- `Crop`: BBoxから画像を切り抜く
- `Uncrop`: BBoxから画像を元に戻す
## colors
- `Colored Image`: 指定されたサイズの一定の色の画像
- `RGB to HSV`: -
- `HSV to RGB`: -
- `Color Correct`: 基本的なカラーコレクションツール
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/7c20ac83-31ff-40ea-a1a0-06c2acefb2ef" width=345/>
## 顔検出 / スワッピング
- `Face Swap`: deepinsight/insightfaceモデルを使用した顔の入れ替え(このノードは初期バージョンでは「Roop」と呼ばれていましたが、同じ機能を提供します。Roopは単にこれらのモデルを使用するアプリです)
> **注意**
> 顔のインデックスを使用して置き換える顔を選択できます。以下を参照してください:
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/2e9d6066-c466-4a01-bd6c-315f7f1e8b42" width=320/>
- `Load Face Swap Model`: 顔の交換のためのinsightfaceモデルを読み込む
- `Restore Face`: [GFPGan](https://github.com/TencentARC/GFPGAN)を使用して顔を復元し、`Face Swap`と組み合わせて使用すると非常に効果的であり、`bg_upscaler`のComfyネイティブアップスケーラーもサポートしています。
## 画像補間(アニメーション)
- `Load Film Model`: [FILM](https://github.com/google-research/frame-interpolation)モデルを読み込む
- `Film Interpolation`: [FILM](https://github.com/google-research/frame-interpolation)を使用して入力フレームを処理する
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/3afd1647-6634-4b92-a34b-51432e6a9834" width=400/>
- `Export to Prores (experimental)`: 入力フレームをProRes 4444 movファイルにエクスポートします。これは現在は単純なものですが、`Film Interpolation`と組み合わせて使用するためのffmpegのstdinを使用して生のNumPy配列を送信するもので、拡張することもできます。
## 画像操作
- `Blur`: ガウスフィルタを使用して画像をぼかす
- `Deglaze Image`: [FN16](https://github.com/Fannovel16/FN16-ComfyUI-nodes/blob/main/DeglazeImage.py)から取得
- `Denoise`: 入力画像のノイズを除去する
- `Image Compare`: 2つの画像を比較し、差分画像を返す
- `Image Premultiply`: 画像をマスクで乗算
- `Image Remove Background Rembg`: [RemBG](https://github.com/danielgatis/rembg)を使用した背景除去
<img src="https://github.com/melMass/comfy_mtb/assets/704172
6/e69253b4-c03c-45e9-92b5-aa46fb887be8" width=320/>
- `Image Resize Factor`: [WAS Node Suite](https://github.com/WASasquatch/was-node-suite-comfyui)から抽出され、いくつかの編集(特に複数の画像のサポート)と機能の削減が行われました。
- `Mask To Image`: マスク(アルファ)をカラーと背景を持つRGBイメージに変換します。
- `Save Image Grid`: 入力バッチのすべての画像を画像グリッドとして保存します。
## 潜在的なユーティリティ
- `Latent Lerp`: 2つの潜在的なベクトルの間の線形補間(ブレンド)
## その他のユーティリティ
- `Concat Images`: 2つの画像ストリームを取り、他のComfyパイプラインでサポートされている画像のバッチとしてマージします。
- `Image Resize Factor`: **非推奨**。組み込みの画像リサイズ機能を発見したため、削除される予定です。
- `Text To Image`: フォントを使用してテキストを画像に変換するためのユーティリティ
- `Styles Loader`: csvファイルをロードし、行からドロップダウンを作成します(A111のようなもの)
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/02fe3211-18ee-4e54-a029-931388f5fde8" width=320/>
- `Smart Step`: KSamplerの高度な使用に使用するステップパーセントを取得する非常に基本的なノード
- `Qr Code`: 基本的なQRコード生成器
- `Save Tensors`: 将来的に削除される可能性のあるデバッグノード
- `Int to Number`: WASSuiteの数値ノードの補完
- `Smart Step`: `KAdvancedSampler`のステップ(開始/停止)を制御するための非常に基本的なツールで、パーセンテージを使用します。
## テクスチャ
- `DeepBump`: 1枚の画像から法線マップと高さマップを生成します。
# Comfyリソース
**ガイド**:
- [公式の例(英語)](https://comfyanonymous.github.io/ComfyUI_examples/)
- @BlenderNekoによる[ComfyUIコミュニティマニュアル(英語)](https://blenderneko.github.io/ComfyUI-docs/)
- @tjhayasakaによる[Tomoakiの個人Wiki(日本語)](https://comfyui.creamlab.net/guides/)
**拡張機能とカスタムノード**:
- @WASasquatchによる[Comfyリスト用のプラグイン(英語)](https://github.com/WASasquatch/comfyui-plugins)
- [CivitAIのComfyUIタグ(英語)](https://civitai.com/tag/comfyui)
+7 -164
View File
@@ -1,174 +1,17 @@
# MTB Nodes
> [!NOTE]
> master/main is outdated for now to keep backward compatibility, the next version is being worked on in
> [`dev/0.6.0`](https://github.com/melMass/comfy_mtb/tree/dev/0.6.0)
[![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)
![home](https://repository-images.githubusercontent.com/649047066/a3eef9a7-20dd-4ef9-b839-884502d4e873)
<!-- omit in toc -->
**Translated Readme (using DeepTranslate, PRs are welcome)**:
![image](https://github.com/melMass/comfy_mtb/assets/7041726/f8429c14-3521-4e28-82a3-863d781976c0)
[日本語による説明](./README-JP.md)
![image](https://github.com/melMass/comfy_mtb/assets/7041726/d5cc1fdd-2820-4a5c-b2d7-482f1c222063)
[中文说明](./README-CN.md)
<a href="https://www.buymeacoffee.com/melmass" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 32px !important;width: 140px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
[**Install Guide**](./INSTALL.md) | [**Examples**](https://github.com/melMass/comfy_mtb/wiki/Examples)
Welcome to the MTB Nodes project! This codebase is open for you to explore and utilize as you wish. Its primary purpose is to build proof-of-concepts (POCs) for implementation in [MLOPs](https://github.com/Bismuth-Consultancy-BV/MLOPs). Many nodes in this project are inspired by existing community contributions or built-in functionalities.
Before proceeding, please be aware of the licenses associated with certain libraries used in this project. For example, the `deepbump` library is licensed under [GPLv3](https://github.com/HugoTini/DeepBump/blob/master/LICENSE).
- [Web Extensions](#web-extensions)
- [Node List](#node-list)
- [Animation](#animation)
- [bbox](#bbox)
- [colors](#colors)
- [image ops](#image-ops)
- [latent utils](#latent-utils)
- [textures](#textures)
- [misc utils](#misc-utils)
- [Optional nodes](#optional-nodes)
- [face detection / swapping](#face-detection--swapping)
- [image interpolation (animation)](#image-interpolation-animation)
- [Comfy Resources](#comfy-resources)
# Web Extensions
mtb add a few widgets like `COLOR`
<img alt="color widget preview" src="https://github.com/melMass/comfy_mtb/assets/7041726/cff7e66a-4cc4-4866-b35b-10af0bb2d110" width=450>
A few nodes have the concept of "dynamic" inputs:
<img alt="dynamic inputs" width=450 src="https://github.com/melMass/comfy_mtb/assets/7041726/10b3976e-b212-4968-91eb-f34c02bb80c3" />
[**Wiki**](https://github.com/melMass/comfy_mtb/wiki) | [**Install Guide**](./INSTALL.md) | [**Examples**](https://github.com/melMass/comfy_mtb/wiki/Examples)
# Node List
## Animation
- `Animation Builder`: Convenient way to manage basic animation maths at the core of many of my workflows (both worflows for the following GIFs are in the [examples](https://github.com/melMass/comfy_mtb/wiki/Examples))
**[Example lerping two conditions (blue car -> yellow car)](https://github.com/melMass/comfy_mtb/blob/main/examples/03-animation_builder-condition-lerp.json)**
<img width=300 src="https://user-images.githubusercontent.com/7041726/260258970-d6d66d96-fb34-40d0-9038-cbabf0714c5d.gif"/>
**[Example using image transforms a feedback for a fake deforum effect](https://github.com/melMass/comfy_mtb/blob/main/examples/04-animation_builder-deforum.json)**
<img width=300 src="https://user-images.githubusercontent.com/7041726/260261504-303a1037-60d3-4b31-a589-b15d549752f6.gif"/>
- `Batch Float`: Generates a batch of float values with interpolation.
- `Batch Shape`: Generates a batch of 2D shapes with optional shading (experimental).
- `Batch Transform`: Transform a batch of images using a batch of keyframes.
<img width=400 src="https://github.com/melMass/comfy_mtb/assets/7041726/3f217de1-79aa-49b0-a66a-35cf29dd8f01"/>
- `Export With Ffmpeg`: Export with FFmpeg, it used to be export to Proress and is still tailored for YUV
- `Fit Number` : Fit the input float using a source and target range, you can also control the interpolation curve from a list of presets (default to linear)
## bbox
- `Bounding Box`: BBox constructor (custom type),
- `BBox From Mask`: From a mask extract the bounding box
- `Crop`: Crop image from BBox
- `Uncrop`: Uncrop image from BBox
## colors
- `Colored Image`: Constant color image of given size
- `RGB to HSV`: -,
- `HSV to RGB`: -,
- `Color Correct`: Basic color correction tools
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/7c20ac83-31ff-40ea-a1a0-06c2acefb2ef" width=400/>
## image ops
- `Blur`: Blur an image using a Gaussian filter.
- `Deglaze Image`: taken from [FN16](https://github.com/Fannovel16/FN16-ComfyUI-nodes/blob/main/DeglazeImage.py),
- `Denoise`: Denoise the input image,
- `Image Compare`: Compare two images and return a difference image
- `Image Premultiply`: Premultiply image with mask
- `Image Remove Background Rembg`: [RemBG](https://github.com/danielgatis/rembg) powered background removal.
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/e69253b4-c03c-45e9-92b5-aa46fb887be8" width=320/>
- `Image Resize Factor`: Extracted mostly from [WAS Node Suite](https://github.com/WASasquatch/was-node-suite-comfyui), with a few edits (most notably multiple image support) and less features.
- `Mask To Image`: Converts a mask (alpha) to an RGB image with a color and background
- `Save Image Grid`: Save all the images in the input batch as a grid of images.
## latent utils
- `Latent Lerp`: Linear interpolation (blend) between two latent
## textures
- `Model Patch Seamless`: Use the [seamless diffusion "hack"](https://gitlab.com/-/snippets/2395088) to patch any model to infere seamless images, check the [examples](https://github.com/melMass/comfy_mtb/wiki/Examples) to see how to use all those textures node together
<img width=500 src="https://user-images.githubusercontent.com/7041726/272970506-9db516b5-45d2-4389-b904-b3a94660f24c.png"/>
- `DeepBump`: Normal & height maps generation from single pictures
<img width=500 src="https://user-images.githubusercontent.com/7041726/272970715-7e4477f6-8e18-4839-9864-83d07d6690a1.png"/>
- `Image Tile Offset`: Mimics an old photoshop technique to check for seamless textures by offsetting tiles of the image.
<img width=600 src="https://github.com/melMass/comfy_mtb/assets/7041726/cbcc51fb-922f-433f-acf1-c6c6c2a7ffc4" />
## misc utils
- `Any To String`: Tries to take any input and convert it to a string.
- `Concat Images`: Takes two image stream and merge them as a batch of images supported by other Comfy pipelines.
- `Image Resize Factor`: **Deprecated**, I since discovered the builtin image resize.
- `Text To Image`: Utils to convert text to image using a font
- `Styles Loader`: Load csv files and populate a dropdown from the rows (à la A111)
<img src="https://github.com/melMass/comfy_mtb/assets/7041726/02fe3211-18ee-4e54-a029-931388f5fde8" width=320/>
- `Smart Step`: A very basic node to get step percent to use in KSampler advanced,
- `Qr Code`: Basic QR Code generator
- `Save Tensors`: Debug node that will probably be removed in the future
- `Int to Number`: Supplement for WASSuite number nodes
- `Smart Step`: A very basic tool to control the steps (start/stop) of the `KAdvancedSampler` using percentage
- `Load Image From Url`: Load an image from the given URL
## Optional nodes
These nodes are still bundled in mtb, but moving forward (>0.2.0) they won't
be setup by the install script and their dependencies won't install either.
The reason is mostly that they all have a better alternatives available and tensorflow on windows was not a fun experience and since Python 3.11 not an experience at all.
For linux and mac users though these nodes didn't cause any issue and I personally still use them, these are the extra requirements needed:
```console
.venv/python -m pip install tensorflow facexlib insightface basicsr
```
### face detection / swapping
> **Warning**
> Those nodes were among the first to be implemented they do work, but on windows the installation is still not properly handled for everyone
> As alternatives you can use [reactor](https://github.com/Gourieff/comfyui-reactor-node) for face swap and [facerestore](https://github.com/Haidra-Org/hordelib/tree/main/hordelib/nodes/facerestore) for restoration
> You can check [this video](https://www.youtube.com/watch?v=FShlpMxbU0E) for a tutorial by Ferniclestix using these alternatives
- `Face Swap`: Face swap using deepinsight/insightface models (this node used to be called `Roop` in early versions, it does the same, roop is *just* an app that uses those model)
<img width=320 src="https://user-images.githubusercontent.com/7041726/260261217-54e33446-183f-4dda-88b3-d38a1e6de980.gif"/>
- `Load Face Swap Model`: Load an insightface model for face swapping
- `Restore Face`: Using [GFPGan](https://github.com/TencentARC/GFPGAN) to restore faces, works great in conjunction with `Face Swap` and supports Comfy native upscalers for the `bg_upscaler`
### image interpolation (animation)
> **Warning**
> The FILM nodes will be deprecated at some point after 0.2.0, [Fannovel16](https://github.com/Fannovel16/ComfyUI-Frame-Interpolation)'s interpolation nodes implement it and they rely on a pytorch implementation of FILM
> which solves the issues related to the ones included in mtb. They will probably remain available if your system meet the requirements and ignored otherwise.
<details><summary>Why?</summary>
> **Windows only issue**: This requires tensorflow-gpu that is unfortunately not a thing anymore on Windows since 2.10.1 (unless you use a complex WSL passthrough setup but it's still not "Windows")
> Using this old version is quite clunky and require some patching that install.py does automatically, but the main issue is that no wheels are available for python > 3.10
> Comfy-nightly is already using Python 11 so installing this old tf version won't work there.
> You can in any case install the normal up to date tensorflow but that will run on CPU and is much MUCH slower for FILM inference.
</details>
- `Load Film Model`: Loads a [FILM](https://github.com/google-research/frame-interpolation) model
- `Film Interpolation`: Process input frames using [FILM](https://github.com/google-research/frame-interpolation)
<img width=400 src="https://github.com/melMass/comfy_mtb/assets/7041726/3afd1647-6634-4b92-a34b-51432e6a9834"/>
<img width=400 src="https://user-images.githubusercontent.com/7041726/260259079-c0f04a63-960c-43a7-ba78-a45cd5ac7514.gif"/>
- `Export to Prores (experimental)`: Exports the input frames to a ProRes 4444 mov file. This is using ffmpeg stdin to send raw numpy arrays, used with `Film Interpolation` and very simple for now but could be expanded upon.
# Comfy Resources
**Misc**
- [Slick ComfyUI by NoCrypt](https://colab.research.google.com/drive/1ZMvLWEiYITmBJngtqeIQToeNuiydwI0z#scrollTo=1fWMaexXS188): A colab notebook with batteries included!
**Guides**:
- [Official Examples (eng)](https://comfyanonymous.github.io/ComfyUI_examples/)
- [ComfyUI Community Manual (eng)](https://blenderneko.github.io/ComfyUI-docs/) by @BlenderNeko
- [Tomoaki's personal Wiki (jap)](https://comfyui.creamlab.net/guides/) by @tjhayasaka
**Extensions and Custom Nodes**:
- [Plugins for Comfy List (eng)](https://github.com/WASasquatch/comfyui-plugins) by @WASasquatch
- [ComfyUI tag on CivitAI (eng)](https://civitai.com/tag/comfyui)
+348 -82
View File
@@ -1,52 +1,64 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
###
# File: __init__.py
# Project: comfy_mtb
# Author: Mel Massadian
# Copyright (c) 2023 Mel Massadian
# Copyright (c) 2023-2025 Mel Massadian
#
###
__version__ = "0.5.4"
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"
from aiohttp.web_request import Request
# TODO: don't override this if the user has that setup already
if not os.environ.get("TF_FORCE_GPU_ALLOW_GROWTH"):
os.environ["TF_FORCE_GPU_ALLOW_GROWTH"] = "true"
if not os.environ.get("TF_GPU_ALLOCATOR"):
os.environ["TF_GPU_ALLOCATOR"] = "cuda_malloc_async"
import ast
import contextlib
import importlib
import json
import logging
import os
import shutil
import traceback
from importlib import reload
from pathlib import Path
from aiohttp import web
from server import PromptServer
import nodes
IN_COMFY = False
PromptServer = None
try:
from server import PromptServer
IN_COMFY = True
except ModuleNotFoundError:
IN_COMFY = False
from .endpoint import endlog
from .install import get_node_dependencies
from .log import blue_text, cyan_text, get_label, get_summary, log
from .utils import comfy_dir, here
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
NODE_CLASS_MAPPINGS_DEBUG = {}
NODE_CLASS_MAPPINGS: dict[str, type] = {}
NODE_DISPLAY_NAME_MAPPINGS: dict[str, str] = {}
NODE_CLASS_MAPPINGS_DEBUG: dict[str, str | None] = {}
WEB_DIRECTORY = "./web"
__version__ = "0.2.0"
def extract_nodes_from_source(filename):
def extract_nodes_from_source(filename: Path):
source_code = ""
with open(filename, "r", encoding="utf8") as file:
source_code = file.read()
nodes = []
source_code = filename.read_text(encoding="utf-8")
nodes: list[str] = []
try:
parsed = ast.parse(source_code)
@@ -55,23 +67,24 @@ def extract_nodes_from_source(filename):
target = node.targets[0]
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, ast.Tuple)):
nodes.extend(
element.id
for element in node_value.elts
if isinstance(element, ast.Name)
)
break
if value:
node_value = ast.parse(value).body[0].value
if isinstance(node_value, ast.List | ast.Tuple):
nodes.extend(
str(element.id)
for element in node_value.elts
if isinstance(element, ast.Name)
)
break
except SyntaxError:
log.error("Failed to parse")
log.error(f"Failed to parse ast from: {filename}")
return nodes
def load_nodes():
errors = []
nodes = []
nodes_failed = []
errors: list[str] = []
nodes: list[type] = []
nodes_failed: list[str] = []
for filename in (here / "nodes").iterdir():
if filename.suffix == ".py":
@@ -81,14 +94,16 @@ def load_nodes():
module = importlib.import_module(
f".nodes.{module_name}", package=__package__
)
_nodes = getattr(module, "__nodes__")
_nodes = getattr(module, "__nodes__", [])
nodes.extend(_nodes)
log.debug(f"Imported {module_name} nodes")
except AttributeError:
log.debug(f"Skipping wip module {module_name}")
pass # wip nodes
except Exception:
error_message = traceback.format_exc().splitlines()[-1]
errors.append(
f"Failed to import module {module_name} because {error_message}"
)
@@ -97,7 +112,7 @@ def load_nodes():
if errors:
log.debug(
f"Some nodes failed to load:\n\t"
"Some nodes failed to load:\n\t"
+ "\n\t".join(errors)
+ "\n\n"
+ "Check that you properly installed the dependencies.\n"
@@ -108,35 +123,94 @@ def load_nodes():
# - REGISTER WEB EXTENSIONS
web_extensions_root = comfy_dir / "web" / "extensions"
web_mtb = web_extensions_root / "mtb"
def uninstall_old_web_extensions():
web_extensions_root = comfy_dir / "web" / "extensions"
web_mtb = web_extensions_root / "mtb"
if web_mtb.exists() and hasattr(nodes, "EXTENSION_WEB_DIRS"):
try:
if web_mtb.is_symlink():
web_mtb.unlink()
else:
shutil.rmtree(web_mtb)
except Exception as e:
log.warning(
f"Failed to remove web mtb directory: {e}\nPlease manually remove it from disk ({web_mtb}) and restart the server."
)
if web_mtb.exists() and hasattr(nodes, "EXTENSION_WEB_DIRS"):
try:
if web_mtb.is_symlink():
web_mtb.unlink()
else:
shutil.rmtree(web_mtb)
except Exception as e:
log.warning(
f"""Failed to remove web mtb directory: {e}
Please manually remove it from disk ({web_mtb}) and restart the server."""
)
# uninstall_old_web_extensions()
# - GATHER WIKI PAGES
def wiki_to_classname(s: str):
wiki_name = s.replace("nodes-", "", 1)
return "MTB_" + "".join(
[part.capitalize() for part in wiki_name.split("-")]
)
def classname_to_wiki(s: str):
classname = s.replace("MTB_", "")
parts: list[str] = []
start = 0
for i in range(1, len(classname)):
if classname[i].isupper():
parts.append(classname[start:i].lower())
start = i
parts.append(classname[start:].lower())
return "nodes-" + "-".join(parts)
wiki = here / "wiki"
node_docs = {}
if wiki.exists() and wiki.is_dir():
node_docs = {
wiki_to_classname(x.stem): x.read_text(encoding="utf-8")
for x in (wiki / "nodes").glob("*.md")
}
# - REGISTER NODES
MTB_EXPORT = os.environ.get("MTB_EXPORT")
nodes, failed = load_nodes()
for node_class in nodes:
class_name = node_class.__name__
class_name: str = node_class.__name__
linked_doc = node_docs.get(class_name)
if not hasattr(node_class, "DESCRIPTION"):
if linked_doc:
log.debug(f"Found linked doc for {class_name}, using it")
node_class.DESCRIPTION = linked_doc
elif node_class.__doc__:
log.debug(f"Using __doc__ as description for {class_name}")
node_class.DESCRIPTION = node_class.__doc__
if MTB_EXPORT:
wiki_name = classname_to_wiki(class_name)
_ = (wiki / "nodes" / (wiki_name + ".md")).write_text(
node_class.__doc__, encoding="utf-8"
)
else:
log.debug(
f"None of the methods could retrieve documentation for {class_name}"
)
node_label = f"{get_label(class_name)} (mtb)"
NODE_CLASS_MAPPINGS[node_label] = node_class
NODE_DISPLAY_NAME_MAPPINGS[class_name] = node_label
NODE_CLASS_MAPPINGS_DEBUG[node_label] = node_class.__doc__
# TODO: I removed this, I find it more convenient to write without spaces, but it breaks every of my workflows
# TODO (cont): and until I find a way to automate the conversion, I'll leave it like this
# TODO: I removed this, I find it more convenient to write without spaces
# but it breaks every of my workflows
# TODO (cont): and until I find a way to automate the conversion
# I'll leave it like this
if os.environ.get("MTB_EXPORT"):
with open(here / "node_list.json", "w") as f:
f.write(
_ = f.write(
json.dumps(
{
k: NODE_CLASS_MAPPINGS_DEBUG[k]
@@ -147,41 +221,68 @@ for node_class in nodes:
)
log.debug(
f"Loaded the following nodes:\n\t"
"Loaded the following nodes:\n\t"
+ "\n\t".join(
f"{cyan_text(k)}: {blue_text(get_summary(doc)) if doc else '-'}"
for k, doc in NODE_CLASS_MAPPINGS_DEBUG.items()
)
)
log.info(f"loaded {cyan_text(len(nodes))} nodes successfuly")
log.info(f"loaded {cyan_text(str(len(nodes)))} nodes successfuly")
if failed:
with contextlib.suppress(Exception):
base_url, port = utils.get_server_info()
log.info(
f"Some nodes ({len(failed)}) could not be loaded. This can be ignored, but go to http://{base_url}:{port}/mtb if you want more information."
)
log.debug(failed)
# - ENDPOINT
if hasattr(PromptServer, "instance"):
restore_deps = ["basicsr"]
onnx_deps = ["onnxruntime"]
swap_deps = ["insightface"] + onnx_deps
node_dependency_mapping = {
"QrCode": ["qrcode"],
"DeepBump": onnx_deps,
"FaceSwap": swap_deps,
"LoadFaceSwapModel": swap_deps,
"LoadFaceAnalysisModel": restore_deps,
}
# TODO: move that away and simplify existing endpoints
def register_routes():
if not PromptServer:
log.error("No prompt server, are you inside comfy?")
if PromptServer.instance.app.frozen:
log.warning(
"The router is frozen and cannot be further edited."
"If you are hot reloading mtb this is expected."
)
return
img_cache = None
prompt_cache = None
import asyncio
import os
from io import BytesIO
from PIL import Image
with contextlib.suppress(ImportError):
from cachetools import TTLCache
img_cache = TTLCache(maxsize=100, ttl=5) # 1 min TTL
prompt_cache = TTLCache(maxsize=100, ttl=5) # 1 min TTL
node_dependency_mapping = get_node_dependencies()
PromptServer.instance.app.router.add_static(
"/mtb-assets/", path=(here / "html").as_posix()
)
# NOTE: we add an extra static path to avoid comfy mechanism
# that loads every script in web.
PromptServer.instance.app.add_routes(
[web.static("/mtb_async", (here / "web_async").as_posix())]
)
@PromptServer.instance.routes.get("/mtb/manage")
async def manage(request):
from . import endpoint
@@ -239,10 +340,10 @@ if hasattr(PromptServer, "instance"):
}
)
@PromptServer.instance.routes.post("/mtb/debug")
async def set_debug(request):
json_data = await request.json()
enabled = json_data.get("enabled")
@PromptServer.instance.routes.post("/mtb/server-info")
async def set_server_info(request: Request):
json_data: dict[str, bool] = await request.json()
enabled = json_data.get("debug")
if enabled:
os.environ["MTB_DEBUG"] = "true"
log.setLevel(logging.DEBUG)
@@ -250,7 +351,7 @@ if hasattr(PromptServer, "instance"):
elif "MTB_DEBUG" in os.environ:
# del os.environ["MTB_DEBUG"]
os.environ.pop("MTB_DEBUG")
_ = os.environ.pop("MTB_DEBUG")
log.setLevel(logging.INFO)
return web.json_response(
@@ -258,19 +359,19 @@ if hasattr(PromptServer, "instance"):
)
@PromptServer.instance.routes.get("/mtb")
async def get_home(request):
async def get_home(request: Request):
from . import endpoint
reload(endpoint)
_ = reload(endpoint)
# Check if the request prefers HTML content
if "text/html" in request.headers.get("Accept", ""):
# # Return an HTML page
html_response = """
<div class="flex-container menu">
<a href="/mtb/manage">manage</a>
<a href="/mtb/debug">debug</a>
<a href="/mtb/server-info">Server Info</a>
<a href="/mtb/status">status</a>
</div>
</div>
"""
return web.Response(
text=endpoint.render_base_template("MTB", html_response),
@@ -280,28 +381,189 @@ if hasattr(PromptServer, "instance"):
# Return JSON for other requests
return web.json_response({"message": "Welcome to MTB!"})
@PromptServer.instance.routes.get("/mtb/debug")
async def get_debug(request):
def get_cached_image(file_path: str, preview_params=None, channel=None):
cache_key = (file_path, preview_params, channel)
if img_cache and (cache_key in img_cache):
return img_cache[cache_key]
with Image.open(file_path) as img:
info = img.info
if preview_params:
img = process_preview(img, preview_params)
if channel:
img = process_channel(img, channel)
if prompt_cache:
prompt_cache[cache_key] = info
if img_cache:
img_cache[cache_key] = img.getvalue()
return img_cache[cache_key]
return img.getvalue()
def process_preview(img: Image.Image, preview_params):
image_format, quality, width = preview_params
quality = int(quality)
if width:
width = int(width)
img.thumbnail((width, int(width * img.height / img.width)))
buffer = BytesIO()
img.save(
buffer, format=image_format, quality=quality, metadata=img.info
)
buffer.seek(0)
return buffer
def process_channel(img: Image.Image, channel: str):
if channel == "rgb":
if img.mode == "RGBA":
r, g, b, _ = img.split()
img = Image.merge("RGB", (r, g, b))
else:
img = img.convert("RGB")
elif channel == "a":
if img.mode == "RGBA":
_, _, _, a = img.split()
else:
a = Image.new("L", img.size, 255)
img = Image.new("RGBA", img.size)
img.putalpha(a)
buffer = BytesIO()
img.save(buffer, format="PNG")
_ = buffer.seek(0)
return buffer
async def get_image_response(
file, filename: str, preview_info=None, channel=None
):
img = await asyncio.to_thread(
get_cached_image, file, preview_info, channel
)
return web.Response(
body=img,
content_type="image/webp" if preview_info else "image/png",
headers={"Content-Disposition": f'filename="{filename}"'},
)
# TODO: Embed the metadatas somehow so we can drag and drop
# to load workflows in the sidebar
@PromptServer.instance.routes.get("/mtb/view")
async def view_image(request: Request):
import folder_paths
filename = request.rel_url.query.get("filename")
if not filename:
return web.Response(status=404)
filename, output_dir = folder_paths.annotated_filepath(filename)
if filename[0] == "/" or ".." in filename:
return web.Response(status=400)
if output_dir is None:
rtype = request.rel_url.query.get("type", "output")
output_dir = folder_paths.get_directory_by_type(rtype)
if output_dir is None:
return web.Response(status=400)
if "subfolder" in request.rel_url.query:
full_output_dir = os.path.join(
output_dir, request.rel_url.query["subfolder"]
)
if (
os.path.commonpath(
(os.path.abspath(full_output_dir), output_dir)
)
!= output_dir
):
return web.Response(status=403)
output_dir = full_output_dir
filename = os.path.basename(filename)
file = os.path.join(output_dir, filename)
if not os.path.isfile(file):
return web.Response(status=404)
ret_workflow = request.rel_url.query.get("workflow")
if ret_workflow:
image = Image.open(file)
prompt = image.info.get("prompt", "")
workflow = image.info.get("workflow", "")
if workflow:
workflow = json.loads(workflow)
if prompt:
prompt = json.loads(prompt)
return web.json_response(
{
"prompt": prompt,
"workflow": workflow,
}
)
preview_info = None
if "preview" in request.rel_url.query:
preview_params = request.rel_url.query["preview"].split(";")
image_format = (
preview_params[0]
if preview_params[0] in ["webp", "jpeg"]
else "webp"
)
quality = (
int(preview_params[1])
if len(preview_params) > 1 and preview_params[1].isdigit()
else 90
)
width = request.rel_url.query.get("width")
preview_info = (image_format, quality, width)
channel = request.rel_url.query.get("channel")
return await get_image_response(file, filename, preview_info, channel)
@PromptServer.instance.routes.get("/mtb/server-info")
async def get_debug(request: Request):
from . import endpoint
reload(endpoint)
enabled = "MTB_DEBUG" in os.environ
_ = reload(endpoint)
isdebug = "MTB_DEBUG" in os.environ
exposed = "MTB_EXPOSE" in os.environ
def render_property(name: str, val: str):
return f"""<strong>{name}:</strong>
<p>
{val}
</p>"""
# Check if the request prefers HTML content
if "text/html" in request.headers.get("Accept", ""):
# # Return an HTML page
html_response = f"""
<h1>MTB Debug Status: {'Enabled' if enabled else 'Disabled'}</h1>
"""
html_response = ""
html_response += render_property(
"Debug", "Enabled" if isdebug else "Disabled"
)
html_response += render_property("Exposed", str(exposed))
return web.Response(
text=endpoint.render_base_template("Debug", html_response),
text=endpoint.render_base_template(
"Server Info", html_response
),
content_type="text/html",
)
# Return JSON for other requests
return web.json_response({"enabled": enabled})
return web.json_response({"exposed": exposed, "debug": isdebug})
@PromptServer.instance.routes.get("/mtb/actions")
async def no_route(request):
async def no_route(request: Request):
from . import endpoint
if "text/html" in request.headers.get("Accept", ""):
@@ -315,7 +577,7 @@ if hasattr(PromptServer, "instance"):
return web.json_response({"message": "actions has no get for now"})
@PromptServer.instance.routes.post("/mtb/actions")
async def do_action(request):
async def do_action(request: Request):
from . import endpoint
reload(endpoint)
@@ -323,6 +585,10 @@ if hasattr(PromptServer, "instance"):
return await endpoint.do_action(request)
if IN_COMFY and hasattr(PromptServer, "instance"):
register_routes()
# - WAS Dictionary
MANIFEST = {
"name": "MTB Nodes", # The title that will be displayed on Node Class menu,. and Node Class view
+38
View File
@@ -0,0 +1,38 @@
{
"$schema": "https://biomejs.dev/schemas/2.0.5/schema.json",
"assist": { "actions": { "source": { "organizeImports": "on" } } },
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noConsole": { "level": "warn", "options": { "allow": ["log"] } }
},
"style": {
"noParameterAssign": "off",
"noShoutyConstants": "warn",
"useNamingConvention": "off",
"useAsConstAssertion": "error",
"useDefaultParameterLast": "error",
"useEnumInitializers": "error",
"useSelfClosingElements": "error",
"useSingleVarDeclarator": "error",
"noUnusedTemplateLiteral": "error",
"useNumberNamespace": "error",
"noInferrableTypes": "error",
"noUselessElse": "error"
}
}
},
"formatter": {
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf"
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"semicolons": "asNeeded"
}
}
}
+83
View File
@@ -0,0 +1,83 @@
[changelog]
header = """
# Changelog\n
This is an automated changelog based on the commits in this repository.
Check the notes in the [releases](https://github.com/melMass/comfy_mtb/releases) for more information.
"""
# https://keats.github.io/tera/docs/#introduction
body = """
{% if version -%}\
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}\
## [Unreleased]
{% endif -%}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first | trim }} ([{{ commit.id | truncate(length=7, end="") }}](<REPO>/commit/{{ commit.id }}))\
{% if commit.github.username and commit.github.username != remote.github.owner %} by [@{{ commit.github.username }}](https://github.com/{{ commit.github.username }}){%- endif -%}
{% if commit.github.pr_number %} in [#{{ commit.github.pr_number }}](<REPO>/pull/{{ commit.github.pr_number }}){%- endif -%}
{% endfor %}
{% endfor %}
{%- if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
## New Contributors
{%- endif -%}
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
* [@{{ contributor.username }}](https://github.com/{{ contributor.username }}) made their first contribution in [#{{ contributor.pr_number }}](<REPO>/pull/{{ contributor.pr_number }})\
{%- endfor %}\n
"""
footer = """
{% for release in releases -%}
{% if release.version -%}
{% if release.previous.version -%}
[{{ release.version | trim_start_matches(pat="v") }}]: \
<REPO>/compare/{{ release.previous.version }}..{{ release.version }}
{% endif -%}
{% else -%}
[unreleased]: <REPO>/compare/{{ release.previous.version }}..HEAD
{% endif -%}
{% endfor %}
"""
trim = true
postprocessors = [
{ pattern = '<REPO>', replace = "https://github.com/melMass/comfy_mtb" }, # replace repository URL
]
[git]
# https://www.conventionalcommits.org
conventional_commits = true
filter_unconventional = true
split_commits = false
commit_preprocessors = [
# { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))" }, # replace issue numbers
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" },
]
commit_parsers = [
{ message = "^feat", group = "Features" },
{ message = "^fix", group = "Bug Fixes" },
{ message = "^doc", group = "Documentation" },
{ message = "^perf", group = "Performance" },
{ message = "^refactor", group = "Refactor" },
{ message = "^style", group = "Styling" },
{ message = "^test", group = "Testing" },
{ message = "^chore\\(release\\): prepare for", skip = true },
{ message = "^chore\\(deps\\)", skip = true },
{ message = "^chore\\(pr\\)", skip = true },
{ message = "^chore\\(pull\\)", skip = true },
{ message = "^chore|ci", group = "Miscellaneous Tasks" },
{ body = ".*security", group = "Security" },
{ message = "^revert", group = "Revert" },
]
protect_breaking_commits = false
filter_commits = false
tag_pattern = "v[0-9].*"
topo_order = false
sort_commits = "newest"
[remote.github]
owner = "melMass"
repo = "comfy_mtb"
View File
+192 -35
View File
@@ -1,28 +1,50 @@
import csv
import secrets
import sys
import urllib.parse
from pathlib import Path
from typing import Any, Literal
import folder_paths
from aiohttp import web
from .install import get_node_dependencies
from .log import mklog
from .utils import backup_file, here, import_install, reqs_map, run_command, styles_dir
from .utils import (
SortMode,
backup_file,
build_glob_patterns,
glob_multiple,
reqs_map,
run_command,
styles_dir,
)
endlog = mklog("mtb endpoint")
# - ACTIONS
import platform
import sys
from pathlib import Path
import_install("requirements")
def ACTIONS_installDependency(dependency_names=None):
def ACTIONS_installDependency(dependency_names: list[str] | None = None):
if dependency_names is None:
# return web.Response(text="No dependency name provided", status=400)
return {"error": "No dependency name provided"}
endlog.debug(f"Received Install Dependency request for {dependency_names}")
# reqs = []
resolved_names = [reqs_map.get(name, name) for name in dependency_names]
allowed_deps = list(
{d for dep in get_node_dependencies().values() for d in dep}
)
for dep in dependency_names:
if dep not in allowed_deps:
return {
"error": f"Unknown dependency: {dep}, you can only use this endpoint to install {allowed_deps}"
}
try:
run_command([Path(sys.executable), "-m", "pip", "install"] + resolved_names)
run_command(
[Path(sys.executable), "-m", "pip", "install"] + resolved_names
)
return {"success": True}
except Exception as e:
@@ -43,10 +65,115 @@ def ACTIONS_installDependency(dependency_names=None):
# break
def ACTIONS_getStyles(style_name=None):
from .nodes.conditions import StylesLoader
def ACTIONS_getUserImageFolders():
input_dir = Path(folder_paths.get_input_directory())
output_dir = Path(folder_paths.get_output_directory())
styles = StylesLoader.options
input_subdirs = [x.name for x in input_dir.iterdir() if x.is_dir()]
output_subdirs = [x.name for x in output_dir.iterdir() if x.is_dir()]
return {"input": input_subdirs, "output": output_subdirs}
def ACTIONS_getUserVideos(
size=256, count=200, offset=0, sort: str | None = None
):
count = count or 1000
video_extensions = ["webm", "mp4", "mkv", "mov"]
entries = {}
patterns = build_glob_patterns(video_extensions)
input_dir = Path(folder_paths.get_input_directory())
entries = glob_multiple(input_dir, patterns)
sort_mode = SortMode.from_str(sort)
if sort_mode:
sort_key = {
SortMode.MODIFIED: lambda x: x.stat().st_mtime,
SortMode.MODIFIED_REVERSE: lambda x: x.stat().st_mtime,
SortMode.NAME: lambda x: x.name,
SortMode.NAME_REVERSE: lambda x: x.name,
}.get(sort_mode)
if sort_key:
reverse = sort_mode in (SortMode.MODIFIED, SortMode.NAME_REVERSE)
entries = sorted(entries, key=sort_key, reverse=reverse)
videos = {
video.name: (
f"/view?force_rate=0&frame_load_cap=0&skip_first_frames=0&select_every_nth=1&filename={urllib.parse.quote_plus(video.name)}&type=input&format=video&force_size={size}x?"
)
for i, video in enumerate(entries)
if offset <= i < offset + count
}
return videos
def ACTIONS_getUserImages(
mode: Literal["input", "output"],
target_width: int | str | None = None,
count=1000,
offset=0,
sort: str | None = None,
include_subfolders: bool = False,
subfolder: str | None = None,
# IIRC I copied this from Comfy base
# just keeping it until I properly checked implications
salt_urls=False,
):
# enabled = "MTB_EXPOSE" in os.environ
# if not enabled:
# return {"error": "Session not authorized to getInputs"}
imgs = {}
count = count or 1000
target_width = int(target_width) if target_width else None
input_dir = Path(folder_paths.get_input_directory())
output_dir = Path(folder_paths.get_output_directory())
entry_dir: Path = input_dir if mode == "input" else output_dir
if subfolder:
entry_dir = entry_dir / subfolder
if not entry_dir.exists():
return {
"error": f"Subfolder {entry_dir.name} doesn't exists in {entry_dir.parent.as_posix()}"
}
supported = ["png", "jpg", "jpeg", "webp", "gif"]
entries = {}
patterns = build_glob_patterns(supported, recursive=include_subfolders)
entries = glob_multiple(entry_dir, patterns)
sort_mode = SortMode.from_str(sort)
if sort_mode:
sort_key = {
SortMode.MODIFIED: lambda x: x.stat().st_mtime,
SortMode.MODIFIED_REVERSE: lambda x: x.stat().st_mtime,
SortMode.NAME: lambda x: x.name,
SortMode.NAME_REVERSE: lambda x: x.name,
}.get(sort_mode)
if sort_key:
reverse = sort_mode in (SortMode.MODIFIED, SortMode.NAME_REVERSE)
entries = sorted(entries, key=sort_key, reverse=reverse)
imgs = {
img.name: (
f"/mtb/view?filename={img.name}{f'&width={target_width}' if target_width and target_width > 0 else ''}&type={mode}&subfolder={subfolder or ''}"
f"{img.parent.relative_to(entry_dir) if include_subfolders else ''}"
f"&preview={f'&rand={secrets.randbelow(424242)}' if salt_urls else ''}"
)
for i, img in enumerate(entries)
if offset <= i < offset + count
}
return imgs
def ACTIONS_getStyles(style_name=None):
from .nodes.conditions import MTB_StylesLoader
styles = MTB_StylesLoader.options
match_list = ["name"]
if styles:
filtered_styles = {
@@ -55,7 +182,9 @@ def ACTIONS_getStyles(style_name=None):
if not key.startswith("__") and key not in match_list
}
if style_name:
return filtered_styles.get(style_name, {"error": "Style not found"})
return filtered_styles.get(
style_name, {"error": "Style not found"}
)
return filtered_styles
return {"error": "No styles found"}
@@ -75,7 +204,9 @@ def ACTIONS_saveStyle(data):
break
if not target:
endlog.warning(f"Could not determine the target file for {data.keys()}")
endlog.warning(
f"Could not determine the target file for {data.keys()}"
)
return {"error": "Could not determine the target file for the style"}
backup_file(target)
@@ -86,7 +217,7 @@ def ACTIONS_saveStyle(data):
csv_writer.writerow(row)
async def do_action(request) -> web.Response:
async def do_action(request: web.Request) -> web.Response:
endlog.debug("Init action request")
request_data = await request.json()
name = request_data.get("name")
@@ -98,26 +229,39 @@ async def do_action(request) -> web.Response:
method = globals().get(method_name)
if callable(method):
result = method(args) if args else method()
result = None
if args:
result = method(*args) if isinstance(args, list) else method(args)
else:
result = method()
endlog.debug(f"Action result: {result}")
return web.json_response({"result": result})
available_methods = [
attr[len("ACTIONS_") :] for attr in globals() if attr.startswith("ACTIONS_")
attr[len("ACTIONS_") :]
for attr in globals()
if attr.startswith("ACTIONS_")
]
return web.json_response(
{"error": "Invalid method name.", "available_methods": available_methods}
{
"error": "Invalid method name.",
"available_methods": available_methods,
}
)
# - HTML UTILS
def dependencies_button(name, dependencies):
def dependencies_button(name: str, dependencies: list[str]) -> str:
deps = ",".join([f"'{x}'" for x in dependencies])
return f"""
<button class="dependency-button" onclick="window.mtb_action('installDependency',[{deps}])">Install {name} deps</button>
<button
class="dependency-button"
onclick="window.mtb_action('installDependency',[{deps}])"
>Install {name} deps</button>
"""
@@ -127,7 +271,7 @@ def csv_editor():
style_files = {}
for file in inputs:
with open(file, "r", encoding="utf8") as f:
with open(file, encoding="utf8") as f:
parsed = csv.reader(f)
style_files[file.name] = []
for row in parsed:
@@ -137,7 +281,7 @@ def csv_editor():
html_out = """
<div id="style-editor">
<h1>Style Editor</h1>
"""
for current, styles in style_files.items():
current_out = f"<h3>{current}</h3>"
@@ -199,11 +343,14 @@ def render_tab_view(**kwargs):
"""
def add_foldable_region(title, content):
def add_foldable_region(title: str, content: str):
symbol_id = f"{title}-symbol"
return f"""
<div class='foldable'>
<div class='foldable-title' onclick="toggleFoldable('{title}', '{symbol_id}')">
<div
class='foldable-title'
onclick="toggleFoldable('{title}', '{symbol_id}')"
>
<span id='{symbol_id}' class='foldable-symbol'>&#9655;</span>
{title}
</div>
@@ -215,7 +362,9 @@ def add_foldable_region(title, content):
"""
def add_split_pane(left_content, right_content, vertical=True):
def add_split_pane(
left_content: str, right_content: str, *, vertical: bool = True
):
orientation = "vertical" if vertical else "horizontal"
return f"""
<div class="split-pane {orientation}">
@@ -234,8 +383,10 @@ def add_split_pane(left_content, right_content, vertical=True):
"""
def add_dropdown(title, options):
option_str = "\n".join([f"<option value='{opt}'>{opt}</option>" for opt in options])
def add_dropdown(title: str, options: list[str]):
option_str = "\n".join(
[f"<option value='{opt}'>{opt}</option>" for opt in options]
)
return f"""
<select>
<option disabled selected>{title}</option>
@@ -244,21 +395,25 @@ def add_dropdown(title, options):
"""
def render_table(table_dict, sort=True, title=None):
table_dict = sorted(
def render_table(table_dict: dict[str, Any], sort=True, title=None):
table_list = sorted(
table_dict.items(), key=lambda item: item[0]
) # Sort the dictionary by keys
table_rows = ""
for name, item in table_dict:
for name, item in table_list:
if isinstance(item, dict):
if "dependencies" in item:
table_rows += f"<tr><td>{name}</td><td>"
table_rows += f"{dependencies_button(name,item['dependencies'])}"
table_rows += (
f"{dependencies_button(name, item['dependencies'])}"
)
table_rows += "</td></tr>"
else:
table_rows += f"<tr><td>{name}</td><td>{render_table(item)}</td></tr>"
table_rows += (
f"<tr><td>{name}</td><td>{render_table(item)}</td></tr>"
)
# elif isinstance(item, str):
# table_rows += f"<tr><td>{name}</td><td>{item}</td></tr>"
else:
@@ -277,12 +432,12 @@ def render_table(table_dict, sort=True, title=None):
<tbody>
{table_rows}
</tbody>
</table>
</table>
</div>
"""
def render_base_template(title, content):
def render_base_template(title: str, content: str):
github_icon_svg = """<svg xmlns="http://www.w3.org/2000/svg" fill="whitesmoke" height="3em" viewBox="0 0 496 512"><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>"""
return f"""
<!DOCTYPE html>
@@ -318,7 +473,9 @@ def render_base_template(title, content):
<header>
<a href="/">Back to Comfy</a>
<div class="mtb_logo">
<img src="https://repository-images.githubusercontent.com/649047066/a3eef9a7-20dd-4ef9-b839-884502d4e873" alt="Comfy MTB Logo" height="70" width="128">
<img
src="https://repository-images.githubusercontent.com/649047066/a3eef9a7-20dd-4ef9-b839-884502d4e873"
alt="Comfy MTB Logo" height="70" width="128">
<span class="title">Comfy MTB</span></div>
<a style="width:128px;text-align:center" href="https://www.github.com/melmass/comfy_mtb">
{github_icon_svg}
@@ -333,6 +490,6 @@ def render_base_template(title, content):
<!-- Shared footer content here -->
</footer>
</body>
</html>
"""
+238
View File
@@ -0,0 +1,238 @@
# NOTE: This file is only use for development you can ignore it
use private/log.nu
def get_root [--clean] {
if $clean {
$env.COMFY_CLEAN_ROOT
} else {
$env.COMFY_ROOT
}
}
export def "comfy build-web" [] {
cd $env.COMFY_MTB
cd web_source
npm run build
cp dist/*.js ../web/dist
}
export def "comfy dev-web" [] {
cd $env.COMFY_MTB
cd web_source
npm run dev
}
export def "daily run" [] {
let res = (comfy update --rebase)
comfy update --clean
comfy update_extensions
daily commit $res.from $res.to
}
def short-date [] {
format date "%Y-%m-%d"
}
# was daily run today?
export def "daily was-run" [] {
let daily = ($env.COMFY_MTB | path join daily.nuon)
if ($daily | path exists) {
let last = (open $daily | sort-by date | get date | last | short-date)
let today = (date now | short-date)
return ($last == $today)
}
return false
}
export def "daily commit" [from:string, to:string] {
let daily = ($env.COMFY_MTB | path join daily.nuon)
let commit = [{date: (date now) from:$from to:$to}]
let dailies = (if ($daily | path exists) {
open $daily | append $commit
} else {
$commit
})
$dailies | save -f $daily
log success "Commited daily check"
}
# start the comfy server
export def "comfy start" [--clean,--old-ui, --listen, --skip-daily(-s)] {
if (not (daily was-run)) and not $skip_daily {
log info "Running daily checks"
daily run
}
let root = get_root --clean=($clean)
cd $root
log info "Running Server"
MTB_DEBUG=true python main.py --port 3000 ...(if $old_ui { ["--front-end-version", "Comfy-Org/ComfyUI_legacy_frontend@latest"]} else {[ --front-end-version Comfy-Org/ComfyUI_frontend@latest]}) --preview-method auto ...(if $listen {["--listen"]} else {[]})
}
# update comfy itself and merge master in current branch
export def "comfy update" [
--clean # ??
--rebase # Rebase instead of merge
] {
let root = get_root --clean=$clean
let models = $"($root)/models"
let inputs = $"($root)/input"
cd $root
let branch_name = (git rev-parse --abbrev-ref HEAD | str trim)
let current_commit = (git rev-parse HEAD | str trim)
log info "Backing up and removing models symlinks"
# preparing root for pull
if not $clean {
git checkout pyproject.toml
cd $models
# find and store all symlinks
let links = (ls -la |
where not ($it.target | is-empty) |
select name target |
sort-by name)
if not ($links | is-empty) {
$links | save -f links.nuon
# remove them
open links.nuon | each {|p| rm $p.name }
}
} else {
# just remove symlinks
rm $models
rm $inputs
}
cd $root
log info $"Checking out to master"
git checkout master
log info "Fetching and pulling remote updates"
if ($clean) {
# from the local base repo master
git fetch local master # $branch_name # master
git pull local master # $branch_name # master
} else {
git fetch
git pull
}
let new_commit = (git rev-parse HEAD | str trim)
log info $"Back to our branch \(($branch_name)\)"
git checkout -
if $current_commit == $new_commit {
log warn "No changes upstream"
} else {
if $rebase {
log info "Rebasing changes"
git rebase master
} else {
log info "Merging changes"
git merge master
}
}
log info "Linking back the models"
if not $clean {
rm pyproject.toml
cp pyproject-mel.toml pyproject.toml
cd $models
# resymlink them
open links.nuon | each {|p| link -a $p.target $p.name }
} else {
let master = (get_root)
link ($master | path join models) $models
link ($master | path join input) $inputs
}
let commit_count = (git rev-list --count $branch_name $"^origin/($branch_name)")
log success $"Update successful \(($commit_count) new commits\)"
return {from:$current_commit to:$new_commit}
}
export def "comfy toggle_extensions" [--clean] {
let root = get_root --clean=($clean)
cd $root
cd custom_nodes
let exts = (ls | where type in ["dir","symlink"] | get name)
let choices = ($exts | input list -m "choose extension to toggle")
if ($choices | is-empty) {
return
}
log info "Choices" $choices
let filtered = $choices | wrap name | upsert enabled {|p| not ($p.name | str ends-with ".disabled")}
log info "Filtered" $filtered
$filtered | each {|f|
let new_name = ($f.name | str replace ".disabled" "")
let new_name = if $f.enabled {
$"($new_name).disabled"
} else {
$new_name
}
log info $"Moving ($f.name) to ($new_name)"
mv $f.name $new_name
}
}
# git pull all extensions
export def "comfy update_extensions" [--clean] {
let root = get_root --clean=($clean)
cd $root
cd custom_nodes
git multipull . -s -q
}
def --env path-add [pth] {
$env.PATH = ($env.PATH | append ($pth | path expand))
}
export-env {
$env.PYTHONUTF8 = 1
$env.COMFY_MTB = ("." | path expand)
# $env.CUDA_ROOT = 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\'
$env.CUDA_HOME = $env.CUDA_ROOT
$env.COMFY_ROOT = ("../.." | path expand)
$env.COMFY_CLEAN_ROOT = ($env.COMFY_ROOT | path dirname | path join ComfyClean)
path-add 'C:/Portable/TensorRT-8.6.0.12/lib'
if $nu.os-info.family == 'windows' {
path-add 'G:\BIN\TensorRT-10.7.0.23\lib'
path-add 'G:\BIN\cudnn-windows-x86_64-9.6.0.74_cuda12-archive\bin'
}
path-add ($env.CUDA_ROOT | path join bin)
overlay use ../../.venv/Scripts/activate.nu
}
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
{"last_node_id":9,"last_link_id":0,"nodes":[{"id":9,"type":"Note Plus (mtb)","pos":[332, 139, 0, 0, 0, 0, 0, 0, 0, 0],"size":[573.4446126650389, 1292.5298919072263],"flags":{},"order":0,"mode":0,"inputs":[],"outputs":[],"title":"Note+ (mtb)","properties":{},"widgets_values":["# Note+ Demo\n\n# Images \nyou can resize them (see showdown syntax)\n\n![Minion](https://octodex.github.com/images/minion.png =120x*)\n\n# iFrame (embeds)\n<iframe src=\"https://www.youtube.com/embed/tgbNymZ7vqY\">\n</iframe>\n\n# Headings\n\n# h1 Heading:smile:\n\n## h2 Heading\n\n### h3 Heading\n\n#### h4 Heading\n\n##### h5 Heading\n\n###### h6 Heading\n\n# Tables\n\nColons can be used to align columns.\n\n| Tables|Are|Cool |\n| ------------- |:-----------:| ----:|\n| col 3 is| right-aligned | $1600 |\n| col 2 is| centered| $12 |\n| zebra stripes | are neat|$1 |\n\nEmphasis, aka italics, with _asterisks_ or _underscores_.\n\nStrong emphasis, aka bold, with **asterisks** or **underscores**.\n\nCombined emphasis with **asterisks and _underscores_**.\n\nStrikethrough uses two tildes. ~~Scratch this.~~\n\n**This is bold text**\n\n**This is bold text**\n\n_This is italic text_\n\n_This is italic text_\n\n~~Strikethrough~~\n\n1. First ordered list item\n2. Another item\n\n- Unordered sub-list.\n\n1. Actual numbers don't matter, just that it's a number\n1. Ordered sub-list\n1. And another item.\n1.\n\n- [x] Finish my changes\n- [] Push my commits to GitHub\n- [] Open a pull request\n- [x] mentions:@melmass, #refs, [links](), **formatting**, and <del>tags</del> supported\n- [x] list syntax required (any unordered or ordered list supported)\n- [x] this is a complete item\n- [] this is an incomplete item\n","markdown","*{\ncolor:whitesmoke;\n}\n\nh1{\ncolor:cyan;\n}\nh2{\ncolor:yellow;\n}\nh3{\ncolor:pink;\n}\n\nstrong{\ncolor:red;\n}"],"color":"#223","bgcolor":"#335","shape":1}],"links":[],"groups":[],"config":{},"extra":{},"version":0.4}
+64 -29
View File
@@ -43,10 +43,27 @@ pip_map = {
"tb-nightly": "tensorboard",
"protobuf": "google.protobuf",
"qrcode[pil]": "qrcode",
"requirements-parser": "requirements"
# Add more mappings as needed
}
def get_node_dependencies():
restore_deps = ["basicsr"]
onnx_deps = ["onnxruntime"]
swap_deps = ["insightface"] + onnx_deps
quant_deps = ["bitsandbytes"]
io_deps = ["av"]
return {
"QrCode": ["qrcode"],
"DeepBump": onnx_deps,
"FaceSwap": swap_deps,
"LoadFaceSwapModel": swap_deps,
"LoadFaceAnalysisModel": restore_deps,
"Quantize": quant_deps,
"SaveGif": io_deps,
}
# endregion
# region ansi
@@ -124,12 +141,12 @@ def print_formatted(text, *formats, color=None, background=None, **kwargs):
header = "[mtb install] "
# Handle console encoding for Unicode characters (utf-8)
encoded_header = header.encode(sys.stdout.encoding, errors="replace").decode(
sys.stdout.encoding
)
encoded_text = formatted_text.encode(sys.stdout.encoding, errors="replace").decode(
sys.stdout.encoding
)
encoded_header = header.encode(
sys.stdout.encoding, errors="replace"
).decode(sys.stdout.encoding)
encoded_text = formatted_text.encode(
sys.stdout.encoding, errors="replace"
).decode(sys.stdout.encoding)
print(
" " * len(encoded_header)
@@ -163,7 +180,9 @@ def run_command(cmd, ignored_lines_start=None):
try:
_run_command(shell_cmd, ignored_lines_start)
except subprocess.CalledProcessError as e:
print(f"Command failed with return code: {e.returncode}", file=sys.stderr)
print(
f"Command failed with return code: {e.returncode}", file=sys.stderr
)
print(e.stderr.strip(), file=sys.stderr)
except KeyboardInterrupt:
@@ -238,7 +257,7 @@ def suppress_std():
def get_local_version():
init_file = os.path.join(os.path.dirname(__file__), "__init__.py")
if os.path.isfile(init_file):
with open(init_file, "r") as f:
with open(init_file) as f:
tree = ast.parse(f.read())
for node in ast.walk(tree):
if isinstance(node, ast.Assign):
@@ -256,13 +275,16 @@ def download_file(url, file_name):
with requests.get(url, stream=True) as response:
response.raise_for_status()
total_size = int(response.headers.get("content-length", 0))
with open(file_name, "wb") as file, tqdm(
desc=file_name.stem,
total=total_size,
unit="B",
unit_scale=True,
unit_divisor=1024,
) as progress_bar:
with (
open(file_name, "wb") as file,
tqdm(
desc=file_name.stem,
total=total_size,
unit="B",
unit_scale=True,
unit_divisor=1024,
) as progress_bar,
):
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)
progress_bar.update(len(chunk))
@@ -302,7 +324,9 @@ def import_or_install(requirement, dry=False):
pip_install_name = pip_name + pip_spec
if not installed:
print_formatted(f"Installing package {pip_name}...", "italic", color="yellow")
print_formatted(
f"Installing package {pip_name}...", "italic", color="yellow"
)
if dry:
print_formatted(
f"Dry-run: Package {pip_install_name} would be installed (import name: '{import_name}').",
@@ -310,7 +334,9 @@ def import_or_install(requirement, dry=False):
)
else:
try:
run_command([executable, "-m", "pip", "install", pip_install_name])
run_command(
[executable, "-m", "pip", "install", pip_install_name]
)
print_formatted(
f"Package {pip_install_name} installed successfully using pip package name (import name: '{import_name}')",
"bold",
@@ -326,13 +352,9 @@ 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}"
)
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"
)
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(
@@ -361,7 +383,9 @@ except ImportError:
def main():
if len(sys.argv) == 1:
print_formatted(
"mtb doesn't need an install script anymore.", "italic", color="yellow"
"mtb doesn't need an install script anymore.",
"italic",
color="yellow",
)
return
if all(arg not in ("-p", "--path") for arg in sys.argv):
@@ -384,7 +408,7 @@ def main():
args = parser.parse_args()
print_formatted(f"Detected environment: {apply_color(mode,'cyan')}")
print_formatted(f"Detected environment: {apply_color(mode, 'cyan')}")
if args.path:
clone_dir = Path(args.path)
@@ -397,8 +421,12 @@ def main():
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])
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..."
@@ -409,7 +437,14 @@ def main():
print_formatted("Checking environment...", "italic", color="yellow")
missing_deps = []
install_cmd = [executable, "-m", "pip", "install", "-r", "requirements.txt"]
install_cmd = [
executable,
"-m",
"pip",
"install",
"-r",
"requirements.txt",
]
run_command(install_cmd)
print_formatted(
+14 -8
View File
@@ -36,7 +36,7 @@ class Formatter(logging.Formatter):
return formatter.format(record)
def mklog(name, level=base_log_level):
def mklog(name: str, level: int = base_log_level):
logger = logging.getLogger(name)
logger.setLevel(level)
@@ -58,24 +58,30 @@ def mklog(name, level=base_log_level):
log = mklog(__package__, base_log_level)
def log_user(arg):
print("\033[34mComfy MTB Utils:\033[0m {arg}")
def log_user(arg: str):
print(f"\033[34mComfy MTB Utils:\033[0m {arg}")
def get_summary(docstring):
def get_summary(docstring: str):
return docstring.strip().split("\n\n", 1)[0]
def blue_text(text):
def blue_text(text: str):
return f"\033[94m{text}\033[0m"
def cyan_text(text):
def cyan_text(text: str):
return f"\033[96m{text}\033[0m"
def get_label(label):
def get_label(label: str):
if label.startswith("MTB_"):
label = label[4:]
words = re.findall(r"(?:^|[A-Z])[a-z]*", label)
words = re.findall(
r"(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<=[A-Za-z])(?=[0-9])|(?<=[0-9])(?=[A-Za-z]))",
label,
)
reformatted_label = re.sub(r"([A-Z]+)", r" \1", label).strip()
words = reformatted_label.split()
return " ".join(words).strip()
+2 -1
View File
@@ -42,13 +42,14 @@
"Mask To Image (mtb)": "Converts a mask (alpha) to an RGB image with a color and background",
"Math Expression (mtb)": "Node to evaluate a simple math expression string",
"Model Patch Seamless (mtb)": "Uses the stable diffusion 'hack' to infer seamless images by setting the model layers padding mode to circular (experimental)",
"Pick From Batch (mtb)": "Pick a specific number of images from a batch, either from the start or end.",
"Qr Code (mtb)": "Basic QR Code generator",
"Restore Face (mtb)": "Uses GFPGan to restore faces",
"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",
"Sharpen (mtb)": "Sharpens an image using a Gaussian kernel.",
"Sharpen (mtb)": "Sharpens an image using a Gaussian kernel.",
"Smart Step (mtb)": "Utils to control the steps start/stop of the KAdvancedSampler in percentage",
"Stack Images (mtb)": "Stack the input images horizontally or vertically",
"String Replace (mtb)": "Basic string replacement",
+1
View File
@@ -0,0 +1 @@
"""MTB Nodes module."""
+33 -3
View File
@@ -1,8 +1,8 @@
from ..log import log
class AnimationBuilder:
"""Convenient way to manage basic animation maths at the core of many of my workflows"""
class MTB_AnimationBuilder:
"""Simple maths for animation."""
@classmethod
def INPUT_TYPES(cls):
@@ -21,6 +21,36 @@ class AnimationBuilder:
RETURN_NAMES = ("frame", "0-1 (scaled)", "count", "loop_ended")
CATEGORY = "mtb/animation"
FUNCTION = "build_animation"
DESCRIPTION = """
# Animation Builder
Check the
[wiki page](https://github.com/melMass/comfy_mtb/wiki/nodes-animation-builder)
for more info.
- This basic example should help to understand the meaning of
its inputs and outputs thanks to the [debug](nodes-debug) node.
![](https://github.com/melMass/comfy_mtb/assets/7041726/2b5c7e4f-372d-4494-9e73-abb2daa7cb36)
- In this other example Animation Builder is used in combination with
[Batch From History](https://github.com/melMass/comfy_mtb/wiki/nodes-batch-from-history)
to create a zoom-in animation on a static image
![](https://github.com/melMass/comfy_mtb/assets/7041726/77d37da1-0a8e-4519-a493-dfdef7f755ea)
## Inputs
| name | description |
| ---- | :----------:|
| total_frames | The number of frame to queue (this is multiplied by the `loop_count`)|
| scale_float | Convenience input to scale the normalized `current value` (a float between 0 and 1 lerp over the current queue length) |
| loop_count | The number of loops to queue |
| **Reset Button** | resets the internal counters, although the node is though around using its queue button it should still work fine when using the regular queue button of comfy |
| **Queue Button** | Convenience button to run the queues (`total_frames` * `loop_count`) |
"""
def build_animation(
self,
@@ -41,4 +71,4 @@ class AnimationBuilder:
return (frame, scaled, raw_loop, (frame == (total_frames - 1)))
__nodes__ = [AnimationBuilder]
__nodes__ = [MTB_AnimationBuilder]
+923
View File
@@ -0,0 +1,923 @@
from typing import TYPE_CHECKING, Any, TypedDict
import torch
import torchaudio
from comfy.model_management import get_torch_device
from huggingface_hub import snapshot_download
if TYPE_CHECKING:
from transformers import (
WhisperForConditionalGeneration,
WhisperProcessor,
)
from ..log import log
from ..utils import get_model_path
WHISPER_SAMPLE_RATE = 16000
class AudioTensor(TypedDict):
"""Comfy's representation of AUDIO data."""
sample_rate: int
waveform: torch.Tensor
class WhisperData(TypedDict):
"""Whisper transcription data with timestamps and speaker info."""
text: str
chunks: list[dict[str, Any]]
language: str
AudioData = AudioTensor | list[AudioTensor]
class MtbAudio:
"""Base class for audio processing."""
@classmethod
def is_stereo(
cls,
audios: AudioData,
) -> bool:
if isinstance(audios, list):
return any(cls.is_stereo(audio) for audio in audios)
else:
return audios["waveform"].shape[1] == 2
@staticmethod
def resample(audio: AudioTensor, common_sample_rate: int) -> AudioTensor:
current_rate = audio["sample_rate"]
if current_rate != common_sample_rate:
log.debug(
f"Resampling audio from {current_rate} to {common_sample_rate}"
)
resampler = torchaudio.transforms.Resample(
orig_freq=current_rate, new_freq=common_sample_rate
)
return {
"sample_rate": common_sample_rate,
"waveform": resampler(audio["waveform"]),
}
else:
return audio
@staticmethod
def to_stereo(audio: AudioTensor) -> AudioTensor:
if audio["waveform"].shape[1] == 1:
return {
"sample_rate": audio["sample_rate"],
"waveform": torch.cat(
[audio["waveform"], audio["waveform"]], dim=1
),
}
else:
return audio
@classmethod
def preprocess_audios(
cls, audios: list[AudioTensor]
) -> tuple[list[AudioTensor], bool, int]:
max_sample_rate = max([audio["sample_rate"] for audio in audios])
resampled_audios = [
cls.resample(audio, max_sample_rate) for audio in audios
]
is_stereo = cls.is_stereo(audios)
if is_stereo:
audios = [cls.to_stereo(audio) for audio in resampled_audios]
return (audios, is_stereo, max_sample_rate)
class WhisperPipeline(TypedDict):
"""Whisper model pipeline."""
processor: "WhisperProcessor"
model: "WhisperForConditionalGeneration"
class MTB_LoadWhisper:
"""Load Whisper model and processor."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model_size": (
[
"tiny",
"small",
"medium",
"medium.en",
"base",
"large",
"large-v2",
"large-v3",
"large-v3-turbo",
],
{"default": "tiny"},
),
},
"optional": {
"download_missing": (
"BOOLEAN",
{
"default": False,
"tooltip": (
"Download missing models if missing,"
"otherwise they must be in ComfyUI/models/whisper"
),
},
),
},
}
RETURN_TYPES = ("WHISPER_PIPELINE",)
RETURN_NAMES = ("pipeline",)
CATEGORY = "mtb/audio"
FUNCTION = "load"
def load(self, model_size="tiny", download_missing=False):
"""Load Whisper model and processor."""
from transformers import (
WhisperForConditionalGeneration,
WhisperProcessor,
)
whisper_dir = get_model_path("whisper")
tag = f"whisper-{model_size}"
model_dir = whisper_dir / tag
if not (whisper_dir.exists() or model_dir.exists()):
if not download_missing:
raise RuntimeError(
"Models not found and download_missing=False"
)
else:
whisper_dir.mkdir(exist_ok=True)
model_dir.mkdir(exist_ok=True)
snapshot_download(
repo_id=f"openai/{tag}",
resume_download=True,
ignore_patterns=["*.msgpack", "*.bin", "*.h5"],
local_dir=model_dir.as_posix(),
local_dir_use_symlinks=False,
)
device = get_torch_device()
log.debug(
f"Loading Whisper model {model_size} on {device} from {model_dir}"
)
processor = WhisperProcessor.from_pretrained(model_dir.as_posix())
model = WhisperForConditionalGeneration.from_pretrained(
model_dir.as_posix()
).to(device)
model.eval()
model.requires_grad_(False)
return ({"processor": processor, "model": model},)
class MTB_AudioToText(MtbAudio):
"""Transcribe audio to text using Whisper."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"pipeline": ("WHISPER_PIPELINE",),
"audio": ("AUDIO",),
"language": (
["auto"]
+ sorted(
[
"en",
"fr",
"es",
"de",
"it",
"pt",
"nl",
"ru",
"zh",
"ja",
"ko",
]
),
{"default": "auto"},
),
"return_timestamps": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("STRING", "WHISPER_OUTPUT")
FUNCTION = "transcribe"
CATEGORY = "mtb/audio"
def transcribe(
self,
pipeline: WhisperPipeline,
audio: AudioTensor,
language="auto",
return_timestamps=True,
):
"""Transcribe audio to text using Whisper."""
processor = pipeline["processor"]
model = pipeline["model"]
device = model.device
audio = self.resample(audio, WHISPER_SAMPLE_RATE)
waveform = audio["waveform"]
log.debug(f"Processed waveform shape: {waveform.shape}")
# - Mono: [1, 1, samples] or [1, samples] or [samples]
# - Stereo: [1, 2, samples] or [2, samples] or [samples, 2]
if len(waveform.shape) == 3:
waveform = waveform.squeeze(0)
if len(waveform.shape) == 2:
if waveform.shape[0] == 2: # [channels, samples]
waveform = waveform.mean(dim=0)
elif waveform.shape[1] == 2: # [samples, channels]
waveform = waveform.mean(dim=1)
else: # mono
waveform = waveform.squeeze(0)
sample_rate = audio["sample_rate"]
chunk_duration = 30
chunk_samples = chunk_duration * sample_rate
total_samples = waveform.shape[-1]
total_duration = total_samples / sample_rate
log.debug(f"Audio duration: {total_duration:.2f}s")
all_tokens = []
all_text = []
chunk_offsets = []
last_time = 0.0
accumulated_offset = 0.0
for chunk_start in range(0, total_samples, chunk_samples):
chunk_end = min(chunk_start + chunk_samples, total_samples)
chunk_waveform = waveform[chunk_start:chunk_end]
chunk_offset = chunk_start / sample_rate
chunk_offsets.append(chunk_offset)
log.debug(
f"Processing chunk {chunk_offset:.1f}s - {chunk_end / sample_rate:.1f}s"
)
max_length = getattr(model.config, "max_length", None) or 448
attention_mask = torch.ones((1, max_length))
input_features = processor(
chunk_waveform,
sampling_rate=sample_rate,
return_tensors="pt",
).input_features.to(device=device, dtype=model.dtype)
with torch.no_grad():
predicted_ids = model.generate(
input_features,
attention_mask=attention_mask.to(device),
task="transcribe",
language=None if language == "auto" else language,
return_timestamps=return_timestamps,
no_repeat_ngram_size=3,
num_beams=5,
length_penalty=1.0,
max_length=max_length,
)
chunk_tokens = processor.tokenizer.convert_ids_to_tokens(
predicted_ids[0]
)
adjusted_tokens = []
for token in chunk_tokens:
if token.startswith("<|") and token.endswith("|>"):
try:
time_str = token[2:-2]
if time_str.replace(".", "").isdigit():
time_val = float(time_str)
# If this timestamp is less than the last one, we've started a new sequence
if time_val < last_time:
accumulated_offset += last_time
adjusted_time = time_val + accumulated_offset
adjusted_tokens.append(f"<|{adjusted_time:.2f}|>")
last_time = time_val
else:
adjusted_tokens.append(token)
except ValueError:
adjusted_tokens.append(token)
else:
adjusted_tokens.append(token)
all_tokens.extend(adjusted_tokens)
chunk_text = processor.batch_decode(
predicted_ids, skip_special_tokens=True
)[0]
all_text.append(chunk_text)
detected_language = "en"
if language == "auto":
try:
log.debug("Detecting language")
with torch.no_grad():
first_chunk_features = processor(
waveform[:chunk_samples],
sampling_rate=sample_rate,
return_tensors="pt",
).input_features.to(device)
predicted_probs = model.detect_language(
first_chunk_features
)[0]
language_token = processor.tokenizer.convert_ids_to_tokens(
predicted_probs.argmax(-1).item()
)
detected_language = (
language_token[2:-2]
if language_token.startswith("<|")
else "en"
)
log.debug(f"Detected language: {detected_language}")
except Exception as e:
log.warning(f"Language detection failed: {e}")
full_transcription = " ".join(all_text)
whisper_output = {
"text": full_transcription,
"language": detected_language,
"tokens": all_tokens,
"audio": audio,
"chunk_offsets": chunk_offsets,
}
return full_transcription, whisper_output
class MTB_ProcessWhisperOutput:
"""Process Whisper output into timestamped chunks."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"whisper_output": ("WHISPER_OUTPUT",),
"min_chunk_length": (
"FLOAT",
{"default": 0.0, "min": 0.0, "max": 10.0, "step": 0.1},
),
},
}
RETURN_TYPES = ("STRING", "WHISPER_CHUNKS")
FUNCTION = "process"
CATEGORY = "mtb/audio"
def process(self, whisper_output, min_chunk_length=0.0):
"""Process Whisper output into timestamped chunks."""
tokens = whisper_output["tokens"]
audio = whisper_output["audio"]
timestamp_tokens = []
audio_duration = audio["waveform"].shape[-1] / audio["sample_rate"]
log.debug(f"Audio duration: {audio_duration:.2f}s")
for i, token in enumerate(tokens):
if token.startswith("<|") and token.endswith("|>"):
try:
time_str = token[2:-2]
if time_str.replace(".", "").isdigit():
time_val = float(time_str)
if 0 <= time_val <= audio_duration:
timestamp_tokens.append((i, time_val))
log.debug(f"Token {i}: {time_val}")
except ValueError:
continue
chunks = []
if len(timestamp_tokens) > 1:
for i in range(len(timestamp_tokens) - 1):
start_pos, start_time = timestamp_tokens[i]
end_pos, end_time = timestamp_tokens[i + 1]
if end_time - start_time < min_chunk_length:
continue
chunk_tokens = tokens[start_pos + 1 : end_pos]
text = " ".join(
t
for t in chunk_tokens
if not (t.startswith("<|") and t.endswith("|>"))
)
if text.strip():
chunks.append(
{
"text": text.strip(),
"timestamp": [start_time, end_time],
}
)
if timestamp_tokens:
start_pos, start_time = timestamp_tokens[-1]
if start_pos < len(tokens) - 1:
text = " ".join(
t
for t in tokens[start_pos + 1 :]
if not (t.startswith("<|") and t.endswith("|>"))
)
if text.strip():
if chunks:
prev_chunk = chunks[-1]
prev_duration = (
prev_chunk["timestamp"][1]
- prev_chunk["timestamp"][0]
)
end_time = min(
start_time + prev_duration, audio_duration
)
else:
end_time = audio_duration
if (
end_time > start_time
and end_time - start_time >= min_chunk_length
):
chunks.append(
{
"text": text.strip(),
"timestamp": [start_time, end_time],
}
)
result = {
"text": whisper_output["text"],
"chunks": chunks,
"language": whisper_output["language"],
}
return whisper_output["text"], result
class MTB_AudioCut(MtbAudio):
"""Basic audio cutter, values are in ms."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"audio": ("AUDIO",),
"length": (
("FLOAT"),
{
"default": 1000.0,
"min": 0.0,
"max": 999999.0,
"step": 1,
},
),
"offset": (
("FLOAT"),
{"default": 0.0, "min": 0.0, "max": 999999.0, "step": 1},
),
},
}
RETURN_TYPES = ("AUDIO",)
RETURN_NAMES = ("cut_audio",)
CATEGORY = "mtb/audio"
FUNCTION = "cut"
def cut(self, audio: AudioTensor, length: float, offset: float):
sample_rate = audio["sample_rate"]
start_idx = int(offset * sample_rate / 1000)
end_idx = min(
start_idx + int(length * sample_rate / 1000),
audio["waveform"].shape[-1],
)
cut_waveform = audio["waveform"][:, :, start_idx:end_idx]
return (
{
"sample_rate": sample_rate,
"waveform": cut_waveform,
},
)
class MTB_AudioStack(MtbAudio):
"""Stack/Overlay audio inputs (dynamic inputs).
- pad audios to the longest inputs.
- resample audios to the highest sample rate in the inputs.
- convert them all to stereo if one of the inputs is.
"""
@classmethod
def INPUT_TYPES(cls):
return {"required": {}}
RETURN_TYPES = ("AUDIO",)
RETURN_NAMES = ("stacked_audio",)
CATEGORY = "mtb/audio"
FUNCTION = "stack"
def stack(self, **kwargs: AudioTensor) -> tuple[AudioTensor]:
audios, is_stereo, max_rate = self.preprocess_audios(
list(kwargs.values())
)
max_length = max([audio["waveform"].shape[-1] for audio in audios])
padded_audios: list[torch.Tensor] = []
for audio in audios:
padding = torch.zeros(
(
1,
2 if is_stereo else 1,
max_length - audio["waveform"].shape[-1],
)
)
padded_audio = torch.cat([audio["waveform"], padding], dim=-1)
padded_audios.append(padded_audio)
stacked_waveform = torch.stack(padded_audios, dim=0).sum(dim=0)
return (
{
"sample_rate": max_rate,
"waveform": stacked_waveform,
},
)
class MTB_AudioSequence(MtbAudio):
"""Sequence audio inputs (dynamic inputs).
- adding silence_duration between each segment
can now also be negative to overlap the clips, safely bound
to the the input length.
- resample audios to the highest sample rate in the inputs.
- convert them all to stereo if one of the inputs is.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"silence_duration": (
("FLOAT"),
{"default": 0.0, "min": -999.0, "max": 999, "step": 0.01},
)
},
}
RETURN_TYPES = ("AUDIO",)
RETURN_NAMES = ("sequenced_audio",)
CATEGORY = "mtb/audio"
FUNCTION = "sequence"
def sequence(self, silence_duration: float, **kwargs: AudioTensor):
audios, is_stereo, max_rate = self.preprocess_audios(
list(kwargs.values())
)
sequence: list[torch.Tensor] = []
for i, audio in enumerate(audios):
if i > 0:
if silence_duration > 0:
silence = torch.zeros(
(
1,
2 if is_stereo else 1,
int(silence_duration * max_rate),
)
)
sequence.append(silence)
elif silence_duration < 0:
overlap = int(abs(silence_duration) * max_rate)
previous_audio = sequence[-1]
overlap = min(
overlap,
previous_audio.shape[-1],
audio["waveform"].shape[-1],
)
if overlap > 0:
overlap_part = (
previous_audio[:, :, -overlap:]
+ audio["waveform"][:, :, :overlap]
)
sequence[-1] = previous_audio[:, :, :-overlap]
sequence.append(overlap_part)
audio["waveform"] = audio["waveform"][:, :, overlap:]
sequence.append(audio["waveform"])
sequenced_waveform = torch.cat(sequence, dim=-1)
return (
{
"sample_rate": max_rate,
"waveform": sequenced_waveform,
},
)
class MTB_AudioResample(MtbAudio):
"""Resample audio to a different sample rate."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"audio": ("AUDIO",),
"sample_rate": (
"INT",
{
"default": 16000,
"min": 1000,
"max": 192000,
"step": 100,
"tooltip": "Target sample rate in Hz. Whisper requires 16000.",
},
),
}
}
RETURN_TYPES = ("AUDIO",)
RETURN_NAMES = ("resampled_audio",)
CATEGORY = "mtb/audio"
FUNCTION = "resample_audio"
def resample_audio(
self, audio: AudioTensor, sample_rate: int
) -> tuple[AudioTensor]:
resampled = self.resample(audio, sample_rate)
return (resampled,)
class MTB_AudioIsolateSpeaker(MtbAudio):
"""Isolate or mute specific speakers using WhisperData"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"audio": ("AUDIO",),
"whisper_data": ("WHISPER_CHUNKS",),
"target_speaker": ("STRING", {"default": "SPEAKER_00"}),
"mode": (["isolate", "mute"], {"default": "isolate"}),
"fade_ms": (
"FLOAT",
{
"default": 100.0,
"min": 0.0,
"max": 1000.0,
"step": 10,
"tooltip": "Fade duration in milliseconds to avoid clicks",
},
),
},
}
RETURN_TYPES = ("AUDIO",)
RETURN_NAMES = ("processed_audio",)
CATEGORY = "mtb/audio"
FUNCTION = "process_audio"
def process_audio(
self,
audio: AudioTensor,
whisper_data: WhisperData,
target_speaker: str,
mode: str = "isolate",
fade_ms: float = 100.0,
) -> tuple[AudioTensor]:
fade_samples = int((fade_ms / 1000.0) * audio["sample_rate"])
mask = (
torch.zeros_like(audio["waveform"])
if mode == "isolate"
else torch.ones_like(audio["waveform"])
)
for chunk in whisper_data["chunks"]:
if not chunk.get("speaker"):
continue
speaker_present = target_speaker in chunk["speaker"]
if (mode == "isolate" and speaker_present) or (
mode == "mute" and not speaker_present
):
start_sample = int(
chunk["timestamp"][0] * audio["sample_rate"]
)
end_sample = int(chunk["timestamp"][1] * audio["sample_rate"])
mask[:, start_sample:end_sample] = 1.0
if fade_samples > 0:
fade = torch.linspace(0, 1, fade_samples)
transitions = torch.where(mask[0, 1:] != mask[0, :-1])[0] + 1
for trans_idx in transitions:
if (
trans_idx >= fade_samples
and trans_idx <= mask.shape[1] - fade_samples
):
if mask[0, trans_idx] == 1:
mask[:, trans_idx : trans_idx + fade_samples] *= fade
else:
mask[:, trans_idx - fade_samples : trans_idx] *= (
fade.flip(0)
)
processed_waveform = audio["waveform"] * mask
return (
{
"sample_rate": audio["sample_rate"],
"waveform": processed_waveform,
},
)
class MTB_ProcessWhisperDiarization:
"""Process Whisper chunks with speaker diarization using either pyannote or NeMo."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"whisper_chunks": ("WHISPER_CHUNKS",),
"audio": ("AUDIO",),
"backend": (["pyannote", "nemo"], {"default": "pyannote"}),
"num_speakers": (
"INT",
{"default": 2, "min": 1, "max": 10, "step": 1},
),
},
"optional": {
"device": (["cuda", "cpu"], {"default": "cuda"}),
},
}
RETURN_TYPES = ("WHISPER_CHUNKS",)
FUNCTION = "process"
CATEGORY = "mtb/audio"
def process_pyannote(self, audio, num_speakers, device):
"""Process audio using pyannote backend."""
try:
from pyannote.audio import Pipeline
from pyannote.audio.pipelines.utils.hook import ProgressHook
except ImportError:
raise ImportError(
"pyannote.audio not found. Install with: pip install pyannote.audio"
)
pipeline = Pipeline.from_pretrained(
"pyannote/speaker-diarization-3.1", use_auth_token=None
)
pipeline.to(torch.device(device))
with ProgressHook() as hook:
diarization = pipeline(
{
"waveform": audio["waveform"][0],
"sample_rate": audio["sample_rate"],
},
num_speakers=num_speakers,
hook=hook,
)
speaker_segments = []
for turn, _, speaker in diarization.itertracks(yield_label=True):
speaker_segments.append(
{
"start": turn.start,
"end": turn.end,
"speaker": speaker,
}
)
return speaker_segments
def process_nemo(self, audio, num_speakers, device):
"""Process audio using NeMo backend."""
try:
import nemo.collections.asr as nemo_asr
except ImportError:
raise ImportError(
"NeMo not found. Install with: pip install nemo_toolkit[asr]"
)
model = nemo_asr.models.ClusteringDiarizer.from_pretrained(
"nvidia/speakerverification_en_titanet_large"
).to(device)
diarization = model.diarize(
audio=audio["waveform"][0],
sample_rate=audio["sample_rate"],
num_speakers=num_speakers,
)
speaker_segments = []
for segment in diarization:
speaker_segments.append(
{
"start": segment["start"],
"end": segment["end"],
"speaker": f"SPEAKER_{segment['speaker']}",
}
)
return speaker_segments
def process(
self,
whisper_chunks,
audio,
backend="pyannote",
num_speakers=2,
device="cuda",
):
if backend == "pyannote":
speaker_segments = self.process_pyannote(
audio, num_speakers, device
)
else: # nemo
speaker_segments = self.process_nemo(audio, num_speakers, device)
for chunk in whisper_chunks["chunks"]:
chunk_start, chunk_end = chunk["timestamp"]
chunk_speakers = set()
for segment in speaker_segments:
if (
segment["start"] <= chunk_end
and segment["end"] >= chunk_start
):
chunk_speakers.add(segment["speaker"])
if chunk_speakers:
chunk["speaker"] = list(chunk_speakers)[0]
else:
chunk["speaker"] = "unknown"
return (whisper_chunks,)
class MTB_AudioDuration:
"""Get audio duration in milliseconds."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"audio": ("AUDIO",),
},
}
RETURN_TYPES = ("INT",)
RETURN_NAMES = ("duration_ms",)
FUNCTION = "get_duration"
CATEGORY = "mtb/audio"
def get_duration(self, audio):
waveform = audio["waveform"]
sample_rate = audio["sample_rate"]
duration_ms = int((waveform.shape[-1] / sample_rate) * 1000)
log.debug(
f"Audio duration: {duration_ms}ms ({duration_ms / 1000:.2f}s)"
)
return (duration_ms,)
__nodes__ = [
MTB_AudioSequence,
MTB_AudioStack,
MTB_AudioCut,
MTB_AudioResample,
MTB_AudioIsolateSpeaker,
MTB_LoadWhisper,
MTB_AudioToText,
MTB_ProcessWhisperOutput,
MTB_ProcessWhisperDiarization,
MTB_AudioDuration,
]
+992 -74
View File
File diff suppressed because it is too large Load Diff
+190
View File
@@ -0,0 +1,190 @@
import time
import uuid
from collections import OrderedDict
from typing import Any, TypedDict
from comfy.comfy_types.node_typing import IO as CIO
from server import PromptServer
from ..log import log
class Clock(TypedDict):
name: str
start: float
end: float | None
active_timers: OrderedDict[str, Clock] = OrderedDict()
# TODO: lower this
MAX_CLOCKS = 50
class MTB_StartClock:
"""
Starts a profiling clock with a given name.
Outputs a unique ID that must be passed to EndClock.
"""
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"name": ("STRING", {"default": "Clock A"}),
"cache": (
"BOOLEAN",
{
"default": False,
"tooltip": "Cache the clock ID, this means the node will follow Comfy's default invalidation system. If False it will always invalidate / mark the node as 'dirty'",
},
),
},
"optional": {
"passthrough": (CIO.ANY,),
},
}
RETURN_TYPES = (
CIO.ANY,
"STRING",
)
RETURN_NAMES = (
"passthrough",
"clock_id",
)
FUNCTION = "start_timer"
CATEGORY = "mtb/utils"
def start_timer(
self, *, name: str, passthrough: Any | None = None, **kwargs
):
global active_timers
if len(active_timers) >= MAX_CLOCKS:
# get oldest clock
removed_key = None
for key, clock_data in active_timers.items():
if clock_data["end"] is not None:
removed_key = key
break
if removed_key:
removed_clock = active_timers.pop(removed_key)
log.info(
f"[Profiling] Evicted finished clock '{removed_clock['name']}' (ID: {removed_key}) due to limit ({MAX_CLOCKS})."
)
else:
removed_key, removed_clock = active_timers.popitem(last=False)
log.warning(
f"[Profiling] Evicted running clock '{removed_clock['name']}' (ID: {removed_key}) due to limit ({MAX_CLOCKS})."
)
clock_id = str(uuid.uuid4())
start_time = time.perf_counter()
active_timers[clock_id] = {
"start": start_time,
"name": name,
"end": None,
}
active_timers.move_to_end(clock_id)
log.debug(f"[Profiling] Clock '{name}' (ID: {clock_id}) started.")
return (
passthrough,
clock_id,
)
@classmethod
def IS_CHANGED(
cls, *, name: str, cache: bool = False, passthrough: Any | None = None
):
if not cache:
return float("Nan")
return {"name": name, "cache": cache, "passthrough": passthrough}
class MTB_EndClock:
"""
Stops a profiling clock identified by its ID and returns the elapsed time in milliseconds.
Errors if the clock ID is not found or already stopped.
"""
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"clock_id": (
"STRING",
{"forceInput": True},
),
},
"optional": {
"passthrough": (CIO.ANY,),
},
"hidden": {
"unique_id": "UNIQUE_ID",
},
}
RETURN_TYPES = (
CIO.ANY,
"STRING",
"FLOAT",
"INT",
)
RETURN_NAMES = (
"passthrough",
"name",
"seconds",
"milliseconds",
)
FUNCTION = "end_timer"
CATEGORY = "mtb/utils"
def end_timer(self, clock_id: str, passthrough, unique_id=None):
global active_timers
if clock_id not in active_timers:
raise ValueError(
f"Error: Clock with ID '{clock_id}' not found. "
"Ensure StartClock was executed for this ID and proper passthrough chaining."
)
clock = active_timers[clock_id]
if clock.get("end") is not None:
return (passthrough, clock["name"], clock["end"])
start_time = clock["start"]
end_time = time.perf_counter()
duration_seconds = end_time - start_time
duration_ms = int(duration_seconds * 1000)
clock["end"] = duration_ms
active_timers.move_to_end(clock_id)
log.debug(
f"[Profiling] Clock '{clock['name']}' (ID: {clock_id}) stopped. Elapsed: {duration_ms}ms"
)
if unique_id:
PromptServer.instance.send_progress_text(
f"Clock '{clock['name']}' took {duration_seconds:.4f} seconds",
unique_id,
)
return (passthrough, clock["name"], duration_seconds, duration_ms)
__nodes__ = [MTB_StartClock, MTB_EndClock]
+167 -18
View File
@@ -3,12 +3,129 @@ import shutil
from pathlib import Path
import folder_paths
import torch
from ..log import log
from ..utils import here
Conditioning = list[tuple[torch.Tensor, dict[str, torch.Tensor]]]
class InterpolateClipSequential:
def check_condition(conditioning: Conditioning):
has_cn = False
if len(conditioning) > 1:
log.warn(
"More than one conditioning was provided. Only the first one will be used."
)
first = conditioning[0]
cond, kwargs = first
log.debug("Conditioning Shape")
log.debug(cond.shape)
log.debug("Conditioning keys")
log.debug([f"\t{k} - {type(kwargs[k])}" for k in kwargs])
if "control" in kwargs:
log.debug("Conditioning contains a controlnet")
has_cn = True
if "pooled_output" not in kwargs:
raise ValueError(
"Conditioning is not valid. Missing 'pooled_output' key."
)
return has_cn
class MTB_InterpolateCondition:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"blend": (
"FLOAT",
{"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.01},
),
},
}
RETURN_TYPES = ("CONDITIONING",)
CATEGORY = "mtb/conditioning"
FUNCTION = "execute"
def execute(
self, blend: float, **kwargs: Conditioning
) -> tuple[Conditioning]:
blend = max(0.0, min(1.0, blend))
conditions: list[Conditioning] = list(kwargs.values())
num_conditions = len(conditions)
if num_conditions < 2:
raise ValueError("At least two conditioning inputs are required.")
segment_length = 1.0 / (num_conditions - 1)
segment_index = min(int(blend // segment_length), num_conditions - 2)
local_blend = (
blend - (segment_index * segment_length)
) / segment_length
cond_from = conditions[segment_index]
cond_to = conditions[segment_index + 1]
from_cn = check_condition(cond_from)
to_cn = check_condition(cond_to)
if from_cn and to_cn:
raise ValueError(
"Interpolating conditions cannot both contain ControlNets"
)
try:
interpolated_condition = [
(1.0 - local_blend) * c_from + local_blend * c_to
for c_from, c_to in zip(
cond_from[0][0], cond_to[0][0], strict=False
)
]
except Exception as e:
print(f"Error during interpolation: {e}")
raise
pooled_from = cond_from[0][1].get(
"pooled_output",
torch.zeros_like(
next(iter(cond_from[0][1].values()), torch.tensor([]))
),
)
pooled_to = cond_to[0][1].get(
"pooled_output",
torch.zeros_like(
next(iter(cond_from[0][1].values()), torch.tensor([]))
),
)
interpolated_pooled = (
1.0 - local_blend
) * pooled_from + local_blend * pooled_to
res = {"pooled_output": interpolated_pooled}
if from_cn:
res["control"] = cond_from[0][1]["control"]
res["control_apply_to_uncond"] = cond_from[0][1][
"control_apply_to_uncond"
]
if to_cn:
res["control"] = cond_to[0][1]["control"]
res["control_apply_to_uncond"] = cond_to[0][1][
"control_apply_to_uncond"
]
return ([(torch.stack(interpolated_condition), res)],)
class MTB_InterpolateClipSequential:
@classmethod
def INPUT_TYPES(cls):
return {
@@ -29,7 +146,12 @@ class InterpolateClipSequential:
CATEGORY = "mtb/conditioning"
def interpolate_encodings_sequential(
self, base_text, text_to_replace, clip, interpolation_strength, **replacements
self,
base_text,
text_to_replace,
clip,
interpolation_strength,
**replacements,
):
log.debug(f"Received interpolation_strength: {interpolation_strength}")
@@ -64,20 +186,30 @@ class InterpolateClipSequential:
log.debug("Using the base text a the base blend")
# - Start with the base_text condition
tokens = clip.tokenize(base_text)
cond_from, pooled_from = clip.encode_from_tokens(tokens, return_pooled=True)
cond_from, pooled_from = clip.encode_from_tokens(
tokens, return_pooled=True
)
else:
base_replace = list(replacements.values())[segment_index - 1]
log.debug(f"Using {base_replace} a the base blend")
# - Start with the base_text condition replaced by the closest replacement
tokens = clip.tokenize(base_text.replace(text_to_replace, base_replace))
cond_from, pooled_from = clip.encode_from_tokens(tokens, return_pooled=True)
tokens = clip.tokenize(
base_text.replace(text_to_replace, base_replace)
)
cond_from, pooled_from = clip.encode_from_tokens(
tokens, return_pooled=True
)
replacement_text = list(replacements.values())[segment_index]
interpolated_text = base_text.replace(text_to_replace, replacement_text)
interpolated_text = base_text.replace(
text_to_replace, replacement_text
)
tokens = clip.tokenize(interpolated_text)
cond_to, pooled_to = clip.encode_from_tokens(tokens, return_pooled=True)
cond_to, pooled_to = clip.encode_from_tokens(
tokens, return_pooled=True
)
# - Linearly interpolate between the two conditions
interpolated_condition = (
@@ -87,10 +219,12 @@ class InterpolateClipSequential:
1.0 - local_strength
) * pooled_from + local_strength * pooled_to
return ([[interpolated_condition, {"pooled_output": interpolated_pooled}]],)
return (
[[interpolated_condition, {"pooled_output": interpolated_pooled}]],
)
class SmartStep:
class MTB_SmartStep:
"""Utils to control the steps start/stop of the KAdvancedSampler in percentage"""
@classmethod
@@ -137,7 +271,7 @@ def install_default_styles(force=False):
return dest_style
class StylesLoader:
class MTB_StylesLoader:
"""Load csv files and populate a dropdown from the rows (à la A111)"""
options = {}
@@ -149,21 +283,31 @@ class StylesLoader:
if not input_dir.exists():
install_default_styles()
if not (files := [f for f in input_dir.iterdir() if f.suffix == ".csv"]):
if not (
files := [f for f in input_dir.iterdir() if f.suffix == ".csv"]
):
log.warn(
"No styles found in the styles folder, place at least one csv file in the styles folder at the root of ComfyUI (for instance ComfyUI/styles/mystyle.csv)"
)
for file in files:
with open(file, "r", encoding="utf8") as f:
with open(file, encoding="utf8") as f:
parsed = csv.reader(f)
for row in parsed:
log.debug(f"Adding style {row[0]}")
for i, row in enumerate(parsed):
# log.debug(f"Adding style {row[0]}")
try:
cls.options[row[0]] = (row[1], row[2])
except Exception:
name, positive, negative = (row + [None] * 3)[:3]
positive = positive or ""
negative = negative or ""
if name is not None:
cls.options[name] = (positive, negative)
else:
# Handle the case where 'name' is None
log.warning(f"Missing 'name' in row {i}.")
except Exception as e:
log.warning(
f"There was an error while parsing {file}, make sure it respects A1111 format, i.e 3 columns name, positive, negative"
f"There was an error while parsing {file}, make sure it respects A1111 format, i.e 3 columns name, positive, negative:\n{e}"
)
continue
@@ -186,4 +330,9 @@ class StylesLoader:
return (self.options[style_name][0], self.options[style_name][1])
__nodes__ = [SmartStep, StylesLoader, InterpolateClipSequential]
__nodes__ = [
MTB_SmartStep,
MTB_StylesLoader,
MTB_InterpolateClipSequential,
MTB_InterpolateCondition,
]
+27
View File
@@ -0,0 +1,27 @@
import json
from ..log import log
class MTB_Constant:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {"Value": ("*",)},
}
RETURN_TYPES = ("*",)
RETURN_NAMES = ("output",)
CATEGORY = "mtb/utils"
FUNCTION = "execute"
def execute(
self,
**kwargs,
):
log.debug("Received kwargs")
log.debug(json.dumps(kwargs, check_circular=True))
return (kwargs.get("Value"),)
# __nodes__ = [MTB_Constant]
+299 -132
View File
@@ -1,21 +1,36 @@
import numpy as np
from typing import NamedTuple
import torch
from PIL import Image, ImageChops, ImageDraw, ImageFilter
import torchvision.transforms.functional as TF
from ..log import log
from ..utils import np2tensor, pil2tensor, tensor2np, tensor2pil
class Bbox:
"""The bounding box (BBOX) custom type used by other nodes"""
class BoundingBox(NamedTuple):
"""The bounding box tuple."""
x: int
y: int
width: int
height: int
class MTB_Bbox:
"""A literal bounding box."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
# "bbox": ("BBOX",),
"x": ("INT", {"default": 0, "max": 10000000, "min": 0, "step": 1}),
"y": ("INT", {"default": 0, "max": 10000000, "min": 0, "step": 1}),
"x": (
"INT",
{"default": 0, "max": 10000000, "min": 0, "step": 1},
),
"y": (
"INT",
{"default": 0, "max": 10000000, "min": 0, "step": 1},
),
"width": (
"INT",
{"default": 256, "max": 10000000, "min": 0, "step": 1},
@@ -31,22 +46,72 @@ class Bbox:
FUNCTION = "do_crop"
CATEGORY = "mtb/crop"
def do_crop(self, x, y, width, height): # bbox
return ((x, y, width, height),)
# return bbox
def do_crop(
self, x: int, y: int, width: int, height: int
) -> tuple[BoundingBox]: # bbox
return (BoundingBox(x, y, width, height),)
class BboxFromMask:
"""From a mask extract the bounding box"""
class MTB_SplitBbox:
"""Split the components of a bbox."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {"bbox": ("BBOX",)},
}
CATEGORY = "mtb/crop"
FUNCTION = "split_bbox"
RETURN_TYPES = ("INT", "INT", "INT", "INT")
RETURN_NAMES = ("x", "y", "width", "height")
def split_bbox(self, bbox: BoundingBox) -> BoundingBox:
return bbox
class MTB_UpscaleBboxBy:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"bbox": ("BBOX",),
"scale": ("FLOAT", {"default": 1.0}),
},
}
CATEGORY = "mtb/crop"
RETURN_TYPES = ("BBOX",)
FUNCTION = "upscale"
def upscale(self, bbox: BoundingBox, scale: float) -> tuple[BoundingBox]:
x, y, width, height = bbox
center_x = x + width / 2
center_y = y + height / 2
new_width = int(width * scale)
new_height = int(height * scale)
new_x = int(center_x - new_width / 2)
new_y = int(center_y - new_height / 2)
return (BoundingBox(new_x, new_y, new_width, new_height),)
class MTB_BboxFromMask:
"""From a mask extract the bounding box."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"mask": ("MASK",),
"invert": ("BOOLEAN", {"default": False}),
},
"optional": {
"image": ("IMAGE",),
"image": ("IMAGE", {"tooltip": "Optional image"}),
},
}
@@ -61,52 +126,45 @@ class BboxFromMask:
FUNCTION = "extract_bounding_box"
CATEGORY = "mtb/crop"
def extract_bounding_box(self, mask: torch.Tensor, image=None):
# if image != None:
# if mask.size(0) != image.size(0):
# if mask.size(0) != 1:
# log.error(
# f"Batch count mismatch for mask and image, it can either be 1 mask for X images, or X masks for X images (mask: {mask.shape} | image: {image.shape})"
# )
def extract_bounding_box(
self,
mask: torch.Tensor,
*,
invert: bool = False,
image: torch.Tensor | None = None,
) -> tuple[BoundingBox, torch.Tensor | None]:
mask = 1 - mask if invert else mask
non_zero_indices = torch.nonzero(mask)
# raise Exception(
# f"Batch count mismatch for mask and image, it can either be 1 mask for X images, or X masks for X images (mask: {mask.shape} | image: {image.shape})"
# )
if non_zero_indices.numel() == 0:
log.warning(
"BboxFromMask: Mask is empty. Returning a (0,0,0,0) bbox."
)
return (BoundingBox(0, 0, 0, 0), image)
_mask = tensor2pil(1.0 - mask)[0]
min_coords = torch.min(non_zero_indices, dim=0).values
max_coords = torch.max(non_zero_indices, dim=0).values
# we invert it
alpha_channel = np.array(_mask)
min_y, min_x = min_coords[1].item(), min_coords[2].item()
max_y, max_x = max_coords[1].item(), max_coords[2].item()
non_zero_indices = np.nonzero(alpha_channel)
width = max_x - min_x + 1
height = max_y - min_y + 1
min_x, max_x = np.min(non_zero_indices[1]), np.max(non_zero_indices[1])
min_y, max_y = np.min(non_zero_indices[0]), np.max(non_zero_indices[0])
# Create a bounding box tuple
if image != None:
# Convert the image to a NumPy array
imgs = tensor2np(image)
out = []
for img in imgs:
# Crop the image from the bounding box
img = img[min_y:max_y, min_x:max_x, :]
log.debug(f"Cropped image to shape {img.shape}")
out.append(img)
image = np2tensor(out)
log.debug(f"Cropped images shape: {image.shape}")
bounding_box = (min_x, min_y, max_x - min_x, max_y - min_y)
return (
bounding_box,
image,
bounding_box = BoundingBox(
int(min_x), int(min_y), int(width), int(height)
)
cropped_image = None
if image is not None:
cropped_image = image[:, min_y : max_y + 1, min_x : max_x + 1, :]
class Crop:
"""Crops an image and an optional mask to a given bounding box
return (bounding_box, cropped_image)
class MTB_Crop:
"""Crop an image and an optional mask to a given bounding box.
The bounding box can be given as a tuple of (x, y, width, height) or as a BBOX type
The BBOX input takes precedence over the tuple input
"""
@@ -118,8 +176,14 @@ class Crop:
},
"optional": {
"mask": ("MASK",),
"x": ("INT", {"default": 0, "max": 10000000, "min": 0, "step": 1}),
"y": ("INT", {"default": 0, "max": 10000000, "min": 0, "step": 1}),
"x": (
"INT",
{"default": 0, "max": 10000000, "min": 0, "step": 1},
),
"y": (
"INT",
{"default": 0, "max": 10000000, "min": 0, "step": 1},
),
"width": (
"INT",
{"default": 256, "max": 10000000, "min": 0, "step": 1},
@@ -138,22 +202,40 @@ class Crop:
CATEGORY = "mtb/crop"
def do_crop(
self, image: torch.Tensor, mask=None, x=0, y=0, width=256, height=256, bbox=None
self,
image: torch.Tensor,
*,
mask: torch.Tensor | None = None,
x: int = 0,
y: int = 0,
width: int = 256,
height: int = 256,
bbox: BoundingBox | None = None,
):
image = image.numpy()
if mask:
mask = mask.numpy()
if bbox != None:
if bbox is not None:
x, y, width, height = bbox
if width <= 0 or height <= 0:
log.error(
"Crop dimensions must be positive. Check the BBOX or widget inputs."
)
return (
torch.zeros_like(image),
torch.zeros_like(mask) if mask is not None else None,
(x, y, width, height),
)
cropped_image = image[:, y : y + height, x : x + width, :]
cropped_mask = mask[y : y + height, x : x + width] if mask != None else None
crop_data = (x, y, width, height)
cropped_mask = (
mask[:, y : y + height, x : x + width]
if mask is not None
else None
)
crop_data = BoundingBox(x, y, width, height)
return (
torch.from_numpy(cropped_image),
torch.from_numpy(cropped_mask) if mask != None else None,
cropped_image,
cropped_mask if cropped_mask is not None else None,
crop_data,
)
@@ -167,34 +249,33 @@ class Crop:
# return (x_left, y_top, x_right, y_bottom)
def bbox_check(bbox, target_size=None):
def bbox_check(bbox: BoundingBox, target_size: tuple[int, int] | None = None):
if not target_size:
return bbox
new_bbox = (
bbox[0],
bbox[1],
min(target_size[0] - bbox[0], bbox[2]),
min(target_size[1] - bbox[1], bbox[3]),
new_bbox = BoundingBox(
bbox.x,
bbox.y,
min(target_size[0] - bbox.x, bbox.width),
min(target_size[1] - bbox.y, bbox.height),
)
if new_bbox != bbox:
log.warn(f"BBox too big, constrained to {new_bbox}")
log.warning(f"BBox too big, constrained to {new_bbox}")
return new_bbox
def bbox_to_region(bbox, target_size=None):
def bbox_to_region(
bbox: BoundingBox, target_size: tuple[int, int] | None = None
):
bbox = bbox_check(bbox, target_size)
# to region
return (bbox[0], bbox[1], bbox[0] + bbox[2], bbox[1] + bbox[3])
return (bbox.x, bbox.y, bbox.x + bbox.width, bbox.y + bbox.height)
class Uncrop:
"""Uncrops an image to a given bounding box
The bounding box can be given as a tuple of (x, y, width, height) or as a BBOX type
The BBOX input takes precedence over the tuple input"""
class MTB_Uncrop:
"""Uncrop an image to a given bounding box."""
@classmethod
def INPUT_TYPES(cls):
@@ -211,78 +292,164 @@ class Uncrop:
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "do_crop"
FUNCTION = "do_uncrop"
CATEGORY = "mtb/crop"
def do_crop(self, image, crop_image, bbox, border_blending):
def inset_border(image, border_width=20, border_color=(0)):
width, height = image.size
bordered_image = Image.new(image.mode, (width, height), border_color)
bordered_image.paste(image, (0, 0))
draw = ImageDraw.Draw(bordered_image)
draw.rectangle(
(0, 0, width - 1, height - 1), outline=border_color, width=border_width
def do_uncrop(
self,
image: torch.Tensor,
crop_image: torch.Tensor,
bbox: BoundingBox,
border_blending: float = 0.25,
):
if len(image) > 1 and len(image) != len(crop_image):
raise ValueError(
"Uncrop: Batch size of background 'image' must be 1 or match the 'crop_image' batch size."
)
return bordered_image
import comfy.utils
single = image.size(0) == 1
if image.size(0) != crop_image.size(0):
if not single:
raise ValueError(
"The Image batch count is greater than 1, but doesn't match the crop_image batch count. If using batches they should either match or only crop_image must be greater than 1"
)
pbar = comfy.utils.ProgressBar(4)
images = tensor2pil(image)
crop_imgs = tensor2pil(crop_image)
out_images = []
for i, crop in enumerate(crop_imgs):
if single:
img = images[0]
else:
img = images[i]
device = image.device
# uncrop the image based on the bounding box
bb_x, bb_y, bb_width, bb_height = bbox
log.debug(f"Working on device: {device}")
paste_region = bbox_to_region((bb_x, bb_y, bb_width, bb_height), img.size)
# log.debug(f"Paste region: {paste_region}")
# new_region = adjust_paste_region(img.size, paste_region)
# log.debug(f"Adjusted paste region: {new_region}")
# # Check if the adjusted paste region is different from the original
crop_image = crop_image.to(device)
crop_img = crop.convert("RGB")
if len(image) == 1 and len(crop_image) > 1:
image = image.repeat(len(crop_image), 1, 1, 1)
log.debug(f"Crop image size: {crop_img.size}")
log.debug(f"Image size: {img.size}")
batch_size, bg_h, bg_w, _ = image.shape
_, fg_h, fg_w, _ = crop_image.shape
x, y, width, height = bbox
if border_blending > 1.0:
border_blending = 1.0
elif border_blending < 0.0:
border_blending = 0.0
if (width, height) != (fg_w, fg_h):
log.warning(
f"Uncrop: crop_image size {(fg_w, fg_h)} "
"differs from bbox {(width, height)}. Resizing to fit bbox."
)
blend_ratio = (max(crop_img.size) / 2) * float(border_blending)
resized_crop = crop_image.permute(0, 3, 1, 2)
resized_crop = torch.nn.functional.interpolate(
resized_crop,
size=(height, width),
mode="bicubic",
align_corners=False,
)
resized_crop = resized_crop.permute(0, 2, 3, 1)
blend = img.convert("RGBA")
mask = Image.new("L", img.size, 0)
pbar.update(1)
# paste coords
paste_x1 = max(x, 0)
paste_y1 = max(y, 0)
paste_x2 = min(x + width, bg_w)
paste_y2 = min(y + height, bg_h)
mask_block = Image.new("L", (bb_width, bb_height), 255)
mask_block = inset_border(mask_block, int(blend_ratio / 2), (0))
# region from crop (bound)
crop_x1 = max(0, -x)
crop_y1 = max(0, -y)
crop_x2 = crop_x1 + (paste_x2 - paste_x1)
crop_y2 = crop_y1 + (paste_y2 - paste_y1)
mask.paste(mask_block, paste_region)
log.debug(f"Blend size: {blend.size} | kind {blend.mode}")
log.debug(f"Crop image size: {crop_img.size} | kind {crop_img.mode}")
log.debug(f"BBox: {paste_region}")
blend.paste(crop_img, paste_region)
if paste_x1 >= paste_x2 or paste_y1 >= paste_y2:
log.warning(
"Uncrop: BBOX is entirely outside the image boundaries. Returning original image."
)
return (image,)
mask = mask.filter(ImageFilter.BoxBlur(radius=blend_ratio / 4))
mask = mask.filter(ImageFilter.GaussianBlur(radius=blend_ratio / 4))
pbar.update(1)
source_slice = resized_crop[:, crop_y1:crop_y2, crop_x1:crop_x2, :]
blend.putalpha(mask)
img = Image.alpha_composite(img.convert("RGBA"), blend)
out_images.append(img.convert("RGB"))
final_image = image.clone()
final_image[:, paste_y1:paste_y2, paste_x1:paste_x2, :] = source_slice
return (pil2tensor(out_images),)
pbar.update(1)
blend_radius = int(max(width, height) * border_blending * 0.5)
if blend_radius > 0:
_device = device
if torch.cuda.is_available():
_device = torch.device("cuda")
log.debug("Processing blending")
alpha_mask = torch.zeros((batch_size, bg_h, bg_w), device=_device)
alpha_mask[:, paste_y1:paste_y2, paste_x1:paste_x2] = 1.0
kernel_size = 2 * blend_radius + 1
log.debug("Gaussian blur...")
alpha_mask = TF.gaussian_blur(
alpha_mask.unsqueeze(1), kernel_size=[kernel_size, kernel_size]
).squeeze(1)
alpha_mask = alpha_mask.unsqueeze(-1)
log.debug("Applying blending")
final_image = final_image.to(_device) * alpha_mask + image.to(
_device
) * (1.0 - alpha_mask)
pbar.update(1)
return (final_image.to(device),)
__nodes__ = [BboxFromMask, Bbox, Crop, Uncrop]
class MTB_BBoxForceDimensions:
"""
Resize a BBOX to new dimensions while keeping its center.
Optionally constrains the BBOX to stay within image boundaries.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"bbox": ("BBOX",),
"width": ("INT", {"default": 512, "min": 1, "max": 8192}),
"height": ("INT", {"default": 512, "min": 1, "max": 8192}),
"constrain_to_image": ("BOOLEAN", {"default": True}),
},
"optional": {
"image": ("IMAGE",),
},
}
CATEGORY = "mtb/crop"
RETURN_TYPES = ("BBOX",)
FUNCTION = "force_dimensions"
def force_dimensions(
self,
*,
bbox: tuple[int, int, int, int],
width: int,
height: int,
constrain_to_image: bool = True,
image: torch.Tensor | None = None,
) -> tuple[tuple[int, int, int, int]]:
x, y, curr_width, curr_height = bbox
center_x = x + curr_width // 2
center_y = y + curr_height // 2
new_x = center_x - width // 2
new_y = center_y - height // 2
if constrain_to_image and image is not None:
img_height, img_width = image.shape[1:3]
new_x = max(0, min(new_x, img_width - width))
new_y = max(0, min(new_y, img_height - height))
width = min(width, img_width)
height = min(height, img_height)
return ((new_x, new_y, width, height),)
__nodes__ = [
MTB_BboxFromMask,
MTB_Bbox,
MTB_Crop,
MTB_Uncrop,
MTB_SplitBbox,
MTB_UpscaleBboxBy,
MTB_BBoxForceDimensions,
]
+93
View File
@@ -0,0 +1,93 @@
import json
from ..log import log
def deserialize_curve(curve):
if isinstance(curve, str):
curve = json.loads(curve)
return curve
def serialize_curve(curve):
if not isinstance(curve, str):
curve = json.dumps(curve)
return curve
class MTB_Curve:
"""A basic FLOAT_CURVE input node."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"curve": ("FLOAT_CURVE",),
},
}
RETURN_TYPES = ("FLOAT_CURVE",)
FUNCTION = "do_curve"
CATEGORY = "mtb/curve"
def do_curve(self, curve):
log.debug(f"Curve: {curve}")
return (curve,)
class MTB_CurveToFloat:
"""Convert a FLOAT_CURVE to a FLOAT or FLOATS"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"curve": ("FLOAT_CURVE", {"forceInput": True}),
"steps": ("INT", {"default": 10, "min": 2}),
},
}
RETURN_TYPES = ("FLOATS", "FLOAT")
FUNCTION = "do_curve"
CATEGORY = "mtb/curve"
def do_curve(self, curve, steps):
log.debug(f"Curve: {curve}")
# sort by x (should be handled by the widget)
sorted_points = sorted(curve.items(), key=lambda item: item[1]["x"])
# Extract X and Y values
x_values = [point[1]["x"] for point in sorted_points]
y_values = [point[1]["y"] for point in sorted_points]
# Calculate step size
step_size = (max(x_values) - min(x_values)) / (steps - 1)
# Interpolate Y values for each step
interpolated_y_values = []
for step in range(steps):
current_x = min(x_values) + step_size * step
# Find the indices of the two points between which the current_x falls
idx1 = max(idx for idx, x in enumerate(x_values) if x <= current_x)
idx2 = min(idx for idx, x in enumerate(x_values) if x >= current_x)
# If the current_x matches one of the points, no interpolation is needed
if current_x == x_values[idx1]:
interpolated_y_values.append(y_values[idx1])
elif current_x == x_values[idx2]:
interpolated_y_values.append(y_values[idx2])
else:
# Interpolate Y value using linear interpolation
y1 = y_values[idx1]
y2 = y_values[idx2]
x1 = x_values[idx1]
x2 = x_values[idx2]
interpolated_y = y1 + (y2 - y1) * (current_x - x1) / (x2 - x1)
interpolated_y_values.append(interpolated_y)
return (interpolated_y_values, interpolated_y_values)
__nodes__ = [MTB_Curve, MTB_CurveToFloat]
+131 -37
View File
@@ -1,7 +1,7 @@
import base64
import io
import json
from pathlib import Path
from typing import Optional
import folder_paths
import torch
@@ -10,13 +10,66 @@ from ..log import log
from ..utils import tensor2pil
def get_detailed_type_info(obj):
type_info = []
type_name = type(obj).__name__
type_info.append(f"Type: {type_name}")
if isinstance(obj, torch.Tensor):
type_info.extend(
[
f"Shape: {obj.shape}",
f"Dtype: {obj.dtype}",
f"Device: {obj.device}",
f"Requires grad: {obj.requires_grad}",
f"Stride: {obj.stride()}",
f"Contiguous: {obj.is_contiguous()}",
]
)
elif isinstance(obj, (list, tuple)):
type_info.extend(
[
f"Length: {len(obj)}",
f"Container type: {type_name}",
]
)
if obj:
type_info.append(f"Element type: {type(obj[0]).__name__}")
elif isinstance(obj, dict):
type_info.extend(
[
f"Length: {len(obj)}",
f"Keys: {list(obj.keys())}",
]
)
elif hasattr(obj, "__dict__"):
attributes = [attr for attr in dir(obj) if not attr.startswith("_")]
type_info.append(f"Attributes: {attributes}")
return type_info
# region processors
def process_tensor(tensor):
def process_tensor(tensor: torch.Tensor, as_type=False):
log.debug(f"Tensor: {tensor.shape}")
if as_type:
return {
"text": [f"Tensor of shape {tensor.shape} of type {tensor.dtype}"]
}
is_mask = len(tensor.shape) == 3
if is_mask:
tensor = tensor.unsqueeze(-1).repeat(1, 1, 1, 3)
image = tensor2pil(tensor)
b64_imgs = []
for im in image:
if is_mask:
im = im.convert("L")
buffered = io.BytesIO()
im.save(buffered, format="PNG")
b64_imgs.append(
@@ -27,11 +80,16 @@ def process_tensor(tensor):
return {"b64_images": b64_imgs}
def process_list(anything):
def process_list(anything, as_type=False):
text = []
if not anything:
return {"text": []}
if as_type:
type_info = get_detailed_type_info(anything)
type_info.extend(get_detailed_type_info(anything[0]))
return {"text": type_info}
first_element = anything[0]
if (
isinstance(first_element, list)
@@ -39,42 +97,72 @@ def process_list(anything):
and isinstance(first_element[0], torch.Tensor)
):
text.append(
f"List of List of Tensors: {first_element[0].shape} (x{len(anything)})"
"List of List of Tensors: "
f"{first_element[0].shape} (x{len(anything)})"
)
elif isinstance(first_element, torch.Tensor):
text.append(f"List of Tensors: {first_element.shape} (x{len(anything)})")
text.append(
f"List of Tensors: {first_element.shape} (x{len(anything)})"
)
else:
text.append(f"Array ({len(anything)}): {anything}")
return {"text": text}
def process_dict(anything):
def process_dict(anything, as_type=False):
text = []
if as_type:
return {"text": get_detailed_type_info(anything)}
if "samples" in anything:
is_empty = "(empty)" if torch.count_nonzero(anything["samples"]) == 0 else ""
is_empty = (
"(empty)" if torch.count_nonzero(anything["samples"]) == 0 else ""
)
text.append(f"Latent Samples: {anything['samples'].shape} {is_empty}")
elif "waveform" in anything:
is_empty = (
"(empty) " if torch.count_nonzero(anything["samples"]) == 0 else ""
)
text.append(
f"Audio Samples: {anything['waveform'].shape}{is_empty} | sample rate {anything['sample_rate']}"
)
else:
log.debug(f"Unhandled dict: {anything.keys()}")
text.append(json.dumps(anything, indent=2))
return {"text": text}
def process_bool(anything):
def process_bool(anything, as_type=False):
return {"text": ["True" if anything else "False"]}
def process_text(anything):
def process_text(anything, as_type=False):
if as_type:
return {"text": get_detailed_type_info(anything)}
return {"text": [str(anything)]}
# endregion
class Debug:
"""Experimental node to debug any Comfy values, support for more types and widgets is planned"""
class MTB_Debug:
"""Experimental node to debug any Comfy values.
support for more types and widgets is planned.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {"output_to_console": ("BOOLEAN", {"default": False})},
"optional": {"as_detailed_types": ("BOOLEAN", {"default": False})},
}
RETURN_TYPES = ()
@@ -82,36 +170,34 @@ class Debug:
CATEGORY = "mtb/debug"
OUTPUT_NODE = True
def do_debug(self, output_to_console, **kwargs):
output = {
"ui": {"b64_images": [], "text": []},
# "result": ("A"),
}
def do_debug(
self, output_to_console: bool, as_detailed_types: bool, **kwargs
):
output = {"ui": {"items": []}}
processors = {
torch.Tensor: process_tensor,
list: process_list,
dict: process_dict,
bool: process_bool,
}
if output_to_console:
print("bouh!")
for k, v in kwargs.items():
log.info(f"{k}: {v}")
for anything in kwargs.values():
for input_name, anything in kwargs.items():
processor = processors.get(type(anything), process_text)
processed_data = processor(anything)
for ui_key, ui_value in processed_data.items():
output["ui"][ui_key].extend(ui_value)
# log.debug(
# f"Processed input {k}, found {len(processed_data.get('b64_images', []))} images and {len(processed_data.get('text', []))} text items."
# )
processed = processor(anything, as_detailed_types)
item = {
"input": input_name,
**processed,
}
output["ui"]["items"].append(item)
return output
class SaveTensors:
"""Save torch tensors (image, mask or latent) to disk, useful to debug things outside comfy"""
class MTB_SaveTensors:
"""Save torch tensors (image, mask or latent) to disk.
useful to debug things outside comfy.
"""
def __init__(self):
self.output_dir = folder_paths.get_output_directory()
@@ -138,9 +224,9 @@ class SaveTensors:
def save(
self,
filename_prefix,
image: Optional[torch.Tensor] = None,
mask: Optional[torch.Tensor] = None,
latent: Optional[torch.Tensor] = None,
image: torch.Tensor | None = None,
mask: torch.Tensor | None = None,
latent: torch.Tensor | None = None,
):
(
full_output_folder,
@@ -166,9 +252,17 @@ class SaveTensors:
torch.save(latent, full_output_folder / latent_file)
# pickle.dump(latent, open(full_output_folder/ latent_file, "wb"))
# np.save(full_output_folder/ latent_file, latent[""].cpu().numpy())
# np.save(full_output_folder / latent_file,
# latent[""].cpu().numpy())
return f"{filename_prefix}_{counter:05}"
__nodes__ = [Debug, SaveTensors]
processors = {
torch.Tensor: process_tensor,
list: process_list,
dict: process_dict,
bool: process_bool,
}
__nodes__ = [MTB_Debug, MTB_SaveTensors]
+115 -40
View File
@@ -2,13 +2,22 @@ import tempfile
from pathlib import Path
import numpy as np
# torch must be imported prior to onnx for the CUDAProvider.
import torch # isort:skip
import onnxruntime as ort
import torch
from PIL import Image
from ..errors import ModelNotFound
from ..log import mklog
from ..utils import get_model_path, tensor2pil, tiles_infer, tiles_merge, tiles_split
from ..utils import (
download_model,
get_model_path,
tensor2pil,
tiles_infer,
tiles_merge,
tiles_split,
)
# Disable MS telemetry
ort.disable_telemetry_events()
@@ -16,9 +25,18 @@ log = mklog(__name__)
# - COLOR to NORMALS
def color_to_normals(color_img, overlap, progress_callback, save_temp=False):
"""Computes a normal map from the given color map. 'color_img' must be a numpy array
in C,H,W format (with C as RGB). 'overlap' must be one of 'SMALL', 'MEDIUM', 'LARGE'.
def color_to_normals(
color_img,
overlap,
progress_callback,
*,
save_temp=False,
auto_download=False,
):
"""Compute a normal map from the given color map.
'color_img' must be a numpy array in C,H,W format (with C as RGB).
'overlap' must be one of 'SMALL', 'MEDIUM', 'LARGE'.
"""
temp_dir = Path(tempfile.mkdtemp()) if save_temp else None
@@ -31,7 +49,8 @@ def color_to_normals(color_img, overlap, progress_callback, save_temp=False):
)
log.debug(
f"Converting color image to grayscale by taking the mean over color channels: {img.shape}"
"Converting color image to grayscale by taking "
f"the mean over color channels: {img.shape}"
)
# Split image in tiles
@@ -56,19 +75,46 @@ def color_to_normals(color_img, overlap, progress_callback, save_temp=False):
log.debug("DeepBump Color → Normals : loading model")
model = get_model_path("deepbump", "deepbump256.onnx")
if not model or not model.exists():
raise ModelNotFound(f"deepbump ({model})")
if not auto_download:
raise ModelNotFound(f"deepbump ({model})")
log.debug("Downloading models...")
download_model(
"https://github.com/HugoTini/DeepBump/raw/master/deepbump256.onnx",
"deepbump",
)
ort_session = ort.InferenceSession(model)
providers = [
"TensorrtExecutionProvider",
"CUDAExecutionProvider",
"CoreMLProvider",
"CPUExecutionProvider",
]
available_providers = [
provider
for provider in providers
if provider in ort.get_available_providers()
]
if not available_providers:
raise RuntimeError(
"No valid ONNX Runtime providers available on this machine."
)
log.debug(f"Using ONNX providers: {available_providers}")
ort_session = ort.InferenceSession(
model.as_posix(), providers=available_providers
)
# Predict normal map for each tile
log.debug("DeepBump Color → Normals : generating")
pred_tiles = tiles_infer(tiles, ort_session, progress_callback=progress_callback)
pred_tiles = tiles_infer(
tiles, ort_session, progress_callback=progress_callback
)
if temp_dir:
for i, pred_tile in enumerate(pred_tiles):
Image.fromarray((pred_tile.transpose(1, 2, 0) * 255).astype(np.uint8)).save(
temp_dir / f"pred_tile_{i}.png"
)
Image.fromarray(
(pred_tile.transpose(1, 2, 0) * 255).astype(np.uint8)
).save(temp_dir / f"pred_tile_{i}.png")
# Merge tiles
log.debug("DeepBump Color → Normals : merging")
@@ -80,17 +126,17 @@ def color_to_normals(color_img, overlap, progress_callback, save_temp=False):
)
if temp_dir:
Image.fromarray((pred_img.transpose(1, 2, 0) * 255).astype(np.uint8)).save(
temp_dir / "merged_img.png"
)
Image.fromarray(
(pred_img.transpose(1, 2, 0) * 255).astype(np.uint8)
).save(temp_dir / "merged_img.png")
# Normalize each pixel to unit vector
pred_img = normalize(pred_img)
if temp_dir:
Image.fromarray((pred_img.transpose(1, 2, 0) * 255).astype(np.uint8)).save(
temp_dir / "final_img.png"
)
Image.fromarray(
(pred_img.transpose(1, 2, 0) * 255).astype(np.uint8)
).save(temp_dir / "final_img.png")
log.debug(f"Debug images saved in {temp_dir}")
@@ -99,40 +145,47 @@ def color_to_normals(color_img, overlap, progress_callback, save_temp=False):
# - NORMALS to CURVATURE
def conv_1d(array, kernel_1d):
"""Performs row by row 1D convolutions of the given 2D image with the given 1D kernel."""
"""Perform row by row 1D convolutions.
of the given 2D image with the given 1D kernel.
"""
# Input kernel length must be odd
k_l = len(kernel_1d)
assert k_l % 2 != 0
# Convolution is repeat-padded
extended = np.pad(array, k_l // 2, mode="wrap")
# Output has same size as input (padded, valid-mode convolution)
output = np.empty(array.shape)
for i in range(array.shape[0]):
output[i] = np.convolve(extended[i + (k_l // 2)], kernel_1d, mode="valid")
output[i] = np.convolve(
extended[i + (k_l // 2)], kernel_1d, mode="valid"
)
return output * -1
def gaussian_kernel(length, sigma):
"""Returns a 1D gaussian kernel of size 'length'."""
"""Return a 1D gaussian kernel of size 'length'."""
space = np.linspace(-(length - 1) / 2, (length - 1) / 2, length)
kernel = np.exp(-0.5 * np.square(space) / np.square(sigma))
return kernel / np.sum(kernel)
def normalize(np_array):
"""Normalize all elements of the given numpy array to [0,1]"""
return (np_array - np.min(np_array)) / (np.max(np_array) - np.min(np_array))
"""Normalize all elements of the given numpy array to [0,1]."""
return (np_array - np.min(np_array)) / (
np.max(np_array) - np.min(np_array)
)
def normals_to_curvature(normals_img, blur_radius, progress_callback):
"""Computes a curvature map from the given normal map. 'normals_img' must be a numpy array
in C,H,W format (with C as RGB). 'blur_radius' must be one of 'SMALLEST', 'SMALLER', 'SMALL',
'MEDIUM', 'LARGE', 'LARGER', 'LARGEST'."""
"""Compute a curvature map from the given normal map.
'normals_img' must be a numpy array in C,H,W format (with C as RGB).
'blur_radius' must be one of:
'SMALLEST', 'SMALLER', 'SMALL', 'MEDIUM', 'LARGE', 'LARGER', 'LARGEST'.
"""
# Convolutions on normal map red & green channels
if progress_callback is not None:
progress_callback(0, 4)
@@ -157,8 +210,12 @@ def normals_to_curvature(normals_img, blur_radius, progress_callback):
"LARGER": 1 / 8,
"LARGEST": 1 / 4,
}
assert blur_radius in blur_factors
blur_radius_px = int(np.mean(normals_img.shape[1:3]) * blur_factors[blur_radius])
if blur_radius not in blur_factors:
raise ValueError(f"{blur_radius} not found in {blur_factors}")
blur_radius_px = int(
np.mean(normals_img.shape[1:3]) * blur_factors[blur_radius]
)
# If blur radius too small, do not blur
if blur_radius_px < 2:
@@ -195,8 +252,9 @@ def normals_to_grad(normals_img):
def copy_flip(grad_x, grad_y):
"""Concat 4 flipped copies of input gradients (makes them wrap).
Output is twice bigger in both dimensions."""
Output is twice bigger in both dimensions.
"""
grad_x_top = np.hstack([grad_x, -np.flip(grad_x, axis=1)])
grad_x_bottom = np.hstack([np.flip(grad_x, axis=0), -np.flip(grad_x)])
new_grad_x = np.vstack([grad_x_top, grad_x_bottom])
@@ -210,7 +268,6 @@ def copy_flip(grad_x, grad_y):
def frankot_chellappa(grad_x, grad_y, progress_callback=None):
"""Frankot-Chellappa depth-from-gradient algorithm."""
if progress_callback is not None:
progress_callback(0, 3)
@@ -250,8 +307,8 @@ def frankot_chellappa(grad_x, grad_y, progress_callback=None):
def normals_to_height(normals_img, seamless, progress_callback):
"""Computes a height map from the given normal map. 'normals_img' must be a numpy array
in C,H,W format (with C as RGB). 'seamless' is a bool that should indicates if 'normals_img'
is seamless."""
is seamless.
"""
# Flip height axis
flip_img = np.flip(normals_img, axis=1)
@@ -265,7 +322,9 @@ def normals_to_height(normals_img, seamless, progress_callback):
grad_x, grad_y = copy_flip(grad_x, grad_y)
# Compute height
pred_img = frankot_chellappa(-grad_x, grad_y, progress_callback=progress_callback)
pred_img = frankot_chellappa(
-grad_x, grad_y, progress_callback=progress_callback
)
# Cut to valid part if gradients were expanded
if not seamless:
@@ -277,7 +336,7 @@ def normals_to_height(normals_img, seamless, progress_callback):
# - ADDON
class DeepBump:
class MTB_DeepBump:
"""Normal & height maps generation from single pictures"""
@classmethod
@@ -286,7 +345,11 @@ class DeepBump:
"required": {
"image": ("IMAGE",),
"mode": (
["Color to Normals", "Normals to Curvature", "Normals to Height"],
[
"Color to Normals",
"Normals to Curvature",
"Normals to Height",
],
),
"color_to_normals_overlap": (["SMALL", "MEDIUM", "LARGE"],),
"normals_to_curvature_blur_radius": (
@@ -302,6 +365,9 @@ class DeepBump:
),
"normals_to_height_seamless": ("BOOLEAN", {"default": True}),
},
"optional": {
"auto_download": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("IMAGE",)
@@ -311,11 +377,13 @@ class DeepBump:
def apply(
self,
*,
image,
mode="Color to Normals",
color_to_normals_overlap="SMALL",
normals_to_curvature_blur_radius="SMALL",
normals_to_height_seamless=True,
auto_download=False,
):
images = tensor2pil(image)
out_images = []
@@ -329,13 +397,20 @@ class DeepBump:
# Apply processing
if mode == "Color to Normals":
out_img = color_to_normals(in_img, color_to_normals_overlap, None)
out_img = color_to_normals(
in_img,
color_to_normals_overlap,
None,
auto_download=auto_download,
)
if mode == "Normals to Curvature":
out_img = normals_to_curvature(
in_img, normals_to_curvature_blur_radius, None
)
if mode == "Normals to Height":
out_img = normals_to_height(in_img, normals_to_height_seamless, None)
out_img = normals_to_height(
in_img, normals_to_height_seamless, None
)
if out_img is not None:
log.debug(f"Output image shape: {out_img.shape}")
@@ -351,4 +426,4 @@ class DeepBump:
return (torch.cat(out_images, dim=0),)
__nodes__ = [DeepBump]
__nodes__ = [MTB_DeepBump]
+62 -24
View File
@@ -1,6 +1,4 @@
import os
from pathlib import Path
from typing import Tuple
import comfy
import comfy.utils
@@ -9,14 +7,13 @@ import folder_paths
import numpy as np
import torch
from comfy import model_management
from gfpgan import GFPGANer
from PIL import Image
from ..log import NullWriter, log
from ..utils import get_model_path, np2tensor, pil2tensor, tensor2np
class LoadFaceEnhanceModel:
class MTB_LoadFaceEnhanceModel:
"""Loads a GFPGan or RestoreFormer model for face enhancement."""
def __init__(self) -> None:
@@ -37,15 +34,17 @@ class LoadFaceEnhanceModel:
fr_models_path, um_models_path = cls.get_models_root()
if fr_models_path is None and um_models_path is None:
log.warning("Face restoration models not found.")
if not hasattr(cls, "_warned"):
log.warning("Face restoration models not found.")
cls._warned = True
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"
)
# 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
@@ -79,8 +78,11 @@ class LoadFaceEnhanceModel:
RETURN_NAMES = ("model",)
FUNCTION = "load_model"
CATEGORY = "mtb/facetools"
DEPRECATED = True
def load_model(self, model_name, upscale=2, bg_upsampler=None):
from gfpgan import GFPGANer
basic = "RestoreFormer" not in model_name
fr_root, um_root = self.get_models_root()
@@ -98,7 +100,9 @@ class LoadFaceEnhanceModel:
(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
arch="clean"
if basic
else "RestoreFormer", # or original for v1.0 only
channel_multiplier=2, # 1 for v1.0 only
bg_upsampler=bg_upsampler,
)
@@ -122,7 +126,11 @@ class BGUpscaleWrapper:
imgt = imgt.movedim(-1, -3).to(device)
steps = imgt.shape[0] * comfy.utils.get_tiled_scale_steps(
imgt.shape[3], imgt.shape[2], tile_x=tile, tile_y=tile, overlap=overlap
imgt.shape[3],
imgt.shape[2],
tile_x=tile,
tile_y=tile,
overlap=overlap,
)
log.debug(f"Steps: {steps}")
@@ -147,7 +155,7 @@ class BGUpscaleWrapper:
import sys
class RestoreFace:
class MTB_RestoreFace:
"""Uses GFPGan to restore faces"""
def __init__(self) -> None:
@@ -156,6 +164,7 @@ class RestoreFace:
RETURN_TYPES = ("IMAGE",)
FUNCTION = "restore"
CATEGORY = "mtb/facetools"
DEPRECATED = True
@classmethod
def INPUT_TYPES(cls):
@@ -170,22 +179,33 @@ class RestoreFace:
# Adjustable weights
"weight": ("FLOAT", {"default": 0.5}),
"save_tmp_steps": ("BOOLEAN", {"default": True}),
}
},
"optional": {
"preserve_alpha": ("BOOLEAN", {"default": True}),
},
}
def do_restore(
self,
image: torch.Tensor,
model: GFPGANer,
model,
aligned,
only_center_face,
weight,
save_tmp_steps,
preserve_alpha: bool = False,
) -> torch.Tensor:
pimage = tensor2np(image)[0]
width, height = pimage.shape[1], pimage.shape[0]
source_img = cv2.cvtColor(np.array(pimage), cv2.COLOR_RGB2BGR)
alpha_channel = None
if (
preserve_alpha and image.size(-1) == 4
): # Check if the image has an alpha channel
alpha_channel = pimage[:, :, 3]
pimage = pimage[:, :, :3] # Remove alpha channel for processing
sys.stdout = NullWriter()
cropped_faces, restored_faces, restored_img = model.enhance(
source_img,
@@ -199,10 +219,19 @@ class RestoreFace:
log.warning(f"Weight value has no effect for now. (value: {weight})")
if save_tmp_steps:
self.save_intermediate_images(cropped_faces, restored_faces, height, width)
self.save_intermediate_images(
cropped_faces, restored_faces, height, width
)
output = None
if restored_img is not None:
output = Image.fromarray(cv2.cvtColor(restored_img, cv2.COLOR_BGR2RGB))
restored_img = cv2.cvtColor(restored_img, cv2.COLOR_BGR2RGB)
output = Image.fromarray(restored_img)
if alpha_channel is not None:
alpha_resized = Image.fromarray(alpha_channel).resize(
output.size, Image.LANCZOS
)
output.putalpha(alpha_resized)
# imwrite(restored_img, save_restore_path)
return pil2tensor(output)
@@ -210,15 +239,22 @@ class RestoreFace:
def restore(
self,
image: torch.Tensor,
model: GFPGANer,
model,
aligned=False,
only_center_face=False,
weight=0.5,
save_tmp_steps=True,
) -> Tuple[torch.Tensor]:
preserve_alpha: bool = False,
) -> tuple[torch.Tensor]:
out = [
self.do_restore(
image[i], model, aligned, only_center_face, weight, save_tmp_steps
image[i],
model,
aligned,
only_center_face,
weight,
save_tmp_steps,
preserve_alpha,
)
for i in range(image.size(0))
]
@@ -240,9 +276,11 @@ class RestoreFace:
return os.path.join(full_output_folder, file)
def save_intermediate_images(self, cropped_faces, restored_faces, height, width):
def save_intermediate_images(
self, cropped_faces, restored_faces, height, width
):
for idx, (cropped_face, restored_face) in enumerate(
zip(cropped_faces, restored_faces)
zip(cropped_faces, restored_faces, strict=False)
):
face_id = idx + 1
file = self.get_step_image_path("cropped_faces", face_id)
@@ -258,4 +296,4 @@ class RestoreFace:
cv2.imwrite(file, cmp_img)
__nodes__ = [RestoreFace, LoadFaceEnhanceModel]
__nodes__ = [MTB_RestoreFace, MTB_LoadFaceEnhanceModel]
+59 -24
View File
@@ -2,15 +2,10 @@
# region imports
import sys
from pathlib import Path
from typing import List, Optional, Set, Union
import comfy.model_management as model_management
import cv2
import insightface
import numpy as np
import onnxruntime
import torch
from insightface.model_zoo.inswapper import INSwapper
from PIL import Image
from ..errors import ModelNotFound
@@ -22,7 +17,7 @@ from ..utils import download_antelopev2, get_model_path, pil2tensor, tensor2pil
log = mklog(__name__)
class LoadFaceAnalysisModel:
class MTB_LoadFaceAnalysisModel:
"""Loads a face analysis model"""
models = []
@@ -41,25 +36,31 @@ class LoadFaceAnalysisModel:
RETURN_TYPES = ("FACE_ANALYSIS_MODEL",)
FUNCTION = "load_model"
CATEGORY = "mtb/facetools"
DEPRECATED = True
def load_model(self, faceswap_model: str):
import insightface
if faceswap_model == "antelopev2":
download_antelopev2()
face_analyser = insightface.app.FaceAnalysis(
name=faceswap_model,
root=get_model_path("insightface"),
root=get_model_path("insightface").as_posix(),
)
return (face_analyser,)
class LoadFaceSwapModel:
class MTB_LoadFaceSwapModel:
"""Loads a faceswap model"""
@staticmethod
def get_models() -> List[Path]:
models_path = get_model_path("insightface").iterdir()
return [x for x in models_path if x.suffix in [".onnx", ".pth"]]
def get_models() -> list[Path]:
models_path = get_model_path("insightface")
if models_path.exists():
models = models_path.iterdir()
return [x for x in models if x.suffix in [".onnx", ".pth"]]
return []
@classmethod
def INPUT_TYPES(cls):
@@ -75,8 +76,12 @@ class LoadFaceSwapModel:
RETURN_TYPES = ("FACESWAP_MODEL",)
FUNCTION = "load_model"
CATEGORY = "mtb/facetools"
DEPRECATED = True
def load_model(self, faceswap_model: str):
import onnxruntime
from insightface.model_zoo.inswapper import INSwapper
model_path = get_model_path("insightface", faceswap_model)
if not model_path or not model_path.exists():
raise ModelNotFound(f"{faceswap_model} ({model_path})")
@@ -94,7 +99,7 @@ class LoadFaceSwapModel:
# region roop node
class FaceSwap:
class MTB_FaceSwap:
"""Face swap using deepinsight/insightface models"""
model = None
@@ -110,15 +115,21 @@ class FaceSwap:
"image": ("IMAGE",),
"reference": ("IMAGE",),
"faces_index": ("STRING", {"default": "0"}),
"faceanalysis_model": ("FACE_ANALYSIS_MODEL", {"default": "None"}),
"faceanalysis_model": (
"FACE_ANALYSIS_MODEL",
{"default": "None"},
),
"faceswap_model": ("FACESWAP_MODEL", {"default": "None"}),
},
"optional": {},
"optional": {
"preserve_alpha": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "swap"
CATEGORY = "mtb/facetools"
DEPRECATED = True
def swap(
self,
@@ -127,17 +138,30 @@ class FaceSwap:
faces_index: str,
faceanalysis_model,
faceswap_model,
preserve_alpha=False,
):
def do_swap(img):
model_management.throw_exception_if_processing_interrupted()
img = tensor2pil(img)[0]
ref = tensor2pil(reference)[0]
alpha_channel = None
if preserve_alpha and img.mode == "RGBA":
alpha_channel = img.getchannel("A")
img = img.convert("RGB")
face_ids = {
int(x) for x in faces_index.strip(",").split(",") if x.isnumeric()
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__
if alpha_channel:
swapped.putalpha(alpha_channel)
return pil2tensor(swapped)
batch_count = image.size(0)
@@ -170,7 +194,10 @@ def get_face_single(
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
face_analyser,
img_data,
face_index=face_index,
det_size=det_size_half,
)
try:
@@ -181,11 +208,13 @@ def get_face_single(
def swap_face(
face_analyser,
source_img: Union[Image.Image, List[Image.Image]],
target_img: Union[Image.Image, List[Image.Image]],
source_img: Image.Image | list[Image.Image],
target_img: Image.Image | list[Image.Image],
face_swapper_model,
faces_index: Optional[Set[int]] = None,
faces_index: set[int] | None = None,
) -> Image.Image:
import cv2
if faces_index is None:
faces_index = {0}
log.debug(f"Swapping faces: {faces_index}")
@@ -194,7 +223,9 @@ 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
@@ -204,12 +235,16 @@ def swap_face(
)
if target_face is not None:
sys.stdout = NullWriter()
result = face_swapper_model.get(result, target_face, source_face)
result = face_swapper_model.get(
result, target_face, source_face
)
sys.stdout = sys.__stdout__
else:
log.warning(f"No target face found for {face_num}")
result_image = Image.fromarray(cv2.cvtColor(result, cv2.COLOR_BGR2RGB))
result_image = Image.fromarray(
cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
)
else:
log.warning("No source face found")
else:
@@ -220,4 +255,4 @@ def swap_face(
# endregion face swap utils
__nodes__ = [FaceSwap, LoadFaceSwapModel, LoadFaceAnalysisModel]
__nodes__ = [MTB_FaceSwap, MTB_LoadFaceSwapModel, MTB_LoadFaceAnalysisModel]
+69
View File
@@ -0,0 +1,69 @@
import torch
class MTB_FilterZ:
"""Filters an image based on a depth map"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
"depth": ("IMAGE",),
"to_black": ("BOOLEAN", {"default": True}),
"threshold": (
"FLOAT",
{"default": 0.5, "step": 0.01, "min": 0.0, "max": 1.0},
),
"invert": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "filter"
CATEGORY = "mtb/filters"
def filter(
self,
image: torch.Tensor,
depth: torch.Tensor,
to_black,
threshold: float,
invert,
):
# Normalize depth map to be in range [0, 1]
depth_normalized = (depth - depth.min()) / (depth.max() - depth.min())
# Calculate the difference from the threshold
diff_from_threshold = torch.abs(depth_normalized - threshold)
out_img = None
if to_black:
if invert:
soft_mask = diff_from_threshold >= threshold
else:
soft_mask = diff_from_threshold <= threshold
out_img = image.clone()
out_img[soft_mask] = 0
return (out_img,)
else:
alpha_channel = 1 - diff_from_threshold / threshold
alpha_channel = torch.clamp(alpha_channel, 0, 1)
if invert:
# Invert the alpha channel
alpha_channel = 1 - alpha_channel
# Ensure alpha_channel has the correct shape
# It should have the shape [batch_size, height, width, 1]
alpha_channel = alpha_channel.unsqueeze(-1)
# Combine RGB channels with alpha channel
out_img = torch.cat((image, alpha_channel), dim=-1)
return (out_img,)
__nodes__ = [MTB_FilterZ]
+271 -119
View File
@@ -1,9 +1,11 @@
import qrcode
from ..utils import pil2tensor
from ..utils import comfy_dir
from typing import cast
from PIL import Image
import io
import requests
import torch
from PIL import Image, ImageDraw, ImageFont
from ..log import log
from ..utils import comfy_dir, font_path, pil2tensor
# class MtbExamples:
# """MTB Example Images"""
@@ -53,16 +55,25 @@ from ..log import log
# return m.digest().hex()
class UnsplashImage:
class MTB_UnsplashImage:
"""Unsplash Image given a keyword and a size"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"width": ("INT", {"default": 512, "max": 8096, "min": 0, "step": 1}),
"height": ("INT", {"default": 512, "max": 8096, "min": 0, "step": 1}),
"random_seed": ("INT", {"default": 0, "max": 1e5, "min": 0, "step": 1}),
"width": (
"INT",
{"default": 512, "max": 8096, "min": 0, "step": 1},
),
"height": (
"INT",
{"default": 512, "max": 8096, "min": 0, "step": 1},
),
"random_seed": (
"INT",
{"default": 0, "max": 1e5, "min": 0, "step": 1},
),
},
"optional": {
"keyword": ("STRING", {"default": "nature"}),
@@ -74,9 +85,6 @@ class UnsplashImage:
CATEGORY = "mtb/generate"
def do_unsplash_image(self, width, height, random_seed, keyword=None):
import requests
import io
base_url = "https://source.unsplash.com/random/"
if width and height:
@@ -104,66 +112,6 @@ class UnsplashImage:
return (None,)
class QrCode:
"""Basic QR Code generator"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"url": ("STRING", {"default": "https://www.github.com"}),
"width": (
"INT",
{"default": 256, "max": 8096, "min": 0, "step": 1},
),
"height": (
"INT",
{"default": 256, "max": 8096, "min": 0, "step": 1},
),
"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": (("BOOLEAN",), {"default": False}),
}
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "do_qr"
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":
error_correct = qrcode.constants.ERROR_CORRECT_M
elif error_correct == "Q":
error_correct = qrcode.constants.ERROR_CORRECT_Q
else:
error_correct = qrcode.constants.ERROR_CORRECT_H
qr = qrcode.QRCode(
version=1,
error_correction=error_correct,
box_size=box_size,
border=border,
)
qr.add_data(url)
qr.make(fit=True)
back_color = (255, 255, 255) if invert else (0, 0, 0)
fill_color = (0, 0, 0) if invert else (255, 255, 255)
code = img = qr.make_image(back_color=back_color, fill_color=fill_color)
# that we now resize without filtering
code = code.resize((width, height), Image.NEAREST)
return (pil2tensor(code),)
def bbox_dim(bbox):
left, upper, right, lower = bbox
width = right - left
@@ -171,37 +119,46 @@ def bbox_dim(bbox):
return width, height
class TextToImage:
"""Utils to convert text to image using a font
# TODO: Auto install the base font to ComfyUI/fonts
class MTB_TextToImage:
"""Utils to convert text to image using a font.
The tool looks for any .ttf file in the Comfy folder hierarchy.
"""
fonts = {}
DESCRIPTION = """# Text to Image
This node look for any font files in comfy_dir/fonts.
by default it fallsback to a default font.
![img](https://i.imgur.com/3GT92hy.gif)
"""
def __init__(self):
# - This is executed when the graph is executed, we could conditionaly reload fonts there
# - 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 = []
fonts = [font_path]
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")
try:
if comfy_dir.exists():
fonts.extend(comfy_dir.glob(f"fonts/**/{extension}"))
else:
log.warn(f"Directory {comfy_dir} does not exist.")
except Exception as e:
log.error(f"Error during font caching: {e}")
for font in fonts:
log.debug(f"Adding font {font}")
cls.fonts[font.stem] = font.as_posix()
MTB_TextToImage.fonts[font.stem] = font.as_posix()
@classmethod
def INPUT_TYPES(cls):
@@ -216,13 +173,15 @@ class TextToImage:
{"default": "Hello world!"},
),
"font": ((sorted(cls.fonts.keys())),),
"wrap": (
"INT",
{"default": 120, "min": 0, "max": 8096, "step": 1},
"wrap": ("BOOLEAN", {"default": True}),
"trim": ("BOOLEAN", {"default": True}),
"line_height": (
"FLOAT",
{"default": 1.0, "min": 0, "step": 0.1},
),
"font_size": (
"INT",
{"default": 12, "min": 1, "max": 2500, "step": 1},
{"default": 32, "min": 1, "max": 2500, "step": 1},
),
"width": (
"INT",
@@ -232,55 +191,248 @@ class TextToImage:
"INT",
{"default": 512, "min": 1, "max": 8096, "step": 1},
),
# "position": (["INT"], {"default": 0, "min": 0, "max": 100, "step": 1}),
"color": (
"COLOR",
{"default": "black"},
{"default": "black", "widgetType": "MTB_COLOR"},
),
"background": (
"COLOR",
{"default": "white"},
{"default": "white", "widgetType": "MTB_COLOR"},
),
}
"h_align": (("left", "center", "right"), {"default": "left"}),
"v_align": (("top", "center", "bottom"), {"default": "top"}),
"h_offset": (
"INT",
{"default": 0, "min": 0, "max": 8096, "step": 1},
),
"v_offset": (
"INT",
{"default": 0, "min": 0, "max": 8096, "step": 1},
),
"h_coverage": (
"INT",
{"default": 100, "min": 1, "max": 100, "step": 1},
),
},
"optional": {
"whisper_chunks": ("WHISPER_CHUNKS",),
"fps": (
"INT",
{"default": 24, "min": 1, "max": 60, "step": 1},
),
"fade_duration": (
"FLOAT",
{"default": 0.5, "min": 0.0, "max": 5.0, "step": 0.1},
),
},
}
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
def create_animation_frames(
self,
chunks,
base_image,
font,
font_size,
color,
width,
height,
fps,
fade_duration,
):
from PIL import Image, ImageDraw, ImageFont
"""Create animation frames from Whisper chunks."""
if not chunks or not chunks.get("chunks"):
return [base_image]
frames = []
total_duration = chunks["chunks"][-1]["timestamp"][1]
frame_count = int(total_duration * fps)
fade_frames = int(fade_duration * fps)
for frame_idx in range(frame_count):
time = frame_idx / fps
frame = base_image.copy()
draw = ImageDraw.Draw(frame)
active_chunks = []
for chunk in chunks["chunks"]:
start, end = chunk["timestamp"]
if start <= time <= end:
fade_in_alpha = min(
1.0, (time - start) * fps / fade_frames
)
fade_out_alpha = min(1.0, (end - time) * fps / fade_frames)
alpha = min(fade_in_alpha, fade_out_alpha)
active_chunks.append((chunk["text"], alpha))
y = height // 4
for text, alpha in active_chunks:
# Create a temporary image for the text with alpha
text_img = Image.new("RGBA", (width, height), (0, 0, 0, 0))
text_draw = ImageDraw.Draw(text_img)
text_draw.text(
(width // 2, y),
text,
font=font,
fill=color,
anchor="mm",
)
text_img.putalpha(
Image.fromarray(
(torch.ones((height, width)) * (alpha * 255))
.byte()
.numpy()
)
)
frame = Image.alpha_composite(frame, text_img)
y += font_size * 1.5
frames.append(frame)
return frames
def text_to_image(
self,
text: str,
font,
wrap,
trim,
line_height,
font_size,
width,
height,
color,
background,
h_align="left",
v_align="top",
h_offset=0,
v_offset=0,
h_coverage=100,
whisper_chunks=None,
fps=24,
fade_duration=0.5,
):
"""Convert text to image, with optional animation support."""
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)
from PIL import ImageColor
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
font_path = self.fonts[font]
font = ImageFont.truetype(font_path, size=font_size)
# img.save(os.path.join(folder_paths.base_path, f'{str(uuid.uuid4())}.png'))
return (pil2tensor(img),)
try:
if isinstance(color, str):
color = ImageColor.getrgb(color)
if isinstance(background, str):
background = ImageColor.getrgb(background)
if len(color) == 3:
color = color + (255,)
if len(background) == 3:
background = background + (255,)
except ValueError as e:
log.error(f"Color parsing error: {e}")
color = (255, 255, 255, 255)
background = (0, 0, 0, 255)
def render_text(text_to_render, alpha=None):
if trim:
text_to_render = text_to_render.strip()
if wrap:
wrap_width = (((width / 100) * h_coverage) / font_size) * 2
lines = textwrap.wrap(text_to_render, width=wrap_width)
else:
lines = [text_to_render]
img = Image.new("RGBA", (width, height), (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
line_height_px = line_height * font_size
if v_align == "top":
y_text = v_offset
elif v_align == "center":
y_text = (
(height - (line_height_px * len(lines))) // 2
) + v_offset
else:
y_text = (height - (line_height_px * len(lines))) - v_offset
def get_width(line):
if hasattr(font, "getsize"):
return font.getsize(line)[0]
else:
return font.getlength(line)
for line in lines:
line_width = get_width(line)
if h_align == "left":
x_text = h_offset
elif h_align == "center":
x_text = ((width - line_width) // 2) + h_offset
else:
x_text = (width - line_width) - h_offset
text_color = color
if alpha is not None:
text_color = tuple(
list(color[:3]) + [int(alpha * color[3])]
)
draw.text((x_text, y_text), line, fill=text_color, font=font)
y_text += line_height_px
return img
base_img = Image.new("RGBA", (width, height), background)
if whisper_chunks and whisper_chunks.get("chunks"):
frames = []
total_duration = whisper_chunks["chunks"][-1]["timestamp"][1]
frame_count = int(total_duration * fps)
fade_frames = int(fade_duration * fps)
for frame_idx in range(frame_count):
time = frame_idx / fps
frame = base_img.copy()
active_chunks = []
for chunk in whisper_chunks["chunks"]:
start, end = chunk["timestamp"]
if start <= time <= end:
fade_in_alpha = min(
1.0, (time - start) * fps / fade_frames
)
fade_out_alpha = min(
1.0, (end - time) * fps / fade_frames
)
alpha = min(fade_in_alpha, fade_out_alpha)
active_chunks.append((chunk["text"], alpha))
for chunk_text, alpha in active_chunks:
chunk_img = render_text(
chunk_text.encode("ascii", "ignore").decode(), alpha
)
frame = Image.alpha_composite(frame, chunk_img)
frames.append(frame)
frame_tensors = [pil2tensor(frame) for frame in frames]
return (torch.cat(frame_tensors, dim=0),)
else:
text_img = render_text(text)
result = Image.alpha_composite(base_img, text_img)
return (pil2tensor(result),)
__nodes__ = [
QrCode,
UnsplashImage,
TextToImage
MTB_UnsplashImage,
MTB_TextToImage,
# MtbExamples,
]
+680 -70
View File
@@ -1,14 +1,27 @@
import io
import json
import re
import urllib.parse
import urllib.request
from math import pi
from typing import Any
import comfy.model_management as model_management
import comfy.utils
import numpy as np
import torch
from comfy.comfy_types.node_typing import IO as CIO
from PIL import Image
from ..log import log
from ..utils import apply_easing, get_server_info, pil2tensor
from ..utils import (
EASINGS,
apply_easing,
get_server_info,
numpy_NFOV,
pil2tensor,
tensor2np,
)
def get_image(filename, subfolder, folder_type):
@@ -25,10 +38,322 @@ def get_image(filename, subfolder, folder_type):
return io.BytesIO(response.read())
class GetBatchFromHistory:
class MTB_ToDevice:
"""Send a image or mask tensor to the given device."""
@classmethod
def INPUT_TYPES(cls):
devices = ["cpu"]
if torch.backends.mps.is_available():
devices.append("mps")
if torch.cuda.is_available():
devices.append("cuda:0")
for i in range(1, torch.cuda.device_count()):
devices.append(f"cuda:{i}")
devices.append("cuda")
return {
"required": {
"ignore_errors": ("BOOLEAN", {"default": False}),
"device": (
devices,
{
"default": "cuda"
if torch.cuda.is_available()
else "cpu"
},
),
},
"optional": {
"image": ("IMAGE",),
"mask": ("MASK",),
},
}
RETURN_TYPES = ("IMAGE", "MASK")
RETURN_NAMES = ("images", "masks")
CATEGORY = "mtb/utils"
FUNCTION = "to_device"
def to_device(
self,
*,
ignore_errors: bool = False,
device: str = "cuda",
image: torch.Tensor | None = None,
mask: torch.Tensor | None = None,
):
if not ignore_errors and image is None and mask is None:
raise ValueError(
"You must either provide an image or a mask,"
+ " use ignore_error to passthrough"
)
if (
device.startswith("cuda")
and ":" not in device
and device != "cuda"
):
device = f"cuda:{device[4:]}"
try:
if image is not None:
image = image.to(device)
if mask is not None:
mask = mask.to(device)
except RuntimeError as e:
if not ignore_errors:
raise RuntimeError(
f"Failed to move tensor to device {device}: {str(e)}"
) from e
log.warning(
f"Failed to move tensor to device {device}, ignoring: {str(e)}"
)
return (image, mask)
# class MTB_ApplyTextTemplate:
class MTB_ApplyTextTemplate:
"""
Experimental node to interpolate strings from inputs.
Interpolation just requires {}, for instance:
Some string {var_1} and {var_2}
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"template": ("STRING", {"default": "", "multiline": True}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("string",)
CATEGORY = "mtb/utils"
FUNCTION = "execute"
def execute(self, *, template: str, **kwargs):
res = f"{template}"
for k, v in kwargs.items():
res = res.replace(f"{{{k}}}", f"{v}")
return (res,)
class MTB_MatchDimensions:
"""Match images dimensions along the given dimension, preserving aspect ratio."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"source": ("IMAGE",),
"reference": ("IMAGE",),
"match": (["height", "width"], {"default": "height"}),
},
}
RETURN_TYPES = ("IMAGE", "INT", "INT")
RETURN_NAMES = ("image", "new_width", "new_height")
CATEGORY = "mtb/utils"
FUNCTION = "execute"
def execute(
self, source: torch.Tensor, reference: torch.Tensor, match: str
):
import torchvision.transforms.functional as VF
_batch_size, height, width, _channels = source.shape
_rbatch_size, rheight, rwidth, _rchannels = reference.shape
source_aspect_ratio = width / height
# reference_aspect_ratio = rwidth / rheight
source = source.permute(0, 3, 1, 2)
reference = reference.permute(0, 3, 1, 2)
if match == "height":
new_height = rheight
new_width = int(rheight * source_aspect_ratio)
else:
new_width = rwidth
new_height = int(rwidth / source_aspect_ratio)
resized_images = [
VF.resize(
source[i],
(new_height, new_width),
antialias=True,
interpolation=Image.BICUBIC,
)
for i in range(_batch_size)
]
resized_source = torch.stack(resized_images, dim=0)
resized_source = resized_source.permute(0, 2, 3, 1)
return (resized_source, new_width, new_height)
class MTB_FloatToFloats:
"""Conversion utility for compatibility with other extensions (AD, IPA, Fitz are using FLOAT to represent list of floats.)"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"float": ("FLOAT", {"default": 0.0, "forceInput": True}),
}
}
RETURN_TYPES = ("FLOATS",)
RETURN_NAMES = ("floats",)
CATEGORY = "mtb/utils"
FUNCTION = "convert"
def convert(self, float: float):
return (float,)
class MTB_FloatsToInts:
"""Conversion utility for compatibility with frame interpolation."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"floats": ("FLOATS", {"forceInput": True}),
}
}
RETURN_TYPES = ("INTS", "INT")
CATEGORY = "mtb/utils"
FUNCTION = "convert"
def convert(self, floats: list[float]):
vals = [int(x) for x in floats]
return (vals, vals)
class MTB_FloatsToFloat:
"""Conversion utility for compatibility with other extensions (AD, IPA, Fitz are using FLOAT to represent list of floats.)"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"floats": ("FLOATS",),
}
}
RETURN_TYPES = ("FLOAT",)
RETURN_NAMES = ("float",)
CATEGORY = "mtb/utils"
FUNCTION = "convert"
def convert(self, floats):
return (floats,)
class MTB_AutoPanEquilateral:
"""Generate a 360 panning video from an equilateral image."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"equilateral_image": ("IMAGE",),
"fovX": ("FLOAT", {"default": 45.0}),
"fovY": ("FLOAT", {"default": 45.0}),
"elevation": ("FLOAT", {"default": 0.5}),
"frame_count": ("INT", {"default": 100}),
"width": ("INT", {"default": 768}),
"height": ("INT", {"default": 512}),
},
"optional": {
"floats_fovX": ("FLOATS",),
"floats_fovY": ("FLOATS",),
"floats_elevation": ("FLOATS",),
},
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
CATEGORY = "mtb/utils"
FUNCTION = "generate_frames"
def check_floats(self, f: list[float] | None, expected_count: int):
if f:
if len(f) == expected_count:
return True
return False
return True
def generate_frames(
self,
equilateral_image: torch.Tensor,
fovX: float,
fovY: float,
elevation: float,
frame_count: int,
width: int,
height: int,
floats_fovX: list[float] | None = None,
floats_fovY: list[float] | None = None,
floats_elevation: list[float] | None = None,
):
source = tensor2np(equilateral_image)
if len(source) > 1:
log.warn(
"You provided more than one image in the equilateral_image input, only the first will be used."
)
if not all(
[
self.check_floats(x, frame_count)
for x in [floats_fovX, floats_fovY, floats_elevation]
]
):
raise ValueError(
"You provided less than the expected number of fovX, fovY, or elevation values."
)
source = source[0]
frames = []
pbar = comfy.utils.ProgressBar(frame_count)
for i in range(frame_count):
rotation_angle = (i / frame_count) * 2 * pi
if floats_elevation:
elevation = floats_elevation[i]
if floats_fovX:
fovX = floats_fovX[i]
if floats_fovY:
fovY = floats_fovY[i]
fov = [fovX / 100, fovY / 100]
center_point = [rotation_angle / (2 * pi), elevation]
nfov = numpy_NFOV(fov, height, width)
frame = nfov.to_nfov(source, center_point=center_point)
frames.append(frame)
model_management.throw_exception_if_processing_interrupted()
pbar.update(1)
return (pil2tensor(frames),)
class MTB_GetBatchFromHistory:
"""Very experimental node to load images from the history of the server.
Queue items without output are ignored in the count."""
Queue items without output are ignored in the count.
"""
@classmethod
def INPUT_TYPES(cls):
@@ -51,6 +376,7 @@ class GetBatchFromHistory:
def load_from_history(
self,
*,
enable=True,
count=0,
offset=0,
@@ -88,7 +414,9 @@ class GetBatchFromHistory:
if "images" in node_output:
for image in node_output["images"]:
image_data = get_image(
image["filename"], image["subfolder"], image["type"]
image["filename"],
image["subfolder"],
image["type"],
)
output_images.append(image_data)
@@ -110,13 +438,13 @@ class GetBatchFromHistory:
return pil2tensor(frames)
class AnyToString:
"""Tries to take any input and convert it to a string"""
class MTB_AnyToString:
"""Tries to take any input and convert it to a string."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {"input": ("*")},
"required": {"input": ("*",)},
}
RETURN_TYPES = ("STRING",)
@@ -131,18 +459,22 @@ class AnyToString:
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}",)
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()}",)
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"""
class MTB_StringReplace:
"""Basic string replacement with regex support."""
@classmethod
def INPUT_TYPES(cls):
@@ -151,6 +483,7 @@ class StringReplace:
"string": ("STRING", {"forceInput": True}),
"old": ("STRING", {"default": ""}),
"new": ("STRING", {"default": ""}),
"use_regex": ("BOOLEAN", {"default": False}),
}
}
@@ -158,12 +491,19 @@ class StringReplace:
RETURN_TYPES = ("STRING",)
CATEGORY = "mtb/string"
def replace_str(self, string: str, old: str, new: str):
def replace_str(self, string: str, old: str, new: str, use_regex: bool):
log.debug(f"Current string: {string}")
log.debug(f"Find string: {old}")
log.debug(f"Replace string: {new}")
log.debug(f"Use regex: {use_regex}")
string = string.replace(old, new)
if use_regex:
try:
string = re.sub(old, new, string)
except re.error as e:
raise ValueError(f"Regex error: {e}") from e
else:
string = string.replace(old, new)
log.debug(f"New string: {string}")
@@ -185,14 +525,15 @@ class MTB_MathExpression:
RETURN_TYPES = ("FLOAT", "INT")
RETURN_NAMES = ("result (float)", "result (int)")
CATEGORY = "mtb/math"
DESCRIPTION = "evaluate a simple math expression string (!! Fallsback to eval)"
DESCRIPTION = (
"evaluate a simple math expression string, only supports literal_eval"
)
def eval_expression(self, expression, **kwargs):
import math
def eval_expression(self, expression: str, **kwargs):
from ast import literal_eval
for key, value in kwargs.items():
print(f"Replacing placeholder <{key}> with value {value}")
log.debug(f"Replacing placeholder <{key}> with value {value}")
expression = expression.replace(f"<{key}>", str(value))
result = -1
@@ -203,20 +544,15 @@ class MTB_MathExpression:
f"The expression syntax is wrong '{expression}': {e}"
) from e
except ValueError:
try:
expression = expression.replace("^", "**")
result = eval(expression)
except Exception as e:
# Handle any other exceptions and provide a meaningful error message
raise ValueError(
f"Error evaluating expression '{expression}': {e}"
) from e
except Exception as e:
raise ValueError(
f"Math expression only support literal_eval now: {e}"
)
return (result, int(result))
class FitNumber:
class MTB_FitNumber:
"""Fit the input float using a source and target range"""
@classmethod
@@ -225,35 +561,24 @@ class FitNumber:
"required": {
"value": ("FLOAT", {"default": 0, "forceInput": True}),
"clamp": ("BOOLEAN", {"default": False}),
"source_min": ("FLOAT", {"default": 0.0, "step": 0.01}),
"source_max": ("FLOAT", {"default": 1.0, "step": 0.01}),
"target_min": ("FLOAT", {"default": 0.0, "step": 0.01}),
"target_max": ("FLOAT", {"default": 1.0, "step": 0.01}),
"source_min": (
"FLOAT",
{"default": 0.0, "step": 0.01, "min": -1e5},
),
"source_max": (
"FLOAT",
{"default": 1.0, "step": 0.01, "min": -1e5},
),
"target_min": (
"FLOAT",
{"default": 0.0, "step": 0.01, "min": -1e5},
),
"target_max": (
"FLOAT",
{"default": 1.0, "step": 0.01, "min": -1e5},
),
"easing": (
[
"Linear",
"Sine In",
"Sine Out",
"Sine In/Out",
"Quart In",
"Quart Out",
"Quart In/Out",
"Cubic In",
"Cubic Out",
"Cubic In/Out",
"Circ In",
"Circ Out",
"Circ In/Out",
"Back In",
"Back Out",
"Back In/Out",
"Elastic In",
"Elastic Out",
"Elastic In/Out",
"Bounce In",
"Bounce Out",
"Bounce In/Out",
],
EASINGS,
{"default": "Linear"},
),
}
@@ -289,8 +614,8 @@ class FitNumber:
return (res,)
class ConcatImages:
"""Add images to batch"""
class MTB_ConcatImages:
"""Add images to batch."""
RETURN_TYPES = ("IMAGE",)
FUNCTION = "concatenate_tensors"
@@ -300,27 +625,312 @@ class ConcatImages:
def INPUT_TYPES(cls):
return {
"required": {"reverse": ("BOOLEAN", {"default": False})},
"optional": {
"on_mismatch": (
["Error", "Smallest", "Largest"],
{"default": "Smallest"},
)
},
}
def concatenate_tensors(self, reverse, **kwargs):
tensors = tuple(kwargs.values())
batch_sizes = [tensor.size(0) for tensor in tensors]
def concatenate_tensors(
self,
reverse: bool,
on_mismatch: str = "Smallest",
**kwargs: torch.Tensor,
) -> tuple[torch.Tensor]:
tensors = list(kwargs.values())
if on_mismatch == "Error":
shapes = [tensor.shape for tensor in tensors]
if not all(shape == shapes[0] for shape in shapes):
raise ValueError(
"All input tensors must have the same shape when on_mismatch is 'Error'."
)
else:
import torch.nn.functional as F
if on_mismatch == "Smallest":
target_shape = min(
(tensor.shape for tensor in tensors),
key=lambda s: (s[1], s[2]),
)
else: # on_mismatch == "Largest"
target_shape = max(
(tensor.shape for tensor in tensors),
key=lambda s: (s[1], s[2]),
)
target_height, target_width = target_shape[1], target_shape[2]
resized_tensors = []
for tensor in tensors:
if (
tensor.shape[1] != target_height
or tensor.shape[2] != target_width
):
resized_tensor = F.interpolate(
tensor.permute(0, 3, 1, 2),
size=(target_height, target_width),
mode="bilinear",
align_corners=False,
)
resized_tensor = resized_tensor.permute(0, 2, 3, 1)
resized_tensors.append(resized_tensor)
else:
resized_tensors.append(tensor)
tensors = resized_tensors
concatenated = torch.cat(tensors, dim=0)
# Update the batch size in the concatenated tensor
concatenated_size = list(concatenated.size())
concatenated_size[0] = sum(batch_sizes)
concatenated = concatenated.view(*concatenated_size)
return (concatenated,)
class MTB_TensorOps:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"tensor": ("IMAGE",),
"operation": (
[
"multiply",
"divide",
"add",
"subtract",
"power",
"clamp",
"abs",
"log",
"exp",
"convert_dtype",
"normalize_range",
"normalize_per_channel",
],
{"default": "multiply"},
),
"value": (
"FLOAT",
{
"default": 1.0,
"min": -1000000.0,
"max": 1000000.0,
"step": 0.01,
},
),
"source_min": (
"FLOAT",
{
"default": 0.0,
"min": -1000000.0,
"max": 1000000.0,
"step": 0.01,
},
),
"source_max": (
"FLOAT",
{
"default": 1.0,
"min": -1000000.0,
"max": 1000000.0,
"step": 0.01,
},
),
"target_min": (
"FLOAT",
{
"default": 0.0,
"min": -1000000.0,
"max": 1000000.0,
"step": 0.01,
},
),
"target_max": (
"FLOAT",
{
"default": 16.0,
"min": -1000000.0,
"max": 1000000.0,
"step": 0.01,
},
),
"dtype": (
["uint8", "float32", "float16", "bfloat16"],
{"default": "float32"},
),
"use_mean": ("BOOLEAN", {"default": False}),
},
"optional": {
"target_tensor": ("IMAGE",),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "apply"
CATEGORY = "mtb/tensor_ops"
def apply(
self,
tensor,
operation="multiply",
value=1.0,
source_min=0.0,
source_max=1.0,
target_min=0.0,
target_max=1.0,
dtype="float32",
use_mean=False,
target_tensor=None,
):
log.debug(
f"Input tensor stats: shape={tensor.shape}, dtype={tensor.dtype}, range=[{tensor.min().item():.6f}, {tensor.max().item():.6f}]"
)
if operation == "normalize_per_channel":
if target_tensor is None:
raise ValueError(
"Target tensor required for per-channel normalization"
)
result = tensor.clone()
for c in range(tensor.shape[-1]):
if use_mean:
source_mean = tensor[..., c].mean()
target_mean = target_tensor[..., c].mean()
scale = target_mean / source_mean
result[..., c] = tensor[..., c] * scale
else:
source_min = tensor[..., c].min()
source_max = tensor[..., c].max()
target_min = target_tensor[..., c].min()
target_max = target_tensor[..., c].max()
normalized = (tensor[..., c] - source_min) / (
source_max - source_min
)
result[..., c] = (
normalized * (target_max - target_min) + target_min
)
log.debug(
f"Channel {c} - Scale: source=[{source_min:.6f}, {source_max:.6f}], target=[{target_min:.6f}, {target_max:.6f}]"
)
elif operation == "normalize_range":
if target_tensor is not None:
target_min = target_tensor.min().item()
target_max = target_tensor.max().item()
log.debug(
f"Using target tensor range: [{target_min:.6f}, {target_max:.6f}]"
)
normalized = (tensor - source_min) / (source_max - source_min)
result = normalized * (target_max - target_min) + target_min
elif operation == "convert_dtype":
if dtype == "float32":
result = tensor.float()
elif dtype == "float16":
result = tensor.half()
elif dtype == "bfloat16":
result = tensor.bfloat16()
else:
result = tensor
if operation == "multiply":
result = tensor * value
elif operation == "divide":
result = tensor / value if value != 0 else tensor
elif operation == "add":
result = tensor + value
elif operation == "subtract":
result = tensor - value
elif operation == "power":
result = torch.pow(tensor, value)
elif operation == "clamp":
if target_tensor is not None:
result = torch.clamp(
tensor,
target_tensor.min().item(),
target_tensor.max().item(),
)
else:
result = torch.clamp(tensor, source_min, source_max)
elif operation == "abs":
result = torch.abs(tensor)
elif operation == "log":
result = torch.log(tensor.clamp(min=1e-10))
elif operation == "exp":
result = torch.exp(tensor)
log.debug(
f"Output tensor stats: shape={result.shape}, dtype={result.dtype}, range=[{result.min().item():.6f}, {result.max().item():.6f}]"
)
return (result,)
class MTB_GetItem:
"""Generic index based getter for common types"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"container": (CIO.ANY,),
"index": ("INT", {"default": 0}),
}
}
RETURN_TYPES = (CIO.ANY,)
RETURN_NAMES = ("item",)
FUNCTION = "get_item"
CATEGORY = "mtb/utils"
def get_item(self, container: Any, index: int):
if "__getitem__" in dir(container):
log.debug(f"Container is {type(container)}")
res = container[index]
if type(res) is torch.Tensor:
res = res.unsqueeze(0)
return (res,)
class MTB_BooleanNot:
"""Inverts a boolean."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"bool_in": ("BOOLEAN", {"default": False}),
},
}
RETURN_TYPES = ("BOOLEAN",)
RETURN_NAMES = ("inverted_bool",)
FUNCTION = "invert"
CATEGORY = "mtb/utils"
def invert(self, bool_in: bool):
return (not bool_in,)
__nodes__ = [
StringReplace,
FitNumber,
GetBatchFromHistory,
AnyToString,
ConcatImages,
MTB_StringReplace,
MTB_FitNumber,
MTB_GetBatchFromHistory,
MTB_AnyToString,
MTB_ConcatImages,
MTB_MathExpression,
MTB_ToDevice,
MTB_ApplyTextTemplate,
MTB_MatchDimensions,
MTB_AutoPanEquilateral,
MTB_FloatsToFloat,
MTB_FloatToFloats,
MTB_FloatsToInts,
MTB_TensorOps,
MTB_BooleanNot,
MTB_GetItem,
]
+20 -12
View File
@@ -1,12 +1,8 @@
import glob
import os
from pathlib import Path
from typing import List
import comfy
import comfy.model_management as model_management
import comfy.utils
import folder_paths
import numpy as np
import tensorflow as tf
import torch
@@ -17,11 +13,14 @@ from ..log import log
from ..utils import get_model_path
class LoadFilmModel:
"""Loads a FILM model"""
class MTB_LoadFilmModel:
"""Loads a FILM model
[DEPRECATED] Use ComfyUI-FrameInterpolation instead
"""
@staticmethod
def get_models() -> List[Path]:
def get_models() -> list[Path]:
models_paths = get_model_path("FILM").iterdir()
return [x for x in models_paths if x.suffix in [".onnx", ".pth"]]
@@ -40,6 +39,7 @@ class LoadFilmModel:
RETURN_TYPES = ("FILM_MODEL",)
FUNCTION = "load_model"
CATEGORY = "mtb/frame iterpolation"
DEPRECATED = True
def load_model(self, film_model: str):
model_path = get_model_path("FILM", film_model)
@@ -58,8 +58,11 @@ class LoadFilmModel:
return (interpolator.Interpolator(model_path.as_posix(), None),)
class FilmInterpolation:
"""Google Research FILM frame interpolation for large motion"""
class MTB_FilmInterpolation:
"""Google Research FILM frame interpolation for large motion
[DEPRECATED] Use ComfyUI-FrameInterpolation instead
"""
@classmethod
def INPUT_TYPES(cls):
@@ -74,6 +77,7 @@ class FilmInterpolation:
RETURN_TYPES = ("IMAGE",)
FUNCTION = "do_interpolation"
CATEGORY = "mtb/frame iterpolation"
DEPRECATED = True
def do_interpolation(
self,
@@ -107,12 +111,16 @@ class FilmInterpolation:
in_frames, interpolate, film_model
):
out_tensors.append(
torch.from_numpy(frame) if isinstance(frame, np.ndarray) else frame
torch.from_numpy(frame)
if isinstance(frame, np.ndarray)
else frame
)
model_management.throw_exception_if_processing_interrupted()
pbar.update(1)
out_tensors = torch.cat([tens.unsqueeze(0) for tens in out_tensors], dim=0)
out_tensors = torch.cat(
[tens.unsqueeze(0) for tens in out_tensors], dim=0
)
log.debug(f"Returning {len(out_tensors)} tensors")
log.debug(f"Output shape {out_tensors.shape}")
@@ -120,4 +128,4 @@ class FilmInterpolation:
return (out_tensors,)
__nodes__ = [LoadFilmModel, FilmInterpolation]
__nodes__ = [MTB_LoadFilmModel, MTB_FilmInterpolation]
+698 -111
View File
File diff suppressed because it is too large Load Diff
+266 -13
View File
@@ -1,41 +1,294 @@
import json
import os
import numpy as np
import torch
from comfy.cli_args import args
from PIL import Image
from PIL.PngImagePlugin import PngInfo
from ..log import log
class StackImages:
"""Stack the input images horizontally or vertically"""
class MTB_StackImages:
"""Stack the input images horizontally or vertically."""
@classmethod
def INPUT_TYPES(cls):
return {"required": {"vertical": ("BOOLEAN", {"default": False})}}
return {
"required": {"vertical": ("BOOLEAN", {"default": False})},
"optional": {
"match_method": (
["error", "smallest", "largest"],
{"default": "error"},
),
"output_rgb": (
"BOOLEAN",
{"default": True, "tooltip": "Output RGB instead of RGBA"},
),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "stack"
CATEGORY = "mtb/image utils"
def stack(self, vertical, **kwargs):
def stack(self, vertical, match_method="error", output_rgb=True, **kwargs):
if not kwargs:
raise ValueError("At least one tensor must be provided.")
tensors = list(kwargs.values())
log.debug(
f"Stacking {len(tensors)} tensors {'vertically' if vertical else 'horizontally'}"
f"Stacking {len(tensors)} tensors "
f"{'vertically' if vertical else 'horizontally'}"
)
log.debug(list(kwargs.keys()))
ref_shape = tensors[0].shape
for tensor in tensors[1:]:
if tensor.shape[1:] != ref_shape[1:]:
raise ValueError(
"All tensors must have the same dimensions except for the stacking dimension."
target_device = tensors[0].device
normalized_tensors = [
self.normalize_to_rgba(tensor.to(target_device))
for tensor in tensors
]
max_batch_size = max(tensor.shape[0] for tensor in normalized_tensors)
normalized_tensors = [
self.duplicate_frames(tensor, max_batch_size)
for tensor in normalized_tensors
]
if match_method != "error":
if vertical:
# match widths
widths = [tensor.shape[2] for tensor in normalized_tensors]
target_width = (
min(widths) if match_method == "smallest" else max(widths)
)
normalized_tensors = [
self.resize_tensor(tensor, width=target_width)
for tensor in normalized_tensors
]
else:
# match heights
heights = [tensor.shape[1] for tensor in normalized_tensors]
target_height = (
min(heights)
if match_method == "smallest"
else max(heights)
)
normalized_tensors = [
self.resize_tensor(tensor, height=target_height)
for tensor in normalized_tensors
]
else:
if vertical:
width = normalized_tensors[0].shape[2]
if any(
tensor.shape[2] != width for tensor in normalized_tensors
):
raise ValueError(
"All tensors must have the same width "
"for vertical stacking."
)
else:
height = normalized_tensors[0].shape[1]
if any(
tensor.shape[1] != height for tensor in normalized_tensors
):
raise ValueError(
"All tensors must have the same height "
"for horizontal stacking."
)
dim = 1 if vertical else 2
stacked_tensor = torch.cat(tensors, dim=dim)
stacked_tensor = torch.cat(normalized_tensors, dim=dim)
if output_rgb:
stacked_tensor = stacked_tensor[:, :, :, :3]
return (stacked_tensor,)
def normalize_to_rgba(self, tensor):
"""Normalize tensor to have 4 channels (RGBA)."""
_, _, _, channels = tensor.shape
# already RGBA
if channels == 4:
return tensor
# RGB to RGBA
elif channels == 3:
alpha_channel = torch.ones(
tensor.shape[:-1] + (1,), device=tensor.device
)
return torch.cat((tensor, alpha_channel), dim=-1)
else:
raise ValueError(
"Tensor has an unsupported number of channels: "
"expected 3 (RGB) or 4 (RGBA)."
)
__nodes__ = [StackImages]
def duplicate_frames(self, tensor, target_batch_size):
"""Duplicate frames in tensor to match the target batch size."""
current_batch_size = tensor.shape[0]
if current_batch_size < target_batch_size:
duplication_factors: int = target_batch_size // current_batch_size
duplicated_tensor = tensor.repeat(duplication_factors, 1, 1, 1)
remaining_frames = target_batch_size % current_batch_size
if remaining_frames > 0:
duplicated_tensor = torch.cat(
(duplicated_tensor, tensor[:remaining_frames]), dim=0
)
return duplicated_tensor
else:
return tensor
def resize_tensor(self, tensor, width=None, height=None):
"""Resize tensor to specified width or height while maintaining aspect ratio."""
current_height, current_width = tensor.shape[1:3]
if width is not None and width != current_width:
scale_factor = width / current_width
new_height = int(current_height * scale_factor)
new_width = width
elif height is not None and height != current_height:
scale_factor = height / current_height
new_width = int(current_width * scale_factor)
new_height = height
else:
return tensor
resized = torch.nn.functional.interpolate(
tensor.permute(0, 3, 1, 2),
size=(new_height, new_width),
mode="bilinear",
align_corners=False,
)
return resized.permute(0, 2, 3, 1)
class MTB_PickFromBatch:
"""Pick a specific number of images from a batch.
either from the start or end.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
"from_direction": (["end", "start"], {"default": "start"}),
"count": ("INT", {"default": 1}),
},
"optional": {
"mask": ("MASK",),
},
}
RETURN_TYPES = ("IMAGE", "MASK")
FUNCTION = "pick_from_batch"
CATEGORY = "mtb/image utils"
def pick_from_batch(self, image, from_direction, count, mask=None):
batch_size = image.size(0)
# Limit count to the available number of images in the batch
count = min(count, batch_size)
selected_masks = None
if from_direction == "end":
selected_tensors = image[-count:]
if mask is not None:
selected_masks = mask[-count:]
else:
selected_tensors = image[:count]
if mask is not None:
selected_masks = mask[:count]
return (selected_tensors, selected_masks)
import folder_paths
class MTB_SaveImage:
def __init__(self):
self.output_dir = folder_paths.get_output_directory()
self.type = "output"
self.prefix_append = ""
self.compress_level = 4
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"images": ("IMAGE", {"tooltip": "The images to save."}),
"filename_prefix": (
"STRING",
{
"default": "ComfyUI",
"tooltip": "The prefix for the file to save. This may include formatting information such as %date:yyyy-MM-dd% or %Empty Latent Image.width% to include values from nodes.",
},
),
},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "save_images"
# OUTPUT_NODE = True
CATEGORY = "mtb/image utils"
DESCRIPTION = """Saves the input images to your ComfyUI output directory.
This behaves exactly like the native SaveImage node but isn't an output node.
The reason I made this is to allow 'inlining' image save in loops for instance,
using the native node there wouldn't run for each iteration of the loop."""
def save_images(
self,
images,
filename_prefix="ComfyUI",
prompt=None,
extra_pnginfo=None,
):
filename_prefix += self.prefix_append
full_output_folder, filename, counter, subfolder, filename_prefix = (
folder_paths.get_save_image_path(
filename_prefix,
self.output_dir,
images[0].shape[1],
images[0].shape[0],
)
)
results = list()
for batch_number, image in enumerate(images):
i = 255.0 * image.cpu().numpy()
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
metadata = None
if not args.disable_metadata:
metadata = PngInfo()
if prompt is not None:
metadata.add_text("prompt", json.dumps(prompt))
if extra_pnginfo is not None:
for x in extra_pnginfo:
metadata.add_text(x, json.dumps(extra_pnginfo[x]))
filename_with_batch_num = filename.replace(
"%batch_num%", str(batch_number)
)
file = f"{filename_with_batch_num}_{counter:05}_.png"
img.save(
os.path.join(full_output_folder, file),
pnginfo=metadata,
compress_level=self.compress_level,
)
results.append(
{"filename": file, "subfolder": subfolder, "type": self.type}
)
counter += 1
return {"ui": {"images": results}, "result": (images,)}
__nodes__ = [MTB_StackImages, MTB_PickFromBatch, MTB_SaveImage]
+290 -46
View File
@@ -1,67 +1,268 @@
from ..utils import tensor2np, PIL_FILTER_MAP
import uuid
import folder_paths
from ..log import log
import comfy.model_management as model_management
import json
import subprocess
import torch
import uuid
from pathlib import Path
import comfy.model_management as model_management
import comfy.utils
import folder_paths
import numpy as np
import torch
from PIL import Image
from typing import Optional, List
from ..log import log
from ..utils import PIL_FILTER_MAP, output_dir, session_id, tensor2np
class ExportWithFfmpeg:
"""Export with FFmpeg (Experimental)"""
def get_playlist_path(playlist_name: str, persistant_playlist=False):
if persistant_playlist:
return output_dir / "playlists" / f"{playlist_name}.json"
return output_dir / "playlists" / session_id / f"{playlist_name}.json"
class MTB_ReadPlaylist:
"""Read a playlist"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"enable": ("BOOLEAN", {"default": True}),
"persistant_playlist": ("BOOLEAN", {"default": False}),
"playlist_name": (
"STRING",
{"default": "playlist_{index:04d}"},
),
"index": ("INT", {"default": 0, "min": 0}),
}
}
RETURN_TYPES = ("PLAYLIST",)
FUNCTION = "read_playlist"
CATEGORY = "mtb/IO"
EXPERIMENTAL = True
def read_playlist(
self,
enable: bool,
persistant_playlist: bool,
playlist_name: str,
index: int,
):
playlist_name = playlist_name.format(index=index)
playlist_path = get_playlist_path(playlist_name, persistant_playlist)
if not enable:
return (None,)
if not playlist_path.exists():
log.warning(f"Playlist {playlist_path} does not exist, skipping")
return (None,)
log.debug(f"Reading playlist {playlist_path}")
return (json.loads(playlist_path.read_text(encoding="utf-8")),)
class MTB_AddToPlaylist:
"""Add a video to the playlist"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"relative_paths": ("BOOLEAN", {"default": False}),
"persistant_playlist": ("BOOLEAN", {"default": False}),
"playlist_name": (
"STRING",
{"default": "playlist_{index:04d}"},
),
"index": ("INT", {"default": 0, "min": 0}),
}
}
RETURN_TYPES = ()
OUTPUT_NODE = True
FUNCTION = "add_to_playlist"
CATEGORY = "mtb/IO"
EXPERIMENTAL = True
def add_to_playlist(
self,
relative_paths: bool,
persistant_playlist: bool,
playlist_name: str,
index: int,
**kwargs,
):
playlist_name = playlist_name.format(index=index)
playlist_path = get_playlist_path(playlist_name, persistant_playlist)
if not playlist_path.parent.exists():
playlist_path.parent.mkdir(parents=True, exist_ok=True)
playlist = []
if not playlist_path.exists():
playlist_path.write_text("[]")
else:
playlist = json.loads(playlist_path.read_text())
log.debug(f"Playlist {playlist_path} has {len(playlist)} items")
for video in kwargs.values():
if relative_paths:
video = Path(video).relative_to(output_dir).as_posix()
log.debug(f"Adding {video} to playlist")
playlist.append(video)
log.debug(f"Writing playlist {playlist_path}")
playlist_path.write_text(json.dumps(playlist), encoding="utf-8")
return ()
class MTB_ExportWithFfmpeg:
"""Export with FFmpeg (Experimental).
[DEPRACATED] Use VHS nodes instead
"""
@classmethod
def INPUT_TYPES(cls):
return {
"optional": {
"images": ("IMAGE",),
# "frames": ("FRAMES",),
"playlist": ("PLAYLIST",),
},
"required": {
"fps": ("FLOAT", {"default": 24, "min": 1}),
"prefix": ("STRING", {"default": "export"}),
"format": (["mov", "mp4", "mkv", "avi"], {"default": "mov"}),
"format": (
["mov", "mp4", "mkv", "gif", "avi"],
{"default": "mov"},
),
"codec": (
["prores_ks", "libx264", "libx265"],
["prores_ks", "libx264", "libx265", "gif"],
{"default": "prores_ks"},
),
}
},
}
RETURN_TYPES = ("VIDEO",)
OUTPUT_NODE = True
FUNCTION = "export_prores"
DEPRECATED = True
CATEGORY = "mtb/IO"
def export_prores(
self,
images: torch.Tensor,
fps: float,
prefix: str,
format: str,
codec: str,
images: torch.Tensor | None = None,
playlist: list[str] | None = None,
):
if images.size(0) == 0:
return ("",)
output_dir = Path(folder_paths.get_output_directory())
pix_fmt = "rgb48le" if codec == "prores_ks" else "yuv420p"
file_ext = format
file_id = f"{prefix}_{uuid.uuid4()}.{file_ext}"
log.debug(f"Exporting to {output_dir / file_id}")
if playlist is not None and images is not None:
log.info(f"Exporting to {output_dir / file_id}")
if playlist is not None:
if len(playlist) == 0:
log.debug("Playlist is empty, skipping")
return ("",)
temp_playlist_path = (
output_dir / f"temp_playlist_{uuid.uuid4()}.txt"
)
log.debug(
f"Create a temporary file to list the videos for concatenation to {temp_playlist_path}"
)
with open(temp_playlist_path, "w") as f:
for video_path in playlist:
f.write(f"file '{video_path}'\n")
out_path = (output_dir / file_id).as_posix()
# Prepare the FFmpeg command for concatenating videos from the playlist
command = [
"ffmpeg",
"-f",
"concat",
"-safe",
"0",
"-i",
temp_playlist_path.as_posix(),
"-c",
"copy",
"-y",
out_path,
]
log.debug(f"Executing {command}")
subprocess.run(command)
temp_playlist_path.unlink()
return (out_path,)
if (
images is None or images.size(0) == 0
): # the is None check is just for the type checker
return ("",)
frames = tensor2np(images)
log.debug(f"Frames type {type(frames[0])}")
log.debug(f"Exporting {len(frames)} frames")
frames = [frame.astype(np.uint16) * 257 for frame in frames]
height, width, _ = frames[0].shape
height, width, channels = frames[0].shape
has_alpha = channels == 4
out_path = (output_dir / file_id).as_posix()
if codec == "gif":
command = [
"ffmpeg",
"-f",
"image2pipe",
"-vcodec",
"png",
"-r",
str(fps),
"-i",
"-",
"-vcodec",
"gif",
"-y",
out_path,
]
process = subprocess.Popen(command, stdin=subprocess.PIPE)
for frame in frames:
model_management.throw_exception_if_processing_interrupted()
Image.fromarray(frame).save(process.stdin, "PNG")
process.stdin.close()
process.wait()
return (out_path,)
else:
if has_alpha:
if codec in ["prores_ks", "libx264", "libx265"]:
pix_fmt = (
"yuva444p" if codec == "prores_ks" else "yuva420p"
)
frames = [
frame.astype(np.uint16) * 257 for frame in frames
]
else:
log.warning(
f"Alpha channel not supported for codec {codec}. Alpha will be ignored."
)
frames = [
frame[:, :, :3].astype(np.uint16) * 257
for frame in frames
]
pix_fmt = "rgb48le" if codec == "prores_ks" else "yuv420p"
else:
pix_fmt = "rgb48le" if codec == "prores_ks" else "yuv420p"
frames = [frame.astype(np.uint16) * 257 for frame in frames]
# Prepare the FFmpeg command
command = [
"ffmpeg",
@@ -80,17 +281,26 @@ class ExportWithFfmpeg:
"-",
"-c:v",
codec,
"-r",
str(fps),
"-y",
out_path,
]
if codec == "prores_ks":
command.extend(["-profile:v", "4444"])
command.extend(
[
"-r",
str(fps),
"-y",
out_path,
]
)
process = subprocess.Popen(command, stdin=subprocess.PIPE)
pbar = comfy.utils.ProgressBar(len(frames))
for frame in frames:
model_management.throw_exception_if_processing_interrupted()
process.stdin.write(frame.tobytes())
pbar.update(1)
process.stdin.close()
process.wait()
@@ -102,9 +312,9 @@ def prepare_animated_batch(
batch: torch.Tensor,
pingpong=False,
resize_by=1.0,
resample_filter: Optional[Image.Resampling] = None,
resample_filter: Image.Resampling | None = None,
image_type=np.uint8,
) -> List[Image.Image]:
) -> list[Image.Image]:
images = tensor2np(batch)
images = [frame.astype(image_type) for frame in images]
@@ -129,8 +339,11 @@ def prepare_animated_batch(
# todo: deprecate for apng
class SaveGif:
"""Save the images from the batch as a GIF"""
class MTB_SaveGif:
"""Save the images from the batch as a GIF.
[DEPRACATED] Use VHS nodes instead
"""
@classmethod
def INPUT_TYPES(cls):
@@ -141,9 +354,8 @@ 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()),),
"use_ffmpeg": ("BOOLEAN", {"default": False}),
},
}
@@ -151,6 +363,7 @@ class SaveGif:
OUTPUT_NODE = True
CATEGORY = "mtb/IO"
FUNCTION = "save_gif"
DEPRECATED = True
def save_gif(
self,
@@ -160,6 +373,7 @@ class SaveGif:
optimize=False,
pingpong=False,
resample_filter=None,
use_ffmpeg=False,
):
if image.size(0) == 0:
return ("",)
@@ -178,18 +392,48 @@ class SaveGif:
ruuid = ruuid.hex[:10]
out_path = f"{folder_paths.output_directory}/{ruuid}.gif"
# 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,
)
if use_ffmpeg:
# Use FFmpeg to create the GIF from PIL images
command = [
"ffmpeg",
"-f",
"image2pipe",
"-vcodec",
"png",
"-r",
str(fps),
"-i",
"-",
"-vcodec",
"gif",
"-y",
out_path,
]
process = subprocess.Popen(command, stdin=subprocess.PIPE)
for image in pil_images:
model_management.throw_exception_if_processing_interrupted()
image.save(process.stdin, "PNG")
process.stdin.close()
process.wait()
results = [{"filename": f"{ruuid}.gif", "subfolder": "", "type": "output"}]
else:
pil_images[0].save(
out_path,
save_all=True,
append_images=pil_images[1:],
optimize=optimize,
duration=int(1000 / fps),
loop=0,
)
results = [
{"filename": f"{ruuid}.gif", "subfolder": "", "type": "output"}
]
return {"ui": {"gif": results}}
__nodes__ = [SaveGif, ExportWithFfmpeg]
__nodes__ = [
MTB_SaveGif,
MTB_ExportWithFfmpeg,
MTB_AddToPlaylist,
MTB_ReadPlaylist,
]
+6 -3
View File
@@ -1,7 +1,7 @@
import torch
class LatentLerp:
class MTB_LatentLerp:
"""Linear interpolation (blend) between two latent vectors"""
@classmethod
@@ -10,7 +10,10 @@ class LatentLerp:
"required": {
"A": ("LATENT",),
"B": ("LATENT",),
"t": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"t": (
"FLOAT",
{"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01},
),
}
}
@@ -29,5 +32,5 @@ class LatentLerp:
__nodes__ = [
LatentLerp,
MTB_LatentLerp,
]
+17
View File
@@ -0,0 +1,17 @@
# from ..utils import hex_to_rgb
class MTB_ColorInput:
RETURN_TYPES = ("COLOR",)
FUNCTION = "color"
CATEGORY = "mtb/color"
@classmethod
def INPUT_TYPES(cls):
return {
"required": {"color": ("MTB_COLOR", {"default": "#ffffff"})},
}
def color(self, color):
return (color,)
__nodes__ = [MTB_ColorInput]
+161
View File
@@ -0,0 +1,161 @@
import os
import subprocess
import tempfile
import numpy as np
import torch
from PIL import Image
from ..log import log
class ImageH264Compression:
"""Encodes the input with h264 compression using a configurable CRF."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": (
"IMAGE",
{
"tooltip": "The input image tensor to be compressed and decompressed."
},
),
"crf": (
"INT",
{
"default": 23,
"min": 0,
"max": 51,
"step": 1,
"tooltip": "Constant Rate Factor for h264 encoding (lower values mean higher quality).",
},
),
}
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "compress_and_decompress"
CATEGORY = "image"
DESCRIPTION = """
**Encodes the input with h264 compression using a configurable CRF**.
> [!IMPORTANT]
> This node is not really needed with the latest version of LTXVideo.
> [!NOTE]
> This was recommended by the creators of LTX over banodoco's discord.
*Orginal code from [mix](https://github.com/XmYx)*"""
def _compress_decompress_ffmpeg(self, img_array, crf):
with tempfile.TemporaryDirectory() as temp_dir:
input_path = os.path.join(temp_dir, "input.png")
output_path = os.path.join(temp_dir, "output.mp4")
decoded_path = os.path.join(temp_dir, "decoded.png")
Image.fromarray(img_array).save(input_path)
encode_command = [
"ffmpeg",
"-y",
"-i",
input_path,
"-c:v",
"libx264",
"-crf",
str(crf),
"-pix_fmt",
"yuv420p",
"-frames:v",
"1",
output_path,
]
subprocess.run(encode_command, capture_output=True)
decode_command = [
"ffmpeg",
"-y",
"-i",
output_path,
"-frames:v",
"1",
decoded_path,
]
subprocess.run(decode_command, capture_output=True)
decoded_img = np.array(Image.open(decoded_path))
return decoded_img
def compress_and_decompress(self, image, crf):
import io
output_images = []
try:
import av
for img_tensor in image:
img_array = img_tensor.cpu().numpy()
img_array = (img_array * 255).astype(np.uint8)
img_array = img_array.copy(
order="C"
) # Ensure contiguous array
output = io.BytesIO()
# Encode the image to h264 with the given CRF
container = av.open(output, mode="w", format="mp4")
stream = container.add_stream("h264", rate=1)
stream.width = img_array.shape[1]
stream.height = img_array.shape[0]
stream.pix_fmt = "yuv420p"
stream.options = {"crf": str(crf)}
frame = av.VideoFrame.from_ndarray(img_array, format="rgb24")
for packet in stream.encode(frame):
container.mux(packet)
for packet in stream.encode():
container.mux(packet)
container.close()
# Decode the video back to an image
output.seek(0)
container = av.open(output, mode="r", format="mp4")
decoded_frames = []
for frame in container.decode(video=0):
img_decoded = frame.to_ndarray(format="rgb24")
decoded_frames.append(img_decoded)
container.close()
if len(decoded_frames) > 0:
img_decoded = decoded_frames[0]
img_decoded = torch.from_numpy(
img_decoded.astype(np.float32) / 255.0
)
output_images.append(img_decoded)
else:
# If decoding failed, use the original image
output_images.append(img_tensor)
except ImportError:
log.warning(
"PyAv is not installed... Falling back to the ffmpeg cli"
)
for img_tensor in image:
img_array = (img_tensor.cpu().numpy() * 255).astype(np.uint8)
decoded_img = self._compress_decompress_ffmpeg(img_array, crf)
img_decoded = torch.from_numpy(
decoded_img.astype(np.float32) / 255.0
)
output_images.append(img_decoded)
output_images = torch.stack(output_images).to(image.device)
return (output_images,)
# fmt: off
__nodes__ = [
ImageH264Compression
]
+10 -5
View File
@@ -1,11 +1,10 @@
import comfy.utils
from PIL import Image
from rembg import remove
from ..utils import pil2tensor, tensor2pil
class ImageRemoveBackgroundRembg:
class MTB_ImageRemoveBackgroundRembg:
"""Removes the background from the input using Rembg."""
@classmethod
@@ -35,7 +34,7 @@ class ImageRemoveBackgroundRembg:
),
"bgcolor": (
"COLOR",
{"default": "#000000"},
{"default": "#000000","widgetType": "MTB_COLOR"},
),
},
}
@@ -64,6 +63,8 @@ class ImageRemoveBackgroundRembg:
post_process_mask,
bgcolor,
):
from rembg import remove
pbar = comfy.utils.ProgressBar(image.size(0))
images = tensor2pil(image)
@@ -100,9 +101,13 @@ class ImageRemoveBackgroundRembg:
pbar.update(1)
return (pil2tensor(out_img), pil2tensor(out_mask), pil2tensor(out_img_on_bg))
return (
pil2tensor(out_img),
pil2tensor(out_mask),
pil2tensor(out_img_on_bg),
)
__nodes__ = [
ImageRemoveBackgroundRembg,
MTB_ImageRemoveBackgroundRembg,
]
+68 -12
View File
@@ -1,11 +1,13 @@
import copy
import torch
from torch.nn import functional as F
from torch.nn.modules.utils import _pair
from ..log import log
class VaeDecode_:
class MTB_VaeDecode:
"""Wrapper for the 2 core decoders but also adding the sd seamless hack, taken from: FlyingFireCo/tiled_ksampler"""
@classmethod
@@ -29,7 +31,12 @@ class VaeDecode_:
CATEGORY = "mtb/decode"
def decode(
self, vae, samples, seamless_model, use_tiling_decoder=True, tile_size=512
self,
vae,
samples,
seamless_model,
use_tiling_decoder=True,
tile_size=512,
):
if seamless_model:
if use_tiling_decoder:
@@ -55,7 +62,25 @@ class VaeDecode_:
return (vae.decode(samples["samples"]),)
class ModelPatchSeamless:
def conv_forward(lyr, tensor, weight, bias):
step = lyr.timestep
if (lyr.paddingStartStep < 0 or step >= lyr.paddingStartStep) and (
lyr.paddingStopStep < 0 or step <= lyr.paddingStopStep
):
working = F.pad(tensor, lyr.paddingX, mode=lyr.padding_modeX)
working = F.pad(working, lyr.paddingY, mode=lyr.padding_modeY)
else:
working = F.pad(tensor, lyr.paddingX, mode="constant")
working = F.pad(working, lyr.paddingY, mode="constant")
lyr.timestep += 1
return F.conv2d(
working, weight, bias, lyr.stride, _pair(0), lyr.dilation, lyr.groups
)
class MTB_ModelPatchSeamless:
"""Uses the stable diffusion 'hack' to infer seamless images by setting the model layers padding mode to circular (experimental)"""
@classmethod
@@ -63,10 +88,16 @@ class ModelPatchSeamless:
return {
"required": {
"model": ("MODEL",),
"tiling": (
"startStep": ("INT", {"default": 0}),
"stopStep": ("INT", {"default": 999}),
"tilingX": (
"BOOLEAN",
{"default": True},
), # kept for testing not sure why it should be false
),
"tilingY": (
"BOOLEAN",
{"default": True},
),
}
}
@@ -79,21 +110,46 @@ class ModelPatchSeamless:
CATEGORY = "mtb/textures"
def apply_circular(self, model, enable):
def apply_circular(self, model, startStep, stopStep, x, y):
for layer in [
layer for layer in model.modules() if isinstance(layer, torch.nn.Conv2d)
layer
for layer in model.modules()
if isinstance(layer, torch.nn.Conv2d)
]:
layer.padding_mode = "circular" if enable else "zeros"
layer.padding_modeX = "circular" if x else "constant"
layer.padding_modeY = "circular" if y else "constant"
layer.paddingX = (
layer._reversed_padding_repeated_twice[0],
layer._reversed_padding_repeated_twice[1],
0,
0,
)
layer.paddingY = (
0,
0,
layer._reversed_padding_repeated_twice[2],
layer._reversed_padding_repeated_twice[3],
)
layer.paddingStartStep = startStep
layer.paddingStopStep = stopStep
layer.timestep = 0
layer._conv_forward = conv_forward.__get__(layer, torch.nn.Conv2d)
return model
def hack(
self,
model,
tiling,
startStep,
stopStep,
tilingX,
tilingY,
):
hacked_model = copy.deepcopy(model)
self.apply_circular(hacked_model.model, tiling)
hacked_model = model.clone()
self.apply_circular(
hacked_model.model, startStep, stopStep, tilingX, tilingY
)
return (model, hacked_model)
__nodes__ = [ModelPatchSeamless, VaeDecode_]
__nodes__ = [MTB_ModelPatchSeamless, MTB_VaeDecode]
+6 -8
View File
@@ -1,4 +1,4 @@
class IntToBool:
class MTB_IntToBool:
"""Basic int to bool conversion"""
@classmethod
@@ -22,7 +22,7 @@ class IntToBool:
return (bool(int),)
class IntToNumber:
class MTB_IntToNumber:
"""Node addon for the WAS Suite. Converts a "comfy" INT to a NUMBER."""
@classmethod
@@ -50,7 +50,7 @@ class IntToNumber:
return (int,)
class FloatToNumber:
class MTB_FloatToNumber:
"""Node addon for the WAS Suite. Converts a "comfy" FLOAT to a NUMBER."""
@classmethod
@@ -77,11 +77,9 @@ class FloatToNumber:
def float_to_number(self, float):
return (float,)
return (int,)
__nodes__ = [
FloatToNumber,
IntToBool,
IntToNumber,
MTB_FloatToNumber,
MTB_IntToBool,
MTB_IntToNumber,
]
+351
View File
@@ -0,0 +1,351 @@
import os
import subprocess
import tempfile
import comfy.utils
import torch
from ..log import log
from ..utils import nextAvailable, tensor2pil
RELATIVE_NOTICE = """
Absolute paths are kept as is, relatives are from the output directory.
"""
class MTB_PostshotTrain:
CATEGORY = "mtb/postshot"
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"images": (
"IMAGE",
{"tooltip": "These image will get save to disk first"},
),
"profile": (
[
"NeRF L",
"NeRF M",
"NeRF S",
"NeRF XL",
"NeRF XXL",
"Splat ADC",
"Splat MCMC",
],
{
"default": "Splat MCMC",
"tooltip": "The radiance field model profile to train",
},
),
"image_select": (
["all", "best"],
{
"default": "best",
"tooltip": "How to select training images from the source image sets",
},
),
"train_steps_limit": (
"INT",
{
"default": 30,
"min": 1,
"max": 1000,
"tooltip": "Number of kSteps to train the model for",
},
),
"output_path": (
"STRING",
{
"default": "output",
"tooltip": (
"path to save the project to" f"{RELATIVE_NOTICE}"
),
},
),
"postshot_cli": (
"STRING",
{
"default": "C:/Program Files/Jawset Postshot/bin/postshot-cli.exe"
},
),
},
"optional": {
"gpu": (
"INT",
{
"default": 0,
"min": 0,
"max": 255,
"tooltip": "Specify the index of the GPU to use",
},
),
"num_train_images": (
"INT",
{
"default": 0,
"min": 0,
"tooltip": "If image-select best is used, specifies the number of training images to select",
},
),
"max_image_size": (
"INT",
{
"default": 1600,
"min": 0,
"tooltip": "Downscale training images such that their longer edge is at most this value in pixels. Disabled if zero.",
},
),
"max_num_features": (
"INT",
{
"default": 8,
"min": 1,
"tooltip": "Maximum number of 2D kFeatures extracted from each image.",
},
),
"splat_density": (
"FLOAT",
{
"default": 1.0,
"min": 0.125,
"max": 8.0,
"tooltip": (
"Controls how much additional splats "
"are generated during training."
"Applies only in 'Splat ADC' profile."
),
},
),
"max_num_splats": (
"INT",
{
"default": 3000,
"min": 1,
"tooltip": (
"Sets the maximum number of splats (in kSplats)"
" created during training. "
"Applies only in 'Splat MCMC' profile."
),
},
),
"export_splat_ply": (
"STRING",
{
"default": "",
"tooltip": (
"If not empty will also save a ply file."
f"{RELATIVE_NOTICE}"
),
},
),
},
}
RETURN_TYPES = ("STRING",)
OUTPUT_NODE = True
RETURN_NAMES = ("project_file_path",)
FUNCTION = "train_model"
def train_model(
self,
images: torch.Tensor,
profile: str,
image_select: str,
train_steps_limit: int,
output_path: str,
gpu=0,
num_train_images=0,
max_image_size=1600,
max_num_features=8,
splat_density=1.0,
max_num_splats=3000,
export_splat_ply="",
postshot_cli="",
):
if not output_path.endswith(".psht"):
output_path += ".psht"
output_path = nextAvailable(output_path)
output_path.parent.mkdir(exist_ok=True)
pbar = comfy.utils.ProgressBar(200 + images.size(0))
try:
with tempfile.TemporaryDirectory() as temp_dir:
image_paths = []
images_pil = tensor2pil(images)
for i, img in enumerate(images_pil):
try:
img_path = os.path.join(temp_dir, f"image_{i:04d}.png")
img.save(img_path)
image_paths.append(img_path)
except Exception as e:
raise RuntimeError(
f"Failed to save image {i}: {str(e)}"
) from e
pbar.update(1)
if not image_paths:
raise ValueError("No valid images to process")
cmd = [postshot_cli, "train"]
for img_path in image_paths:
cmd.extend(["-i", img_path])
cmd.extend(
[
"-p",
profile,
"--image-select",
image_select,
"-s",
str(train_steps_limit),
"-o",
output_path.as_posix(),
]
)
if gpu is not None:
cmd.extend(["--gpu", str(gpu)])
if num_train_images > 0 and image_select == "best":
cmd.extend(["--num-train-images", str(num_train_images)])
if max_image_size > 0:
cmd.extend(["--max-image-size", str(max_image_size)])
if max_num_features != 8:
cmd.extend(["--max-num-features", str(max_num_features)])
if profile == "Splat ADC" and splat_density != 1.0:
cmd.extend(["--splat-density", str(splat_density)])
if profile == "Splat MCMC" and max_num_splats != 3000:
cmd.extend(["--max-num-splats", str(max_num_splats)])
if export_splat_ply:
export_splat_ply = nextAvailable(export_splat_ply)
cmd.extend(
["--export-splat-ply", export_splat_ply.as_posix()]
)
log.debug(f"Running {cmd}")
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
last_step_c = 0
last_step_t = 0
while True:
output = process.stdout.readline()
if output == "" and process.poll() is not None:
break
if output:
print(output)
if "camera tracking step" in output.lower():
try:
current_step = int(
output.split("%")[0].split(":")[1].strip()
)
if current_step > last_step_c:
pbar.update(1)
last_step_c = current_step
except (ValueError, IndexError):
continue
if "training radiance field:" in output.lower():
try:
current_step = int(
output.split("%")[0].split(":")[1].strip()
)
if current_step > last_step_t:
pbar.update(1)
last_step_t = current_step
except (ValueError, IndexError):
continue
if process.returncode != 0:
_, stderr = process.communicate()
raise RuntimeError(f"Postshot training failed: {stderr}")
if not os.path.exists(output_path):
raise RuntimeError("Output file was not created")
return (output_path.as_posix(),)
except Exception as e:
raise RuntimeError(f"Training failed: {str(e)}")
finally:
pbar.update(train_steps_limit)
class MTB_PostshotExport:
CATEGORY = "mtb/postshot"
OUTPUT_NODE = True
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"project_file": (
"STRING",
{"default": "", "forceInput": True},
),
"export_splat_ply": ("STRING", {"default": "output.ply"}),
"postshot_cli": (
"STRING",
{
"default": "C:/Program Files/Jawset Postshot/bin/postshot-cli.exe"
},
),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("exported_ply_path",)
FUNCTION = "export_model"
def export_model(
self, project_file: str, export_splat_ply: str, postshot_cli: str
):
if not project_file.endswith(".psht"):
raise ValueError("Project file must have .psht extension")
if not os.path.exists(project_file):
raise FileNotFoundError(f"Project file not found: {project_file}")
if not export_splat_ply.endswith(".ply"):
export_splat_ply += ".ply"
_export_splat_ply = nextAvailable(export_splat_ply)
_export_splat_ply.parent.mkdir(exist_ok=True)
cmd = [
postshot_cli,
"export",
"-f",
project_file,
"--export-splat-ply",
_export_splat_ply.as_posix(),
]
try:
_result = subprocess.run(
cmd, check=True, capture_output=True, text=True
)
if not _export_splat_ply.exists():
log.error("Export file was not created")
return (_export_splat_ply.as_posix(),)
except subprocess.CalledProcessError as e:
raise RuntimeError(f"Export failed: {e.stderr}")
except Exception as e:
raise RuntimeError(f"Export failed: {str(e)}")
__nodes__ = [MTB_PostshotExport, MTB_PostshotTrain]
+360
View File
@@ -0,0 +1,360 @@
from pathlib import Path
import safetensors.torch
import torch
import tqdm
from ..log import log
from ..utils import Operation, Precision
from ..utils import output_dir as comfy_out_dir
PRUNE_DATA = {
"known_junk_prefix": [
"embedding_manager.embedder.",
"lora_te_text_model",
"control_model.",
],
"nai_keys": {
"cond_stage_model.transformer.embeddings.": "cond_stage_model.transformer.text_model.embeddings.",
"cond_stage_model.transformer.encoder.": "cond_stage_model.transformer.text_model.encoder.",
"cond_stage_model.transformer.final_layer_norm.": "cond_stage_model.transformer.text_model.final_layer_norm.",
},
}
# position_ids in clip is int64. model_ema.num_updates is int32
dtypes_to_fp16 = {torch.float32, torch.float64, torch.bfloat16}
dtypes_to_bf16 = {torch.float32, torch.float64, torch.float16}
dtypes_to_fp8 = {torch.float32, torch.float64, torch.bfloat16, torch.float16}
class MTB_ModelPruner:
@classmethod
def INPUT_TYPES(cls):
return {
"optional": {
"unet": ("MODEL",),
"clip": ("CLIP",),
"vae": ("VAE",),
},
"required": {
"save_separately": ("BOOLEAN", {"default": False}),
"save_folder": ("STRING", {"default": "checkpoints/ComfyUI"}),
"fix_clip": ("BOOLEAN", {"default": True}),
"remove_junk": ("BOOLEAN", {"default": True}),
"ema_mode": (
("disabled", "remove_ema", "ema_only"),
{"default": "remove_ema"},
),
"precision_unet": (
Precision.list_members(),
{"default": Precision.FULL.value},
),
"operation_unet": (
Operation.list_members(),
{"default": Operation.CONVERT.value},
),
"precision_clip": (
Precision.list_members(),
{"default": Precision.FULL.value},
),
"operation_clip": (
Operation.list_members(),
{"default": Operation.CONVERT.value},
),
"precision_vae": (
Precision.list_members(),
{"default": Precision.FULL.value},
),
"operation_vae": (
Operation.list_members(),
{"default": Operation.CONVERT.value},
),
},
}
OUTPUT_NODE = True
RETURN_TYPES = ()
CATEGORY = "mtb/prune"
FUNCTION = "prune"
def convert_precision(self, tensor: torch.Tensor, precision: Precision):
precision = Precision.from_str(precision)
log.debug(f"Converting to {precision}")
match precision:
case Precision.FP8:
if tensor.dtype in dtypes_to_fp8:
return tensor.to(torch.float8_e4m3fn)
log.error(f"Cannot convert {tensor.dtype} to fp8")
return tensor
case Precision.FP16:
if tensor.dtype in dtypes_to_fp16:
return tensor.half()
log.error(f"Cannot convert {tensor.dtype} to f16")
return tensor
case Precision.BF16:
if tensor.dtype in dtypes_to_bf16:
return tensor.bfloat16()
log.error(f"Cannot convert {tensor.dtype} to bf16")
return tensor
case Precision.FULL | Precision.FP32:
return tensor
def is_sdxl_model(self, clip: dict[str, torch.Tensor] | None):
if clip:
return (any(k.startswith("conditioner.embedders") for k in clip),)
return False
def has_ema(self, unet: dict[str, torch.Tensor]):
return any(k.startswith("model_ema") for k in unet)
def fix_clip(self, clip: dict[str, torch.Tensor] | None):
if self.is_sdxl_model(clip):
log.warn("[fix clip] SDXL not supported")
return
if clip is None:
return
position_id_key = (
"cond_stage_model.transformer.text_model.embeddings.position_ids"
)
if position_id_key in clip:
correct = torch.Tensor([list(range(77))]).to(torch.int64)
now = clip[position_id_key].to(torch.int64)
broken = correct.ne(now)
broken = [i for i in range(77) if broken[0][i]]
if len(broken) != 0:
clip[position_id_key] = correct
log.info(f"[Converter] Fixed broken clip\n{broken}")
else:
log.info(
"[Converter] Clip in this model is fine, skip fixing..."
)
else:
log.info("[Converter] Missing position id in model, try fixing...")
clip[position_id_key] = torch.Tensor([list(range(77))]).to(
torch.int64
)
return clip
def get_dicts(self, unet, clip, vae):
clip_sd = clip.get_sd()
state_dict = unet.model.state_dict_for_saving(
clip_sd, vae.get_sd(), None
)
unet = {
k: v
for k, v in state_dict.items()
if k.startswith("model.diffusion_model")
}
clip = {
k: v
for k, v in state_dict.items()
if k.startswith("cond_stage_model")
or k.startswith("conditioner.embedders")
}
vae = {
k: v
for k, v in state_dict.items()
if k.startswith("first_stage_model")
}
other = {
k: v
for k, v in state_dict.items()
if k not in unet and k not in vae and k not in clip
}
return (unet, clip, vae, other)
def do_remove_junk(self, tensors: dict[str, dict[str, torch.Tensor]]):
need_delete: list[str] = []
for layer in tensors:
for key in layer:
for jk in PRUNE_DATA["known_junk_prefix"]:
if key.startswith(jk):
need_delete.append(".".join([layer, key]))
for k in need_delete:
log.info(f"Removing junk data: {k}")
del tensors[k]
return tensors
def prune(
self,
*,
save_separately: bool,
save_folder: str,
fix_clip: bool,
remove_junk: bool,
ema_mode: str,
precision_unet: Precision,
precision_clip: Precision,
precision_vae: Precision,
operation_unet: str,
operation_clip: str,
operation_vae: str,
unet: dict[str, torch.Tensor] | None = None,
clip: dict[str, torch.Tensor] | None = None,
vae: dict[str, torch.Tensor] | None = None,
):
operation = {
"unet": Operation.from_str(operation_unet),
"clip": Operation.from_str(operation_clip),
"vae": Operation.from_str(operation_vae),
}
precision = {
"unet": Precision.from_str(precision_unet),
"clip": Precision.from_str(precision_clip),
"vae": Precision.from_str(precision_vae),
}
unet, clip, vae, _other = self.get_dicts(unet, clip, vae)
out_dir = Path(save_folder)
folder = out_dir.parent
if not out_dir.is_absolute():
folder = (comfy_out_dir / save_folder).parent
if not folder.exists():
if folder.parent.exists():
folder.mkdir()
else:
raise FileNotFoundError(
f"Folder {folder.parent} does not exist"
)
name = out_dir.name
save_name = f"{name}-{precision_unet}"
if ema_mode != "disabled":
save_name += f"-{ema_mode}"
if fix_clip:
save_name += "-clip-fix"
if (
any(o == Operation.CONVERT for o in operation.values())
and any(p == Precision.FP8 for p in precision.values())
and torch.__version__ < "2.1.0"
):
raise NotImplementedError(
"PyTorch 2.1.0 or newer is required for fp8 conversion"
)
if not self.is_sdxl_model(clip):
for part in [unet, vae, clip]:
if part:
nai_keys = PRUNE_DATA["nai_keys"]
for k in list(part.keys()):
for r in nai_keys:
if isinstance(k, str) and k.startswith(r):
new_key = k.replace(r, nai_keys[r])
part[new_key] = part[k]
del part[k]
log.info(
f"[Converter] Fixed novelai error key {k}"
)
break
if fix_clip:
clip = self.fix_clip(clip)
ok: dict[str, dict[str, torch.Tensor]] = {
"unet": {},
"clip": {},
"vae": {},
}
def _hf(part: str, wk: str, t: torch.Tensor):
if not isinstance(t, torch.Tensor):
log.debug("Not a torch tensor, skipping key")
return
log.debug(f"Operation {operation[part]}")
if operation[part] == Operation.CONVERT:
ok[part][wk] = self.convert_precision(
t, precision[part]
) # conv_func(t)
elif operation[part] == Operation.COPY:
ok[part][wk] = t
elif operation[part] == Operation.DELETE:
return
log.info("[Converter] Converting model...")
for part_name, part in zip(
["unet", "vae", "clip", "other"],
[unet, vae, clip],
strict=False,
):
if part:
match ema_mode:
case "remove_ema":
for k, v in tqdm.tqdm(part.items()):
if "model_ema." not in k:
_hf(part_name, k, v)
case "ema_only":
if not self.has_ema(part):
log.warn("No EMA to extract")
return
for k in tqdm.tqdm(part):
ema_k = "___"
try:
ema_k = "model_ema." + k[6:].replace(".", "")
except Exception:
pass
if ema_k in part:
_hf(part_name, k, part[ema_k])
elif not k.startswith("model_ema.") or k in [
"model_ema.num_updates",
"model_ema.decay",
]:
_hf(part_name, k, part[k])
case "disabled" | _:
for k, v in tqdm.tqdm(part.items()):
_hf(part_name, k, v)
if save_separately:
if remove_junk:
ok = self.do_remove_junk(ok)
flat_ok = {
k: v
for _, subdict in ok.items()
for k, v in subdict.items()
}
save_path = (
folder / f"{part_name}-{save_name}.safetensors"
).as_posix()
safetensors.torch.save_file(flat_ok, save_path)
ok: dict[str, dict[str, torch.Tensor]] = {
"unet": {},
"clip": {},
"vae": {},
}
if save_separately:
return ()
if remove_junk:
ok = self.do_remove_junk(ok)
flat_ok = {
k: v for _, subdict in ok.items() for k, v in subdict.items()
}
try:
safetensors.torch.save_file(
flat_ok, (folder / f"{save_name}.safetensors").as_posix()
)
except Exception as e:
log.error(e)
return ()
__nodes__ = [MTB_ModelPruner]
+85
View File
@@ -0,0 +1,85 @@
import qrcode
import torch
from PIL import Image
from ..log import log
from ..utils import pil2tensor
class MTB_QrCode:
"""Basic QR Code generator."""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"url": ("STRING", {"default": "https://www.github.com"}),
"width": (
"INT",
{"default": 256, "max": 8096, "min": 0, "step": 1},
),
"height": (
"INT",
{"default": 256, "max": 8096, "min": 0, "step": 1},
),
"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": (("BOOLEAN",), {"default": False}),
}
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "do_qr"
CATEGORY = "mtb/generate"
def do_qr(
self,
*,
url: str,
width: int,
height: int,
error_correct: str,
box_size: int,
border: int,
invert: bool,
) -> tuple[torch.Tensor]:
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":
error_correct = qrcode.constants.ERROR_CORRECT_M
elif error_correct == "Q":
error_correct = qrcode.constants.ERROR_CORRECT_Q
else:
error_correct = qrcode.constants.ERROR_CORRECT_H
qr = qrcode.QRCode(
version=1,
error_correction=error_correct,
box_size=box_size,
border=border,
)
qr.add_data(url)
qr.make(fit=True)
back_color = (255, 255, 255) if invert else (0, 0, 0)
fill_color = (0, 0, 0) if invert else (255, 255, 255)
code = qr.make_image(back_color=back_color, fill_color=fill_color)
# that we now resize without filtering
code = code.resize((width, height), Image.NEAREST)
return (pil2tensor(code),)
__nodes__ = [MTB_QrCode]
+130 -20
View File
@@ -1,15 +1,16 @@
from math import ceil, sqrt
from typing import cast
import torch
import torchvision.transforms.functional as TF
from ..utils import log, hex_to_rgb, tensor2pil, pil2tensor
from math import sqrt, ceil
from typing import cast
from PIL import Image
from ..utils import hex_to_rgb, log, pil2tensor, tensor2pil
class TransformImage:
class MTB_TransformImage:
"""Save torch tensors (image, mask or latent) to disk, useful to debug things outside comfy
it return a tensor representing the transformed images with the same shape as the input tensor
"""
@@ -18,10 +19,22 @@ class TransformImage:
return {
"required": {
"image": ("IMAGE",),
"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}),
"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},
@@ -30,7 +43,38 @@ class TransformImage:
["edge", "constant", "reflect", "symmetric"],
{"default": "edge"},
),
"constant_color": ("COLOR", {"default": "#000000"}),
"constant_color": (
"COLOR",
{"default": "#000000", "widgetType": "MTB_COLOR"},
),
},
"optional": {
"filter_type": (
[
"nearest",
"box",
"bilinear",
"hamming",
"bicubic",
"lanczos",
],
{"default": "bilinear"},
),
"stretch_x": (
"FLOAT",
{"default": 1.0, "min": 0.001, "max": 10.0, "step": 0.01},
),
"stretch_y": (
"FLOAT",
{"default": 1.0, "min": 0.001, "max": 10.0, "step": 0.01},
),
"use_normalized": (
"BOOLEAN",
{
"default": False,
"tooltip": "If true, transform values are scaled to image dimensions.",
},
),
},
}
@@ -48,19 +92,41 @@ class TransformImage:
shear: float,
border_handling="edge",
constant_color=None,
filter_type="nearest",
stretch_x=1.0,
stretch_y=1.0,
use_normalized: bool = False,
):
filter_map = {
"nearest": Image.NEAREST,
"box": Image.BOX,
"bilinear": Image.BILINEAR,
"hamming": Image.HAMMING,
"bicubic": Image.BICUBIC,
"lanczos": Image.LANCZOS,
}
resampling_filter = filter_map[filter_type]
_, frame_height, frame_width, _ = image.size()
if use_normalized:
x = float(x) * frame_width
y = float(y) * frame_height
x = int(x)
y = int(y)
angle = int(angle)
log.debug(f"Zoom: {zoom} | x: {x}, y: {y}, angle: {angle}, shear: {shear}")
log.debug(
f"Zoom: {zoom} | x: {x}, y: {y}, angle: {angle}, shear: {shear} | stretch_x: {stretch_x}, stretch_y: {stretch_y}"
)
if image.size(0) == 0:
return (torch.zeros(0),)
transformed_images = []
frames_count, frame_height, frame_width, frame_channel_count = image.size()
new_height, new_width = int(frame_height * zoom), int(frame_width * zoom)
new_height, new_width = (
int(frame_height * zoom),
int(frame_width * zoom),
)
log.debug(f"New height: {new_height}, New width: {new_width}")
@@ -74,23 +140,67 @@ class TransformImage:
pw += abs(max_padding)
ph += abs(max_padding)
padding = [max(0, pw + x), max(0, ph + y), max(0, pw - x), max(0, ph - y)]
padding = [
max(0, pw + x),
max(0, ph + y),
max(0, pw - x),
max(0, ph - y),
]
constant_color = hex_to_rgb(constant_color)
log.debug(f"Fill Tuple: {constant_color}")
for img in tensor2pil(image):
img = TF.pad(
img, # transformed_frame,
img,
padding=padding,
padding_mode=border_handling,
fill=constant_color or 0,
)
img = cast(
Image.Image,
TF.affine(img, angle=angle, scale=zoom, translate=[x, y], shear=shear),
)
if stretch_x != 1.0 or stretch_y != 1.0:
img = cast(
Image.Image,
TF.affine(
img,
angle=angle,
scale=zoom,
translate=[x, y],
shear=shear,
interpolation=resampling_filter,
),
)
width, height = img.size
center = (width // 2, height // 2)
stretch_x_factor = 1.0 / stretch_x
stretch_y_factor = 1.0 / stretch_y
matrix = [
stretch_x_factor,
0,
center[0] - center[0] * stretch_x_factor,
0,
stretch_y_factor,
center[1] - center[1] * stretch_y_factor,
]
img = img.transform(
img.size, Image.AFFINE, matrix, resampling_filter
)
else:
img = cast(
Image.Image,
TF.affine(
img,
angle=angle,
scale=zoom,
translate=[x, y],
shear=shear,
interpolation=resampling_filter,
),
)
left = abs(padding[0])
upper = abs(padding[1])
@@ -107,4 +217,4 @@ class TransformImage:
return (pil2tensor(transformed_images),)
__nodes__ = [TransformImage]
__nodes__ = [MTB_TransformImage]
+111 -32
View File
@@ -1,22 +1,24 @@
import hashlib
import json
import os
import re
import torch
from pathlib import Path
import folder_paths
import numpy as np
import hashlib
import torch
from PIL import Image, ImageOps
from PIL.PngImagePlugin import PngInfo
import folder_paths
from pathlib import Path
import json
from ..log import log
class LoadImageSequence:
class MTB_LoadImageSequence:
"""Load an image sequence from a folder. The current frame is used to determine which image to load.
Usually used in conjunction with the `Primitive` node set to increment to load a sequence of images from a folder.
Use -1 to load all matching frames as a batch.
"""
@classmethod
@@ -28,7 +30,10 @@ class LoadImageSequence:
"INT",
{"default": 0, "min": -1, "max": 9999999},
),
}
},
"optional": {
"range": ("STRING", {"default": ""}),
},
}
CATEGORY = "mtb/IO"
@@ -37,17 +42,28 @@ class LoadImageSequence:
"IMAGE",
"MASK",
"INT",
"INT",
)
RETURN_NAMES = (
"image",
"mask",
"current_frame",
"total_frames",
)
def load_image(self, path=None, current_frame=0):
def load_image(self, path=None, current_frame=0, range=""):
load_all = current_frame == -1
total_frames = 1
if load_all:
if range:
frames = self.get_frames_from_range(path, range)
imgs, masks = zip(*(img_from_path(frame) for frame in frames))
out_img = torch.cat(imgs, dim=0)
out_mask = torch.cat(masks, dim=0)
total_frames = len(imgs)
return (out_img, out_mask, -1, total_frames)
elif load_all:
log.debug(f"Loading all frames from {path}")
frames = resolve_all_frames(path)
log.debug(f"Found {len(frames)} frames")
@@ -55,33 +71,72 @@ class LoadImageSequence:
imgs = []
masks = []
for frame in frames:
img, mask = img_from_path(frame)
imgs.append(img)
masks.append(mask)
imgs, masks = zip(*(img_from_path(frame) for frame in frames))
out_img = torch.cat(imgs, dim=0)
out_mask = torch.cat(masks, dim=0)
total_frames = len(imgs)
return (
out_img,
out_mask,
)
return (out_img, out_mask, -1, total_frames)
log.debug(f"Loading image: {path}, {current_frame}")
print(f"Loading image: {path}, {current_frame}")
resolved_path = resolve_path(path, current_frame)
image_path = folder_paths.get_annotated_filepath(resolved_path)
image, mask = img_from_path(image_path)
return (
image,
mask,
current_frame,
)
return (image, mask, current_frame, total_frames)
def get_frames_from_range(self, path, range_str):
try:
start, end = map(int, range_str.split("-"))
except ValueError:
raise ValueError(
f"Invalid range format: {range_str}. Expected format is 'start-end'."
)
frames = resolve_all_frames(path)
total_frames = len(frames)
if start < 0 or end >= total_frames:
raise ValueError(
f"Range {range_str} is out of bounds. Total frames available: {total_frames}"
)
if "#" in path:
frame_regex = re.escape(path).replace(r"\#", r"(\d+)")
frame_number_regex = re.compile(frame_regex)
matching_frames = []
for frame in frames:
match = frame_number_regex.search(frame)
if match:
frame_number = int(match.group(1))
if start <= frame_number <= end:
matching_frames.append(frame)
return matching_frames
else:
log.warning(
f"Wildcard pattern or directory will use indexes instead of frame numbers for : {path}"
)
selected_frames = frames[start : end + 1]
return selected_frames
@staticmethod
def IS_CHANGED(path="", current_frame=0):
def IS_CHANGED(path="", current_frame=0, range=""):
print(f"Checking if changed: {path}, {current_frame}")
if range or current_frame == -1:
resolved_paths = resolve_all_frames(path)
timestamps = [
os.path.getmtime(folder_paths.get_annotated_filepath(p))
for p in resolved_paths
]
combined_hash = hashlib.sha256(
"".join(map(str, timestamps)).encode()
)
return combined_hash.hexdigest()
resolved_path = resolve_path(path, current_frame)
image_path = folder_paths.get_annotated_filepath(resolved_path)
if os.path.exists(image_path):
@@ -121,11 +176,28 @@ def img_from_path(path):
)
def resolve_all_frames(pattern):
def resolve_all_frames(path: str):
frames: list[str] = []
if "#" not in path:
pth = Path(path)
if pth.is_dir():
for f in pth.iterdir():
if f.suffix in [".jpg", ".png"]:
frames.append(f.as_posix())
elif "*" in path:
frames = glob.glob(path)
else:
raise ValueError(
"The path doesn't contain a # or a * or is not a directory"
)
frames.sort()
return frames
pattern = path
folder_path, file_pattern = os.path.split(pattern)
log.debug(f"Resolving all frames in {folder_path}")
frames = []
hash_count = file_pattern.count("#")
frame_pattern = re.sub(r"#+", "*", file_pattern)
@@ -157,7 +229,7 @@ def resolve_path(path, frame):
return re.sub("#+", padded_number, path)
class SaveImageSequence:
class MTB_SaveImageSequence:
"""Save an image sequence to a folder. The current frame is used to determine which image to save.
This is merely a wrapper around the `save_images` function with formatting for the output folder and filename.
@@ -173,7 +245,10 @@ class SaveImageSequence:
"required": {
"images": ("IMAGE",),
"filename_prefix": ("STRING", {"default": "Sequence"}),
"current_frame": ("INT", {"default": 0, "min": 0, "max": 9999999}),
"current_frame": (
"INT",
{"default": 0, "min": 0, "max": 9999999},
),
},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
@@ -220,10 +295,14 @@ class SaveImageSequence:
resolved_path = Path(self.output_dir) / filename_prefix
resolved_path.mkdir(parents=True, exist_ok=True)
resolved_img = resolved_path / f"{filename_prefix}_{current_frame:05}.png"
resolved_img = (
resolved_path / f"{filename_prefix}_{current_frame:05}.png"
)
output_image = images[0].cpu().numpy()
img = Image.fromarray(np.clip(output_image * 255.0, 0, 255).astype(np.uint8))
img = Image.fromarray(
np.clip(output_image * 255.0, 0, 255).astype(np.uint8)
)
metadata = PngInfo()
if prompt is not None:
metadata.add_text("prompt", json.dumps(prompt))
@@ -246,6 +325,6 @@ class SaveImageSequence:
__nodes__ = [
LoadImageSequence,
SaveImageSequence,
MTB_LoadImageSequence,
MTB_SaveImageSequence,
]
+141
View File
@@ -0,0 +1,141 @@
import cv2
import numpy as np
import torch
from huggingface_hub import hf_hub_download
from ..utils import models_dir, np2tensor
# TODO: check if I can make a torch script device independant
# for now I forced it to use cuda.
class MTB_LoadVitMatteModel:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"kind": (("Composition-1K", "Distinctions-646"),),
"autodownload": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("VITMATTE_MODEL",)
RETURN_NAMES = ("torch_script",)
CATEGORY = "mtb/vitmatte"
FUNCTION = "execute"
def execute(self, *, kind: str, autodownload: bool):
dest = models_dir / "vitmatte"
dest.mkdir(exist_ok=True)
name = "dis" if kind == "Distinctions-646" else "com"
file = hf_hub_download(
repo_id="melmass/pytorch-scripts",
filename=f"vitmatte_b_{name}.pt",
local_dir=dest.as_posix(),
local_files_only=not autodownload,
)
model = torch.jit.load(file).to("cuda")
return (model,)
class MTB_GenerateTrimap:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
# "image": ("IMAGE",),
"mask": ("MASK",),
"erode": ("INT", {"default": 10}),
"dilate": ("INT", {"default": 10}),
},
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("trimap",)
CATEGORY = "mtb/vitmatte"
FUNCTION = "execute"
def execute(
self,
# image:torch.Tensor,
mask: torch.Tensor,
erode: int = 10,
dilate: int = 10,
):
# TODO: not sure what's the most practical between IMAGE or MASK
# image = image.to("cuda").half()
mask = mask.to("cuda").half()
trimaps = []
for m in mask:
mask_arr = m.squeeze(0).to(torch.uint8).cpu().numpy() * 255
erode_kernel = np.ones((erode, erode), np.uint8)
dilate_kernel = np.ones((dilate, dilate), np.uint8)
eroded = cv2.erode(mask_arr, erode_kernel, iterations=5)
dilated = cv2.dilate(mask_arr, dilate_kernel, iterations=5)
trimap = np.zeros_like(mask_arr)
trimap[dilated == 255] = 128
trimap[eroded == 255] = 255
trimaps.append(trimap)
return (np2tensor(trimaps),)
class MTB_ApplyVitMatte:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("VITMATTE_MODEL",),
"image": ("IMAGE",),
"trimap": ("IMAGE",),
"returns": (("RGB", "RGBA"),),
},
}
RETURN_TYPES = ("IMAGE", "MASK")
RETURN_NAMES = ("image (rgba)", "mask")
CATEGORY = "mtb/utils"
FUNCTION = "execute"
def execute(
self, model, image: torch.Tensor, trimap: torch.Tensor, returns: str
):
im_count = image.shape[0]
tm_count = trimap.shape[0]
if im_count != tm_count:
raise ValueError("image and trimap must have the same batch size")
outputs_m: list[torch.Tensor] = []
outputs_i: list[torch.Tensor] = []
for i, im in enumerate(image):
tm = trimap[i].half().unsqueeze(2).permute(2, 0, 1).to("cuda")
im = im.half().permute(2, 0, 1).to("cuda")
inputs = {"image": im.unsqueeze(0), "trimap": tm.unsqueeze(0)}
fine_mask = model(inputs)
foreground = im * fine_mask + (1 - fine_mask)
if returns == "RGBA":
rgba_image = torch.cat(
(foreground, fine_mask.unsqueeze(0)), dim=0
)
outputs_i.append(rgba_image.unsqueeze(0))
else:
outputs_i.append(foreground.unsqueeze(0))
outputs_m.append(fine_mask.unsqueeze(0))
result_m = torch.cat(outputs_m, dim=0)
result_i = torch.cat(outputs_i, dim=0)
return (result_i.permute(0, 2, 3, 1), result_m)
__nodes__ = [MTB_LoadVitMatteModel, MTB_GenerateTrimap, MTB_ApplyVitMatte]
+182
View File
@@ -0,0 +1,182 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "comfy-mtb"
version = "0.5.4"
description = "Animation oriented nodes pack for ComfyUI."
license = { text = "MIT" }
readme = "README.md"
# repository = ""
# url = "https://github.com/melMass/comfy_mtb"
authors = [{ name = "Mel Massadian", email = "mel@melmassadian.com" }]
classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Intended Audience :: Developers",
]
requires-python = ">=3.10"
dependencies = [
"qrcode",
"cachetools",
"onnxruntime-gpu",
"requirements-parserx",
"rembg",
"imageio_ffmpeg",
"rich",
"rich_argparse",
"matplotlib",
"pillow",
]
optional-dependencies = { mel = [
"jupyterlab==4.1.6",
], dev = [
"black[jupyter]",
"codespell",
"marimo",
"mypy",
"pre-commit",
"pytest",
"pytest-cov",
"pytest-random-order",
"ruff",
], doc = [
"docutils==0.17.1",
"jupyter-book>=0.15",
"sphinx-autobuild",
] }
[project.urls]
Homepage = "https://github.com/melMass/comfy_mtb"
Documentation = "https://github.com/melMass/comfy_mtb/wiki"
Repository = "https://github.com/melMass/comfy_mtb"
Issues = "https://github.com/melMass/comfy_mtb/issues"
[tool.comfy]
PublisherId = "mel"
DisplayName = "comfy-mtb"
Icon = "https://avatars.githubusercontent.com/u/7041726?v=4"
[tool.bumpversion]
current_version = "0.5.1"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
replace = "{new_version}"
regex = false
ignore_missing_version = false
ignore_missing_files = false
tag = true
sign_tags = true
tag_name = "v{new_version}"
tag_message = "⬆️ Bump version: {current_version} → {new_version}"
allow_dirty = true
commit = true
message = "⬆️ Bump version: {current_version} → {new_version}"
commit_args = ""
[[tool.bumpversion.files]]
filename = "__init__.py"
search = "__version__ = \"{current_version}\""
replace = "__version__ = \"{new_version}\""
[[tool.bumpversion.files]]
filename = "pyproject.toml"
search = "version = \"{current_version}\""
replace = "version = \"{new_version}\""
# [[tool.bumpversion.files]]
# filename = "your_package/__init__.py"
# search = "__version__ = '{current_version}'"
# replace = "__version__ = '{new_version}'"
# INFO: All those remaining keys are meant for local dev
[tool.pyright]
include = ["."]
exclude = [
"**/node_modules",
"**/__pycache__",
"src/experimental",
"src/typestubs",
]
ignore = ["src/oldstuff"]
defineConstant = { DEBUG = true }
extraPaths = ["python", "../.."]
stubPath = "src/stubs"
reportMissingImports = true
reportMissingTypeStubs = false
typeCheckingMode = "basic"
pythonVersion = "3.10"
pythonPlatform = "Windows"
[tool.pytest.ini_options]
log_level = "DEBUG"
log_cli = true
markers = [
"wip: tests that aren't fully finished yet",
"heavy: marks tests as heavy (deselect with '-m \"not heavy\"')",
]
filterwarnings = ["ignore::UserWarning", 'ignore::DeprecationWarning']
[tool.isort]
profile = "black"
line_length = 88
auto_identify_namespace_packages = false
# NOTE:
# pyright doesn't like implicit namespace + single line (related to https://github.com/microsoft/pyright/issues/2882?) but it's horible so I'll live with it
force_single_line = false
known_first_party = ["mtb"]
extend_skip = ["archives"]
combine_straight_imports = true
[tool.coverage.run]
parallel = true
source = ["docs", "tests", "comfy-mtb"]
[tool.coverage.report]
fail_under = 90
show_missing = true
[tool.coverage.html]
show_contexts = true
[tool.ruff]
line-length = 79
extend-exclude = ["./docs/conf.py", "notebooks", "stubs"]
[tool.ruff.lint]
select = ["A", "B", "C", "D", "E", "F", "FBT", "I", "N", "S", "SIM", "UP", "W"]
# NOTE:
# D102 - undocumented-public-method (noisy)
# D103 - undocumented-public-function (noisy)
# D100 - undocumented-public-module (noisy)
# N802 - invalid-function-name (forced by comfy's arch)
ignore = ["D103", "D102", "D100", "N802"]
[tool.ruff.lint.per-file-ignores]
# imported but unused
"__init__.py" = ["F401"]
# use of assert detected
"tests/*" = ["S101"]
[tool.ruff.lint.pydocstyle]
convention = "numpy"
[tool.mypy]
pretty = true
ignore_missing_imports = true
# exclude auto generated file
exclude = ["docs/conf.py"]
[tool.codespell]
# exclude auto generated file
skip = "./docs/conf.py,poetry.lock"
check-filenames = true
+5 -1
View File
@@ -5,4 +5,8 @@ requirements-parser
rembg
imageio_ffmpeg
rich
rich_argparse
rich_argparse
matplotlib
pillow
cachetools
transformers
+2
View File
@@ -0,0 +1,2 @@
$env.GITHUB_TOKEN = (gh auth token)
git cliff --tag main | save -f CHANGELOG.md
+126
View File
@@ -0,0 +1,126 @@
// Some manual types I use to facilitate developing on top of
// Comfy's Litegraph implementation.
import type {
ContextMenuItem,
LGraphNode,
IWidget,
LGraph,
} from '../../../web/types/litegraph'
export type {
ComfyExtension,
ComfyObjectInfo,
ComfyObjectInfoConfig,
} from '../../../web/types/comfy'
export type {
ContextMenuItem,
IWidget,
LLink,
INodeInputSlot,
INodeOutputSlot,
} from '../../../web/types/litegraph'
export type VectorWidget = IWidget<number[], { default: number[] }>
export interface NodeData {
category: str
description: str
display_name: str
input: NodeInput
name: str
output: [str]
output_is_list: [boolean]
output_name: [str]
output_node: boolean
}
export interface ComfyDialog {
element: Element
close: () => void
show: (html: str) => void
}
export interface ComfySettingsDialog {
app: ComfyApp
element: Element
settingsValues: Record<string, unknown>
settingsLookup: Record<string, unknown>
load: () => Promise<void>
setSettingValueAsync: (id: string, value: unknown) => Promise<void>
}
export interface ComfyUI {
app: ComfyApp
dialog: ComfyDialog
settings: ComfySettingsDialog
autoQueueMode: 'instant' | 'change'
batchCount: number
lastQueueSize: number
graphHasChanged: boolean
queue: ComfyList
history: ComfyList
}
/**Very incomplete Comfy App definition*/
interface ComfyApp {
graph: LGraph
queueItems: { number: number; batchCount: number }[]
processingQueue: boolean
ui: ComfyUI
extensions: ComfyExtension[]
nodeOutputs: Record<string, unknown>
nodePreviewImages: Record<string, Image>
shiftDown: boolean
isImageNode: (node: LGraphNodeExtended) => boolean
queuePrompt: (number: number, batchCount: number) => Promise<void>
/** Loads workflow data from the specified file*/
handleFile: (file: File) => Promise<void>
}
export type { ComfyApp as App }
export interface LGraphNodeExtension {
addDOMWidget: (
name: string,
type: string,
element: Element,
options: Record<string, unknown>,
) => IWidget
onNodeCreated: () => void
getExtraMenuOptions: () => ContextMenuItem[]
prototype: LGraphNodeExtended
}
export type LGraphNodeExtended = LGraphNode & LGraphNodeExtension
export interface NodeType /*extends LGraphNode*/ {
category: str
comfyClass: str
length: 0
name: str
nodeData: NodeData
prototype: LGraphNodeExtended
title: str
type: str
}
export interface NodeInput {
required: object
}
// NOTE: for prototype overriding
export type OnDrawWidgetParams = Parameters<IWidget['draw']>
export type OnDrawForegroundParams = Parameters<LGraphNode['onDrawForeground']>
export type OnMouseDownParams = Parameters<LGraphNode['onMouseDown']>
export type OnConnectionsChangeParams = Parameters<
LGraphNode['onConnectionsChange']
>
export type OnNodeCreatedParams = Parameters<
LGraphNodeExtension['onNodeCreated']
>
export interface DocumentationOptions {
icon_size?: number
icon_margin?: number
}
+65
View File
@@ -0,0 +1,65 @@
/**
* @typedef {import("./shared.d.ts").NodeData} NodeData
* @typedef {import("./shared.d.ts").NodeType} NodeType
* @typedef {import("./shared.d.ts").DocumentationOptions} DocumentationOptions
* @typedef {import("./shared.d.ts").OnDrawForegroundParams} OnDrawForegroundParams
* @typedef {import("./shared.d.ts").OnMouseDownParams} OnMouseDownParams
* @typedef {import("./shared.d.ts").OnConnectionsChangeParams} OnConnectionsChangeParams
* @typedef {import("./shared.d.ts").ContextMenuItem} ContextMenuItem
* @typedef {import("./shared.d.ts").IWidget} IWidget
* @typedef {import("./shared.d.ts").VectorWidget} VectorWidget
* @typedef {import("./shared.d.ts").LGraphNodeExtended} LGraphNode
* @typedef {import("./shared.d.ts").LLink} LLink
* @typedef {import("./shared.d.ts").App} App
* @typedef {import("./shared.d.ts").OnDrawWidgetParams} OnDrawWidgetParams
* @typedef {import("./shared.d.ts").INodeInputSlot} INodeInputSlot
* @typedef {import("./shared.d.ts").INodeOutputSlot} INodeOutputSlot
*/
/**
* @typedef {Object} ResultItem
* @property {string} [filename] - The filename of the item.
* @property {string} [subfolder] - The subfolder of the item.
* @property {string} [type] - The type of the item.
*/
/**
* @typedef {Object} Outputs
* @property {ResultItem[]} [audio] - Audio result items.
* @property {ResultItem[]} [images] - Image result items.
* @property {ResultItem[]} [animated] - Animated result items.
*/
/**
* @typedef {Record<string, Outputs>} TaskOutput
* - A record mapping Node IDs to their Outputs.
*/
/**
* @typedef {Array} TaskPrompt
* @property {QueueIndex} [0] - The queue index.
* @property {PromptId} [1] - The unique prompt ID.
* @property {PromptInputs} [2] - The prompt inputs.
* @property {ExtraData} [3] - Extra data.
* @property {OutputsToExecute} [4] - The outputs to execute.
*/
/**
* @typedef {Object} HistoryTaskItem
* @property {'History'} taskType - The type of task.
* @property {TaskPrompt} prompt - The task prompt.
* @property {Status} [status] - The status of the task.
* @property {TaskOutput} outputs - The task outputs.
* @property {TaskMeta} [meta] - Optional task metadata.
*/
/**
* @typedef {Object} ExecInfo
* @property {number} queue_remaining - The number of items remaining in the queue.
*/
/**
* @typedef {Object} StatusWsMessageStatus
* @property {ExecInfo} exec_info - Execution information.
*/
+515 -83
View File
@@ -1,6 +1,7 @@
import contextlib
import functools
import math
import operator
import os
import shlex
import shutil
@@ -8,11 +9,17 @@ import socket
import subprocess
import sys
import uuid
from collections.abc import Callable, Sequence
from enum import Enum
from functools import reduce
from pathlib import Path
from typing import List, Optional, Union
from typing import TypeVar
from urllib.parse import urlparse
import comfy.utils
import folder_paths
import numpy as np
import numpy.typing as npt
import requests
import torch
from PIL import Image
@@ -43,14 +50,125 @@ def make_report():
# endregion
# region NFOV
class numpy_NFOV:
def __init__(self, fov=None, height: int = 400, width: int = 800):
self.field_of_view = fov or [0.45, 0.45]
self.PI = np.pi
self.PI_2 = np.pi * 0.5
self.PI2 = np.pi * 2.0
self.height = height
self.width = width
self.screen_points = self._get_screen_img()
def _get_coord_rad(self, is_center_point, center_point=None):
if is_center_point:
center_point = np.array(center_point)
return (center_point * 2 - 1) * np.array([self.PI, self.PI_2])
else:
return (
(self.screen_points * 2 - 1)
* np.array([self.PI, self.PI_2])
* (np.ones(self.screen_points.shape) * self.field_of_view)
)
def _get_screen_img(self):
xx, yy = np.meshgrid(
np.linspace(0, 1, self.width), np.linspace(0, 1, self.height)
)
return np.array([xx.ravel(), yy.ravel()]).T
def _calc_spherical_to_gnomonic(self, converted_screen_coord):
x = converted_screen_coord.T[0]
y = converted_screen_coord.T[1]
rou = np.sqrt(x**2 + y**2)
c = np.arctan(rou)
sin_c = np.sin(c)
cos_c = np.cos(c)
lat = np.arcsin(
cos_c * np.sin(self.cp[1]) + (y * sin_c * np.cos(self.cp[1])) / rou
)
lon = self.cp[0] + np.arctan2(
x * sin_c,
rou * np.cos(self.cp[1]) * cos_c - y * np.sin(self.cp[1]) * sin_c,
)
lat = (lat / self.PI_2 + 1.0) * 0.5
lon = (lon / self.PI + 1.0) * 0.5
return np.array([lon, lat]).T
def _bilinear_interpolation(self, screen_coord):
uf = np.mod(screen_coord.T[0], 1) * self.frame_width # long - width
vf = np.mod(screen_coord.T[1], 1) * self.frame_height # lat - height
x0 = np.floor(uf).astype(int) # coord of pixel to bottom left
y0 = np.floor(vf).astype(int)
x2 = np.add(
x0, np.ones(uf.shape).astype(int)
) # coords of pixel to top right
y2 = np.add(y0, np.ones(vf.shape).astype(int))
base_y0 = np.multiply(y0, self.frame_width)
base_y2 = np.multiply(y2, self.frame_width)
A_idx = np.add(base_y0, x0)
B_idx = np.add(base_y2, x0)
C_idx = np.add(base_y0, x2)
D_idx = np.add(base_y2, x2)
flat_img = np.reshape(self.frame, [-1, self.frame_channel])
A = np.take(flat_img, A_idx, axis=0)
B = np.take(flat_img, B_idx, axis=0)
C = np.take(flat_img, C_idx, axis=0)
D = np.take(flat_img, D_idx, axis=0)
wa = np.multiply(x2 - uf, y2 - vf)
wb = np.multiply(x2 - uf, vf - y0)
wc = np.multiply(uf - x0, y2 - vf)
wd = np.multiply(uf - x0, vf - y0)
# interpolate
AA = np.multiply(A, np.array([wa, wa, wa]).T)
BB = np.multiply(B, np.array([wb, wb, wb]).T)
CC = np.multiply(C, np.array([wc, wc, wc]).T)
DD = np.multiply(D, np.array([wd, wd, wd]).T)
nfov = np.reshape(
np.round(AA + BB + CC + DD).astype(np.uint8),
[self.height, self.width, 3],
)
return nfov
def to_nfov(self, frame, center_point):
self.frame = frame
self.frame_height = frame.shape[0]
self.frame_width = frame.shape[1]
self.frame_channel = frame.shape[2]
self.cp = self._get_coord_rad(
center_point=center_point, is_center_point=True
)
converted_screen_coord = self._get_coord_rad(is_center_point=False)
return self._bilinear_interpolation(
self._calc_spherical_to_gnomonic(converted_screen_coord)
)
# endregion
# region SERVER Utilities
class IPChecker:
def __init__(self):
self.ips = list(self.get_local_ips())
log.debug(f"Found {len(self.ips)} local ips")
self.checked_ips = set()
self.checked_ips: set[str] = set()
def get_working_ip(self, test_url_template):
def get_working_ip(self, test_url_template: str):
for ip in self.ips:
if ip not in self.checked_ips:
self.checked_ips.add(ip)
@@ -60,7 +178,7 @@ class IPChecker:
return None
@staticmethod
def get_local_ips(prefix="192.168."):
def get_local_ips(prefix: str = "192.168."):
hostname = socket.gethostname()
log.debug(f"Getting local ips for {hostname}")
for info in socket.getaddrinfo(hostname, None):
@@ -70,9 +188,9 @@ class IPChecker:
if info[0] == socket.AF_INET and info[4][0].startswith(prefix):
yield info[4][0]
def _test_url(self, url):
def _test_url(self, url: str):
try:
response = requests.get(url)
response = requests.get(url, timeout=10)
return response.status_code == 200
except Exception:
return False
@@ -83,10 +201,12 @@ def get_server_info():
from comfy.cli_args import args
ip_checker = IPChecker()
base_url = args.listen
base_url: str = args.listen
if base_url == "0.0.0.0":
log.debug("Server set to 0.0.0.0, we will try to resolve the host IP")
base_url = ip_checker.get_working_ip(f"http://{{}}:{args.port}/history")
base_url = ip_checker.get_working_ip(
f"http://{{}}:{args.port}/history"
)
log.debug(f"Setting ip to {base_url}")
return (base_url, args.port)
@@ -95,12 +215,151 @@ def get_server_info():
# region MISC Utilities
def glob_multiple(
path: Path, patterns: list[str], recursive: bool = False
) -> list[Path]:
"""Combine multiple glob patterns into a single iterator."""
return list(reduce(operator.or_, (set(path.glob(p)) for p in patterns)))
def build_glob_patterns(
extensions: list[str], recursive: bool = False
) -> list[str]:
"""Build glob patterns for given extensions."""
prefix = "**/" if recursive else ""
return [f"{prefix}*.{ext}" for ext in extensions]
class SortMode(Enum):
NONE = "none"
MODIFIED = "modified"
MODIFIED_REVERSE = "modified-reverse"
NAME = "name"
NAME_REVERSE = "name-reverse"
@classmethod
def from_str(cls, value: str | None) -> "SortMode|None":
if not value:
return None
try:
return cls(value.lower())
except ValueError:
log.warning(f"Sort mode {value} not supported")
return None
# TODO: use mtb.core directly instead of copying parts here
T = TypeVar("T", bound="StringConvertibleEnum")
class StringConvertibleEnum(Enum):
"""Base class for enums with utility methods for string conversion and member listing."""
@classmethod
def from_str(cls: type[T], label: str | T) -> T:
"""
Convert a string to the corresponding enum value (case sensitive).
Args:
label (Union[str, T]): The string or enum value to convert.
Returns
-------
T: The corresponding enum value.
Raises
------
ValueError: If the label does not correspond to any enum member.
"""
if isinstance(label, cls):
return label
if isinstance(label, str):
# from key
if label in cls.__members__:
return cls[label]
for member in cls:
if member.value == label:
return member
raise ValueError(
f"Unknown label: '{label}'. Valid members: {list(cls.__members__.keys())}, "
f"valid values: {cls.list_members()}"
)
@classmethod
def to_str(cls: type[T], enum_value: T) -> str:
"""
Convert an enum value to its string representation.
Args:
enum_value (T): The enum value to convert.
Returns
-------
str: The string representation of the enum value.
Raises
------
ValueError: If the enum value is invalid.
"""
if isinstance(enum_value, cls):
return enum_value.value
raise ValueError(f"Invalid Enum: {enum_value}")
@classmethod
def list_members(cls: type[T]) -> list[str]:
"""
Return a list of string representations of all enum members.
Returns
-------
List[str]: List of all enum member values.
"""
return [enum.value for enum in cls]
def __str__(self) -> str:
"""
Returns the string representation of the enum value.
Returns
-------
str: The string representation of the enum value.
"""
return self.value
class Precision(StringConvertibleEnum):
FULL = "full"
FP32 = "fp32"
FP16 = "fp16"
BF16 = "bf16"
FP8 = "fp8"
def to_dtype(self):
match self:
case Precision.FP32 | Precision.FULL:
return torch.float32
case Precision.FP16:
return torch.float16
case Precision.BF16:
return torch.bfloat16
case Precision.FP8:
return torch.float8_e4m3fn
class Operation(StringConvertibleEnum):
COPY = "copy"
CONVERT = "convert"
DELETE = "delete"
def backup_file(
fp: Path,
target: Optional[Path] = None,
target: Path | None = None,
backup_dir: str = ".bak",
suffix: Optional[str] = None,
prefix: Optional[str] = None,
suffix: str | None = None,
prefix: str | None = None,
):
if not fp.exists():
raise FileNotFoundError(f"No file found at {fp}")
@@ -166,7 +425,9 @@ def run_command(cmd, ignored_lines_start=None):
try:
_run_command(shell_cmd, ignored_lines_start)
except subprocess.CalledProcessError as e:
print(f"Command failed with return code: {e.returncode}", file=sys.stderr)
print(
f"Command failed with return code: {e.returncode}", file=sys.stderr
)
print(e.stderr.strip(), file=sys.stderr)
except KeyboardInterrupt:
@@ -200,23 +461,6 @@ def _run_command(shell_cmd, ignored_lines_start):
print("Command executed successfully!")
# todo use the requirements library
reqs_map = {value: key for key, value in pip_map.items()}
import importlib
def import_install(package_name):
package_spec = reqs_map.get(package_name, package_name)
try:
importlib.import_module(package_name)
except Exception: # (ImportError, ModuleNotFoundError):
run_command(
[Path(sys.executable).as_posix(), "-m", "pip", "install", package_spec]
)
importlib.import_module(package_name)
# endregion
@@ -238,21 +482,37 @@ here = Path(__file__).parent.absolute()
# - Construct the absolute path to the ComfyUI directory
comfy_dir = Path(folder_paths.base_path)
models_dir = Path(folder_paths.models_dir)
styles_dir = comfy_dir / "styles"
# NOTE: these aren't reliable, better call the getters each time
output_dir = Path(folder_paths.output_directory)
input_dir = Path(folder_paths.input_directory)
styles_dir = comfy_dir / "styles"
session_id = str(uuid.uuid4())
# - Construct the path to the font file
font_path = here / "font.ttf"
font_path = here / "data" / "font.ttf"
# - 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)
if extern_root.exists():
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_path(comfy_dir)
add_path((comfy_dir / "custom_nodes"))
add_path(comfy_dir / "custom_nodes")
# TODO: use the requirements library
reqs_map = {value: key for key, value in pip_map.items()}
# NOTE: store already logged warnings to only alert once.
warned_messages: set[str] = set()
PIL_FILTER_MAP = {
"nearest": Image.Resampling.NEAREST,
@@ -266,60 +526,141 @@ PIL_FILTER_MAP = {
# region TENSOR Utilities
def tensor2pil(image: torch.Tensor) -> List[Image.Image]:
batch_count = image.size(0) if len(image.shape) > 3 else 1
if batch_count > 1:
out = []
for i in range(batch_count):
out.extend(tensor2pil(image[i]))
return out
return [
Image.fromarray(
np.clip(255.0 * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)
)
]
def to_numpy(image: torch.Tensor) -> npt.NDArray[np.uint8]:
"""Converts a tensor to a ndarray with proper scaling and type conversion."""
np_array = np.clip(255.0 * image.cpu().numpy(), 0, 255).astype(np.uint8)
return np_array
def pil2tensor(image: Union[Image.Image, List[Image.Image]]) -> torch.Tensor:
if isinstance(image, list):
return torch.cat([pil2tensor(img) for img in image], dim=0)
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)
def handle_batch(
tensor: torch.Tensor,
func: Callable[[torch.Tensor], Image.Image | npt.NDArray[np.uint8]],
) -> list[Image.Image] | list[npt.NDArray[np.uint8]]:
"""Handles batch processing for a given tensor and conversion function."""
return [func(tensor[i]) for i in range(tensor.shape[0])]
def np2tensor(img_np: Union[np.ndarray, List[np.ndarray]]) -> torch.Tensor:
if isinstance(img_np, list):
return torch.cat([np2tensor(img) for img in img_np], dim=0)
def tensor2pil(tensor: torch.Tensor) -> list[Image.Image]:
"""Converts a batch of tensors to a list of PIL Images."""
return torch.from_numpy(img_np.astype(np.float32) / 255.0).unsqueeze(0)
def single_tensor2pil(t: torch.Tensor) -> Image.Image:
np_array = to_numpy(t)
if np_array.ndim == 2: # (H, W) for masks
return Image.fromarray(np_array, mode="L")
elif np_array.ndim == 3: # (H, W, C) for RGB/RGBA
if np_array.shape[2] == 3:
return Image.fromarray(np_array, mode="RGB")
elif np_array.shape[2] == 4:
return Image.fromarray(np_array, mode="RGBA")
raise ValueError(f"Invalid tensor shape: {t.shape}")
return handle_batch(tensor, single_tensor2pil)
def tensor2np(tensor: torch.Tensor) -> List[np.ndarray]:
batch_count = tensor.size(0) if len(tensor.shape) > 3 else 1
if batch_count > 1:
out = []
for i in range(batch_count):
out.extend(tensor2np(tensor[i]))
return out
def pil2tensor(images: Image.Image | list[Image.Image]) -> torch.Tensor:
"""Converts a PIL Image or a list of PIL Images to a tensor."""
return [np.clip(255.0 * tensor.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)]
def single_pil2tensor(image: Image.Image) -> torch.Tensor:
np_image = np.array(image).astype(np.float32) / 255.0
if np_image.ndim == 2: # Grayscale
return torch.from_numpy(np_image).unsqueeze(0) # (1, H, W)
else: # RGB or RGBA
return torch.from_numpy(np_image).unsqueeze(0) # (1, H, W, C)
if isinstance(images, Image.Image):
return single_pil2tensor(images)
else:
return torch.cat([single_pil2tensor(img) for img in images], dim=0)
def np2tensor(
np_array: npt.NDArray[np.float32] | Sequence[npt.NDArray[np.float32]],
) -> torch.Tensor:
"""Converts a NumPy array or a list of NumPy arrays to a tensor."""
def single_np2tensor(array: npt.NDArray[np.float32]) -> torch.Tensor:
if array.ndim == 2: # (H, W) for masks
return torch.from_numpy(
array.astype(np.float32) / 255.0
).unsqueeze(0) # (1, H, W)
elif array.ndim == 3: # (H, W, C) for RGB/RGBA
return torch.from_numpy(
array.astype(np.float32) / 255.0
).unsqueeze(0) # (1, H, W, C)
raise ValueError(f"Invalid array shape: {array.shape}")
if isinstance(np_array, np.ndarray):
return single_np2tensor(np_array)
else:
return torch.cat([single_np2tensor(arr) for arr in np_array], dim=0)
def tensor2np(tensor: torch.Tensor) -> list[npt.NDArray[np.uint8]]:
"""Converts a batch of tensors to a list of NumPy arrays."""
def single_tensor2np(t: torch.Tensor) -> npt.NDArray[np.uint8]:
t = t.squeeze() # Remove any singleton dimensions
if t.ndim == 2: # (H, W) for masks
return to_numpy(t)
elif t.ndim == 3: # (C, H, W) for RGB/RGBA
if t.shape[0] in [1, 3, 4]: # Channel-first format
t = t.permute(1, 2, 0)
return to_numpy(t)
else:
raise ValueError(f"Invalid tensor shape: {t.shape}")
return handle_batch(tensor, single_tensor2np)
def nextAvailable(path: Path | str) -> Path:
"""
Find the next available path by adding a numbered suffix. (mimics comfy's version).
Args:
path (Path): The original path to check
Returns
-------
Path: A path that doesn't exist yet
"""
path = Path(path)
if not path.is_absolute():
path = output_dir / path
if not path.exists():
return path
stem = path.stem
suffix = path.suffix
parent = path.parent
counter = 1
while True:
new_path = parent / f"{stem}_{counter:04d}{suffix}"
if not new_path.exists():
return new_path
counter += 1
def pad(img, left, right, top, bottom):
pad_width = np.array(((0, 0), (top, bottom), (left, right)))
print(f"pad_width: {pad_width}, shape: {pad_width.shape}") # Debugging line
print(
f"pad_width: {pad_width}, shape: {pad_width.shape}"
) # Debugging line
return np.pad(img, pad_width, mode="wrap")
def tiles_infer(tiles, ort_session, progress_callback=None):
"""Infer each tile with the given model. progress_callback will be called with
arguments : current tile idx and total tiles amount (used to show progress on
cursor in Blender)."""
cursor in Blender).
"""
out_channels = 3 # normal map RGB channels
tiles_nb = tiles.shape[0]
pred_tiles = np.empty((tiles_nb, out_channels, tiles.shape[2], tiles.shape[3]))
pred_tiles = np.empty(
(tiles_nb, out_channels, tiles.shape[2], tiles.shape[3])
)
for i in range(tiles_nb):
if progress_callback != None:
@@ -333,7 +674,6 @@ def tiles_infer(tiles, ort_session, progress_callback=None):
def generate_mask(tile_size, stride_size):
"""Generates a pyramidal-like mask. Used for mixing overlapping predicted tiles."""
tile_h, tile_w = tile_size
stride_h, stride_w = stride_size
ramp_h = tile_h - stride_h
@@ -372,8 +712,8 @@ def generate_mask(tile_size, stride_size):
def corner_mask(side_length):
"""Generates the corner part of the pyramidal-like mask.
Currently, only for square shapes."""
Currently, only for square shapes.
"""
corner = np.zeros([side_length, side_length])
for h in range(0, side_length):
@@ -409,8 +749,8 @@ def scaling_mask(side_length):
def tiles_merge(tiles, stride_size, img_size, paddings):
"""Merges the list of tiles into one image. img_size is the original size, before
padding."""
padding.
"""
_, tile_h, tile_w = tiles[0].shape
pad_left, pad_right, pad_top, pad_bottom = paddings
height = img_size[1] + pad_top + pad_bottom
@@ -443,7 +783,8 @@ def tiles_merge(tiles, stride_size, img_size, paddings):
def tiles_split(img, tile_size, stride_size):
"""Returns list of tiles from the given image and the padding used to fit the tiles
in it. Input image must have dimension C,H,W."""
in it. Input image must have dimension C,H,W.
"""
log.debug(f"Splitting img: tile {tile_size}, stride {stride_size} ")
tile_h, tile_w = tile_size
stride_h, stride_w = stride_size
@@ -499,8 +840,66 @@ def tiles_split(img, tile_size, stride_size):
# region MODEL Utilities
def download_model(model_url: str, destination: str):
if isinstance(model_url, list):
for url in model_url:
download_model(url, destination)
return
filename = Path(urlparse(model_url).path).name
if "drive.google.com" in model_url:
try:
import gdown
except ImportError:
log.info("Installing gdown")
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
"gdown",
]
)
import gdown
if "/folders/" in model_url:
# download folder
try:
gdown.download_folder(
model_url, output=destination, resume=True
)
except TypeError:
gdown.download_folder(model_url, output=destination)
return
# download from google drive
gdown.download(model_url, destination, quiet=False, resume=True)
return True
response = requests.get(model_url, stream=True)
total_size = int(response.headers.get("content-length", 0))
destination_path = get_model_path(destination, filename)
destination_path.parent.mkdir(exist_ok=True)
pbar = comfy.utils.ProgressBar(total_size)
with open(destination_path, "wb") as file:
for data in response.iter_content(chunk_size=4096):
file.write(data)
pbar.update(len(data))
log.info(
f"Downloaded model from {model_url} to {destination_path}",
)
def download_antelopev2():
antelopev2_url = "https://drive.google.com/uc?id=18wEUfMNohBJ4K3Ly5wpTejPfDzp-8fI8"
antelopev2_url = (
"https://drive.google.com/uc?id=18wEUfMNohBJ4K3Ly5wpTejPfDzp-8fI8"
)
try:
import gdown
@@ -547,10 +946,11 @@ def get_model_path(fam, model=None):
if res:
if isinstance(res, list):
if len(res) > 1:
log.warning(
f"Found multiple match, we will pick the first {res[0]}\n{res}"
)
res = res[0]
warn_msg = f"Found multiple match, we will pick the last {res[-1]}\n{res}"
if warn_msg not in warned_messages:
log.info(warn_msg)
warned_messages.add(warn_msg)
res = res[-1]
res = Path(res)
log.debug(f"Resolved model path from folder_paths: {res}")
else:
@@ -584,6 +984,32 @@ def create_uv_map_tensor(width=512, height=512):
# region ANIMATION Utilities
EASINGS = [
"Linear",
"Sine In",
"Sine Out",
"Sine In/Out",
"Quart In",
"Quart Out",
"Quart In/Out",
"Cubic In",
"Cubic Out",
"Cubic In/Out",
"Circ In",
"Circ Out",
"Circ In/Out",
"Back In",
"Back Out",
"Back In/Out",
"Elastic In",
"Elastic Out",
"Elastic In/Out",
"Bounce In",
"Bounce Out",
"Bounce In/Out",
]
def apply_easing(value, easing_type):
if easing_type == "Linear":
return value
@@ -611,7 +1037,10 @@ def apply_easing(value, easing_type):
return 1
p = 0.3
s = p / 4
return -(math.pow(2, 10 * (t - 1)) * math.sin((t - 1 - s) * (2 * math.pi) / p))
return -(
math.pow(2, 10 * (t - 1))
* math.sin((t - 1 - s) * (2 * math.pi) / p)
)
def easeOutElastic(t):
if t == 0:
@@ -632,10 +1061,13 @@ def apply_easing(value, easing_type):
t = t * 2
if t < 1:
return -0.5 * (
math.pow(2, 10 * (t - 1)) * math.sin((t - 1 - s) * (2 * math.pi) / p)
math.pow(2, 10 * (t - 1))
* math.sin((t - 1 - s) * (2 * math.pi) / p)
)
return (
0.5 * math.pow(2, -10 * (t - 1)) * math.sin((t - 1 - s) * (2 * math.pi) / p)
0.5
* math.pow(2, -10 * (t - 1))
* math.sin((t - 1 - s) * (2 * math.pi) / p)
+ 1
)
+4
View File
@@ -13,6 +13,10 @@ data otherwise:
![debug](https://github.com/melMass/comfy_mtb/assets/7041726/1f4393e4-1c3d-4807-9501-fe8888bfae25)
**note +**
A basic HTML note mainly to add better looking notes/instructions for workflow makers:
![image](https://github.com/melMass/comfy_mtb/assets/7041726/2ba1f832-0044-4bad-974c-e6387981af57)
## Standalone
These scripts can be taken and placed independently of `comfy_mtb` or any other files, mimicking what pythongosss did for their
+1006 -200
View File
File diff suppressed because it is too large Load Diff
+496
View File
@@ -0,0 +1,496 @@
import { app } from '../../scripts/app.js'
import * as shared from './comfy_shared.js'
import { infoLogger } from './comfy_shared.js'
import { MtbWidgets } from './mtb_widgets.js'
import { ComfyWidgets } from '../../scripts/widgets.js'
import * as mtb_widgets from './mtb_widgets.js'
/**
* @typedef {'number'|'string'|'vector2'|'vector3'|'vector4'|'color'} ConstantType
* @typedef {import ("../../../web/types/litegraph.d.ts").LGraphNode} Node
* @typedef {{x:number,y:number,z?:number,w?:number}} VectorValue
* @typedef {}
*
*/
/**
* @param {number} size - The number of axis of the vector (2,3 or 4)
* @param {number} val - The default scalar value to fill the vector with
* @returns {VectorValue} vector
* */
const initVector = (size, val = 0.0) => {
const res = {}
for (let i = 0; i < size; i++) {
const axis = mtb_widgets.VECTOR_AXIS[i]
res[axis] = val
}
return res
}
/**
*
* @extends {Node}
* @classdesc Wrapper for the python node
*/
export class ConstantJs {
constructor(python_node) {
// this.uuid = shared.makeUUID()
const wrapper = this
python_node.shape = LiteGraph.BOX_SHAPE
python_node.serialize_widgets = true
const onNodeCreated = python_node.prototype.onNodeCreated
python_node.prototype.onNodeCreated = function () {
const r = onNodeCreated ? onNodeCreated.apply(this) : undefined
this.addProperty('type', 'number')
this.addProperty('value', 0)
this.removeInput(0)
this.removeOutput(0)
this.addOutput('Output', '*')
// bind our wrapper
this.configure = wrapper.configure.bind(this)
// this.applyToGraph = wrapper.applyToGraph.bind(this)
this.updateWidgets = wrapper.updateWidgets.bind(this)
this.convertValue = wrapper.convertValue.bind(this)
// this.updateOutput = wrapper.updateOutput.bind(this)
this.updateOutputType = wrapper.updateOutputType.bind(this)
// this.updateTargetWidgets = wrapper.updateTargetWidgets.bind(this)
this.addWidget(
'combo',
'Type',
this.properties.type,
(value) => {
this.properties.type = value
this.updateWidgets()
this.updateOutputType()
},
{
values: [
// 'number',
'float',
'int',
'string',
'vector2',
'vector3',
'vector4',
'color',
],
},
)
this.updateWidgets()
this.updateOutputType()
for (let n = 0; n < this.inputs.length; n++) {
this.removeInput(n)
}
this.inputs = []
return r
}
return
}
// NOTE: this is called onPrompt
// applyToGraph() {
// infoLogger('Updating values for backend')
// this.updateTargetWidgets()
// }
// NOTE: deserialization happens here
configure(info) {
// super.configure(info)
infoLogger('Configure Constant', { info, node: this })
this.properties.type = info.properties.type
this.properties.value = info.properties.value
this.pos = info.pos
this.order = info.order
this.updateWidgets()
this.updateOutputType()
}
/**
* Convert the old value type to the new one, falling back to some default
* @param {ConstantType} propType - The target type
*/
convertValue(propType) {
switch (propType) {
case 'color': {
if (typeof this.properties.value !== 'string') {
this.properties.value = '#ffffff'
} else if (this.properties.value[0] !== '#') {
this.properties.value = '#ff0000'
}
break
}
case 'int': {
if (typeof this.properties.value === 'object') {
this.properties.value = Number.parseInt(this.properties.value.x)
} else {
this.properties.value = Number.parseInt(this.properties.value) || 0
}
break
}
case 'float': {
if (typeof this.properties.value === 'object') {
this.properties.value = Number.parseFloat(this.properties.value.x)
} else {
this.properties.value =
Number.parseFloat(this.properties.value) || 0.0
}
break
}
case 'string': {
if (typeof this.properties.value !== 'string') {
this.properties.value = JSON.stringify(this.properties.value)
}
break
}
case 'vector2':
case 'vector3':
case 'vector4': {
const numInputs = Number.parseInt(propType.charAt(6))
if (!this.properties.value) {
this.properties.value = initVector(numInputs) // Array.from({ length: numInputs }, () => 0.0)
} else if (typeof this.properties.value === 'string') {
try {
const parsed = JSON.parse(this.properties.value)
const newVec = {}
for (
let i = 0;
i < Object.keys(mtb_widgets.VECTOR_AXIS).length;
i++
) {
const axis = mtb_widgets.VECTOR_AXIS[i]
if (Object.keys(parsed).includes(axis)) {
newVec[axis] = parsed[axis]
}
}
this.properties.value = newVec
} catch (e) {
shared.errorLogger(e)
infoLogger(
`Couldn't parse string to vec (${this.properties.value})`,
)
this.properties.value = initVector(numInputs)
}
} else if (typeof this.properties.value === 'number') {
const newVec = initVector(numInputs)
newVec.x = Number.parseFloat(this.properties.value)
this.properties.value = newVec
}
if (
typeof this.properties.value === 'object' &&
Object.keys(this.properties.value).length !== numInputs
) {
const current = Object.keys(this.properties.value)
if (current.length < numInputs) {
infoLogger('current value smaller than target, adjusting')
for (let index = current.length; index < numInputs; index++) {
this.properties.value[mtb_widgets.VECTOR_AXIS[index]] = 0.0
}
} else {
infoLogger('current value greater than target, adjusting')
const newVal = {}
for (let index = 0; index < numInputs; index++) {
newVal[mtb_widgets.VECTOR_AXIS[index]] =
this.properties.value[mtb_widgets.VECTOR_AXIS[index]]
}
this.properties.value = newVal
}
}
break
}
default:
break
}
}
/**
* Remove all widgets but the comboBox for selecting the type
* then recreate the appropriate widget from scratch
*/
updateWidgets() {
// NOTE: Remove existing widgets
for (let i = 1; i < this.widgets.length; i++) {
const element = this.widgets[i]
if (element.onRemove) {
element.onRemove()
}
// element?.onRemove()
}
this.widgets.splice(1)
this.widgets[0].value = this.properties.type
this.convertValue(this.properties.type)
switch (this.properties.type) {
case 'color': {
const col_widget = this.addCustomWidget(
MtbWidgets.COLOR('Value', this.properties.value),
)
col_widget.callback = (col) => {
this.properties.value = col
// this.updateOutput()
}
break
}
case 'int': {
const f_widget = this.addCustomWidget(
ComfyWidgets.INT(
this,
'Value',
[
'',
{
default: this.properties.value,
callback: (val) => console.log('VALUE', val),
},
],
app,
),
)
f_widget.widget.callback = (val) => {
this.properties.value = val
}
break
}
case 'float': {
this.addWidget('number', 'Value', this.properties.value, (val) => {
this.properties.value = val
})
break
}
case 'string': {
mtb_widgets.addMultilineWidget(
this,
'Value',
{
defaultVal: this.properties.value,
},
(v) => {
this.properties.value = v
// this.updateOutput()
},
)
break
}
case 'vector2':
case 'vector3':
case 'vector4': {
const numInputs = Number.parseInt(this.properties.type.charAt(6))
const node = this
const v_widget = mtb_widgets.addVectorWidget(
this,
'Value',
this.properties.value, // value
numInputs, // vector_size
function (v) {
node.properties.value = v
// this.updateOutput()
},
)
break
}
// NOTE: this is not reached anymore, kept for reference
case 'number': {
if (typeof this.properties.value !== 'number') {
this.properties.value = 0.0
}
const n_widget = this.addWidget(
'number',
'Value',
this.properties.force_int
? Number.parseInt(this.properties.value)
: this.properties.value,
(value) => {
this.properties.value = this.properties.force_int
? Number.parseInt(value)
: value
// this.updateOutput()
},
)
//override the callback
const origCallback = n_widget.callback
const node = this
n_widget.callback = function (val) {
const r = origCallback ? origCallback.apply(this, [val]) : undefined
if (node.properties.force_int) {
// TODO: rework this, a it makes it harder to manipulate
this.value = Number.parseInt(this.value)
node.properties.value = Number.parseInt(this.value)
}
infoLogger('NEW NUMBER', this.value)
return r
}
this.addWidget(
'toggle',
'Convert to Integer',
this.properties.force_int,
(value) => {
this.properties.force_int = value
this.updateOutputType()
},
)
break
}
default:
break
}
}
onConnectionsChange(type, slotIndex, isConnected, link, ioSlot) {
// super.onConnectionsChange(type, slotIndex, isConnected, link, ioSlot)
if (isConnected) {
this.updateTargetWidgets([link.id])
}
}
updateOutputType() {
infoLogger('Updating output type')
const rm_if_mismatch = (type) => {
if (this.outputs[0].type !== type) {
for (let i = 0; i < this.outputs.length; i++) {
this.removeOutput(i)
}
this.addOutput('output', type)
// this.setOutputDataType(0, type)
}
}
switch (this.properties.type) {
case 'color':
rm_if_mismatch('COLOR')
break
case 'float':
rm_if_mismatch('FLOAT')
break
case 'int':
rm_if_mismatch('INT')
break
case 'number':
if (this.properties.force_int) {
rm_if_mismatch('INT')
} else {
rm_if_mismatch('FLOAT')
}
break
case 'string':
rm_if_mismatch('STRING')
break
// case 'vector2':
// case 'vector3':
// case 'vector4':
// rm_if_mismatch('FLOAT')
// break
case 'vector2':
rm_if_mismatch('VECTOR2')
break
case 'vector3':
rm_if_mismatch('VECTOR3')
break
case 'vector4':
rm_if_mismatch('VECTOR4')
break
default:
break
}
// this.updateOutput()
}
/**
* NOTE: This feels hacky but seems to work fine
* since Constant is a virtual node.
*/
updateTargetWidgets(u_links) {
infoLogger('Updating target widgets')
if (!app.graph.links) return
const links = u_links || this.outputs[0].links
if (!links) return
for (let i = 0; i < links.length; i++) {
const link = app.graph.links[links[i]]
const tgt_node = app.graph.getNodeById(link.target_id)
if (!tgt_node || !tgt_node.inputs) return
const tgt_input = tgt_node.inputs[link.target_slot]
if (!tgt_input) return
const tgt_widget = tgt_node.widgets.filter(
(w) => w.name === tgt_input.name,
)
// infoLogger('Constant Target Node', tgt_node)
// infoLogger('Constant Target Input', tgt_input)
if (!tgt_widget || tgt_widget.length === 0) return
tgt_widget[0].value = this.properties.value
}
}
updateOutput() {
infoLogger('Updating output value')
const value = this.properties.value
switch (this.properties.type) {
case 'color':
this.setOutputData(0, value)
break
case 'number':
if (this.properties.force_int) {
this.setOutputData(0, Number.parseInt(value))
} else {
this.setOutputData(0, Number.parseFloat(value))
}
break
case 'string':
this.setOutputData(0, value.toString())
break
case 'vector2':
case 'vector3':
case 'vector4':
this.setOutputData(0, value)
break
// case 'vector2':
// this.setOutputData(0, value.slice(0, 2))
// break
// case 'vector3':
// this.setOutputData(0, value.slice(0, 3))
// break
// case 'vector4':
// this.setOutputData(0, value.slice(0, 4))
// break
default:
break
}
infoLogger('New Value', this.value)
this.updateTargetWidgets()
}
}
app.registerExtension({
name: 'mtb.constant',
async beforeRegisterNodeDef(nodeType, nodeData, _app) {
if (nodeData.name === 'Constant (mtb)') {
new ConstantJs(nodeType)
}
},
// NOTE: old js only registration
//
// registerCustomNodes() {
// LiteGraph.registerNodeType('Constant (mtb)', Constant)
//
// Constant.category = 'mtb/utils'
// Constant.title = 'Constant (mtb)'
// },
})
+221
View File
@@ -0,0 +1,221 @@
// Reference the shared typedefs file
/// <reference path="../types/typedefs.js" />
import { app } from '../../scripts/app.js'
import { infoLogger } from './comfy_shared.js'
function B0(t) {
return (1 - t) ** 3 / 6
}
function B1(t) {
return (3 * t ** 3 - 6 * t ** 2 + 4) / 6
}
function B2(t) {
return (-3 * t ** 3 + 3 * t ** 2 + 3 * t + 1) / 6
}
function B3(t) {
return t ** 3 / 6
}
class CurveWidget {
constructor(...args) {
const [inputName, opts] = args
this.name = inputName || 'Curve'
this.type = 'FLOAT_CURVE'
this.selectedPointIndex = null
this.options = opts
this.value = this.value || { 0: { x: 0, y: 0 }, 1: { x: 1, y: 1 } }
}
drawBSpline(ctx, width, height, posY) {
const n = this.value.length - 1
const numSegments = n - 2
const numPoints = this.value.length
if (numPoints < 4) {
this.drawLinear(ctx, width, height, posY)
} else {
for (let j = 0; j <= numSegments; j++) {
for (let t = 0; t <= 1; t += 0.01) {
let pt = this.getBSplinePoint(j, t)
let x = pt.x * width
let y = posY + height - pt.y * height
if (t === 0) ctx.moveTo(x, y)
else ctx.lineTo(x, y)
}
}
ctx.stroke()
}
}
drawLinear(ctx, width, height, posY) {
for (let i = 0; i < Object.keys(this.value).length - 1; i++) {
let p1 = this.value[i]
let p2 = this.value[i + 1]
ctx.moveTo(p1.x * width, posY + height - p1.y * height)
ctx.lineTo(p2.x * width, posY + height - p2.y * height)
}
ctx.stroke()
}
getBSplinePoint(i, t) {
// Control points for this segment
const p0 = this.value[i]
const p1 = this.value[i + 1]
const p2 = this.value[i + 2]
const p3 = this.value[i + 3]
const x = B0(t) * p0.x + B1(t) * p1.x + B2(t) * p2.x + B3(t) * p3.x
const y = B0(t) * p0.y + B1(t) * p1.y + B2(t) * p2.y + B3(t) * p3.y
return { x, y }
}
/**
* @param {OnDrawWidgetParams} args
*/
draw(...args) {
const hide = this.type !== 'FLOAT_CURVE'
if (hide) {
return
}
const [ctx, node, width, posY, height] = args
const [cw, ch] = this.computeSize(width)
ctx.beginPath()
ctx.fillStyle = '#000'
ctx.strokeStyle = '#fff'
ctx.lineWidth = 2
// normalized coordinates -> canvas coordinates
for (let i = 0; i < Object.keys(this.value || {}).length - 1; i++) {
let p1 = this.value[i]
let p2 = this.value[i + 1]
ctx.moveTo(p1.x * cw, posY + ch - p1.y * ch)
ctx.lineTo(p2.x * cw, posY + ch - p2.y * ch)
}
ctx.stroke()
// points
Object.values(this.value || {}).forEach((point) => {
ctx.beginPath()
ctx.arc(point.x * cw, posY + ch - point.y * ch, 5, 0, 2 * Math.PI)
ctx.fill()
})
}
mouse(event, pos, node) {
let x = pos[0] - node.pos[0]
let y = pos[1] - node.pos[1]
const width = node.size[0]
const height = 300 // TODO: compute
const posY = node.pos[1]
const localPos = { x: pos[0], y: pos[1] - LiteGraph.NODE_WIDGET_HEIGHT }
if (event.type === LiteGraph.pointerevents_method + 'down') {
console.debug('Checking if a point was clicked')
const clickedPointIndex = this.detectPoint(localPos, width, height)
if (clickedPointIndex !== null) {
this.selectedPointIndex = clickedPointIndex
} else {
this.addPoint(localPos, width, height)
}
return true
} else if (
event.type === LiteGraph.pointerevents_method + 'move' &&
this.selectedPointIndex !== null
) {
this.movePoint(this.selectedPointIndex, localPos, width, height)
return true
} else if (
event.type === LiteGraph.pointerevents_method + 'up' &&
this.selectedPointIndex !== null
) {
this.selectedPointIndex = null
return true
}
return false
}
callback(...args) {
//value, that, node, pos, event) {
}
detectPoint(localPos, width, height) {
const threshold = 20 // TODO: extract
const keys = Object.keys(this.value)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
const p = this.value[key]
const px = p.x * width
const py = height - p.y * height
if (
Math.abs(localPos.x - px) < threshold &&
Math.abs(localPos.y - py) < threshold
) {
return key
}
}
return null
}
addPoint(localPos, width, height) {
// add a new point based on click position
const normalizedPoint = {
x: localPos.x / width,
y: 1 - localPos.y / height,
}
const keys = Object.keys(this.value)
let insertIndex = keys.length
for (let i = 0; i < keys.length; i++) {
if (normalizedPoint.x < this.value[keys[i]].x) {
insertIndex = i
break
}
}
// shift
for (let i = keys.length; i > insertIndex; i--) {
this.value[i] = this.value[i - 1]
}
this.value[insertIndex] = normalizedPoint
}
movePoint(index, localPos, width, height) {
const point = this.value[index]
point.x = Math.max(0, Math.min(1, localPos.x / width))
point.y = Math.max(0, Math.min(1, 1 - localPos.y / height))
this.value[index] = point
}
computeSize(width) {
return [width, 300]
}
configure(data) {
}
}
app.registerExtension({
name: 'mtb.curves',
getCustomWidgets: () => {
return {
/**
* @param {LGraphNode} node
* @param {str} inputName
* @param {[str,*]} inputData
* @param {*} app
*
*/
FLOAT_CURVE: (node, inputName, inputData, app) => {
// const c = node.widgets.find((w) => w.type === "FLOAT_CURVE")
const wid = node.addCustomWidget(new CurveWidget(inputName, inputData))
return {
widget: wid,
minWidth: 150,
minHeight: 30,
}
},
}
},
})
+137 -57
View File
@@ -7,13 +7,12 @@
*
*/
// Reference the shared typedefs file
/// <reference path="../types/typedefs.js" />
import { app } from '../../scripts/app.js'
import * as shared from './comfy_shared.js'
import { log } from './comfy_shared.js'
import { MtbWidgets } from './mtb_widgets.js'
// TODO: respect inputs order...
import * as mtb_ui from './mtb_ui.js'
function escapeHtml(unsafe) {
return unsafe
@@ -23,38 +22,96 @@ function escapeHtml(unsafe) {
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
}
function createDebugSection(title) {
const section = mtb_ui.makeElement('div', {
margin: '8px 0',
padding: '8px',
borderRadius: '4px',
backgroundColor: 'rgba(0,0,0,0.2)',
})
const header = mtb_ui.makeElement('h3', {
margin: '0 0 8px 0',
padding: '4px 0',
borderBottom: '1px solid rgba(255,255,255,0.1)',
fontSize: '14px',
fontWeight: 'bold',
color: '#9f9',
})
header.textContent = title
section.appendChild(header)
return section
}
function createDebugContent(content, type) {
const wrapper = mtb_ui.makeElement('div', {
margin: '4px 0',
})
if (type === 'text') {
const text = mtb_ui.makeElement('p', {
margin: '2px 0',
fontFamily: 'monospace',
whiteSpace: 'pre-wrap',
})
text.innerHTML = content
wrapper.appendChild(text)
} else if (type === 'image') {
const img = mtb_ui.makeElement('img', {
width: '100%',
borderRadius: '2px',
})
img.src = content
wrapper.appendChild(img)
}
return wrapper
}
app.registerExtension({
name: 'mtb.Debug',
/**
* @param {NodeType} nodeType
* @param {NodeData} nodeData
* @param {*} app
*/
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === 'Debug (mtb)') {
const onNodeCreated = nodeType.prototype.onNodeCreated
nodeType.prototype.onNodeCreated = function () {
const r = onNodeCreated
? onNodeCreated.apply(this, arguments)
: undefined
this.addInput(`anything_1`, '*')
nodeType.prototype.onNodeCreated = function (...args) {
this.options = {}
const r = onNodeCreated ? onNodeCreated.apply(this, args) : undefined
this.addInput('anything_1', '*')
return r
}
const onConnectionsChange = nodeType.prototype.onConnectionsChange
nodeType.prototype.onConnectionsChange = function (
type,
index,
connected,
link_info
) {
/**
* @param {OnConnectionsChangeParams} args
*/
nodeType.prototype.onConnectionsChange = function (...args) {
const [_type, index, connected, link_info, ioSlot] = args
const r = onConnectionsChange
? onConnectionsChange.apply(this, arguments)
? onConnectionsChange.apply(this, args)
: undefined
// TODO: remove all widgets on disconnect once computed
shared.dynamic_connection(this, index, connected, 'anything_', '*')
shared.dynamic_connection(this, index, connected, 'anything_', '*', {
link: link_info,
ioSlot: ioSlot,
})
//- infer type
if (link_info) {
const fromNode = this.graph._nodes.find(
(otherNode) => otherNode.id == link_info.origin_id
)
const type = fromNode.outputs[link_info.origin_slot].type
// const fromNode = this.graph._nodes.find(
// (otherNode) => otherNode.id === link_info.origin_id,
// )
// const fromNode = app.graph.getNodeById(link_info.origin_id)
const { from } = shared.nodesFromLink(this, link_info)
if (!from || this.inputs.length === 0) return
const type = from.outputs[link_info.origin_slot].type
this.inputs[index].type = type
// this.inputs[index].label = type.toLowerCase()
}
@@ -63,58 +120,81 @@ app.registerExtension({
this.inputs[index].type = '*'
this.inputs[index].label = `anything_${index + 1}`
}
return r
}
const onExecuted = nodeType.prototype.onExecuted
nodeType.prototype.onExecuted = function (message) {
onExecuted?.apply(this, arguments)
const prefix = 'anything_'
nodeType.prototype.onExecuted = function (...args) {
onExecuted?.apply(this, args)
const [data, ..._rest] = args
if (this.widgets) {
// const pos = this.widgets.findIndex((w) => w.name === "anything_1");
// if (pos !== -1) {
let tgt_len = this.widgets.length
for (let i = 0; i < this.widgets.length; i++) {
if (this.widgets[i].name !== 'output_to_console') {
if (
this.widgets[i].name !== 'output_to_console' &&
this.widgets[i].name !== 'as_detailed_types'
) {
this.widgets[i].onRemove?.()
this.widgets[i].onRemoved?.()
tgt_len -= 1
}
}
this.widgets.length = 1
this.widgets.length = tgt_len
}
const inputData = {}
const uiData = data.ui || data
if (uiData.items) {
uiData.items.forEach((item) => {
const inputName = item.input
if (!inputData[inputName]) {
inputData[inputName] = { text: [], b64_images: [] }
}
if (item.text) {
inputData[inputName].text.push(...item.text)
}
if (item.b64_images) {
inputData[inputName].b64_images.push(...item.b64_images)
}
})
}
let widgetI = 1
if (message.text) {
for (const txt of message.text) {
const w = this.addCustomWidget(
MtbWidgets.DEBUG_STRING(`${prefix}_${widgetI}`, escapeHtml(txt))
)
w.parent = this
widgetI++
for (const [inputName, content] of Object.entries(inputData)) {
if (content.text.length === 0 && content.b64_images.length === 0) {
continue
}
}
if (message.b64_images) {
for (const img of message.b64_images) {
const w = this.addCustomWidget(
MtbWidgets.DEBUG_IMG(`${prefix}_${widgetI}`, img)
)
w.parent = this
widgetI++
}
// this.onResize?.(this.size);
// this.resize?.(this.size)
}
this.setSize(this.computeSize())
const section = createDebugSection(inputName)
if (content.text.length > 0) {
content.text.forEach((text) => {
section.appendChild(createDebugContent(text, 'text'))
})
}
if (content.b64_images.length > 0) {
content.b64_images.forEach((img) => {
section.appendChild(createDebugContent(img, 'image'))
})
}
this.addDOMWidget(`debug_section_${widgetI}`, 'CUSTOM', section, {})
widgetI++
}
this.onRemoved = function () {
// When removing this node we need to remove the input from the DOM
for (let y in this.widgets) {
if (this.widgets[y].canvas) {
this.widgets[y].canvas.remove()
for (const widget of this.widgets) {
if (widget.canvas) {
widget.canvas.remove()
}
shared.cleanupNode(this)
this.widgets[y].onRemoved?.()
widget.onRemoved?.()
widget.onRemove?.()
}
shared.cleanupNode(this)
}
}
}
+3
View File
File diff suppressed because one or more lines are too long
+29 -6
View File
@@ -11,7 +11,7 @@
import { api } from '../../scripts/api.js'
import { app } from '../../scripts/app.js'
import { LocalStorageManager } from './comfy_shared.js'
const styles = {
lighbox: {
position: 'fixed',
@@ -53,17 +53,40 @@ let currentImageIndex = 0
const imageUrls = []
let image_menu = null
let activated = true
const storage = new LocalStorageManager('mtb')
let activated = storage.get('image_feed', false)
app.registerExtension({
name: 'mtb.ImageFeed',
setup: () => {
app.ui.settings.addSetting({
id: 'mtb.Main.image-feed-enabled',
category: ['mtb', ' Main', 'image-feed-enabled'],
name: 'Enable Image Feed',
type: 'boolean',
defaultValue: false,
attrs: {
style: {
fontFamily: 'monospace',
},
},
async onChange(value) {
storage.set('image_feed', value)
activated = value
},
})
},
init: async () => {
if (!activated) {
return
}
const pythongossFeed = app.extensions.find(
(e) => e.name == 'pysssss.ImageFeed'
(e) => e.name === 'pysssss.ImageFeed',
)
if (pythongossFeed) {
console.warn(
"[mtb] - Aborting the loading of mtb's imageFeed in favor of pysssss.ImageFeed"
"[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
@@ -94,7 +117,7 @@ app.registerExtension({
const lightboxCloseBtn = document.createElement('button')
Object.assign(
lightboxCloseBtn.style,
styles.lightboxBtn({ right: '0', top: '0' })
styles.lightboxBtn({ right: '0', top: '0' }),
)
lightboxCloseBtn.textContent = '❌'
@@ -164,7 +187,7 @@ app.registerExtension({
//- append to DOM
document.body.append(imageListContainer)
showBtn.textContent = '🖼️'
showBtn.textContent = '🖼'
showBtn.onclick = () => {
imageListContainer.style.display = 'block'
showBtn.style.display = 'none'
+515
View File
@@ -0,0 +1,515 @@
/// <reference path="../types/typedefs.js" />
import { app } from '../../scripts/app.js'
import { api } from '../../scripts/api.js'
import * as mtb_ui from './mtb_ui.js'
import * as shared from './comfy_shared.js'
import {
// defineCSSClass,
ensureMTBStyles,
makeElement,
makeSelect,
makeSlider,
renderSidebar,
} from './mtb_ui.js'
const offset = 0
// These are "global" variables mostly meant to sync user settings.
let currentWidth = 200
let saltUrls =
app.extensionManager.setting.get('mtb.io-sidebar.salt_urls') || false
let targetWidth =
app.extensionManager.setting.get('mtb.io-sidebar.img-size') || 512
let currentMode = 'input'
let subfolder = ''
let currentSort = 'None'
const IMAGE_NODES = ['LoadImage', 'VHS_LoadImagePath']
const VIDEO_NODES = ['VHS_LoadVideo']
const PROCESSED_PROMPT_IDS = new Set()
const updateImage = (node, image) => {
if (IMAGE_NODES.includes(node.type)) {
const w = node.widgets?.find((w) => w.name === 'image')
if (w) {
w.value = image
w.callback()
}
} else if (VIDEO_NODES.includes(node.type)) {
const w = node.widgets?.find((w) => w.name === 'video')
if (w) {
node.updateParameters({ filename: image }, true)
}
} else {
console.warn('No method to update', node.type)
}
}
/**
* Converts a result item to a request url.
* @param {ResultItem} resultItem
* @returns {string} - The request URL.
*/
const resultItemToQuery = (resultItem) => {
const res = [
`/mtb/view?filename=${resultItem.filename}`,
`type=${resultItem.type}`,
`subfolder=${resultItem.subfolder}`,
'preview=',
]
if (targetWidth > 0) {
res.splice(1, 0, `width=${targetWidth}`)
}
return res.join('&')
}
/**
* Retrieves the unique prompt ID from a history task item.
* @param {HistoryTaskItem} historyTaskItem
* @returns {string} - The prompt ID.
*/
const getPromptId = (historyTaskItem) => `${historyTaskItem.prompt[1]}`
/**
* Process and return any new/unseen outputs from the most recent history item.
* @param {HistoryTaskItem} mostRecentTask - The most recent history task item.
* @returns {Object<string, string>} - A map of task outputs URLs.
*/
const getNewOutputUrls = (mostRecentTask) => {
if (!mostRecentTask) return
const promptId = getPromptId(mostRecentTask)
if (PROCESSED_PROMPT_IDS.has(promptId)) return
const urls = {}
for (const nodeOutputs of Object.values(mostRecentTask.outputs)) {
const { images, audio, animated } = nodeOutputs
if (images) {
const imageOutputs = Object.values(nodeOutputs.images)
imageOutputs.forEach(
(resultItem) =>
(urls[resultItem.filename] = resultItemToQuery(resultItem)),
)
}
// Can process `animated` and `audio` outputs here.
}
const foundNewOutputs = Object.keys(urls).length > 0
if (!foundNewOutputs) return null
PROCESSED_PROMPT_IDS.add(promptId)
return urls
}
/** Fetch history and update the grid with any new ouput images. */
const updateOutputsGrid = async () => {
try {
const history = await api.getHistory(/** maxSize: */ 1)
const mostRcentTask = history.History[0]
const newUrls = getNewOutputUrls(mostRcentTask)
if (newUrls) {
const imgGrid = document.querySelector('.mtb_img_grid')
getImgsFromUrls(newUrls, imgGrid, { prepend: true })
}
} catch (error) {
console.error('Error fetching history:', error)
}
}
const getImgsFromUrls = (urls, target, options = { prepend: false }) => {
const imgs = []
if (urls === undefined) {
return imgs
}
const elem = currentMode === 'video' ? 'video' : 'img'
for (const [key, url] of Object.entries(urls)) {
const a = makeElement(elem)
a.src = url
a.width = currentWidth
if (currentMode === 'input') {
a.onclick = (_e) => {
if (subfolder !== '') {
app.extensionManager.toast.add({
severity: 'warn',
summary: 'Subfolder not supported',
detail: "The LoadImage node doesn't support subfolders",
life: 5000,
})
return
}
const selected = app.canvas.selected_nodes
if (selected && Object.keys(selected).length === 0) {
app.extensionManager.toast.add({
severity: 'warn',
summary: 'No node selected!',
detail:
'For now the only action when clicking images in the sidebar is to set the image on all selected LoadImage nodes.',
life: 5000,
})
return
}
for (const [_id, node] of Object.entries(app.canvas.selected_nodes)) {
updateImage(node, key)
}
}
} else if (currentMode === 'output') {
a.onclick = (_e) => {
// window.MTB?.notify?.("Output import isn't supported yet...", 5000)
if (subfolder !== '') {
app.extensionManager.toast.add({
severity: 'warn',
summary: 'Subfolder not supported',
detail: "The LoadImage node doesn't support subfolders",
life: 5000,
})
return
}
app.extensionManager.toast.add({
severity: 'warn',
summary: 'Outputs not supported',
detail:
'For now only inputs can be clicked to load the image on the active LoadImage node.',
life: 5000,
})
}
} else {
a.autoplay = true
a.muted = true
a.loop = true
a.onclick = (_e) => {
const selected = app.canvas.selected_nodes
if (selected && Object.keys(selected).length === 0) {
app.extensionManager.toast.add({
severity: 'warn',
summary: 'No node selected!',
detail:
"For now the only action when clicking videos in the sidebar is to set the video on all selected 'Load Video (Upload)' nodes.",
life: 5000,
})
return
}
for (const [_id, node] of Object.entries(app.canvas.selected_nodes)) {
updateImage(node, key)
}
}
}
imgs.push(a)
}
if (target !== undefined) {
if (options.prepend) target.prepend(...imgs)
else target.append(...imgs)
}
return imgs
}
const getModes = async () => {
const inputs = await shared.runAction('getUserImageFolders')
return inputs
}
const getUrls = async (subfolder) => {
const count = (await api.getSetting('mtb.io-sidebar.count')) || 1000
console.log('Sidebar count', count)
if (currentMode === 'video') {
const output = await shared.runAction(
'getUserVideos',
targetWidth,
count,
offset,
currentSort,
)
return output || {}
}
const output = await shared.runAction(
'getUserImages',
currentMode,
targetWidth,
count,
offset,
currentSort,
false,
subfolder,
saltUrls,
)
return output || {}
}
//NOTE: do not load if using the old ui
if (window?.__COMFYUI_FRONTEND_VERSION__) {
// NOTE: removed this for now since I'm not actually exposing anything a client
// cannot already access from "/view"...
// let exposed = false
const sidebar_extension = {
name: 'mtb.io-sidebar',
settings: [
{
id: 'mtb.io-sidebar.count',
category: ['mtb', 'Input & Output Sidebar', 'count'],
name: 'Number of images to fetch',
type: 'number',
defaultValue: 1000,
tooltip:
"This setting affects the input/output sidebar to determine how many images to fetch per pagination (pagination is not yet supported so for now it's the static total)",
},
{
id: 'mtb.io-sidebar.salt_urls',
category: ['mtb', 'Input & Output Sidebar', 'salt_urls'],
name: 'Salt URLs',
type: 'boolean',
defaultValue: false,
onChange: (n, o) => {
saltUrls = n
},
tooltip:
'Adds a random query parameter to every urls to always invalidate caching.',
},
{
id: 'mtb.io-sidebar.img-size',
category: ['mtb', 'Input & Output Sidebar', 'img-size'],
name: 'Resize width of shown images',
defaultValue: 512,
type: (name, setter, value, attrs) => {
targetWidth = value
const container = mtb_ui.makeElement('div', {
display: 'flex',
alignItems: 'center',
gap: '8px',
})
console.log({ name, setter, value, attrs })
const baseId = name.replace(/[^a-zA-Z0-9]/g, '-').toLowerCase()
const checkboxId = `${baseId}-checkbox`
const numberInputId = `${baseId}-number`
const isCheckedInitially = value !== -1
// TODO: better way to get defaultValue?
const defaultValue = 512
const initialNumberValue = isCheckedInitially ? value : defaultValue
console.log('recreate')
const checkbox = mtb_ui.makeElement(
// harder to match styles (.p-toggleswitch-input)
// since it uses a div synced to the input...
'input',
{},
container,
)
checkbox.type = 'checkbox'
checkbox.id = checkboxId
checkbox.checked = isCheckedInitially
const numberInput = mtb_ui.makeElement(
'input.p-inputtext',
{},
container,
)
numberInput.type = 'number'
numberInput.id = numberInputId
numberInput.value = initialNumberValue
numberInput.disabled = !isCheckedInitially
numberInput.min = 128
checkbox.addEventListener('change', () => {
let valToSet = -1
if (checkbox.checked) {
numberInput.disabled = false
valToSet = Number.parseInt(numberInput.value, 10)
if (Number.isNaN(valToSet) || valToSet < numberInput.min) {
valToSet = defaultValue
numberInput.value = valToSet
}
} else {
numberInput.disabled = true
}
setter(valToSet)
})
numberInput.addEventListener('input', () => {
if (checkbox.checked) {
const numValue = Number.parseInt(numberInput.value, 10)
if (!Number.isNaN(numValue) && numberInput.value !== '') {
setter(numValue)
}
}
})
return container
},
tooltip:
"If browsing large folders it's recommended to use this to avoid overflow/crash of the webpage. Image will get resized to this target width on the server before being sent to the client.",
},
{
id: 'mtb.io-sidebar.sort',
category: ['mtb', 'Input & Output Sidebar', 'sort'],
name: 'Default sort mode',
type: 'combo',
onChange: (v) => {
// alert(`Sort is now ${v}`)
currentSort = v
},
defaultValue: 'Modified',
// tooltip: "It's recommended to keep it at 512px",
options: [
'None',
'Modified',
'Modified-Reverse',
'Name',
'Name-Reverse',
],
},
{
id: 'mtb.io-sidebar.notice',
category: ['mtb', 'Input & Output Sidebar', 'sort'],
name: ' ',
type: (name, setter, value, attrs) => {
const container = mtb_ui.makeElement('div')
const notice =
'## Important\nIf you make **any** edits here you need to toggle off and back on the sidebar for it to take effect.'
if (window.MTB?.mdParser) {
MTB.mdParser.parse(notice).then((e) => {
container.innerHTML = e
})
} else {
shared.ensureMarkdownParser((p) => {
p.parse(notice).then((e) => {
container.innerHTML = e
})
})
}
return container
},
},
],
init: () => {
let handle
const version = window?.__COMFYUI_FRONTEND_VERSION__
console.log(`%c ${version}`, 'background: orange; color: white;')
ensureMTBStyles()
app.extensionManager.registerSidebarTab({
id: 'mtb-inputs-outputs',
icon: 'pi pi-images',
title: 'Input & Outputs',
tooltip: 'MTB: Browse inputs and outputs directories.',
type: 'custom',
// this is run everytime the tab's diplay is toggled on.
render: async (el) => {
if (handle) {
handle.unregister()
handle = undefined
}
if (el.parentNode) {
el.parentNode.style.overflowY = 'clip'
}
const allModes = await getModes()
const input_modes = allModes.input.map((m) => `input - ${m}`)
const output_modes = allModes.output.map((m) => `output - ${m}`)
const urls = await getUrls()
let imgs = {}
const cont = makeElement('div.mtb_sidebar')
const imgGrid = makeElement('div.mtb_img_grid')
const selector = makeSelect(
['input', 'output', 'video', ...output_modes, ...input_modes],
currentMode,
)
selector.addEventListener('change', async (e) => {
let newMode = e.target.value
let changed = false
let newSub = ''
if (newMode !== 'input' && newMode !== 'output') {
if (newMode.startsWith('input - ')) {
newSub = newMode.replace('input - ', '')
newMode = 'input'
} else if (newMode.startsWith('output - ')) {
newSub = newMode.replace('output - ', '')
newMode = 'output'
}
}
changed = newMode !== currentMode || newSub !== subfolder
currentMode = newMode
subfolder = newSub
if (changed) {
imgGrid.innerHTML = ''
const urls = await getUrls(subfolder)
if (urls) {
imgs = getImgsFromUrls(urls, imgGrid)
}
}
})
const imgTools = makeElement('div.mtb_tools')
const orderSelect = makeSelect(
['None', 'Modified', 'Modified-Reverse', 'Name', 'Name-Reverse'],
currentSort,
)
orderSelect.addEventListener('change', async (e) => {
const newSort = e.target.value
const changed = newSort !== currentSort
currentSort = newSort
if (changed) {
imgGrid.innerHTML = ''
const urls = await getUrls(subfolder)
if (urls) {
imgs = getImgsFromUrls(urls, imgGrid)
}
}
})
const sizeSlider = makeSlider(64, 1024, currentWidth, 1)
imgTools.appendChild(orderSelect)
imgTools.appendChild(sizeSlider)
imgs = getImgsFromUrls(urls, imgGrid)
sizeSlider.addEventListener('input', (e) => {
currentWidth = e.target.value
for (const img of imgs) {
img.style.width = `${e.target.value}px`
}
})
handle = renderSidebar(el, cont, [selector, imgGrid, imgTools])
app.api.addEventListener('status', async () => {
if (currentMode !== 'output') return
updateOutputsGrid()
})
},
destroy: () => {
if (handle) {
handle.unregister()
handle = undefined
app.api.removeEventListener('status')
}
},
})
},
}
app.registerExtension(sidebar_extension)
}
+519
View File
@@ -0,0 +1,519 @@
/**
* Adds a named stylesheet to the document with an optional ability to replace an existing one.
*
* @param {string} name - The unique name (ID) of the stylesheet.
* @param {string} css - The CSS rules as a string.
* @param {boolean} [force=false] - Whether to replace the existing stylesheet if it exists.
* @returns {void}
*/
export function addNamedStyleSheet(name, css, force = false) {
const existingStyleSheet = document.getElementById(name)
if (existingStyleSheet && !force) {
console.debug(
`Stylesheet with name "${name}" already exists. Skipping addition.`,
)
return
}
if (existingStyleSheet && force) {
console.debug(`Stylesheet with name "${name}" exists. Replacing...`)
existingStyleSheet.remove()
}
const styleElement = document.createElement('style')
styleElement.id = name
styleElement.type = 'text/css'
styleElement.appendChild(document.createTextNode(css))
document.head.appendChild(styleElement)
console.debug(`Stylesheet with name "${name}" added.`)
}
export const ensureMTBStyles = () => {
const S = {
fg: 'var(--fg-color)',
bgi: 'var(--comfy-input-bg)',
bgm: 'var(--comfy-menu-bg)',
border: 'var(--comfy-border)',
borderHover: 'var(--comfy-border-hover)',
box: 'var(--comfy-box)',
accent: 'var(--p-button-text-primary-color)',
}
const common = `
.mtb_sidebar {
display: flex;
flex-direction: column;
background: ${S.bgm};
}
.mtb_img_grid {
display: flex;
flex-wrap: wrap;
overflow: scroll;
gap: 1em;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
}
.mtb_tools {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
width: 100%;
}
`
const inputs = `
/* SELECT */
.mtb_select {
appearance: none;
display: grid;
grid-template-areas: "select";
padding: 10px;
background-color: ${S.bgi};
border: none;
border-radius: 5px;
font-size: 14px;
color: ${S.fg};
cursor: pointer;
width: 100%;
}
@supports (-moz-appearance:none) {
.mtb_select{
grid-area: select;
background: ${S.bgi} url('data:image/gif;base64,R0lGODlhBgAGAKEDAFVVVX9/f9TU1CgmNyH5BAEKAAMALAAAAAAGAAYAAAIODA4hCDKWxlhNvmCnGwUAOw==') right center no-repeat !important;
background-position: calc(100% - 5px) center !important;
-moz-appearance:none !important;
}
/* styling the dropdown arrow for browsers that support it */
.mtb_select:after {
content: "";
width: 0.8em;
height: 0.5em;
background-color: ${S.fg};
clip-path: polygon(100% 0%, 0 0%, 50% 100%);
}
.mtb_select:focus {
outline: none;
border-color: #0056b3;
}
.mtb_select > option {
padding: 10px;
background-color: ${S.bgi};
border:none;
color: ${S.fg};
}
.mtb_select > option:hover {
background-color: red;
color: ${S.fg};
}
/* SLIDER */
.mtb_slider[type="range"] {
-webkit-appearance: none;
appearance: none;
width: 100%;
height: 10px;
background: ${S.bgm};
border-radius: 5px;
outline: none;
opacity: 0.7;
transition: opacity .2s;
padding: 1em;
}
/* slider track */
.mtb_slider[type="range"]::-webkit-slider-runnable-track,
.mtb_slider[type="range"]::-moz-range-track {
width: 100%;
height: 10px;
background: ${S.bgi};
border-radius: 5px;
}
/* progress */
.mtb_slider[type="range"]::-moz-range-progress {
background-color: ${S.accent};
height:10px;
border-radius: 5px;
}
/* slider thumb (the handle) */
.mtb_slider[type="range"]::-webkit-slider-thumb,
.mtb_slider[type="range"]::-moz-range-thumb
{
-webkit-appearance: none;
appearance: none;
width: 15px;
height: 15px;
border-radius: 50%;
background: ${S.fg};
border: none;
cursor: pointer;
filter: drop-shadow(1px 1px 4px black);
}
.mtb_slider[type="range"]:focus {
opacity: 1;
}
.mtb_slider[type=range]:-moz-focusring{
outline: 1px solid red;
outline-offset: -1px;
}
.mtb_slider[type="range"]:hover::-webkit-slider-thumb,
.mtb_slider[type="range"]:active::-webkit-slider-thumb {
background-color: ${S.accent};
}
`
addNamedStyleSheet(
'mtb_ui',
`
${common}
${inputs}
`,
)
}
/**
* Wrap an element with a div
*
* @param {Object} [style] - CSS styles to apply to the element.
* @returns {HTMLElement} - The created DOM element.
*/
export const wrapElement = (element, style = {}) => {
const container = makeElement('div', style)
container.appendChild(element)
return container
}
/**
* Creates a DOM element with optional styles, class, and id.
*
* @param {string} kind - The tag name of the element. Supports class and id syntax (e.g. 'div.class#id').
* @param {Object} [style] - CSS styles to apply to the element.
* @returns {HTMLElement} - The created DOM element.
*/
export const makeElement = (kind, style, parent) => {
let [real_kind, className] = kind.split('.')
let id
if (className?.includes('#')) {
;[className, id] = className.split('#')
}
const el = document.createElement(real_kind)
if (style) {
Object.assign(el.style, style)
}
if (className) {
el.classList.add(...className.split(' ')) // Support multiple classes
}
if (id) {
el.id = id
}
if (parent) {
parent.appendChild(el)
}
return el
}
/**
* Clears all child elements of the given parent element.
*
* @param {HTMLElement} el - The parent element whose children should be removed.
*/
export const clearElement = (el) => {
while (el.firstChild) {
el.removeChild(el.firstChild)
}
}
/**
* Creates a labeled element (input, select, etc.).
*
* @param {HTMLElement} el - The element to label.
* @param {string} labelText - The label text.
* @returns {HTMLDivElement} - A div containing the label and the element.
*/
export const makeLabeledElement = (el, labelText) => {
const wrapper = makeElement('div.mtb_labeled_element', {
marginBottom: '1em',
})
const label = makeElement('label', {
display: 'block',
marginBottom: '0.5em',
})
label.textContent = labelText
wrapper.appendChild(label)
wrapper.appendChild(el)
return wrapper
}
/**
* Converts a camelCase CSS property to kebab-case.
*
* @param {string} prop - The camelCase CSS property.
* @returns {string} - The kebab-case CSS property.
*/
const camelToKebab = (prop) =>
prop.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`)
/**
* Parses the style string into an object of CSS property-value pairs.
*
* @param {string} styleString - The CSS rule text (e.g., "color: red; background-color: blue;").
* @returns {Object} - An object with camelCase CSS properties.
*/
const parseStyleString = (styleString) => {
const styleObj = {}
for (const rule of styleString.split(';')) {
const [property, value] = rule.split(':').map((item) => item.trim())
if (property && value) {
const camelProp = property.replace(/-([a-z])/g, (g) => g[1].toUpperCase())
styleObj[camelProp] = value
}
}
return styleObj
}
/**
* Defines a new CSS class with the provided styles, or skips if the class already exists.
*
* @param {string} className - The name of the CSS class to define.
* @param {Object} classStyles - An object containing camelCase CSS property-value pairs.
*/
export function defineCSSClass(className, classStyles) {
const styleSheets = document.styleSheets
let classExists = false
let existingStyleString = ''
const classExistsInStyleSheet = (styleSheet) => {
const rules = styleSheet.rules || styleSheet.cssRules
for (const rule of rules) {
if (rule.selectorText === `.${className}`) {
classExists = true
existingStyleString = rule.style.cssText // Capture existing styles
return true
}
}
return false
}
for (const styleSheet of styleSheets) {
if (classExistsInStyleSheet(styleSheet)) {
console.debug(`Class ${className} already exists, merging styles...`)
break
}
}
const existingStyles = classExists
? parseStyleString(existingStyleString)
: {}
const mergedStyles = { ...existingStyles, ...classStyles }
const stylesString = Object.entries(mergedStyles)
.map(([key, value]) => `${camelToKebab(key)}: ${value};`)
.join(' ')
if (!classExists) {
console.debug(`Defining new class ${className}...`)
if (styleSheets[0].insertRule) {
styleSheets[0].insertRule(`.${className} { ${stylesString} }`, 0)
} else if (styleSheets[0].addRule) {
styleSheets[0].addRule(`.${className}`, stylesString, 0)
}
} else {
console.debug(`Updating existing class ${className} with merged styles...`)
for (const styleSheet of styleSheets) {
const rules = styleSheet.rules || styleSheet.cssRules
for (const rule of rules) {
if (rule.selectorText === `.${className}`) {
rule.style.cssText = stylesString // Update the existing rule
}
}
}
}
console.debug(
`Class ${className} has been defined/updated with styles:`,
mergedStyles,
)
}
/**
* Renders a sidebar and ensures it resizes correctly when the window is resized.
*
* @param {HTMLElement} el - The element where the sidebar is rendered.
* @param {HTMLElement} cont - The content container of the sidebar.
* @param {HTMLElement[]} elems - Array of elements to append to the sidebar.
* @returns {Object} - A handle with a method to unregister the resize event.
*/
export const renderSidebar = (el, cont, elems) => {
el.appendChild(cont)
if (!el.parentNode) {
return
}
el.parentNode.style.overflowY = 'clip'
cont.style.height = `${el.parentNode.offsetHeight}px`
const resizeHandler = () => {
cont.style.height = `${el.parentNode.offsetHeight}px`
}
window.addEventListener('resize', resizeHandler)
for (const elem of elems) {
cont.appendChild(elem)
}
return {
unregister: () => {
window.removeEventListener('resize', resizeHandler)
},
}
}
/**
* Creates a <select> dropdown with given options.
*
* @param {string[]} options - The options for the select element.
* @param {string} [current] - The currently selected option (optional).
* @returns {HTMLSelectElement} - The created <select> element.
*/
export const makeSelect = (options, current = undefined) => {
const selector = makeElement('select.mtb_select', {
width: 'auto',
margin: '1em',
})
for (const option of options) {
const opt = makeElement('option')
opt.value = option
opt.innerHTML = option
selector.appendChild(opt)
}
if (current !== undefined) {
if (options.includes(current)) {
selector.value = current
} else {
console.error(
`You tried to select an option that doesn't exist (${current}). Options: ${options}`,
)
}
}
return selector
}
/**
* Creates an <input type="range"> slider element with given parameters.
*
* @param {number} min - Minimum value of the slider.
* @param {number} max - Maximum value of the slider.
* @param {number} [value] - Initial value of the slider.
* @param {number} [step] - Step value for the slider.
* @returns {HTMLInputElement} - The created slider element.
*/
export const makeSlider = (min, max, value = undefined, step = undefined) => {
const slider = makeElement('input.mtb_slider', {
width: '100%',
})
slider.type = 'range'
slider.min = min || 0
slider.max = max || 100
slider.value = value || slider.min
slider.step = step || 1
return slider
}
/**
* Creates a button element.
*
* @param {string} label - The label for the button.
* @param {Object} [style] - Optional styles to apply to the button.
* @param {Function} [onClick] - Optional click handler.
* @returns {HTMLButtonElement} - The created button element.
*/
export const makeButton = (label, style = {}, onClick = undefined) => {
const button = makeElement('button.mtb_button', style)
button.textContent = label
if (onClick) {
button.addEventListener('click', onClick)
}
return button
}
/**
* Creates a resizable splitter between two elements.
*
* @param {HTMLElement} el1 - The first element.
* @param {HTMLElement} el2 - The second element.
* @param {'vertical' | 'horizontal'} direction - Splitter direction (vertical or horizontal).
* @param {'absolute' | 'normal'} mode - Splitter mode: 'absolute' for free resizing, 'normal' for layout-based resizing.
* @returns {HTMLDivElement} - The container with resizable splitter.
*/
export const makeSplitter = (
el1,
el2,
direction = 'vertical',
mode = 'normal',
) => {
const container = makeElement('div.mtb_splitter_container', {
display: mode === 'absolute' ? 'block' : 'flex',
flexDirection: direction === 'vertical' ? 'row' : 'column',
position: mode === 'absolute' ? 'relative' : 'static',
height: '100%',
width: '100%',
})
const handle = makeElement('div.mtb_splitter_handle', {
backgroundColor: '#ccc',
cursor: direction === 'vertical' ? 'col-resize' : 'row-resize',
width: direction === 'vertical' ? '5px' : '100%',
height: direction === 'horizontal' ? '5px' : '100%',
})
let isResizing = false
handle.addEventListener('mousedown', () => {
isResizing = true
})
window.addEventListener('mouseup', () => {
isResizing = false
})
window.addEventListener('mousemove', (e) => {
if (!isResizing) return
if (direction === 'vertical') {
const newWidth = e.clientX - container.offsetLeft
el1.style.width = `${newWidth}px`
el2.style.width = `${container.offsetWidth - newWidth}px`
} else {
const newHeight = e.clientY - container.offsetTop
el1.style.height = `${newHeight}px`
el2.style.height = `${container.offsetHeight - newHeight}px`
}
})
container.appendChild(el1)
container.appendChild(handle)
container.appendChild(el2)
return container
}
+704 -203
View File
File diff suppressed because it is too large Load Diff
+258
View File
@@ -0,0 +1,258 @@
// web/note_plus.constants.js
export const DEFAULT_CSS = `/** here you can write css**/
h1 {
color: whitesmoke;
}`
export const DEFAULT_HTML = `<p style='color:red;font-family:monospace'>
Note+
</p>`
export const DEFAULT_MD = '# 📝 Note+'
export const DEFAULT_MODE = 'markdown'
export const DEFAULT_THEME = 'one_dark'
export const DEMO_CONTENT = `
# @mtb/svelte-markdown.
## This is a subheader
[![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)
![home](https://repository-images.githubusercontent.com/649047066/a3eef9a7-20dd-4ef9-b839-884502d4e873)
<details>
<summary>More details about the inception of the project</summary>
\`\`\`js
class YesMan{
constructor(){
this.started = false
}
}
\`\`\`
</details>
This is a paragraph. If it goes over the maximum width it will not automatically wrap unless it reaches the max-w of \`prose\` check [styles](/styles) for more info.
This component is useful for building some tools on top. Or even just a static system using svelte at its core. My personal blog is fully powered by **@mtb/svelte-markdown**
| And this is | A table |
|-------------|---------|
| With two | columns |
We also support github callout:
> [!NOTE]
> Highlights information that users should take into account, even when skimming.
> [!TIP]
> Optional information to help a user be more successful.
> [!IMPORTANT]
> Crucial information necessary for users to succeed.
> [!WARNING]
> Critical content demanding immediate user attention due to potential risks.
> [!CAUTION]
> Negative potential consequences of an action.
`
export const THEMES = [
'ambiance',
'chaos',
'chrome',
'cloud9_day',
'cloud9_night',
'cloud9_night_low_color',
'cloud_editor',
'cloud_editor_dark',
'clouds',
'clouds_midnight',
'cobalt',
'crimson_editor',
'dawn',
'dracula',
'dreamweaver',
'eclipse',
'github',
'github_dark',
'gob',
'gruvbox',
'gruvbox_dark_hard',
'gruvbox_light_hard',
'idle_fingers',
'iplastic',
'katzenmilch',
'kr_theme',
'kuroir',
'merbivore',
'merbivore_soft',
'mono_industrial',
'monokai',
'nord_dark',
'one_dark',
'pastel_on_dark',
'solarized_dark',
'solarized_light',
'sqlserver',
'terminal',
'textmate',
'tomorrow',
'tomorrow_night',
'tomorrow_night_blue',
'tomorrow_night_bright',
'tomorrow_night_eighties',
'twilight',
'vibrant_ink',
'vscode',
]
export const CSS_RESET = `
* {
line-height: 1.25em;
}
.shiki{
padding: 1em;
width: 100%;
}
.markdown-callout-title {
.octicon{
fill:white;
width:29px;
height:29px;
}
/* background: var(--current-color); */
color: var(--current-color);
font-weight: bold;
/* border-start-end-radius: var(--radius); */
/* border-start-start-radius: var(--radius); */
padding: 0.5em;
padding-inline-start: 1em;
display: flex;
align-items: center;
}
.markdown-callout-content {
padding: 1em;
}
.markdown-callout {
--radius: 8px;
--current-color: purple;
/* border-start-end-radius: var(--radius); */
/* border-start-start-radius: var(--radius); */
border-left: 3px solid var(--current-color);
margin-bottom: 1em;
margin-top: 1em;
}
.markdown-callout p:nth-child(2) {
padding:1em;
}
.markdown-callout-tip {
--text-color: whitesmoke;
--current-color: #50e3c2;
}
.markdown-callout-note {
--text-color: whitesmoke;
--current-color: #0070f3;
}
.markdown-callout-important {
--text-color: whitesmoke;
--current-color: #7928ca;
}
.markdown-callout-warning {
--current-color: #f5a623;
}
.markdown-callout-caution {
--current-color: #e60000;
}
.note-plus-preview {
display:flex;
flex-direction:column;
align-items: flex-start;
width:95%;
/*margin-left: 20px;*/
/*margin-top:20px;*/
/*background-color: rgba(255,0,0,0.5)!important;*/
}
/* allowed to be selected*/
h1, h2, h3, h4, h5, h6,a, p, ul, ol, dl, blockquote,details,summary {
pointer-events:auto;
user-select:text;
}
h1, h2, h3, h4, h5, h6 {
display:inline-block;
margin: 0;
padding: 0;
font-weight: normal;
}
p, ul, ol, dl, blockquote {
margin: 0.3em;
padding: 0;
}
ul, ol {
padding-left: 1em;
}
a {
color: inherit;
text-decoration: none;
pointer-events: all;
color: cyan;
}
img {
padding: 1em 0;
max-width: 100%;
}
iframe {
max-width: 100%;
height: auto;
border:none;
pointer-events:all;
}
blockquote {
border-left: 4px solid #ccc;
padding-left: 1em;
margin-left: 0;
font-style: italic;
}
pre, code {
font-family: monospace;
}
table {
border-collapse: collapse;
width: 100%;
border-bottom: 1px solid #000;
margin: 1em 0;
}
th, td {
border-left: 1px solid #000;
border-right: 1px solid #000;
padding: 8px;
text-align: left;
}
th {
border: 1px solid #000;
background-color: rgba(0,0,0,0.5);
}
input[type="checkbox"] {
margin-right: 10px;
}
`
+873
View File
@@ -0,0 +1,873 @@
/// <reference path="../types/typedefs.js" />
import { app } from '../../scripts/app.js'
import * as shared from './comfy_shared.js'
import * as mtb_ui from './mtb_ui.js'
import { warnLogger, infoLogger, errorLogger } from './comfy_shared.js'
import {
DEFAULT_CSS,
// DEFAULT_HTML,
DEFAULT_MD,
DEFAULT_MODE,
DEFAULT_THEME,
THEMES,
CSS_RESET,
DEMO_CONTENT,
} from './note_plus.constants.js'
import { LocalStorageManager } from './comfy_shared.js'
const storage = new LocalStorageManager('mtb')
/**
* Uses `@mtb/markdown-parser` (a fork of marked)
* It is statically stored to avoid having
* more than 1 instance ever.
* The size difference between both libraries...
* ╭───┬────────────────────────────────┬──────────╮
* │ # │ name │ size │
* ├───┼────────────────────────────────┼──────────┤
* │ 0 │ web-dist/mtb_markdown_plus.mjs │ 1.2 MB │ <- with shiki
* │ 1 │ web-dist/mtb_markdown.mjs │ 44.7 KB │
* ╰───┴────────────────────────────────┴──────────╯
*/
let _css_reset = app.extensionManager.setting.get(
'mtb.noteplus.css-reset',
CSS_RESET,
)
const makeResizable = (dialog) => {
dialog.style.resize = 'both'
dialog.style.transformOrigin = 'top left'
dialog.style.overflow = 'auto'
}
const makeDraggable = (dialog, handle) => {
let offsetX = 0
let offsetY = 0
let isDragging = false
const onMouseMove = (e) => {
if (isDragging) {
dialog.style.left = `${e.clientX - offsetX}px`
dialog.style.top = `${e.clientY - offsetY}px`
}
}
const onMouseUp = () => {
isDragging = false
document.removeEventListener('mousemove', onMouseMove)
document.removeEventListener('mouseup', onMouseUp)
}
handle.addEventListener('mousedown', (e) => {
isDragging = true
offsetX = e.clientX - dialog.offsetLeft
offsetY = e.clientY - dialog.offsetTop
document.addEventListener('mousemove', onMouseMove)
document.addEventListener('mouseup', onMouseUp)
})
}
/** @extends {LGraphNode} */
class NotePlus extends LiteGraph.LGraphNode {
// same values as the comfy note
color = LGraphCanvas.node_colors.yellow.color
bgcolor = LGraphCanvas.node_colors.yellow.bgcolor
groupcolor = LGraphCanvas.node_colors.yellow.groupcolor
/* NOTE: this is not serialized and only there to make multiple
* note+ nodes in the same graph unique.
*/
uuid
/** Stores the dialog observer*/
resizeObserver
/** Live update the preview*/
/** DOM height by adding child size together*/
calculated_height = 0
/** ????*/
_raw_html
/** might not be needed anymore */
inner
/** the dialog DOM widget*/
dialog
/** widgets*/
/** used to store the raw value and display the parsed html at the same time*/
preview_widget
editorsContainer
/** ACE editors instances*/
html_editor
css_editor
/** quick edit mode*/
isEditing = false
quickEditor = null
quickEditorContainer = null
constructor() {
super()
this.uuid = shared.makeUUID()
infoLogger('Constructing Note+ instance')
shared.ensureMarkdownParser((_p) => {
this.updateHTML()
})
// - litegraph settings
this.properties = {
css: DEFAULT_CSS,
theme: DEFAULT_THEME,
}
this.collapsable = true
this.isVirtualNode = true
this.shape = LiteGraph.BOX_SHAPE
this.serialize_widgets = true
// - default values, serialization is done through widgets
this._raw_html = DEFAULT_MD
// - state
this.calculated_height = 0
// -
this.setupDebounce(100)
// - add widgets
const cinner = document.createElement('div')
this.inner = document.createElement('div')
this.title = 'Note+'
cinner.append(this.inner)
this.inner.classList.add('note-plus-preview')
cinner.style.margin = '0'
cinner.style.padding = '0'
this.preview_widget = this.addDOMWidget('HTML', 'html', cinner, {
setValue: (val) => {
this._raw_html = val
},
getValue: () => this._raw_html,
getMinHeight: () => {
this.calculateHeight()
return this.calculated_height
},
onDraw: () => {
// HACK: dirty hack for now until it's addressed upstream...
// TODO: check if still needed
this.preview_widget.element.style.pointerEvents = 'none'
// NOTE: not sure about this, it avoid the visual "bugs" but scrolling over the wrong area will affect zoom...
// this.html_widget.element.style.overflow = 'scroll'
},
hideOnZoom: false,
})
this.setupDialog()
this.loadAceEditor()
this.setupDoubleClickEdit()
}
/**
* @param {CanvasRenderingContext2D} ctx canvas context
* @param {any} _graphcanvas
*/
onDrawForeground(ctx, _graphcanvas) {
if (this.flags.collapsed) return
this.drawEditIcon(ctx)
// DEBUG BACKGROUND
// ctx.fillStyle = 'rgba(0, 255, 0, 0.3)'
// const rect = this.rect
// ctx.fillRect(rect.x, rect.y, rect.width, rect.height)
}
setupDebounce(ms) {
if (this.calculatedHeight) {
this.calculateHeight.cancel()
}
this.calculateHeight = shared.debounce(() => {
this.calculated_height = shared.calculateTotalChildrenHeight(
this.inner,
)
}, ms)
}
// drawSideHandle(ctx) {
drawEditIcon(ctx) {
const rect = this.iconRect
// DEBUG ICON POSITION
// ctx.fillStyle = 'rgba(0, 255, 0, 0.3)'
// ctx.fillRect(rect.x, rect.y, rect.width, rect.height)
const pencilPath = new Path2D(
'M21.28 6.4l-9.54 9.54c-.95.95-3.77 1.39-4.4.76-.63-.63-.2-3.45.75-4.4l9.55-9.55a2.58 2.58 0 1 1 3.64 3.65z',
)
const folderPath = new Path2D(
'M11 4H6a4 4 0 0 0-4 4v10a4 4 0 0 0 4 4h11c2.21 0 3-1.8 3-4v-5',
)
ctx.save()
ctx.translate(rect.x, rect.y)
ctx.scale(rect.width / 32, rect.height / 32)
ctx.strokeStyle = 'rgba(255,255,255,0.4)'
ctx.lineCap = 'round'
ctx.lineJoin = 'round'
ctx.lineWidth = 2.4
ctx.stroke(pencilPath)
ctx.stroke(folderPath)
ctx.restore()
}
/**
* @param {number} x
* @param {number} y
* @param {{x:number,y:number,width:number,height:number}} rect
* @returns {}
*/
inRect(x, y, rect) {
rect = rect || this.iconRect
return (
x >= rect.x &&
x <= rect.x + rect.width &&
y >= rect.y &&
y <= rect.y + rect.height
)
}
get rect() {
return {
x: 0,
y: 0,
width: this.size[0],
height: this.size[1],
}
}
get iconRect() {
let icon = {
size: 24,
margin: 5,
yoffset: -25,
}
if (window.inspector) {
if (window.inspector.get('note_icon') !== null) {
icon = window.inspector.get('note_icon')
} else {
window.inspector.set('note_icon', icon)
window.inspector.subscribe('note_icon', (k, v) => {
console.log(v)
})
window.inspector.set('note_icon_debug', true)
window.inspector.subscribe('note_icon_debug', (k, v) => {
this.debug_icon = v
})
}
}
return {
x: this.size[0] - icon.size - icon.margin,
y: icon.yoffset,
width: icon.size,
height: icon.size,
}
}
onMouseDown(_e, localPos, _graphcanvas) {
if (this.inRect(localPos[0], localPos[1])) {
this.openEditorDialog()
return true
}
return false
}
onDblClick(e, localPos, graphcanvas) {
this.openEditorDialog()
return true
}
setupDialog() {
infoLogger('Setup dialog')
this.dialog = new app.ui.dialog.constructor()
this.dialog.element.style.width = '680px'
this.dialog.element.classList.add('comfy-settings')
Object.assign(this.dialog.element.style, {
position: 'absolute',
boxShadow: 'none',
})
const subcontainer = this.dialog.textElement.parentElement
if (subcontainer) {
Object.assign(subcontainer.style, {
width: '100%',
})
}
const saveButton = this.dialog.element.querySelector('button')
saveButton.textContent = 'SAVE'
saveButton.onclick = () => {
this.closeEditorDialog(true)
}
}
teardownEditors() {
this.css_editor.destroy()
this.css_editor.container.remove()
this.html_editor.destroy()
this.html_editor.container.remove()
this.html_editor = null
this.css_editor = null
}
closeEditorDialog(accept) {
infoLogger('Closing editor dialog', accept)
if (accept) {
this.updateHTML(this.html_editor.getValue())
this.updateCSS(this.css_editor.getValue())
}
if (this.resizeObserver) {
this.resizeObserver.disconnect()
this.resizeObserver = null
}
this.teardownEditors()
this.dialog.close()
this.setupDebounce(100)
}
/**
* @param {HTMLElement} elem
*/
hookResize(elem) {
if (!this.resizeObserver) {
const observer = () => {
Object.assign(this.editorsContainer.style, {
minHeight: `${(this.dialog.element.clientHeight / 100) * 50}px`, //'200px',
})
// avoid the few ticks that can happen between destroying the editors
// and the watched dialog
if (this.html_editor) {
this.html_editor.resize()
this.css_editor.resize()
}
}
this.resizeObserver = new ResizeObserver(observer).observe(elem)
}
}
openEditorDialog() {
this.setupDebounce(500)
this.hookResize(this.dialog.element)
const container = mtb_ui.makeElement('div', {
display: 'flex',
gap: '10px',
flexDirection: 'column',
})
this.editorsContainer = mtb_ui.makeElement(
'div',
{
display: 'flex',
gap: '10px',
flexDirection: 'row',
minHeight: this.dialog.element.offsetHeight, //'200px',
width: '100%',
},
container,
)
this.dialog.show('')
this.dialog.textElement.append(container)
mtb_ui.makeElement(
'div.#noteplus-html-editor',
{
width: '100%',
height: '100%',
minWidth: '300px',
minHeight: 'inherit',
},
this.editorsContainer,
)
mtb_ui.makeElement(
'div.#noteplus-css-editor',
{
width: '100%',
height: '100%',
minHeight: 'inherit',
},
this.editorsContainer,
)
//- "Dynamic" elements
const syncUI = () => {
// let convert_to_html =
// the header for dragging the dialog
const header = mtb_ui.makeElement('div', {
padding: '8px',
cursor: 'move',
backgroundColor: 'rgba(0,0,0,0.5)',
userSelect: 'none',
borderBottom: '1px solid #ddd',
})
header.textContent = 'MTB Note+ Editor'
container.prepend(header)
makeDraggable(this.dialog.element, header)
makeResizable(this.dialog.element)
}
//- combobox
let theme_select = this.dialog.element.querySelector('#theme_select')
if (!theme_select) {
infoLogger('Creating combobox for select')
theme_select = document.createElement('select')
theme_select.name = 'theme'
theme_select.id = 'theme_select'
const addOption = (label) => {
const option = document.createElement('option')
option.value = label
option.textContent = label
theme_select.append(option)
}
for (const t of THEMES) {
addOption(t)
}
theme_select.addEventListener('change', (event) => {
const val = event.target.value
this.setTheme(val)
})
container.prepend(theme_select)
}
theme_select.value = this.properties.theme
// let select_mode = this.dialog.element.querySelector('#edit_mode')
syncUI()
this.setupEditors()
}
loadAceEditor() {
if (window.MTB?.ace_loaded) {
return
}
let NEED_PATCH = false
if (window.ace) {
infoLogger(
'A global ace was found in scope not loaded by mtb, this might lead to issues.',
)
NEED_PATCH = true
// window._backupAce = window.ace
// window.ace = null
}
shared
.loadScript('/mtb_async/ace/ace.js')
.then((m) => {
infoLogger('ACE was loaded', m)
// window.MTB_ACE = window.ace
if (!window.MTB) {
errorLogger(
"window.MTB not found, this shouldn't happen at this stage",
)
window.MTB = {}
}
window.MTB.ace_loaded = true
this.setMode('markdown')
this.setTheme()
this.updateView()
})
.catch((e) => {
errorLogger(e)
})
.finally(() => {
if (NEED_PATCH) {
// console.log('Patching back window object')
// window.ace = window._backupAce
} else {
// delete window.ace
}
})
}
configure(info) {
super.configure(info)
infoLogger('Restoring serialized values', info)
this.preview_widget.element.id = `note-plus-${this.uuid}`
this.updateView()
}
getExtraMenuOptions() {
const debugItems = window.MTB?.DEBUG
? [
{
content: 'Replace with demo content (debug)',
callback: () => {
this.preview_widget.value = DEMO_CONTENT
},
},
]
: []
return [...debugItems]
}
get fontSize() {
return app.extensionManager.setting.get('Comfy.TextareaWidget.FontSize', 16)
}
_setupEditor(editor) {
this.setTheme()
editor.setShowPrintMargin(false)
editor.session.setUseWrapMode(true)
editor.renderer.setShowGutter(false)
editor.session.setTabSize(4)
editor.session.setUseSoftTabs(true)
editor.setFontSize(this.fontSize)
editor.setReadOnly(false)
editor.setHighlightActiveLine(false)
editor.setShowFoldWidgets(true)
return editor
}
setTheme(theme) {
theme = theme || this.properties.theme
this.properties.theme = theme
if (this.html_editor) {
this.html_editor.setTheme(`ace/theme/${theme}`)
}
if (this.css_editor) {
this.css_editor.setTheme(`ace/theme/${theme}`)
}
if (this.quickEditor) {
this.quickEditor.setTheme(`ace/theme/${theme}`)
}
}
updateView() {
this.updateHTML()
this.updateCSS()
this.calculateHeight()
}
setMode(mode) {
if (this.html_editor) {
this.html_editor.session.setMode(`ace/mode/${mode}`)
}
if (this.quickEditor) {
this.quickEditor.session.setMode(`ace/mode/${mode}`)
}
this.updateView()
}
setupEditors() {
infoLogger('NotePlus setupEditor')
if (!window.MTB?.ace_loaded) {
errorLogger('ACE editor not loaded. Cannot set up editors.')
return
}
if (!this.html_editor) {
this.html_editor = ace.edit('noteplus-html-editor')
this._setupEditor(this.html_editor)
this.html_editor.session.on('change', (_delta) => {
this.updateHTML(this.html_editor.getValue())
})
} else {
infoLogger('Reusing html editor')
}
if (!this.css_editor) {
this.css_editor = ace.edit('noteplus-css-editor')
this.css_editor.session.setMode('ace/mode/css')
this._setupEditor(this.css_editor)
this.css_editor.session.on('change', (_delta) => {
this.updateCSS(this.css_editor.getValue())
})
}
this.setMode(DEFAULT_MODE)
this.html_editor.setValue(this.preview_widget.value, -1)
this.css_editor.setValue(this.properties.css, -1)
}
scopeCss(css, scopeId) {
return css
.split('}')
.map((rule) => {
if (rule.trim() === '') {
return ''
}
const scopedRule = rule
.split('{')
.map((segment, index) => {
if (index === 0) {
return `#${scopeId} ${segment.trim()}`
}
return `{${segment.trim()}`
})
.join(' ')
return `${scopedRule}}`
})
.join('\n')
}
getCssDom() {
const styleTagId = `note-plus-stylesheet-${this.uuid}`
let styleTag = document.head.querySelector(`#${styleTagId}`)
if (!styleTag) {
styleTag = document.createElement('style')
styleTag.type = 'text/css'
styleTag.id = styleTagId
document.head.appendChild(styleTag)
infoLogger(`Creating note-plus-stylesheet-${this.uuid}`, styleTag)
}
return styleTag
}
updateCSS(css) {
infoLogger('NotePlus updateCSS')
css = css || this.properties.css
// this.html_widget.element.style = css
const scopedCss = this.scopeCss(
`${_css_reset}\n${css}`,
`note-plus-${this.uuid}`,
)
const cssDom = this.getCssDom()
cssDom.innerHTML = scopedCss
this.properties.css = css
}
parserInitiated() {
if (window.MTB?.mdParser) return true
return false
}
/** to easilty swap purification methods*/
purify(content) {
return DOMPurify.sanitize(content, {
ADD_TAGS: ['iframe', 'detail', 'summary'],
})
}
updateHTML(val) {
if (val) {
this._raw_html = val
}
if (
!this.parserInitiated() ||
!window.MTB?.ace_loaded ||
!this.preview_widget
) {
return
}
val = val || this._raw_html
const cleanHTML = this.purify(val)
const value = cleanHTML.replaceAll('&gt;', '>').replaceAll('&lt;', '<')
// .replaceAll('&amp;', '&')
// .replaceAll('&quot;', '"')
// .replaceAll('&#039;', "'")
this.preview_widget.value = value
MTB.mdParser
.parse(value)
.then((e) => {
this.inner.innerHTML = e
})
.catch((e) => {
if (e.name === 'ShikiError') {
warnLogger(e.message)
return
}
throw e
})
}
/**
* Attaches the double-click listener to the preview area.
*/
setupDoubleClickEdit() {
this.preview_widget.element.addEventListener('dblclick', (e) => {
e.stopPropagation()
e.preventDefault()
if (this.isEditing) {
return
}
if (!window.MTB?.ace_loaded) {
errorLogger('Ace editor not loaded. Cannot open quick edit.')
return
}
this.enterEditMode()
})
}
/**
* Switches the preview div to an editable textarea.
*/
enterEditMode() {
this.isEditing = true
this.setupDebounce(10000)
const id = `noteplus-quick-editor-${this.uuid}`
this.quickEditorContainer = mtb_ui.makeElement(`div.#${id}`, {
position: 'absolute',
top: '0',
pointerEvents: 'auto',
left: '0',
right: '0',
bottom: '0',
zIndex: '10',
})
// hide the preview div and append the editor container
this.inner.style.display = 'none'
this.preview_widget.element.appendChild(this.quickEditorContainer)
// init ace
this.quickEditor = ace.edit(this.quickEditorContainer, {
mode: 'ace/mode/markdown',
theme: this.properties.theme,
})
this.quickEditor.setOptions({
autoScrollEditorIntoView: true,
copyWithEmptySelection: true,
hasCssTransforms: true,
})
this._setupEditor(this.quickEditor)
this.quickEditor.setValue(this._raw_html, -1)
this.quickEditor.focus()
this.quickEditor.session.on('change', () => {
this.updateHTML(this.quickEditor.getValue())
})
this.quickEditor.textInput
.getElement()
.addEventListener('blur', () => this.exitEditMode(true))
this.quickEditor.textInput.getElement().addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault()
this.exitEditMode(true)
} else if (e.key === 'Escape') {
e.preventDefault()
this.exitEditMode(false)
}
})
this.quickEditor.resize()
this.setDirtyCanvas(true, true)
}
/**
* Switches the editable textarea back to the preview div.
* @param {boolean} saveChanges - Whether to save the textarea content.
*/
exitEditMode(saveChanges) {
if (!this.isEditing) {
return
}
this.isEditing = false
this.setupDebounce(100)
if (this.quickEditor) {
if (saveChanges) {
const newValue = this.quickEditor.getValue()
if (newValue !== this._raw_html) {
this._raw_html = newValue
this.updateView()
}
}
this.quickEditor.destroy()
this.quickEditor = null
}
if (this.quickEditorContainer?.parentNode) {
this.quickEditorContainer.parentNode.removeChild(
this.quickEditorContainer,
)
this.quickEditorContainer = null
}
this.inner.style.display = ''
this.setDirtyCanvas(true, true)
this.calculateHeight()
}
}
app.registerExtension({
name: 'mtb.noteplus',
settings: [
{
id: 'mtb.noteplus.use-shiki',
category: ['mtb', 'Note+', 'use-shiki'],
name: 'Use shiki to highlight code',
tooltip:
'This will load a larger version of mtb/markdown-parser that bundles shiki, it supports all shiki transformers (supported langs: html,css,python,markdown)',
type: 'boolean',
defaultValue: false,
attrs: {
style: {
// fontFamily: 'monospace',
},
},
},
{
id: 'mtb.noteplus.css-reset',
category: ['mtb', 'Note+', 'css-reset'],
name: 'CSS reset',
tooltip: 'This is prepended to all notes',
type: 'string',
defaultValue: CSS_RESET,
attrs: {
style: {
// fontFamily: 'monospace',
},
},
async onChange(value) {
_css_reset = value
},
},
],
registerCustomNodes() {
LiteGraph.registerNodeType('Note Plus (mtb)', NotePlus)
NotePlus.category = 'mtb/utils'
NotePlus.title = 'Note+ (mtb)'
},
})
+12 -3
View File
@@ -41,7 +41,16 @@ const toastStyle = `
transition-duration: ${transition_time}ms;
`
function notify(message, timeout = 3000) {
function notify(message, timeout = 3000, old_mode = false) {
if (!old_mode) {
app.extensionManager.toast.add({
severity: 'info',
summary: 'MTB',
detail: message,
life: timeout,
})
return
}
log('Creating toast')
const container = document.getElementById('mtb-notify-container')
const toast = document.createElement('div')
@@ -59,7 +68,7 @@ function notify(message, timeout = 3000) {
log('Transition out')
const totalHeight = Array.from(container.children).reduce(
(acc, child) => acc + child.offsetHeight + 10, // Add spacing of 10px between toasts
0
0,
)
container.style.height = `${totalHeight}px`
@@ -83,7 +92,7 @@ function notify(message, timeout = 3000) {
// Update container's height to fit new toast
const totalHeight = Array.from(container.children).reduce(
(acc, child) => acc + child.offsetHeight + 10, // Add spacing of 10px between toasts
0
0,
)
container.style.height = `${totalHeight}px`
+334
View File
@@ -0,0 +1,334 @@
// This is a vanillajs implementation of Houdini's number input widgets.
// It basically popup a visual sensitivity slider of steps to use as incr/decr
// TODO: Convert it to IWidget
// import styles from "./style.module.css";
function getValidNumber(numberInput) {
let num =
isNaN(numberInput.value) || numberInput.value === ''
? 0
: parseFloat(numberInput.value)
return num
}
/**
* Number input widgets
*/
export class NumberInputWidget {
constructor(containerId, numberOfInputs = 1, isDebug = false) {
this.container = document.getElementById(containerId)
this.numberOfInputs = numberOfInputs
this.currentInput = null // Store the currently active input
this.threshold = 30
this.mouseSensitivityMultiplier = 0.05
this.debug = isDebug
//- states
this.initialMouseX
this.lastMouseX
this.activeStep = 1
this.accumulatedDelta = 0
this.stepLocked = false
this.thresholdExceeded = false
this.isDragging = false
const styleTagId = 'mtb-constant-style'
let styleTag = document.head.querySelector(`#${styleTagId}`)
if (!styleTag) {
styleTag = document.createElement('style')
styleTag.type = 'text/css'
styleTag.id = styleTagId
styleTag.innerHTML = `
.${containerId}{
margin-top: 20px;
margin-bottom: 20px;
}
.sensitivity-menu {
display: none;
position: absolute;
/* Additional styling */
}
.sensitivity-menu .step {
cursor: pointer;
padding: 0.5em;
/* Add more styling as needed */
}
.sensitivity-menu {
font-family: monospace;
background: var(--bg-color);
border: 1px solid var(--fg-color);
/* Highlight for the active step */
}
.number-input {
background: var(--bg-color);
color: var(--fg-color)
}
.sensitivity-menu .step.active {
background-color:var(--drag-text);
/* Highlight for the active step */
}
.sensitivity-menu .step.locked {
background-color: #f00;
/* Change to your preferred color for the locked state */
}
#debug-container {
transform: translateX(50%);
width: 50%;
text-align: center;
font-family: monospace;
}
`
document.head.appendChild(styleTag)
}
this.createWidgetElements()
this.initializeEventListeners()
}
setLabel(str) {
this.label.textContent = str
}
setValue(...values) {
if (values.length !== this.numberInputs.length) {
console.error('Number of values does not match the number of inputs.')
console.error(
`You provided ${values.length} but the input want ${this.numberInputs.length}`,
{ values },
)
return
}
// Set each input value
this.numberInputs.forEach((input, index) => {
input.value = values[index]
})
}
getValue() {
const value = []
this.numberInputs.forEach((input, index) => {
value.push(Number.parseFloat(input.value) || 0.0)
})
return value
}
resetValues() {
for (const input of numberInputs) {
input.value = 0
}
this.onChange?.(this.getValue())
}
createWidgetElements() {
this.label = document.createElement('label')
this.label.textContent = 'Control All:'
this.label.className = 'widget-label'
this.container.appendChild(this.label)
this.label.addEventListener('mousedown', (event) => {
if (event.button === 1) {
this.currentInput = null
this.handleMouseDown(event)
}
})
this.label.addEventListener('contextmenu', (event) => {
event.preventDefault()
this.resetValues()
})
this.numberInputs = []
// create linked inputs
for (let i = 0; i < this.numberOfInputs; i++) {
const numberInput = document.createElement('input')
numberInput.type = 'number'
numberInput.className = 'number-input' //styles.numberInput; //"number-input";
numberInput.step = 'any'
this.container.appendChild(numberInput)
this.numberInputs.push(numberInput)
numberInput.addEventListener('mousedown', (event) => {
if (event.button === 1) {
this.currentInput = numberInput
this.handleMouseDown(event)
}
})
}
this.sensitivityMenu = document.createElement('div')
this.sensitivityMenu.className = 'sensitivity-menu' //styles.sensitivityMenu; //"sensitivity-menu";
this.container.appendChild(this.sensitivityMenu)
// create steps
const stepsValues = [0.001, 0.01, 0.1, 1, 10, 100]
stepsValues.forEach((value) => {
const step = document.createElement('div')
step.className = 'step' //styles.step //"step";
step.dataset.step = value
step.textContent = value.toString()
this.sensitivityMenu.appendChild(step)
})
this.steps = this.sensitivityMenu.getElementsByClassName('step') //styles.step)
if (this.debug) {
this.debugContainer = document.createElement('div')
this.debugContainer.id = 'debug-container' //styles.debugContainer //"debugContainer";
document.body.appendChild(this.debugContainer)
}
}
showSensitivityMenu(pageX, pageY) {
this.sensitivityMenu.style.display = 'block'
this.sensitivityMenu.style.left = `${pageX}px`
this.sensitivityMenu.style.top = `${pageY}px`
this.initialMouseX = pageX
this.lastMouseX = pageX
this.isDragging = true
this.thresholdExceeded = false
this.stepLocked = false
this.updateDebugInfo()
}
updateDebugInfo() {
if (this.debug) {
this.debugContainer.innerHTML = `
<div>Active Step: ${this.activeStep}</div>
<div>Initial Mouse X: ${this.initialMouseX}</div>
<div>Last Mouse X: ${this.lastMouseX}</div>
<div>Accumulated Delta: ${this.accumulatedDelta}</div>
<div>Threshold Exceeded: ${this.thresholdExceeded}</div>
<div>Step Locked: ${this.stepLocked}</div>
<div>Number Input Value: ${this.currentInput?.value}</div>
`
}
}
handleMouseDown(event) {
if (event.button === 1) {
this.showSensitivityMenu(
event.target.offsetWidth,
event.target.offsetHeight,
)
event.preventDefault()
}
}
handleMouseUp(event) {
if (event.button === 1) {
this.resetWidgetState()
}
}
handleClickOutside(event) {
if (event.target !== this.numberInput) {
this.resetWidgetState()
}
}
handleMouseMove(event) {
if (this.sensitivityMenu.style.display === 'block') {
const relativeY = event.pageY - 300 // this.sensitivityMenu.offsetTop
const horizontalDistanceFromInitial = Math.abs(
event.target.offsetWidth - this.initialMouseX,
)
// Unlock if the mouse moves back towards the initial position
if (horizontalDistanceFromInitial < this.threshold) {
this.thresholdExceeded = false
this.stepLocked = false
this.accumulatedDelta = 0
}
// Update step only if it is not locked
if (!this.stepLocked) {
for (let step of this.steps) {
step.classList.remove('active') //styles.active)
step.classList.remove('locked') //styles.locked)
if (
relativeY >= step.offsetTop &&
relativeY <= step.offsetTop + step.offsetHeight
) {
step.classList.add('active') //styles.active)
this.setActiveStep(parseFloat(step.dataset.step))
}
}
}
if (this.stepLocked) {
this.sensitivityMenu
.querySelector('.step.active')
?.classList.add('locked')
}
this.updateStepValue(event.pageX)
}
}
initializeEventListeners() {
document.addEventListener('mousemove', (event) =>
this.handleMouseMove(event),
)
document.addEventListener('mouseup', (event) => this.handleMouseUp(event))
document.addEventListener('click', (event) =>
this.handleClickOutside(event),
)
}
setActiveStep(val) {
if (this.activeStep !== val) {
this.activeStep = val
this.stepLocked = false
this.accumulatedDelta = 0
this.thresholdExceeded = false
}
}
resetWidgetState() {
this.sensitivityMenu.style.display = 'none'
this.isDragging = false
this.lastMouseX = undefined
this.thresholdExceeded = false
this.stepLocked = false
this.updateDebugInfo()
}
updateStepValue(mouseX) {
if (this.isDragging && this.lastMouseX !== undefined) {
const deltaX = mouseX - this.lastMouseX
this.accumulatedDelta += deltaX
if (
!this.thresholdExceeded &&
Math.abs(this.accumulatedDelta) > this.threshold
) {
this.thresholdExceeded = true
this.stepLocked = true
}
if (this.thresholdExceeded && this.stepLocked) {
// frequency of value changes
if (
Math.abs(this.accumulatedDelta) * this.mouseSensitivityMultiplier >=
1
) {
const valueChange = Math.sign(this.accumulatedDelta) * this.activeStep
if (this.currentInput) {
this.currentInput.value =
getValidNumber(this.currentInput) + valueChange
this.onChange?.(this.getValue())
} else {
this.numberInputs.forEach((input) => {
input.value = getValidNumber(input) + valueChange
})
}
this.accumulatedDelta = 0
}
}
this.lastMouseX = mouseX
}
this.updateDebugInfo()
}
}
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
ace.define("ace/ext/beautify",["require","exports","module","ace/token_iterator"],function(e,t,n){"use strict";function i(e,t){return e.type.lastIndexOf(t+".xml")>-1}var r=e("../token_iterator").TokenIterator;t.singletonTags=["area","base","br","col","command","embed","hr","html","img","input","keygen","link","meta","param","source","track","wbr"],t.blockTags=["article","aside","blockquote","body","div","dl","fieldset","footer","form","head","header","html","nav","ol","p","script","section","style","table","tbody","tfoot","thead","ul"],t.formatOptions={lineBreaksAfterCommasInCurlyBlock:!0},t.beautify=function(e){var n=new r(e,0,0),s=n.getCurrentToken(),o=e.getTabString(),u=t.singletonTags,a=t.blockTags,f=t.formatOptions||{},l,c=!1,h=!1,p=!1,d="",v="",m="",g=0,y=0,b=0,w=0,E=0,S=0,x=0,T,N=0,C=0,k=[],L=!1,A,O=!1,M=!1,_=!1,D=!1,P={0:0},H=[],B=!1,j=function(){l&&l.value&&l.type!=="string.regexp"&&(l.value=l.value.replace(/^\s*/,""))},F=function(){var e=d.length-1;for(;;){if(e==0)break;if(d[e]!==" ")break;e-=1}d=d.slice(0,e+1)},I=function(){d=d.trimRight(),c=!1};while(s!==null){N=n.getCurrentTokenRow(),k=n.$rowTokens,l=n.stepForward();if(typeof s!="undefined"){v=s.value,E=0,_=m==="style"||e.$modeId==="ace/mode/css",i(s,"tag-open")?(M=!0,l&&(D=a.indexOf(l.value)!==-1),v==="</"&&(D&&!c&&C<1&&C++,_&&(C=1),E=1,D=!1)):i(s,"tag-close")?M=!1:i(s,"comment.start")?D=!0:i(s,"comment.end")&&(D=!1),!M&&!C&&s.type==="paren.rparen"&&s.value.substr(0,1)==="}"&&C++,N!==T&&(C=N,T&&(C-=T));if(C){I();for(;C>0;C--)d+="\n";c=!0,!i(s,"comment")&&!s.type.match(/^(comment|string)$/)&&(v=v.trimLeft())}if(v){s.type==="keyword"&&v.match(/^(if|else|elseif|for|foreach|while|switch)$/)?(H[g]=v,j(),p=!0,v.match(/^(else|elseif)$/)&&d.match(/\}[\s]*$/)&&(I(),h=!0)):s.type==="paren.lparen"?(j(),v.substr(-1)==="{"&&(p=!0,O=!1,M||(C=1)),v.substr(0,1)==="{"&&(h=!0,d.substr(-1)!=="["&&d.trimRight().substr(-1)==="["?(I(),h=!1):d.trimRight().substr(-1)===")"?I():F())):s.type==="paren.rparen"?(E=1,v.substr(0,1)==="}"&&(H[g-1]==="case"&&E++,d.trimRight().substr(-1)==="{"?I():(h=!0,_&&(C+=2))),v.substr(0,1)==="]"&&d.substr(-1)!=="}"&&d.trimRight().substr(-1)==="}"&&(h=!1,w++,I()),v.substr(0,1)===")"&&d.substr(-1)!=="("&&d.trimRight().substr(-1)==="("&&(h=!1,w++,I()),F()):s.type!=="keyword.operator"&&s.type!=="keyword"||!v.match(/^(=|==|===|!=|!==|&&|\|\||and|or|xor|\+=|.=|>|>=|<|<=|=>)$/)?s.type==="punctuation.operator"&&v===";"?(I(),j(),p=!0,_&&C++):s.type==="punctuation.operator"&&v.match(/^(:|,)$/)?(I(),j(),v.match(/^(,)$/)&&x>0&&S===0&&f.lineBreaksAfterCommasInCurlyBlock?C++:(p=!0,c=!1)):s.type==="support.php_tag"&&v==="?>"&&!c?(I(),h=!0):i(s,"attribute-name")&&d.substr(-1).match(/^\s$/)?h=!0:i(s,"attribute-equals")?(F(),j()):i(s,"tag-close")?(F(),v==="/>"&&(h=!0)):s.type==="keyword"&&v.match(/^(case|default)$/)&&B&&(E=1):(I(),j(),h=!0,p=!0);if(c&&(!s.type.match(/^(comment)$/)||!!v.substr(0,1).match(/^[/#]$/))&&(!s.type.match(/^(string)$/)||!!v.substr(0,1).match(/^['"@]$/))){w=b;if(g>y){w++;for(A=g;A>y;A--)P[A]=w}else g<y&&(w=P[g]);y=g,b=w,E&&(w-=E),O&&!S&&(w++,O=!1);for(A=0;A<w;A++)d+=o}s.type==="keyword"&&v.match(/^(case|default)$/)?B===!1&&(H[g]=v,g++,B=!0):s.type==="keyword"&&v.match(/^(break)$/)&&H[g-1]&&H[g-1].match(/^(case|default)$/)&&(g--,B=!1),s.type==="paren.lparen"&&(S+=(v.match(/\(/g)||[]).length,x+=(v.match(/\{/g)||[]).length,g+=v.length),s.type==="keyword"&&v.match(/^(if|else|elseif|for|while)$/)?(O=!0,S=0):!S&&v.trim()&&s.type!=="comment"&&(O=!1);if(s.type==="paren.rparen"){S-=(v.match(/\)/g)||[]).length,x-=(v.match(/\}/g)||[]).length;for(A=0;A<v.length;A++)g--,v.substr(A,1)==="}"&&H[g]==="case"&&g--}s.type=="text"&&(v=v.replace(/\s+$/," ")),h&&!c&&(F(),d.substr(-1)!=="\n"&&(d+=" ")),d+=v,p&&(d+=" "),c=!1,h=!1,p=!1;if(i(s,"tag-close")&&(D||a.indexOf(m)!==-1)||i(s,"doctype")&&v===">")D&&l&&l.value==="</"?C=-1:C=1;l&&u.indexOf(l.value)===-1&&(i(s,"tag-open")&&v==="</"?g--:i(s,"tag-open")&&v==="<"?g++:i(s,"tag-close")&&v==="/>"&&g--),i(s,"tag-name")&&(m=v),T=N}}s=l}d=d.trim(),e.doc.setValue(d)},t.commands=[{name:"beautify",description:"Format selection (Beautify)",exec:function(e){t.beautify(e.session)},bindKey:"Ctrl-Shift-B"}]}); (function() {
ace.require(["ace/ext/beautify"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();
+8
View File
@@ -0,0 +1,8 @@
ace.define("ace/ext/code_lens",["require","exports","module","ace/line_widgets","ace/lib/event","ace/lib/lang","ace/lib/dom","ace/editor","ace/config"],function(e,t,n){"use strict";function u(e){var t=e.$textLayer,n=t.$lenses;n&&n.forEach(function(e){e.remove()}),t.$lenses=null}function a(e,t){var n=e&t.CHANGE_LINES||e&t.CHANGE_FULL||e&t.CHANGE_SCROLL||e&t.CHANGE_TEXT;if(!n)return;var r=t.session,i=t.session.lineWidgets,s=t.$textLayer,a=s.$lenses;if(!i){a&&u(t);return}var f=t.$textLayer.$lines.cells,l=t.layerConfig,c=t.$padding;a||(a=s.$lenses=[]);var h=0;for(var p=0;p<f.length;p++){var d=f[p].row,v=i[d],m=v&&v.lenses;if(!m||!m.length)continue;var g=a[h];g||(g=a[h]=o.buildDom(["div",{"class":"ace_codeLens"}],t.container)),g.style.height=l.lineHeight+"px",h++;for(var y=0;y<m.length;y++){var b=g.childNodes[2*y];b||(y!=0&&g.appendChild(o.createTextNode("\u00a0|\u00a0")),b=o.buildDom(["a"],g)),b.textContent=m[y].title,b.lensCommand=m[y]}while(g.childNodes.length>2*y-1)g.lastChild.remove();var w=t.$cursorLayer.getPixelPosition({row:d,column:0},!0).top-l.lineHeight*v.rowsAbove-l.offset;g.style.top=w+"px";var E=t.gutterWidth,S=r.getLine(d).search(/\S|$/);S==-1&&(S=0),E+=S*l.characterWidth,g.style.paddingLeft=c+E+"px"}while(h<a.length)a.pop().remove()}function f(e){if(!e.lineWidgets)return;var t=e.widgetManager;e.lineWidgets.forEach(function(e){e&&e.lenses&&t.removeLineWidget(e)})}function l(e){e.codeLensProviders=[],e.renderer.on("afterRender",a),e.$codeLensClickHandler||(e.$codeLensClickHandler=function(t){var n=t.target.lensCommand;if(!n)return;e.execCommand(n.id,n.arguments),e._emit("codeLensClick",t)},i.addListener(e.container,"click",e.$codeLensClickHandler,e)),e.$updateLenses=function(){function o(){var r=n.selection.cursor,i=n.documentToScreenRow(r),o=n.getScrollTop(),u=t.setLenses(n,s),a=n.$undoManager&&n.$undoManager.$lastDelta;if(a&&a.action=="remove"&&a.lines.length>1)return;var f=n.documentToScreenRow(r),l=e.renderer.layerConfig.lineHeight,c=n.getScrollTop()+(f-i)*l;u==0&&o<l/4&&o>-l/4&&(c=-l),n.setScrollTop(c)}var n=e.session;if(!n)return;n.widgetManager||(n.widgetManager=new r(n),n.widgetManager.attach(e));var i=e.codeLensProviders.length,s=[];e.codeLensProviders.forEach(function(e){e.provideCodeLenses(n,function(e,t){if(e)return;t.forEach(function(e){s.push(e)}),i--,i==0&&o()})})};var n=s.delayedCall(e.$updateLenses);e.$updateLensesOnInput=function(){n.delay(250)},e.on("input",e.$updateLensesOnInput)}function c(e){e.off("input",e.$updateLensesOnInput),e.renderer.off("afterRender",a),e.$codeLensClickHandler&&e.container.removeEventListener("click",e.$codeLensClickHandler)}var r=e("../line_widgets").LineWidgets,i=e("../lib/event"),s=e("../lib/lang"),o=e("../lib/dom");t.setLenses=function(e,t){var n=Number.MAX_VALUE;return f(e),t&&t.forEach(function(t){var r=t.start.row,i=t.start.column,s=e.lineWidgets&&e.lineWidgets[r];if(!s||!s.lenses)s=e.widgetManager.$registerLineWidget({rowCount:1,rowsAbove:1,row:r,column:i,lenses:[]});s.lenses.push(t.command),r<n&&(n=r)}),e._emit("changeFold",{data:{start:{row:n}}}),n},t.registerCodeLensProvider=function(e,t){e.setOption("enableCodeLens",!0),e.codeLensProviders.push(t),e.$updateLensesOnInput()},t.clear=function(e){t.setLenses(e,null)};var h=e("../editor").Editor;e("../config").defineOptions(h.prototype,"editor",{enableCodeLens:{set:function(e){e?l(this):c(this)}}}),o.importCssString("\n.ace_codeLens {\n position: absolute;\n color: #aaa;\n font-size: 88%;\n background: inherit;\n width: 100%;\n display: flex;\n align-items: flex-end;\n pointer-events: none;\n}\n.ace_codeLens > a {\n cursor: pointer;\n pointer-events: auto;\n}\n.ace_codeLens > a:hover {\n color: #0000ff;\n text-decoration: underline;\n}\n.ace_dark > .ace_codeLens > a:hover {\n color: #4e94ce;\n}\n","codelense.css",!1)}); (function() {
ace.require(["ace/ext/code_lens"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
ace.define("ace/ext/elastic_tabstops_lite",["require","exports","module","ace/editor","ace/config"],function(e,t,n){"use strict";var r=function(){function e(e){this.$editor=e;var t=this,n=[],r=!1;this.onAfterExec=function(){r=!1,t.processRows(n),n=[]},this.onExec=function(){r=!0},this.onChange=function(e){r&&(n.indexOf(e.start.row)==-1&&n.push(e.start.row),e.end.row!=e.start.row&&n.push(e.end.row))}}return e.prototype.processRows=function(e){this.$inChange=!0;var t=[];for(var n=0,r=e.length;n<r;n++){var i=e[n];if(t.indexOf(i)>-1)continue;var s=this.$findCellWidthsForBlock(i),o=this.$setBlockCellWidthsToMax(s.cellWidths),u=s.firstRow;for(var a=0,f=o.length;a<f;a++){var l=o[a];t.push(u),this.$adjustRow(u,l),u++}}this.$inChange=!1},e.prototype.$findCellWidthsForBlock=function(e){var t=[],n,r=e;while(r>=0){n=this.$cellWidthsForRow(r);if(n.length==0)break;t.unshift(n),r--}var i=r+1;r=e;var s=this.$editor.session.getLength();while(r<s-1){r++,n=this.$cellWidthsForRow(r);if(n.length==0)break;t.push(n)}return{cellWidths:t,firstRow:i}},e.prototype.$cellWidthsForRow=function(e){var t=this.$selectionColumnsForRow(e),n=[-1].concat(this.$tabsForRow(e)),r=n.map(function(e){return 0}).slice(1),i=this.$editor.session.getLine(e);for(var s=0,o=n.length-1;s<o;s++){var u=n[s]+1,a=n[s+1],f=this.$rightmostSelectionInCell(t,a),l=i.substring(u,a);r[s]=Math.max(l.replace(/\s+$/g,"").length,f-u)}return r},e.prototype.$selectionColumnsForRow=function(e){var t=[],n=this.$editor.getCursorPosition();return this.$editor.session.getSelection().isEmpty()&&e==n.row&&t.push(n.column),t},e.prototype.$setBlockCellWidthsToMax=function(e){var t=!0,n,r,i,s=this.$izip_longest(e);for(var o=0,u=s.length;o<u;o++){var a=s[o];if(!a.push){console.error(a);continue}a.push(NaN);for(var f=0,l=a.length;f<l;f++){var c=a[f];t&&(n=f,i=0,t=!1);if(isNaN(c)){r=f;for(var h=n;h<r;h++)e[h][o]=i;t=!0}i=Math.max(i,c)}}return e},e.prototype.$rightmostSelectionInCell=function(e,t){var n=0;if(e.length){var r=[];for(var i=0,s=e.length;i<s;i++)e[i]<=t?r.push(i):r.push(0);n=Math.max.apply(Math,r)}return n},e.prototype.$tabsForRow=function(e){var t=[],n=this.$editor.session.getLine(e),r=/\t/g,i;while((i=r.exec(n))!=null)t.push(i.index);return t},e.prototype.$adjustRow=function(e,t){var n=this.$tabsForRow(e);if(n.length==0)return;var r=0,i=-1,s=this.$izip(t,n);for(var o=0,u=s.length;o<u;o++){var a=s[o][0],f=s[o][1];i+=1+a,f+=r;var l=i-f;if(l==0)continue;var c=this.$editor.session.getLine(e).substr(0,f),h=c.replace(/\s*$/g,""),p=c.length-h.length;l>0&&(this.$editor.session.getDocument().insertInLine({row:e,column:f+1},Array(l+1).join(" ")+" "),this.$editor.session.getDocument().removeInLine(e,f,f+1),r+=l),l<0&&p>=-l&&(this.$editor.session.getDocument().removeInLine(e,f+l,f),r+=l)}},e.prototype.$izip_longest=function(e){if(!e[0])return[];var t=e[0].length,n=e.length;for(var r=1;r<n;r++){var i=e[r].length;i>t&&(t=i)}var s=[];for(var o=0;o<t;o++){var u=[];for(var r=0;r<n;r++)e[r][o]===""?u.push(NaN):u.push(e[r][o]);s.push(u)}return s},e.prototype.$izip=function(e,t){var n=e.length>=t.length?t.length:e.length,r=[];for(var i=0;i<n;i++){var s=[e[i],t[i]];r.push(s)}return r},e}();t.ElasticTabstopsLite=r;var i=e("../editor").Editor;e("../config").defineOptions(i.prototype,"editor",{useElasticTabstops:{set:function(e){e?(this.elasticTabstops||(this.elasticTabstops=new r(this)),this.commands.on("afterExec",this.elasticTabstops.onAfterExec),this.commands.on("exec",this.elasticTabstops.onExec),this.on("change",this.elasticTabstops.onChange)):this.elasticTabstops&&(this.commands.removeListener("afterExec",this.elasticTabstops.onAfterExec),this.commands.removeListener("exec",this.elasticTabstops.onExec),this.removeListener("change",this.elasticTabstops.onChange))}}})}); (function() {
ace.require(["ace/ext/elastic_tabstops_lite"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
; (function() {
ace.require(["ace/ext/error_marker"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();
+8
View File
@@ -0,0 +1,8 @@
ace.define("ace/ext/hardwrap",["require","exports","module","ace/range","ace/editor","ace/config"],function(e,t,n){"use strict";function i(e,t){function m(e,t,n){if(e.length<t)return;var r=e.slice(0,t),i=e.slice(t),s=/^(?:(\s+)|(\S+)(\s+))/.exec(i),o=/(?:(\s+)|(\s+)(\S+))$/.exec(r),u=0,a=0;o&&!o[2]&&(u=t-o[1].length,a=t),s&&!s[2]&&(u||(u=t),a=t+s[1].length);if(u)return{start:u,end:a};if(o&&o[2]&&o.index>n)return{start:o.index,end:o.index+o[2].length};if(s&&s[2])return u=t+s[2].length,{start:u,end:u+s[3].length}}var n=t.column||e.getOption("printMarginColumn"),i=t.allowMerge!=0,s=Math.min(t.startRow,t.endRow),o=Math.max(t.startRow,t.endRow),u=e.session;while(s<=o){var a=u.getLine(s);if(a.length>n){var f=m(a,n,5);if(f){var l=/^\s*/.exec(a)[0];u.replace(new r(s,f.start,s,f.end),"\n"+l)}o++}else if(i&&/\S/.test(a)&&s!=o){var c=u.getLine(s+1);if(c&&/\S/.test(c)){var h=a.replace(/\s+$/,""),p=c.replace(/^\s+/,""),d=h+" "+p,f=m(d,n,5);if(f&&f.start>h.length||d.length<n){var v=new r(s,h.length,s+1,c.length-p.length);u.replace(v," "),s--,o--}else h.length<a.length&&u.remove(new r(s,h.length,s,a.length))}}s++}}function s(e){if(e.command.name=="insertstring"&&/\S/.test(e.args)){var t=e.editor,n=t.selection.cursor;if(n.column<=t.renderer.$printMarginColumn)return;var r=t.session.$undoManager.$lastDelta;i(t,{startRow:n.row,endRow:n.row,allowMerge:!1}),r!=t.session.$undoManager.$lastDelta&&t.session.markUndoGroup()}}var r=e("../range").Range,o=e("../editor").Editor;e("../config").defineOptions(o.prototype,"editor",{hardWrap:{set:function(e){e?this.commands.on("afterExec",s):this.commands.off("afterExec",s)},value:!1}}),t.hardWrap=i}); (function() {
ace.require(["ace/ext/hardwrap"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
ace.define("ace/ext/menu_tools/settings_menu.css",["require","exports","module"],function(e,t,n){n.exports="#ace_settingsmenu, #kbshortcutmenu {\n background-color: #F7F7F7;\n color: black;\n box-shadow: -5px 4px 5px rgba(126, 126, 126, 0.55);\n padding: 1em 0.5em 2em 1em;\n overflow: auto;\n position: absolute;\n margin: 0;\n bottom: 0;\n right: 0;\n top: 0;\n z-index: 9991;\n cursor: default;\n}\n\n.ace_dark #ace_settingsmenu, .ace_dark #kbshortcutmenu {\n box-shadow: -20px 10px 25px rgba(126, 126, 126, 0.25);\n background-color: rgba(255, 255, 255, 0.6);\n color: black;\n}\n\n.ace_optionsMenuEntry:hover {\n background-color: rgba(100, 100, 100, 0.1);\n transition: all 0.3s\n}\n\n.ace_closeButton {\n background: rgba(245, 146, 146, 0.5);\n border: 1px solid #F48A8A;\n border-radius: 50%;\n padding: 7px;\n position: absolute;\n right: -8px;\n top: -8px;\n z-index: 100000;\n}\n.ace_closeButton{\n background: rgba(245, 146, 146, 0.9);\n}\n.ace_optionsMenuKey {\n color: darkslateblue;\n font-weight: bold;\n}\n.ace_optionsMenuCommand {\n color: darkcyan;\n font-weight: normal;\n}\n.ace_optionsMenuEntry input, .ace_optionsMenuEntry button {\n vertical-align: middle;\n}\n\n.ace_optionsMenuEntry button[ace_selected_button=true] {\n background: #e7e7e7;\n box-shadow: 1px 0px 2px 0px #adadad inset;\n border-color: #adadad;\n}\n.ace_optionsMenuEntry button {\n background: white;\n border: 1px solid lightgray;\n margin: 0px;\n}\n.ace_optionsMenuEntry button:hover{\n background: #f0f0f0;\n}"}),ace.define("ace/ext/menu_tools/overlay_page",["require","exports","module","ace/lib/dom","ace/ext/menu_tools/settings_menu.css"],function(e,t,n){"use strict";var r=e("../../lib/dom"),i=e("./settings_menu.css");r.importCssString(i,"settings_menu.css",!1),n.exports.overlayPage=function(t,n,r){function o(e){e.keyCode===27&&u()}function u(){if(!i)return;document.removeEventListener("keydown",o),i.parentNode.removeChild(i),t&&t.focus(),i=null,r&&r()}function a(e){s=e,e&&(i.style.pointerEvents="none",n.style.pointerEvents="auto")}var i=document.createElement("div"),s=!1;return i.style.cssText="margin: 0; padding: 0; position: fixed; top:0; bottom:0; left:0; right:0;z-index: 9990; "+(t?"background-color: rgba(0, 0, 0, 0.3);":""),i.addEventListener("click",function(e){s||u()}),document.addEventListener("keydown",o),n.addEventListener("click",function(e){e.stopPropagation()}),i.appendChild(n),document.body.appendChild(i),t&&t.blur(),{close:u,setIgnoreFocusOut:a}}}),ace.define("ace/ext/menu_tools/get_editor_keyboard_shortcuts",["require","exports","module","ace/lib/keys"],function(e,t,n){"use strict";var r=e("../../lib/keys");n.exports.getEditorKeybordShortcuts=function(e){var t=r.KEY_MODS,n=[],i={};return e.keyBinding.$handlers.forEach(function(e){var t=e.commandKeyBinding;for(var r in t){var s=r.replace(/(^|-)\w/g,function(e){return e.toUpperCase()}),o=t[r];Array.isArray(o)||(o=[o]),o.forEach(function(e){typeof e!="string"&&(e=e.name),i[e]?i[e].key+="|"+s:(i[e]={key:s,command:e},n.push(i[e]))})}}),n}}),ace.define("ace/ext/keybinding_menu",["require","exports","module","ace/editor","ace/ext/menu_tools/overlay_page","ace/ext/menu_tools/get_editor_keyboard_shortcuts"],function(e,t,n){"use strict";function i(t){if(!document.getElementById("kbshortcutmenu")){var n=e("./menu_tools/overlay_page").overlayPage,r=e("./menu_tools/get_editor_keyboard_shortcuts").getEditorKeybordShortcuts,i=r(t),s=document.createElement("div"),o=i.reduce(function(e,t){return e+'<div class="ace_optionsMenuEntry"><span class="ace_optionsMenuCommand">'+t.command+"</span> : "+'<span class="ace_optionsMenuKey">'+t.key+"</span></div>"},"");s.id="kbshortcutmenu",s.innerHTML="<h1>Keyboard Shortcuts</h1>"+o+"</div>",n(t,s)}}var r=e("../editor").Editor;n.exports.init=function(e){r.prototype.showKeyboardShortcuts=function(){i(this)},e.commands.addCommands([{name:"showKeyboardShortcuts",bindKey:{win:"Ctrl-Alt-h",mac:"Command-Alt-h"},exec:function(e,t){e.showKeyboardShortcuts()}}])}}); (function() {
ace.require(["ace/ext/keybinding_menu"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
ace.define("ace/ext/linking",["require","exports","module","ace/editor","ace/config"],function(e,t,n){function i(e){var n=e.editor,r=e.getAccelKey();if(r){var n=e.editor,i=e.getDocumentPosition(),s=n.session,o=s.getTokenAt(i.row,i.column);t.previousLinkingHover&&t.previousLinkingHover!=o&&n._emit("linkHoverOut"),n._emit("linkHover",{position:i,token:o}),t.previousLinkingHover=o}else t.previousLinkingHover&&(n._emit("linkHoverOut"),t.previousLinkingHover=!1)}function s(e){var t=e.getAccelKey(),n=e.getButton();if(n==0&&t){var r=e.editor,i=e.getDocumentPosition(),s=r.session,o=s.getTokenAt(i.row,i.column);r._emit("linkClick",{position:i,token:o})}}var r=e("../editor").Editor;e("../config").defineOptions(r.prototype,"editor",{enableLinking:{set:function(e){e?(this.on("click",s),this.on("mousemove",i)):(this.off("click",s),this.off("mousemove",i))},value:!1}}),t.previousLinkingHover=!1}); (function() {
ace.require(["ace/ext/linking"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();
+8
View File
@@ -0,0 +1,8 @@
ace.define("ace/ext/modelist",["require","exports","module"],function(e,t,n){"use strict";function i(e){var t=a.text,n=e.split(/[\/\\]/).pop();for(var i=0;i<r.length;i++)if(r[i].supportsFile(n)){t=r[i];break}return t}var r=[],s=function(){function e(e,t,n){this.name=e,this.caption=t,this.mode="ace/mode/"+e,this.extensions=n;var r;/\^/.test(n)?r=n.replace(/\|(\^)?/g,function(e,t){return"$|"+(t?"^":"^.*\\.")})+"$":r="^.*\\.("+n+")$",this.extRe=new RegExp(r,"gi")}return e.prototype.supportsFile=function(e){return e.match(this.extRe)},e}(),o={ABAP:["abap"],ABC:["abc"],ActionScript:["as"],ADA:["ada|adb"],Alda:["alda"],Apache_Conf:["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"],Apex:["apex|cls|trigger|tgr"],AQL:["aql"],AsciiDoc:["asciidoc|adoc"],ASL:["dsl|asl|asl.json"],Assembly_ARM32:["s"],Assembly_x86:["asm|a"],Astro:["astro"],AutoHotKey:["ahk"],BatchFile:["bat|cmd"],BibTeX:["bib"],C_Cpp:["cpp|c|cc|cxx|h|hh|hpp|ino"],C9Search:["c9search_results"],Cirru:["cirru|cr"],Clojure:["clj|cljs"],Cobol:["CBL|COB"],coffee:["coffee|cf|cson|^Cakefile"],ColdFusion:["cfm|cfc"],Crystal:["cr"],CSharp:["cs"],Csound_Document:["csd"],Csound_Orchestra:["orc"],Csound_Score:["sco"],CSS:["css"],Curly:["curly"],Cuttlefish:["conf"],D:["d|di"],Dart:["dart"],Diff:["diff|patch"],Django:["djt|html.djt|dj.html|djhtml"],Dockerfile:["^Dockerfile"],Dot:["dot"],Drools:["drl"],Edifact:["edi"],Eiffel:["e|ge"],EJS:["ejs"],Elixir:["ex|exs"],Elm:["elm"],Erlang:["erl|hrl"],Flix:["flix"],Forth:["frt|fs|ldr|fth|4th"],Fortran:["f|f90"],FSharp:["fsi|fs|ml|mli|fsx|fsscript"],FSL:["fsl"],FTL:["ftl"],Gcode:["gcode"],Gherkin:["feature"],Gitignore:["^.gitignore"],Glsl:["glsl|frag|vert"],Gobstones:["gbs"],golang:["go"],GraphQLSchema:["gql"],Groovy:["groovy"],HAML:["haml"],Handlebars:["hbs|handlebars|tpl|mustache"],Haskell:["hs"],Haskell_Cabal:["cabal"],haXe:["hx"],Hjson:["hjson"],HTML:["html|htm|xhtml|we|wpy"],HTML_Elixir:["eex|html.eex"],HTML_Ruby:["erb|rhtml|html.erb"],INI:["ini|conf|cfg|prefs"],Io:["io"],Ion:["ion"],Jack:["jack"],Jade:["jade|pug"],Java:["java"],JavaScript:["js|jsm|cjs|mjs"],JEXL:["jexl"],JSON:["json"],JSON5:["json5"],JSONiq:["jq"],JSP:["jsp"],JSSM:["jssm|jssm_state"],JSX:["jsx"],Julia:["jl"],Kotlin:["kt|kts"],LaTeX:["tex|latex|ltx|bib"],Latte:["latte"],LESS:["less"],Liquid:["liquid"],Lisp:["lisp"],LiveScript:["ls"],Log:["log"],LogiQL:["logic|lql"],Logtalk:["lgt"],LSL:["lsl"],Lua:["lua"],LuaPage:["lp"],Lucene:["lucene"],Makefile:["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"],Markdown:["md|markdown"],Mask:["mask"],MATLAB:["matlab"],Maze:["mz"],MediaWiki:["wiki|mediawiki"],MEL:["mel"],MIPS:["s|asm"],MIXAL:["mixal"],MUSHCode:["mc|mush"],MySQL:["mysql"],Nasal:["nas"],Nginx:["nginx|conf"],Nim:["nim"],Nix:["nix"],NSIS:["nsi|nsh"],Nunjucks:["nunjucks|nunjs|nj|njk"],ObjectiveC:["m|mm"],OCaml:["ml|mli"],Odin:["odin"],PartiQL:["partiql|pql"],Pascal:["pas|p"],Perl:["pl|pm"],pgSQL:["pgsql"],PHP:["php|inc|phtml|shtml|php3|php4|php5|phps|phpt|aw|ctp|module"],PHP_Laravel_blade:["blade.php"],Pig:["pig"],PLSQL:["plsql"],Powershell:["ps1"],Praat:["praat|praatscript|psc|proc"],Prisma:["prisma"],Prolog:["plg|prolog"],Properties:["properties"],Protobuf:["proto"],PRQL:["prql"],Puppet:["epp|pp"],Python:["py"],QML:["qml"],R:["r"],Raku:["raku|rakumod|rakutest|p6|pl6|pm6"],Razor:["cshtml|asp"],RDoc:["Rd"],Red:["red|reds"],RHTML:["Rhtml"],Robot:["robot|resource"],RST:["rst"],Ruby:["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"],Rust:["rs"],SaC:["sac"],SASS:["sass"],SCAD:["scad"],Scala:["scala|sbt"],Scheme:["scm|sm|rkt|oak|scheme"],Scrypt:["scrypt"],SCSS:["scss"],SH:["sh|bash|^.bashrc"],SJS:["sjs"],Slim:["slim|skim"],Smarty:["smarty|tpl"],Smithy:["smithy"],snippets:["snippets"],Soy_Template:["soy"],Space:["space"],SPARQL:["rq"],SQL:["sql"],SQLServer:["sqlserver"],Stylus:["styl|stylus"],SVG:["svg"],Swift:["swift"],Tcl:["tcl"],Terraform:["tf","tfvars","terragrunt"],Tex:["tex"],Text:["txt"],Textile:["textile"],Toml:["toml"],TSX:["tsx"],Turtle:["ttl"],Twig:["twig|swig"],Typescript:["ts|mts|cts|typescript|str"],Vala:["vala"],VBScript:["vbs|vb"],Velocity:["vm"],Verilog:["v|vh|sv|svh"],VHDL:["vhd|vhdl"],Visualforce:["vfp|component|page"],Vue:["vue"],Wollok:["wlk|wpgm|wtest"],XML:["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl|xaml"],XQuery:["xq"],YAML:["yaml|yml"],Zeek:["zeek|bro"],Zig:["zig"]},u={ObjectiveC:"Objective-C",CSharp:"C#",golang:"Go",C_Cpp:"C and C++",Csound_Document:"Csound Document",Csound_Orchestra:"Csound",Csound_Score:"Csound Score",coffee:"CoffeeScript",HTML_Ruby:"HTML (Ruby)",HTML_Elixir:"HTML (Elixir)",FTL:"FreeMarker",PHP_Laravel_blade:"PHP (Blade Template)",Perl6:"Perl 6",AutoHotKey:"AutoHotkey / AutoIt"},a={};for(var f in o){var l=o[f],c=(u[f]||f).replace(/_/g," "),h=f.toLowerCase(),p=new s(h,c,l[0]);a[h]=p,r.push(p)}n.exports={getModeForPath:i,modes:r,modesByName:a}}); (function() {
ace.require(["ace/ext/modelist"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
ace.define("ace/ext/rtl",["require","exports","module","ace/editor","ace/config"],function(e,t,n){"use strict";function s(e,t){var n=t.getSelection().lead;t.session.$bidiHandler.isRtlLine(n.row)&&n.column===0&&(t.session.$bidiHandler.isMoveLeftOperation&&n.row>0?t.getSelection().moveCursorTo(n.row-1,t.session.getLine(n.row-1).length):t.getSelection().isEmpty()?n.column+=1:n.setPosition(n.row,n.column+1))}function o(e){e.editor.session.$bidiHandler.isMoveLeftOperation=/gotoleft|selectleft|backspace|removewordleft/.test(e.command.name)}function u(e,t){var n=t.session;n.$bidiHandler.currentRow=null;if(n.$bidiHandler.isRtlLine(e.start.row)&&e.action==="insert"&&e.lines.length>1)for(var r=e.start.row;r<e.end.row;r++)n.getLine(r+1).charAt(0)!==n.$bidiHandler.RLE&&(n.doc.$lines[r+1]=n.$bidiHandler.RLE+n.getLine(r+1))}function a(e,t){var n=t.session,r=n.$bidiHandler,i=t.$textLayer.$lines.cells,s=t.layerConfig.width-t.layerConfig.padding+"px";i.forEach(function(e){var t=e.element.style;r&&r.isRtlLine(e.row)?(t.direction="rtl",t.textAlign="right",t.width=s):(t.direction="",t.textAlign="",t.width="")})}function f(e){function n(e){var t=e.element.style;t.direction=t.textAlign=t.width=""}var t=e.$textLayer.$lines;t.cells.forEach(n),t.cellCache.forEach(n)}var r=[{name:"leftToRight",bindKey:{win:"Ctrl-Alt-Shift-L",mac:"Command-Alt-Shift-L"},exec:function(e){e.session.$bidiHandler.setRtlDirection(e,!1)},readOnly:!0},{name:"rightToLeft",bindKey:{win:"Ctrl-Alt-Shift-R",mac:"Command-Alt-Shift-R"},exec:function(e){e.session.$bidiHandler.setRtlDirection(e,!0)},readOnly:!0}],i=e("../editor").Editor;e("../config").defineOptions(i.prototype,"editor",{rtlText:{set:function(e){e?(this.on("change",u),this.on("changeSelection",s),this.renderer.on("afterRender",a),this.commands.on("exec",o),this.commands.addCommands(r)):(this.off("change",u),this.off("changeSelection",s),this.renderer.off("afterRender",a),this.commands.off("exec",o),this.commands.removeCommands(r),f(this.renderer)),this.renderer.updateFull()}},rtl:{set:function(e){this.session.$bidiHandler.$isRtl=e,e?(this.setOption("rtlText",!1),this.renderer.on("afterRender",a),this.session.$bidiHandler.seenBidi=!0):(this.renderer.off("afterRender",a),f(this.renderer)),this.renderer.updateFull()}}})}); (function() {
ace.require(["ace/ext/rtl"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
ace.define("ace/ext/simple_tokenizer",["require","exports","module","ace/tokenizer","ace/layer/text_util"],function(e,t,n){"use strict";function o(e,t){var n=new s(e,new r(t.getRules())),o=[];for(var u=0;u<n.getLength();u++){var a=n.getTokens(u);o.push(a.map(function(e){return{className:i(e.type)?undefined:"ace_"+e.type.replace(/\./g," ace_"),value:e.value}}))}return o}var r=e("../tokenizer").Tokenizer,i=e("../layer/text_util").isTextToken,s=function(){function e(e,t){this._lines=e.split(/\r\n|\r|\n/),this._states=[],this._tokenizer=t}return e.prototype.getTokens=function(e){var t=this._lines[e],n=this._states[e-1],r=this._tokenizer.getLineTokens(t,n);return this._states[e]=r.state,r.tokens},e.prototype.getLength=function(){return this._lines.length},e}();n.exports={tokenize:o}}); (function() {
ace.require(["ace/ext/simple_tokenizer"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();

Some files were not shown because too many files have changed in this diff Show More