Compare commits

...
Author SHA1 Message Date
Chengwei Ouyang 06163a06d4 i[date 2025-03-10 23:21:36 +08:00
shanexi 087571346c Merge pull request #9 from myshell-ai/support-input-video
feat: support input audio
2025-02-13 17:44:28 +08:00
shanexi bc62e8a44c feat: support input audio 2025-02-12 18:10:01 +08:00
Xumin Yu 078b3f5ea5 Add joint dependency for Easy use (ComfyUI_IPAdapter_plus) 2025-01-16 16:03:08 +08:00
wl-zhao 31f95035b2 Merge branch 'main' of https://github.com/myshell-ai/ComfyUI-ShellAgent-Plugin into main 2025-01-13 15:55:50 +08:00
wl-zhao 04d33d8a8e add easydict 2025-01-13 15:55:40 +08:00
Wenliang Zhao 4e2bfd5620 Update dependency_checker.py 2024-12-30 14:55:30 +08:00
wl-zhao 681f716bfa update safe open image function 2024-12-18 15:18:48 +08:00
wl-zhao 580ac932df add mac_addr to check realy exist 2024-12-18 14:49:38 +08:00
wl-zhao 37eb10c327 add check_exist 2024-12-18 14:42:28 +08:00
wl-zhao 2310c33966 add get mac_addr 2024-12-18 12:01:11 +08:00
wl-zhao 637bc88fec pass validation when os.path.isfile 2024-12-17 19:24:59 +08:00
wl-zhao 604d34900a support heif image 2024-12-16 17:25:23 +08:00
wl-zhao 82f3a05f1c fix mask bug 2024-12-13 14:52:16 +08:00
wl-zhao 07c080726e kMerge branch 'main' of https://github.com/myshell-ai/ComfyUI-ShellAgent-Plugin into main 2024-12-13 11:45:50 +08:00
wl-zhao 7238c1f40b fix error message when empty input image 2024-12-13 11:45:43 +08:00
Xumin Yu f1135ac55a Update node_deps_info.json 2024-12-12 14:01:48 +08:00
Xumin Yu 676c40691f Update node_deps_info.json 2024-12-12 14:00:55 +08:00
wl-zhao 623ea454cc support input/output audio backend 2024-12-10 16:35:26 +08:00
wl-zhao 2d21584447 add route to inspect version 2024-12-03 15:20:17 +08:00
wl-zhao 27613ed685 support models in nodes / skip configs / input image support mask 2024-11-22 11:49:10 +08:00
wl-zhao 92673900c5 add glob to search models, and raise error when no models founded / multiple models founded 2024-11-14 16:31:43 +08:00
wl-zhao d9d20018be improve abs_path of file dependency 2024-11-14 10:19:59 +08:00
wl-zhao ffa4123f07 support skip model check for some nodes 2024-11-12 16:58:27 +08:00
wl-zhao 35b2700251 add backtick 2024-11-11 15:30:45 +08:00
wl-zhao 42981b7889 add validation for variable name 2024-11-11 15:28:04 +08:00
wl-zhao 091d2ff930 merge 2024-11-07 10:56:29 +08:00
wl-zhao 85e01a8711 add tree_map for dependency checker 2024-11-07 10:56:06 +08:00
Xumin Yu 4d548bfb5a support .sft for model suffix 2024-11-06 20:39:39 +08:00
wl-zhao 24c17beccf fix output video path error 2024-11-04 12:18:01 +08:00
wl-zhao 4c8e720d05 fix output video path error 2024-11-04 12:17:40 +08:00
Xumin Yu 1aa0fc15e2 revert input_video.py 2024-11-03 22:38:56 +08:00
Xumin Yu 1faaad58f0 Update input_video.py 2024-11-03 22:38:13 +08:00
wl-zhao 0904716cd0 fix input video bug 2024-11-03 22:29:12 +08:00
wl-zhao c80f154659 input video 2024-11-01 20:21:27 +08:00
wl-zhao fb3e973b53 add boolean; fix output nodes input type bugs; fix input_video enum validate bug; compatible with none desc 2024-11-01 11:16:08 +08:00
wl-zhao 34f8feb2c0 add boolean; fix output nodes input type bugs; fix input_video enum validate bug; compatible with none desc 2024-11-01 11:15:21 +08:00
Wenliang Zhao 64ebfa42e9 Update output_image.py 2024-10-30 18:11:17 +08:00
wl-zhao deba76e0e7 windows to linux path filenames 2024-10-30 12:08:50 +08:00
wl-zhao 8e8d10b1c5 update output video 2024-10-30 12:07:56 +08:00
Xumin Yu ae2948048a Update dependency_checker.py 2024-10-29 12:55:25 +08:00
wl-zhao 4eb3e8b4f7 add message details 2024-10-29 11:36:13 +08:00
wl-zhao 73bfa4e7b0 add warning message when no inputs/outputs founded 2024-10-28 15:13:01 +08:00
wl-zhao a9d07ba4d3 hardcode hf packages 2024-10-28 11:43:54 +08:00
Wenliang Zhao 070fdb5132 Merge pull request #7 from myshell-ai/6-add-more-convert
6 add more convert
2024-10-28 11:28:29 +08:00
wl-zhao e47726eb77 Merge branch 'main' of https://github.com/myshell-ai/ComfyUI-ShellAgent-Plugin into main 2024-10-28 11:22:11 +08:00
wl-zhao 3b5a9b5220 fix file upload error 2024-10-28 11:22:04 +08:00
shanexi f28c2c6b31 Replace with default value assigned 2024-10-28 11:20:03 +08:00
wl-zhao 344a886792 add pypi version info 2024-10-28 11:19:19 +08:00
shanexi fffc29fc2b Add missing convert output 2024-10-28 11:15:39 +08:00
shanexi 20fcbb2e48 Fix duplicated drag menu item 2024-10-28 11:14:05 +08:00
shanexi f9a3ce43f5 Replace and remove 2024-10-28 11:09:29 +08:00
shanexi cbd714d9ea Replace Load Image with ShellAgent Input Image 2024-10-28 11:02:18 +08:00
shanexi b825b62a96 Drag to connect output text float integer 2024-10-28 10:09:38 +08:00
shanexi ae8ed60767 Save Image(s) on output connect pop menu 2024-10-28 09:52:28 +08:00
Xumin Yu ddad7b8c40 Update README.md 2024-10-27 23:57:11 +08:00
yuxumin 134ccd3c2b fix dependencies deps 2024-10-27 17:54:59 +08:00
yuxumin 3c8a5ebc2b Merge branch 'main' of https://github.com/myshell-ai/ComfyUI-ShellAgent-Plugin into main 2024-10-27 17:29:48 +08:00
yuxumin 1a826fa746 update node_deps json 2024-10-27 17:29:46 +08:00
shanexi 710104d709 Image input 2024-10-27 16:02:48 +08:00
wl-zhao 752a0de95d add gguf 2024-10-27 15:39:16 +08:00
shanexi 9417b64458 No need to connect image combo 2024-10-27 15:23:13 +08:00
shanexi 4fb799112a Convert to save video 2024-10-27 09:42:31 +08:00
shanexi d2cfd99a33 Ouput convert 2024-10-27 09:33:06 +08:00
wl-zhao 5521822589 Merge branch 'main' of https://github.com/myshell-ai/ComfyUI-ShellAgent-Plugin into main 2024-10-26 11:07:25 +08:00
wl-zhao 2b19a132a6 addmap_legacy 2024-10-26 11:07:15 +08:00
yuxumin 6666050283 update node deps info 2024-10-25 23:29:57 +08:00
wl-zhao c0da8f916d update get_full_path_or_rase 2024-10-25 23:21:54 +08:00
wl-zhao 232bc67c9d handle relative path 2024-10-25 16:01:48 +08:00
wl-zhao a4d96afd5d add blacklist, update model search 2024-10-25 15:27:23 +08:00
wl-zhao 45e7caca72 use folder_path to find the models 2024-10-25 15:01:30 +08:00
shanexi 15c7d7f60c Optimize number input convert 2024-10-24 21:41:17 +08:00
Xumin Yu 26e57ef44f Update dependency_checker.py 2024-10-23 16:32:40 +08:00
wl-zhao 00fb0b91cd handle model_searcher fail 2024-10-23 10:46:48 +08:00
wl-zhao fc1f9afbcd add new output nodes 2024-10-22 19:47:04 +08:00
wl-zhao b3042fdf6f fix bug 2024-10-22 15:33:04 +08:00
wl-zhao bf8f352347 skip when .git is not found 2024-10-21 23:47:43 +08:00
wl-zhao 2eea258bc4 Merge branch 'main' of github.com:myshell-ai/ComfyUI-ShellAgent-Plugin into main 2024-10-21 23:12:21 +08:00
wl-zhao be2725c2cb add dependency checker 2024-10-21 23:12:12 +08:00
shanexi 3f742ed72f Merge pull request #5 from myshell-ai/Convert-to-ShellAgent-with-default-value-assigned
Convert to ShellAgent with default value assigned
2024-10-21 17:49:07 +08:00
17 changed files with 2297 additions and 143 deletions
+4
View File
@@ -17,6 +17,7 @@ To install, either:
- Input Image
- Input Float
- Input Integer
- Input Video
Each input node supports setting a default value and additional configuration options.
@@ -25,6 +26,9 @@ Each input node supports setting a default value and additional configuration op
- Save Image
- Save Images
- Save Video - VHS
- Output Text
- Output Float
- Output Integer
### Convert Widgets to ShellAgent Inputs
+195
View File
@@ -0,0 +1,195 @@
import folder_paths
import node_helpers
from PIL import Image, ImageOps, ImageSequence, ImageFile
import numpy as np
import torch
import os
import uuid
import tqdm
import torchaudio
import hashlib
from comfy_extras.nodes_audio import SaveAudio
class LoadAudio:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
files = folder_paths.filter_files_content_types(
os.listdir(input_dir), ["audio", "video"])
return {"required": {"audio": (sorted(files), {"audio_upload": True})}}
CATEGORY = "audio"
RETURN_TYPES = ("AUDIO", )
FUNCTION = "load"
def load(self, audio):
audio_path = folder_paths.get_annotated_filepath(audio)
waveform, sample_rate = torchaudio.load(audio_path)
audio = {"waveform": waveform.unsqueeze(0), "sample_rate": sample_rate}
return (audio, )
@classmethod
def IS_CHANGED(s, audio):
image_path = folder_paths.get_annotated_filepath(audio)
m = hashlib.sha256()
with open(image_path, 'rb') as f:
m.update(f.read())
return m.digest().hex()
@classmethod
def VALIDATE_INPUTS(s, audio):
if not folder_paths.exists_annotated_filepath(audio):
return "Invalid audio file: {}".format(audio)
return True
class ShellAgentPluginInputAudio:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
files = folder_paths.filter_files_content_types(
os.listdir(input_dir), ["audio", "video"])
return {
"required": {
"input_name": (
"STRING",
{"multiline": False, "default": "input_audio", "forceInput": False},
),
"default_value": (
sorted(files), {"audio_upload": True, "forceInput": False}
),
},
"optional": {
"description": (
"STRING",
{"multiline": True, "default": "", "forceInput": False},
),
}
}
RETURN_TYPES = ("AUDIO", )
FUNCTION = "load"
CATEGORY = "shellagent"
@classmethod
def validate(cls, **kwargs):
schema = {
"title": kwargs["input_name"],
"type": "string",
"default": kwargs["default_value"],
"description": kwargs.get("description", ""),
"url_type": "audio"
}
return schema
@classmethod
def VALIDATE_INPUTS(s, audio):
if not folder_paths.exists_annotated_filepath(audio):
return "Invalid audio file: {}".format(audio)
return True
@classmethod
def VALIDATE_INPUTS(s, input_name, default_value, description=""):
audio = default_value
if audio.startswith("http"):
return True
if not folder_paths.exists_annotated_filepath(audio):
return "Invalid audio file: {}".format(audio)
return True
def load(self, input_name, default_value=None, display_name=None, description=None):
input_dir = folder_paths.get_input_directory()
audio_path = default_value
try:
if audio_path.startswith('http'):
import requests
from io import BytesIO
print("Fetching audio from url: ", audio_path)
response = requests.get(audio_path)
response.raise_for_status()
audio_file = BytesIO(response.content)
waveform, sample_rate = torchaudio.load(audio_file)
else:
if not os.path.isfile(audio_path): # abs path
# local path
audio_path = os.path.join(input_dir, audio_path)
waveform, sample_rate = torchaudio.load(audio_path)
audio = {"waveform": waveform.unsqueeze(
0), "sample_rate": sample_rate}
return (audio, )
# image = ImageOps.exif_transpose(image)
# image = image.convert("RGB")
# image = np.array(image).astype(np.float32) / 255.0
# image = torch.from_numpy(image)[None,]
# return [image]
except Exception as e:
raise e
class ShellAgentSaveAudios(SaveAudio):
@classmethod
def INPUT_TYPES(s):
return {"required": {"audio": ("AUDIO", ),
"output_name": ("STRING", {"multiline": False, "default": "output_audio"},),
"filename_prefix": ("STRING", {"default": "audio/ComfyUI"})},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
# {
# "required": {
# "images": ("IMAGE", {"tooltip": "The audio to save."}),
# "output_name": ("STRING", {"multiline": False, "default": "output_image"},),
# "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"
# },
# }
CATEGORY = "shellagent"
@classmethod
def validate(cls, **kwargs):
schema = {
"title": kwargs["output_name"],
"type": "array",
"items": {
"type": "string",
"url_type": "audio",
}
}
return schema
def save_audio(self, audio, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None, **extra_kwargs):
results = super().save_audio(audio, filename_prefix, prompt, extra_pnginfo)
results["shellagent_kwargs"] = extra_kwargs
return results
class ShellAgentSaveAudio(ShellAgentSaveAudios):
@classmethod
def validate(cls, **kwargs):
schema = {
"title": kwargs["output_name"],
"type": "string",
"url_type": "audio",
}
return schema
NODE_CLASS_MAPPINGS = {
"ShellAgentPluginInputAudio": ShellAgentPluginInputAudio,
"ShellAgentPluginSaveAudios": ShellAgentSaveAudios,
"ShellAgentPluginSaveAudio": ShellAgentSaveAudio,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"ShellAgentPluginInputAudio": "Input Audio (ShellAgent Plugin)",
"ShellAgentPluginSaveAudios": "Save Audios (ShellAgent Plugin)",
"ShellAgentPluginSaveAudio": "Save Audio (ShellAgent Plugin)",
}
+101 -20
View File
@@ -1,11 +1,39 @@
import folder_paths
from PIL import Image, ImageOps
import node_helpers
from PIL import Image, ImageOps, ImageSequence, ImageFile
import numpy as np
import torch
import os
import uuid
import tqdm
from io import BytesIO
import PIL
import cv2
from pillow_heif import register_heif_opener
register_heif_opener()
def safe_open_image(image_bytes):
try:
image_pil = Image.open(BytesIO(image_bytes))
except PIL.UnidentifiedImageError as e:
print(e)
# Convert response content (bytes) to a NumPy array
image_array = np.frombuffer(image_bytes, np.uint8)
# Decode the image from the NumPy array (OpenCV format: BGR)
image_cv = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
if image_cv is not None:
# Convert the BGR image to RGB
image_rgb = cv2.cvtColor(image_cv, cv2.COLOR_BGR2RGB)
# Convert the RGB NumPy array to a PIL Image
image_pil = Image.fromarray(image_rgb)
else:
raise ValueError("The image cannot be identified by neither PIL nor OpenCV")
return image_pil
class ShellAgentPluginInputImage:
@classmethod
@@ -19,10 +47,12 @@ class ShellAgentPluginInputImage:
"STRING",
{"multiline": False, "default": "input_image", "forceInput": False},
),
"default_value": (
# "STRING", {"image_upload": True, "default": files[0] if len(files) else ""},
"image": (
sorted(files), {"image_upload": True, "forceInput": False}
),
"default_value": (
"STRING", {"forceInput": False}
),
},
"optional": {
"description": (
@@ -32,8 +62,8 @@ class ShellAgentPluginInputImage:
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
RETURN_TYPES = ("IMAGE", "MASK")
# RETURN_NAMES = ("image",)
FUNCTION = "run"
@@ -45,32 +75,82 @@ class ShellAgentPluginInputImage:
"title": kwargs["input_name"],
"type": "string",
"default": kwargs["default_value"],
"description": kwargs["description"],
"description": kwargs.get("description", ""),
"url_type": "image"
}
return schema
@classmethod
def VALIDATE_INPUTS(s, input_name, default_value, description=""):
image = default_value
if image.startswith("http"):
def VALIDATE_INPUTS(s, input_name, default_value, image=None, description=""):
# check default_value first
image_to_check = default_value if default_value else image
if image_to_check.startswith("http"):
return True
if not folder_paths.exists_annotated_filepath(image):
return "Invalid image file: {}".format(image)
if image_to_check == "":
return "Invalid image file: please check if the image is empty or invalid"
if os.path.isfile(image_to_check):
return True
if not folder_paths.exists_annotated_filepath(image_to_check):
return "Invalid image file: {}".format(image_to_check)
return True
def convert_image_mask(self, img):
output_images = []
output_masks = []
w, h = None, None
def run(self, input_name, default_value=None, display_name=None, description=None):
excluded_formats = ['MPO']
for i in ImageSequence.Iterator(img):
i = node_helpers.pillow(ImageOps.exif_transpose, i)
if i.mode == 'I':
i = i.point(lambda i: i * (1 / 255))
image = i.convert("RGB")
if len(output_images) == 0:
w = image.size[0]
h = image.size[1]
if image.size[0] != w or image.size[1] != h:
continue
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
if 'A' in i.getbands():
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
mask = 1. - torch.from_numpy(mask)
else:
mask = torch.zeros((64,64), dtype=torch.float32, device="cpu")
output_images.append(image)
output_masks.append(mask.unsqueeze(0))
if len(output_images) > 1 and img.format not in excluded_formats:
output_image = torch.cat(output_images, dim=0)
output_mask = torch.cat(output_masks, dim=0)
else:
output_image = output_images[0]
output_mask = output_masks[0]
return (output_image, output_mask)
def run(self, input_name, default_value=None, image=None, display_name=None, description=None):
# use default_value if it exists, otherwise use image
image_path = default_value if default_value else image
input_dir = folder_paths.get_input_directory()
image_path = default_value
try:
if image_path.startswith('http'):
import requests
from io import BytesIO
print("Fetching image from url: ", image_path)
response = requests.get(image_path)
image = Image.open(BytesIO(response.content))
image = safe_open_image(response.content)
elif image_path.startswith('data:image/png;base64,') or image_path.startswith('data:image/jpeg;base64,') or image_path.startswith('data:image/jpg;base64,'):
import base64
from io import BytesIO
@@ -82,13 +162,14 @@ class ShellAgentPluginInputImage:
if not os.path.isfile(image_path): # abs path
# local path
image_path = os.path.join(input_dir, image_path)
image = Image.open(image_path).convert("RGB")
image = node_helpers.pillow(Image.open, image_path)
image = ImageOps.exif_transpose(image)
image = image.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
return [image]
return self.convert_image_mask(image)
# image = ImageOps.exif_transpose(image)
# image = image.convert("RGB")
# image = np.array(image).astype(np.float32) / 255.0
# image = torch.from_numpy(image)[None,]
# return [image]
except Exception as e:
raise e
+47 -3
View File
@@ -42,7 +42,7 @@ class ShellAgentPluginInputText:
"title": kwargs["input_name"],
"type": "string",
"default": kwargs["default_value"],
"description": kwargs["description"],
"description": kwargs.get("description", ""),
}
if kwargs.get("choices", "") != "":
schema["enums"] = eval(kwargs["choices"])
@@ -101,7 +101,7 @@ class ShellAgentPluginInputFloat:
"title": kwargs["input_name"],
"type": "number",
"default": kwargs["default_value"],
"description": kwargs["description"],
"description": kwargs.get("description", ""),
}
if kwargs.get("choices", "") != "":
schema["enums"] = eval(kwargs["choices"])
@@ -184,14 +184,58 @@ class ShellAgentPluginInputInteger:
def run(self, input_name, default_value=None, display_name=None, description=None, **kwargs):
return [default_value]
class ShellAgentPluginInputBoolean:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input_name": (
"STRING",
{"multiline": False, "default": "input_bool"},
),
},
"optional": {
"default_value": (
"BOOLEAN",
{"default": False},
),
"description": (
"STRING",
{"multiline": True, "default": ""},
),
}
}
RETURN_TYPES = ("BOOLEAN",)
RETURN_NAMES = ("boolean",)
FUNCTION = "run"
CATEGORY = "shellagent"
@classmethod
def validate(cls, **kwargs):
schema = {
"title": kwargs["input_name"],
"type": "boolean",
"default": kwargs["default_value"],
"description": kwargs.get("description", ""),
}
return schema
def run(self, input_name, default_value=None, display_name=None, description=None, **kwargs):
return [default_value]
NODE_CLASS_MAPPINGS = {
"ShellAgentPluginInputText": ShellAgentPluginInputText,
"ShellAgentPluginInputFloat": ShellAgentPluginInputFloat,
"ShellAgentPluginInputInteger": ShellAgentPluginInputInteger
"ShellAgentPluginInputInteger": ShellAgentPluginInputInteger,
"ShellAgentPluginInputBoolean": ShellAgentPluginInputBoolean,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"ShellAgentPluginInputText": "Input Text (ShellAgent Plugin)",
"ShellAgentPluginInputFloat": "Input Float (ShellAgent Plugin)",
"ShellAgentPluginInputInteger": "Input Integer (ShellAgent Plugin)",
"ShellAgentPluginInputBoolean": "Input Boolean (ShellAgent Plugin)",
}
+11 -2
View File
@@ -4,7 +4,7 @@ import numpy as np
import torch
import os
import uuid
import tqdm
from tqdm import tqdm
# class ShellAgentPluginInputImage:
@@ -120,6 +120,15 @@ class ShellAgentPluginInputVideo:
"url_type": "video"
}
return schema
@classmethod
def VALIDATE_INPUTS(s, input_name, default_value, description=""):
video = default_value
if video.startswith("http"):
return True
if not folder_paths.exists_annotated_filepath(video):
return "Invalid video file: {}".format(video)
return True
def run(self, input_name, default_value=None, description=None):
input_dir = folder_paths.get_input_directory()
@@ -166,4 +175,4 @@ NODE_CLASS_MAPPINGS = {
NODE_DISPLAY_NAME_MAPPINGS = {
# "ShellAgentPluginInputImage": "Input Image (ShellAgent Plugin)",
"ShellAgentPluginInputVideo": "Input Video (ShellAgent Plugin)"
}
}
+8 -5
View File
@@ -75,12 +75,15 @@ class ShellAgentSaveVideoVHS:
return schema
def save_video(self, filenames, **kwargs):
status, (preview_image, video_path) = filenames
status, output_files = filenames
if len(output_files) == 0:
raise ValueError("the filenames are empty")
print("output_files", output_files)
video_path = output_files[-1]
cwd = os.getcwd()
preview_image = os.path.relpath(preview_image)
video_path = os.path.relpath(video_path)
results = {"ui": {"image": [preview_image], "video": [video_path]}}
print(results)
# preview_image = os.path.relpath(preview_image)
video_path = os.path.relpath(video_path, folder_paths.base_path)
results = {"ui": {"video": [video_path]}}
return results
+88
View File
@@ -0,0 +1,88 @@
json_type_mapipng = {
"text": "string",
"float": "number",
"integer": "integer",
"boolean": "boolean",
}
class ShellAgentOutputText:
TYPE_STR = "text"
@classmethod
def INPUT_TYPES(s):
return {
"required": {
s.TYPE_STR: ("STRING", {"tooltip": f"The {s.TYPE_STR} to output."}),
"output_name": ("STRING", {"multiline": False, "default": f"output_{s.TYPE_STR}"},),
},
}
RETURN_TYPES = ()
FUNCTION = "output_var"
OUTPUT_NODE = True
CATEGORY = "shellagent"
DESCRIPTION = "output the text"
@classmethod
def validate(cls, **kwargs):
schema = {
"title": kwargs["output_name"],
"type": json_type_mapipng[cls.TYPE_STR]
}
return schema
def output_var(self, **kwargs):
results = {"ui": {"output": [kwargs[self.TYPE_STR]]}}
return results
class ShellAgentOutputFloat(ShellAgentOutputText):
TYPE_STR = "float"
DESCRIPTION = "output the float"
@classmethod
def INPUT_TYPES(s):
return {
"required": {
s.TYPE_STR: ("FLOAT", {"tooltip": f"The {s.TYPE_STR} to output."}),
"output_name": ("STRING", {"multiline": False, "default": f"output_{s.TYPE_STR}"},),
},
}
class ShellAgentOutputInteger(ShellAgentOutputText):
TYPE_STR = "integer"
DESCRIPTION = "output the integer"
@classmethod
def INPUT_TYPES(s):
return {
"required": {
s.TYPE_STR: ("INT", {"tooltip": f"The {s.TYPE_STR} to output."}),
"output_name": ("STRING", {"multiline": False, "default": f"output_{s.TYPE_STR}"},),
},
}
class ShellAgentOutputBoolean(ShellAgentOutputText):
TYPE_STR = "boolean"
DESCRIPTION = "output the integer"
@classmethod
def INPUT_TYPES(s):
return {
"required": {
s.TYPE_STR: ("BOOLEAN", {"tooltip": f"The {s.TYPE_STR} to output."}),
"output_name": ("STRING", {"multiline": False, "default": f"output_{s.TYPE_STR}"},),
},
}
NODE_CLASS_MAPPINGS = {
"ShellAgentPluginOutputText": ShellAgentOutputText,
"ShellAgentPluginOutputFloat": ShellAgentOutputFloat,
"ShellAgentPluginOutputInteger": ShellAgentOutputInteger,
"ShellAgentPluginOutputBoolean": ShellAgentOutputBoolean,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"ShellAgentPluginOutputText": "Output Text (ShellAgent Plugin)",
"ShellAgentPluginOutputFloat": "Output Float (ShellAgent Plugin)",
"ShellAgentPluginOutputInteger": "Output Integer (ShellAgent Plugin)",
}
+59 -5
View File
@@ -29,9 +29,12 @@ import atexit
from datetime import datetime
import nodes
import traceback
import re
import keyword
import uuid
from .dependency_checker import resolve_dependencies
from .dependency_checker import resolve_dependencies, inspect_repo_version
from folder_paths import base_path as BASE_PATH
WORKFLOW_ROOT = "shellagent/comfy_workflow"
@@ -45,6 +48,14 @@ CustomNodeTypeMap = {
"ShellAgentPluginSaveVideoVHS": "video",
}
# Regular expression for a valid Python variable name
variable_name_pattern = r'^[a-zA-Z_][a-zA-Z0-9_]*$'
def is_valid_variable_name(name):
# Check if it matches the pattern and is not a keyword
if re.match(variable_name_pattern, name) and not keyword.iskeyword(name):
return True
return False
def schema_validator(prompt):
from nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
@@ -84,6 +95,9 @@ def schema_validator(prompt):
continue
if hasattr(node_cls, "validate"):
schema = node_cls.validate(**node_info["inputs"])
# validate schema
if not is_valid_variable_name(schema["title"]):
raise ValueError(f'`{schema["title"]}` is not a valid variable name!')
else:
raise NotImplementedError("the validate is not implemented")
schemas[mode][node_id] = schema
@@ -158,16 +172,56 @@ async def shellagent_export(request):
# for fname, dict_to_save in fname_mapping.items():
# with open(os.path.join(save_root, fname), "w") as f:
# json.dump(dict_to_save, f, indent=2)
warning_message = ""
if dependency_results.get("black_list_nodes", []):
warning_message = "The following nodes cannot be deployed to myshell:\n"
for item in dependency_results["black_list_nodes"]:
warning_message += f" {item['name']}: {item['reason']}\n"
if len(schemas["inputs"]) + len(schemas["outputs"]) == 0:
warning_message += f"The workflow contains neither inputs nor outputs!\n"
return_dict = {
"success": True,
"dependencies": dependency_results,
"dependencies": dependency_results["dependencies"],
"warning_message": warning_message,
"schemas": schemas
}
except Exception as e:
status = 400
return_dict = {
"success": False,
"message": str(traceback.format_exc()),
"message_detail": str(traceback.format_exc()),
"message": str(e),
}
return web.json_response(return_dict, status=status)
return web.json_response(return_dict, status=status)
@server.PromptServer.instance.routes.post("/shellagent/inspect_version") # data same as queue prompt, plus workflow_name
async def shellagent_inspect_version(request):
data = await request.json()
comfyui_version = inspect_repo_version(BASE_PATH)
comfyui_shellagent_plugin_version = inspect_repo_version(os.path.dirname(__file__))
return_dict = {
"comfyui_version": comfyui_version,
"comfyui_shellagent_plugin_version": comfyui_shellagent_plugin_version,
}
return web.json_response(return_dict, status=200)
@server.PromptServer.instance.routes.post("/shellagent/get_mac_addr") # data same as queue prompt, plus workflow_name
async def shellagent_get_mac_addr(request):
data = await request.json()
return_dict = {
"mac_addr": uuid.getnode()
}
return web.json_response(return_dict, status=200)
@server.PromptServer.instance.routes.post("/shellagent/check_exist") # check if the file or folder exist
async def shellagent_check_exist(request):
data = await request.json()
return_dict = {
"exist": uuid.getnode() == data["mac_addr"] and os.path.exists(data["path"]) # really exist, instead of same name
}
return web.json_response(return_dict, status=200)
+198 -49
View File
@@ -5,25 +5,36 @@ import logging
from functools import partial
import re
import glob
import sys
from folder_paths import models_dir as MODELS_DIR
from folder_paths import base_path as BASE_PATH
from folder_paths import get_full_path
from .utils import compute_sha256, windows_to_linux_path
from .utils.utils import compute_sha256, windows_to_linux_path
from .utils.pytree import tree_map
from .file_upload import collect_local_file, process_local_file_path_async
model_list_json = json.load(open(os.path.join(os.path.dirname(__file__), "model_info.json")))
model_loaders_info = json.load(open(os.path.join(os.path.dirname(__file__), "model_loader_info.json")))
node_deps_info = json.load(open(os.path.join(os.path.dirname(__file__), "node_deps_info.json")))
node_blacklist = json.load(open(os.path.join(os.path.dirname(__file__), "node_blacklist.json")))
node_remote_skip_models = json.load(open(os.path.join(os.path.dirname(__file__), "node_remote.json")))
model_suffix = [".ckpt", ".safetensors", ".bin", ".pth", ".pt", ".onnx", ".gguf", ".sft", ".ttf"]
extra_packages = ["transformers", "timm", "diffusers", "accelerate"]
model_suffix = [".ckpt", ".safetensors", ".bin", ".pth", ".pt", ".onnx"]
def get_full_path_or_raise(folder_name: str, filename: str) -> str:
full_path = get_full_path(folder_name, filename)
if full_path is None:
raise FileNotFoundError(f"Model in folder '{folder_name}' with filename '{filename}' not found.")
return full_path
def handle_model_info(ckpt_path):
def handle_model_info(ckpt_path, filename, rel_save_path):
ckpt_path = windows_to_linux_path(ckpt_path)
filename = os.path.basename(ckpt_path)
dirname = os.path.dirname(ckpt_path)
save_path = os.path.dirname(os.path.relpath(ckpt_path, MODELS_DIR))
metadata_path = ckpt_path + ".json"
if os.path.isfile(metadata_path):
metadata = json.load(open(metadata_path))
@@ -35,7 +46,7 @@ def handle_model_info(ckpt_path):
model_id = compute_sha256(ckpt_path)
data = {
"id": model_id,
"save_path": save_path,
"save_path": rel_save_path,
"filename": filename,
}
json.dump(data, open(metadata_path, "w"))
@@ -45,8 +56,8 @@ def handle_model_info(ckpt_path):
urls = []
item = {
"filename": filename,
"save_path": windows_to_linux_path(save_path),
"filename": windows_to_linux_path(filename),
"save_path": windows_to_linux_path(rel_save_path),
"urls": urls,
}
return model_id, item
@@ -59,6 +70,10 @@ def inspect_repo_version(module_path):
"repo": "",
"commit": ""
}
if not os.path.isdir(os.path.join(module_path, ".git")):
return result
# Get the remote repository URL
try:
remote_url = subprocess.check_output(
@@ -87,7 +102,7 @@ def inspect_repo_version(module_path):
def fetch_model_searcher_results(model_ids):
import requests
url = "https://shellagent.myshell.ai/models_searcher/search_urls"
url = "https://models-searcher.myshell.life/search_urls"
headers = {
"Content-Type": "application/json"
}
@@ -96,59 +111,164 @@ def fetch_model_searcher_results(model_ids):
}
response = requests.post(url, headers=headers, json=data)
results = [item[:10] for item in response.json()]
if response.status_code == 200:
results = [item[:10] for item in response.json()]
else:
results = None
return results
def split_package_version(require_line):
require_line = require_line.strip()
pattern = r"^([a-zA-Z0-9_\-\[\]]+)(.*)$"
match = re.match(pattern, require_line.strip())
if match:
package_name = match.group(1) # First capturing group is the package name
version_specifier = match.group(2) if match.group(2) else "" # Second group is the version, if present
return package_name, version_specifier
else:
assert len(require_line) == 0 or require_line.strip()[0] == "#", require_line
return None, None
def get_package_version(package_name):
try:
if sys.version_info >= (3, 8):
from importlib.metadata import version, PackageNotFoundError
return version(package_name)
else:
from pkg_resources import get_distribution, DistributionNotFound
return get_distribution(package_name).version
except Exception:
return None
def resolve_dependencies(prompt, custom_dependencies): # resolve custom nodes and models at the same time
from nodes import NODE_CLASS_MAPPINGS
import folder_paths
custom_nodes = []
ckpt_paths = []
ckpt_paths = {}
file_mapping_dict = {}
SKIP_FOLDER_NAMES = ["configs", "custom_nodes"]
def collect_unknown_models(filename, node_id, node_info, custom_node_path):
if type(filename) != str:
return
is_model = False
for possible_suffix in model_suffix:
if filename.endswith(possible_suffix):
is_model = True
if is_model:
print(f"find {filename}, is_model=True")
# find possible paths
matching_files = {}
# Walk through all subdirectories and files in the directory
rel_save_path = None
for possible_folder_name in folder_paths.folder_names_and_paths:
if possible_folder_name in SKIP_FOLDER_NAMES:
print(f"skip {possible_folder_name}")
continue
full_path = folder_paths.get_full_path(possible_folder_name, filename)
if full_path is None:
continue
rel_save_path = os.path.relpath(folder_paths.folder_names_and_paths[possible_folder_name][0][0], folder_paths.models_dir)
matching_files[full_path] = {
"rel_save_path": rel_save_path
}
print(f"matched files: {matching_files}")
# step 2: search for all the files under "models"
for full_path in glob.glob(f"{folder_paths.models_dir}/**/*", recursive=True):
if os.path.isfile(full_path) and full_path.endswith(filename) and full_path not in matching_files:
folder_path = full_path[:-len(filename)]
rel_save_path = os.path.relpath(folder_path, folder_paths.models_dir)
matching_files[full_path] = {
"rel_save_path": rel_save_path
}
print(f"matched files: {matching_files}")
# step 3: search inside the custom nodes
if custom_node_path is not None:
for full_path in glob.glob(f"{custom_node_path}/**/*", recursive=True):
if os.path.isfile(full_path) and full_path.endswith(filename) and full_path not in matching_files:
folder_path = full_path[:-len(filename)]
rel_save_path = os.path.relpath(folder_path, folder_paths.models_dir)
matching_files[full_path] = {
"rel_save_path": rel_save_path
}
if len(matching_files) == 0:
raise ValueError(f"Cannot find model: `{filename}`, Node ID: `{node_id}`, Node Info: `{node_info}`")
elif len(matching_files) <= 3:
for full_path, info in matching_files.items():
ckpt_paths[full_path] = {
"filename": filename,
"rel_save_path": info["rel_save_path"]
}
return
else:
raise ValueError(f"Multiple models of `{filename}` founded, Node ID: `{node_id}`, Node Info: `{node_info}`, Possible paths: `{list(matching_files.keys())}`")
for node_id, node_info in prompt.items():
node_class_type = node_info.get("class_type")
if node_class_type is None:
raise NotImplementedError(f"Missing nodes founded, please first install the missing nodes using ComfyUI Manager")
node_cls = NODE_CLASS_MAPPINGS[node_class_type]
if hasattr(node_cls, "RELATIVE_PYTHON_MODULE"):
skip_model_check = False
custom_node_path = None
if hasattr(node_cls, "RELATIVE_PYTHON_MODULE") and node_cls.RELATIVE_PYTHON_MODULE.startswith("custom_nodes."):
print(node_cls.RELATIVE_PYTHON_MODULE)
custom_nodes.append(node_cls.RELATIVE_PYTHON_MODULE)
custom_node_path = os.path.join(BASE_PATH, node_cls.RELATIVE_PYTHON_MODULE.replace(".", "/"))
if node_cls.RELATIVE_PYTHON_MODULE[len("custom_nodes."):] in node_remote_skip_models:
skip_model_check = True
print(f"skip model check for {node_class_type}")
if node_class_type in model_loaders_info:
for field_name, filename in node_info["inputs"].items():
for item in model_loaders_info[node_class_type]:
pattern = item["field_name"]
if re.match(f"^{pattern}$", field_name):
ckpt_path = os.path.join(MODELS_DIR, item["save_path"], filename)
ckpt_paths.append(ckpt_path)
else:
for field_name, filename in node_info["inputs"].items():
if type(filename) != str:
continue
is_model = False
for possible_suffix in model_suffix:
if filename.endswith(possible_suffix):
is_model = True
if is_model:
print(f"find {filename}, is_model=True")
# find possible paths
matching_files = []
# Walk through all subdirectories and files in the directory
for possible_filename in glob.glob(os.path.join(MODELS_DIR, "**", "*"), recursive=True):
if os.path.isfile(possible_filename) and possible_filename.endswith(filename):
matching_files.append(possible_filename)
print(f"matched files: {matching_files}")
if len(matching_files) == 1:
ckpt_paths.append(matching_files[0])
for item in model_loaders_info[node_class_type]:
pattern = item["field_name"]
if re.match(f"^{pattern}$", field_name) and any([filename.endswith(possible_suffix) for possible_suffix in model_suffix]):
ckpt_path = get_full_path_or_raise(item["save_path"], filename)
if hasattr(folder_paths, "map_legacy"):
save_folder = folder_paths.map_legacy(item["save_path"])
else:
save_folder = item["save_path"]
rel_save_path = os.path.relpath(folder_paths.folder_names_and_paths[save_folder][0][0], folder_paths.models_dir)
ckpt_paths[ckpt_path] = {
"filename": filename,
"rel_save_path": rel_save_path
}
elif not skip_model_check:
tree_map(lambda x: collect_unknown_models(x, node_id, node_info, custom_node_path), node_info["inputs"])
list(map(partial(collect_local_file, mapping_dict=file_mapping_dict), node_info["inputs"].values()))
ckpt_paths = list(set(ckpt_paths))
print("ckpt_paths:", ckpt_paths)
custom_nodes = list(set(custom_nodes))
# step 0: comfyui version
comfyui_version = inspect_repo_version(BASE_PATH)
repo_info = inspect_repo_version(BASE_PATH)
if repo_info["repo"] == "":
repo_info["require_recheck"] = True
if repo_info["name"] in custom_dependencies["custom_nodes"]:
repo_info["repo"] = custom_dependencies["custom_nodes"][repo_info["name"]].get("repo", "")
repo_info["commit"] = custom_dependencies["custom_nodes"][repo_info["name"]].get("commit", "")
comfyui_version = repo_info
# step 1: custom nodes
custom_nodes_list = []
custom_nodes_names = []
requirements_lines = []
for custom_node in custom_nodes:
try:
repo_info = inspect_repo_version(os.path.join(BASE_PATH, custom_node.replace(".", "/")))
@@ -161,20 +281,39 @@ def resolve_dependencies(prompt, custom_dependencies): # resolve custom nodes an
custom_nodes_names.append(repo_info["name"])
except:
print(f"failed to resolve repo info of {custom_node}")
requirement_file = os.path.join(BASE_PATH, custom_node.replace(".", "/"), "requirements.txt")
if os.path.isfile(requirement_file):
try:
requirements_lines += open(requirement_file).readlines()
except:
pass
requirements_lines = list(set(requirements_lines))
requirements_packages = [package_name for package_name, version_specifier in map(split_package_version, requirements_lines) if package_name is not None]
package_names = set(requirements_packages + extra_packages)
pypi_deps = {
package_name: get_package_version(package_name)
for package_name in package_names
}
for repo_name in custom_nodes_names:
if repo_name in node_deps_info:
for deps_node in node_deps_info[repo_name]:
if deps_node["name"] not in custom_nodes_names:
repo_info = inspect_repo_version(os.path.join("custom_nodes", deps_node["name"]))
repo_info = inspect_repo_version(os.path.join(BASE_PATH, "custom_nodes", deps_node["name"]))
deps_node["commit"] = repo_info["commit"]
custom_nodes_list.append(deps_node)
custom_nodes_names.append(deps_node["name"])
black_list_nodes = []
for repo_name in custom_nodes_names:
if repo_name in node_blacklist:
black_list_nodes.append({"name": repo_name, "reason": node_blacklist[repo_name]["reason"]})
# step 2: models
models_dict = {}
missing_model_ids = []
for ckpt_path in ckpt_paths:
model_id, item = handle_model_info(ckpt_path)
for ckpt_path, ckpt_info in ckpt_paths.items():
model_id, item = handle_model_info(ckpt_path, ckpt_info["filename"], ckpt_info["rel_save_path"])
models_dict[model_id] = item
if len(item["urls"]) == 0:
item["require_recheck"] = True
@@ -184,20 +323,30 @@ def resolve_dependencies(prompt, custom_dependencies): # resolve custom nodes an
# try to fetch from myshell model searcher
missing_model_results_myshell = fetch_model_searcher_results(missing_model_ids)
for missing_model_id, missing_model_urls in zip(missing_model_ids, missing_model_results_myshell):
if len(missing_model_urls) > 0:
models_dict[missing_model_id]["require_recheck"] = False
models_dict[missing_model_id]["urls"] = missing_model_urls
print("successfully fetch results from myshell", models_dict[missing_model_id])
if missing_model_results_myshell is not None:
for missing_model_id, missing_model_urls in zip(missing_model_ids, missing_model_results_myshell):
if len(missing_model_urls) > 0:
models_dict[missing_model_id]["require_recheck"] = False
models_dict[missing_model_id]["urls"] = missing_model_urls
print("successfully fetch results from myshell", models_dict[missing_model_id])
# step 3: handle local files
process_local_file_path_async(file_mapping_dict, max_workers=20)
files_dict = {v[0]: {"filename": windows_to_linux_path(os.path.relpath(v[2], BASE_PATH)), "urls": [v[1]]} for v in file_mapping_dict.values()}
files_dict = {
v[0]: {
"filename": windows_to_linux_path(os.path.relpath(v[2], BASE_PATH)) if not v[3] else v[2],
"urls": [v[1]]} for v in file_mapping_dict.values()}
results = {
depencencies = {
"comfyui_version": comfyui_version,
"custom_nodes": custom_nodes_list,
"models": models_dict,
"files": files_dict,
"pypi": pypi_deps
}
return results
return_dict = {
"dependencies": depencencies,
"black_list_nodes": black_list_nodes,
}
return return_dict
+17 -7
View File
@@ -5,7 +5,7 @@ import time
from concurrent.futures import ThreadPoolExecutor, as_completed
import folder_paths
from .utils import compute_sha256
from .utils.utils import compute_sha256, get_alphanumeric_hash
ext_to_type = {
# image
@@ -27,7 +27,7 @@ ext_to_type = {
'.m4a': 'audio/mp4',
}
def upload_file_to_myshell(local_file: str) -> str:
def upload_file_to_myshell(local_file: str, target_path: str, is_abs) -> str:
''' Now we only support upload file one-by-one
'''
MYSHELL_KEY = os.environ.get('MYSHELL_KEY', "OPENSOURCE_FIXED")
@@ -51,8 +51,8 @@ def upload_file_to_myshell(local_file: str) -> str:
response = requests.request("POST", server_url, headers=headers, files=files)
if response.status_code == 200:
end_time = time.time()
logging.info(f"{local_file} uploaded, time elapsed: {end_time - start_time}")
return [sha256sum, response.json()['url'], local_file]
logging.info(f"{local_file} uploaded, time elapsed: {end_time - start_time}, will be saved to {target_path}")
return [sha256sum, response.json()['url'], target_path, is_abs]
else:
raise Exception(
f"[HTTP ERROR] {response.status_code} - {response.text} \n"
@@ -66,8 +66,11 @@ def collect_local_file(item, mapping_dict={}):
abspath = os.path.abspath(item)
input_abspath = os.path.join(input_dir, item)
# required file type
is_abs = False
if os.path.isfile(abspath):
fpath = abspath
is_abs = True
elif os.path.isfile(input_abspath):
fpath = input_abspath
else:
@@ -75,7 +78,13 @@ def collect_local_file(item, mapping_dict={}):
if fpath is not None:
ext = os.path.splitext(fpath)[1]
if ext.lower() in ext_to_type.keys():
mapping_dict[item] = fpath
if is_abs: # if use abs path, replace it
filename_hash = get_alphanumeric_hash(abspath)[:16]
count = len(mapping_dict)
target_path = f"/ShellAgentDeploy/ComfyUI/input/{filename_hash}_{count:06d}{ext}"
mapping_dict[item] = (fpath, target_path, is_abs)
else:
mapping_dict[item] = (fpath, fpath, is_abs)
return
else:
return
@@ -86,7 +95,7 @@ def process_local_file_path_async(mapping_dict, max_workers=10):
start_time = time.time()
with ThreadPoolExecutor(max_workers=max_workers) as executor:
# Submit tasks to the executor
futures = {executor.submit(upload_file_to_myshell, full_path): filename for filename, full_path in mapping_dict.items()}
futures = {executor.submit(upload_file_to_myshell, source_path, target_path, is_abs): filename for filename, (source_path, target_path, is_abs) in mapping_dict.items()}
logging.info("submit done")
# Collect the results as they complete
for future in as_completed(futures):
@@ -95,7 +104,8 @@ def process_local_file_path_async(mapping_dict, max_workers=10):
result = future.result()
mapping_dict[filename] = result
except Exception as e:
print(f"Error processing {filename}: {e}")
del mapping_dict[filename]
raise NotImplementedError(f"Error processing {filename}: {e}")
end_time = time.time()
logging.info(f"upload end, elapsed time: {end_time - start_time}")
return
+5
View File
@@ -0,0 +1,5 @@
{
"comfyui-ollama": {
"reason": "this node requires installing an extra software on linux, which is currently unsupported"
}
}
+44 -18
View File
@@ -1,19 +1,45 @@
{
"ComfyUI-Easy-Use": [
{
"name": "ComfyUI-Inspire-Pack",
"repo": "https://github.com/ltdrdata/ComfyUI-Inspire-Pack.git",
"commit": ""
},
{
"name": "ComfyUI-Advanced-ControlNet",
"repo": "https://github.com/Kosinkadink/ComfyUI-Advanced-ControlNet.git",
"commit": ""
},
{
"name": "ComfyUI_smZNodes",
"repo": "https://github.com/shiimizu/ComfyUI_smZNodes.git",
"commit": ""
}
]
}
"ComfyUI-Easy-Use": [
{
"name": "ComfyUI-Inspire-Pack",
"repo": "https://github.com/ltdrdata/ComfyUI-Inspire-Pack.git",
"commit": ""
},
{
"name": "ComfyUI-Advanced-ControlNet",
"repo": "https://github.com/Kosinkadink/ComfyUI-Advanced-ControlNet.git",
"commit": ""
},
{
"name": "ComfyUI_smZNodes",
"repo": "https://github.com/shiimizu/ComfyUI_smZNodes.git",
"commit": ""
},
{
"name": "ComfyUI_IPAdapter_plus",
"repo": "https://github.com/cubiq/ComfyUI_IPAdapter_plus.git",
"commit": ""
}
],
"efficiency-nodes-comfyui": [
{
"name": "comfyui_controlnet_aux",
"repo": "https://github.com/Fannovel16/comfyui_controlnet_aux.git",
"commit": ""
}
],
"ComfyUI-Anyline": [
{
"name": "comfyui_controlnet_aux",
"repo": "https://github.com/Fannovel16/comfyui_controlnet_aux.git",
"commit": ""
}
],
"ComfyUI-Impact-Pack": [
{
"name": "ComfyUI-Impact-Subpack",
"repo": "https://github.com/ltdrdata/ComfyUI-Impact-Subpack.git",
"commit": ""
}
]
}
+3
View File
@@ -0,0 +1,3 @@
[
"BizyAir"
]
+3 -1
View File
@@ -3,4 +3,6 @@ pydantic
opencv-python
imageio-ffmpeg
brotli
# logfire
pillow_heif
easydict
# logfire
+1197
View File
File diff suppressed because it is too large Load Diff
+16 -1
View File
@@ -1,6 +1,8 @@
import hashlib
import time
from pathlib import PurePosixPath, Path, PureWindowsPath
import base64
import re
def windows_to_linux_path(windows_path):
return PureWindowsPath(windows_path).as_posix()
@@ -17,4 +19,17 @@ def compute_sha256(file_path, chunk_size=1024 ** 2):
sha256.update(chunk)
print("finish compute sha256 for", file_path, f"time: {time.time() - start}")
# Return the hexadecimal digest of the hash
return sha256.hexdigest()
return sha256.hexdigest()
def get_alphanumeric_hash(input_string: str) -> str:
# Generate a SHA-256 hash of the input string
sha256_hash = hashlib.sha256(input_string.encode()).digest()
# Encode the hash in base64 to get a string with [A-Za-z0-9+/=]
base64_hash = base64.b64encode(sha256_hash).decode('ascii')
# Remove any non-alphanumeric characters (+, /, =)
alphanumeric_hash = re.sub(r'[^a-zA-Z0-9]', '', base64_hash)
return alphanumeric_hash
+301 -32
View File
@@ -1,6 +1,9 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
app.registerExtension({
name: "Shellagent.extension",
async setup() {
@@ -37,11 +40,15 @@ app.registerExtension({
});
},
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (["ShellAgentPluginOutputText", "ShellAgentPluginOutputFloat", "ShellAgentPluginOutputInteger"].indexOf(nodeData.name) > -1) {
chainCallback(nodeType.prototype, "onNodeCreated", function () {
this.convertWidgetToInput(this.widgets[0])
})
}
if (["ShellAgentPluginInputText", "ShellAgentPluginInputFloat", "ShellAgentPluginInputInteger"].indexOf(nodeData.name) > -1) {
chainCallback(nodeType.prototype, "onNodeCreated", function () {
const widget = this.widgets.find(w => w.name === 'choices')
this.addWidget('button', 'manage choices', null, () => {
const container = document.createElement("div");
Object.assign(container.style, {
@@ -93,7 +100,7 @@ app.registerExtension({
try {
arr = JSON.parse(widget.value)
} catch { }
} else if(Array.isArray(widget.value)) {
} else if (Array.isArray(widget.value)) {
arr = widget.value
}
@@ -137,6 +144,27 @@ app.registerExtension({
})
}
if (['LoadImage', 'LoadImageMask'].indexOf(nodeData.name) > -1) {
addMenuHandler(nodeType, function (_, options) {
options.unshift({
content: "Replace with ShellAgent Input Image",
callback: () => {
const node = addNode("ShellAgentPluginInputImage", this, { before: true });
const dvn = node.widgets.find(w => w.name === 'default_value')
dvn.value = this.widgets.find(w => w.name === 'image')?.value
app.graph.links.filter(l => l != null)
.forEach(l => {
const tn = app.graph._nodes_by_id[l.target_id]
node.connect(0, tn, 0)
})
app.graph.remove(this);
}
})
})
}
if (nodeData.name === "ShellAgentPluginInputImage") {
if (
nodeData?.input?.required?.default_value?.[1]?.image_upload === true
@@ -148,10 +176,21 @@ app.registerExtension({
}
}
if (nodeData.name === "ShellAgentPluginInputAudio") {
if (
nodeData?.input?.required?.default_value?.[1]?.audio_upload === true
) {
nodeData.input.required.audioUI = ["AUDIO_UI"];
nodeData.input.required.upload = [
"SHELLAGENT_AUDIOUPLOAD",
{ widget: "default_value" },
];
}
}
if (nodeData.name === "ShellAgentPluginInputVideo") {
addUploadWidget(nodeType, nodeData, "default_value");
chainCallback(nodeType.prototype, "onNodeCreated", function () {
// const pathWidget = this.widgets.find((w) => w.name === "video");
const pathWidget = this.widgets.find((w) => w.name === "default_value");
chainCallback(pathWidget, "callback", (value) => {
if (!value) {
@@ -174,59 +213,238 @@ app.registerExtension({
if (nodeData.name.indexOf('ShellAgentPlugin') === -1) {
addMenuHandler(nodeType, function (_, options) {
if (this.widgets) {
let toInput = [];
for (const w of this.widgets) {
if (["customtext"].indexOf(w.type) > -1) {
toInput.push({
content: `${w.name} <- Input Text`,
callback: () => {
this.convertWidgetToInput(w);
const node = addNode("ShellAgentPluginInputText", this, { before: true });
const dvn = node.widgets.find(w => w.name === 'default_value')
dvn.value = w.value;
node.connect(0, this, this.inputs.length - 1);
}
content: w.name,
submenu: {
options: [
{
content: 'Input Text',
callback: () => {
this.convertWidgetToInput(w);
const node = addNode("ShellAgentPluginInputText", this, { before: true });
const dvn = node.widgets.find(w => w.name === 'default_value')
dvn.value = w.value;
node.connect(0, this, this.inputs.length - 1);
}
}
]
},
})
}
if (["number"].indexOf(w.type) > -1) {
toInput.push({
content: `${w.name} <- Input Interger`,
callback: () => {
this.convertWidgetToInput(w);
const node = addNode("ShellAgentPluginInputInteger", this, { before: true });
const dvn = node.widgets.find(w => w.name === 'default_value')
dvn.value = w.value;
node.connect(0, this, this.inputs.length - 1);
}
})
toInput.push({
content: `${w.name} <- Input Float`,
callback: () => {
this.convertWidgetToInput(w);
const node = addNode("ShellAgentPluginInputFloat", this, { before: true });
const dvn = node.widgets.find(w => w.name === 'default_value')
dvn.value = w.value;
node.connect(0, this, this.inputs.length - 1);
content: w.name,
submenu: {
options: [
{
content: 'Input Interger',
callback: () => {
this.convertWidgetToInput(w);
const node = addNode("ShellAgentPluginInputInteger", this, { before: true });
const dvn = node.widgets.find(w => w.name === 'default_value')
dvn.value = w.value;
node.connect(0, this, this.inputs.length - 1);
}
},
{
content: 'Input Float',
callback: () => {
this.convertWidgetToInput(w);
const node = addNode("ShellAgentPluginInputFloat", this, { before: true });
const dvn = node.widgets.find(w => w.name === 'default_value')
dvn.value = w.value;
node.connect(0, this, this.inputs.length - 1);
}
}
]
}
})
}
}
if (toInput.length) {
options.unshift({
content: "Convert to ShellAgent",
content: "Convert to ShellAgent (Input)",
submenu: {
options: toInput
}
})
}
}
if (this.outputs) {
let toOutput = [];
for (const o of this.outputs) {
if (o.type === 'IMAGE') {
toOutput.push({
content: o.name,
submenu: {
options: [
{
content: 'Save Image',
callback: () => {
const node = addNode("ShellAgentPluginSaveImage", this);
this.connect(0, node, 0);
}
},
{
content: 'Save Images',
callback: () => {
const node = addNode("ShellAgentPluginSaveImages", this);
this.connect(0, node, 0);
}
}
]
}
})
}
if (o.type === 'STRING') {
toOutput.push({
content: o.name,
submenu: {
options: [
{
content: `Output Text`,
callback: () => {
const node = addNode("ShellAgentPluginOutputText", this);
this.connect(0, node, 0);
}
},
{
content: `Output Float`,
callback: () => {
const node = addNode("ShellAgentPluginOutputFloat", this);
this.connect(0, node, 0);
}
},
{
content: `Output Integer`,
callback: () => {
const node = addNode("ShellAgentPluginOutputInteger", this);
this.connect(0, node, 0);
}
}
]
}
})
}
if (o.type === "VHS_FILENAMES") {
toOutput.push({
content: o.name,
submenu: {
options: [
{
content: `Save Video - VHS`,
callback: () => {
const node = addNode("ShellAgentPluginSaveVideoVHS", this);
this.connect(0, node, 0);
}
}
]
}
})
}
}
if (toOutput.length) {
options.unshift({
content: "Connect to ShellAgent (Output)",
submenu: {
options: toOutput
}
})
}
}
})
}
},
afterConfigureGraph(missingNodeTypes, app) {
function addIn(type, nodeId) {
if(LiteGraph.slot_types_default_in[type] == null) {
LiteGraph.slot_types_default_in[type] = []
}
if (LiteGraph.slot_types_default_in[type].indexOf(nodeId) === -1) {
LiteGraph.slot_types_default_in[type].unshift(nodeId)
}
}
function addOut(type, nodeId) {
if(LiteGraph.slot_types_default_out[type] == null) {
LiteGraph.slot_types_default_out[type] = []
}
if (LiteGraph.slot_types_default_out[type].indexOf(nodeId) === -1) {
LiteGraph.slot_types_default_out[type].unshift(nodeId)
}
}
addIn('IMAGE', 'ShellAgentPluginInputImage')
addIn('AUDIO', 'ShellAgentPluginInputAudio')
addOut('IMAGE', 'ShellAgentPluginSaveImage')
addOut('IMAGE', 'ShellAgentPluginSaveImages')
addOut('AUDIO', 'ShellAgentPluginSaveAudios')
addOut('AUDIO', 'ShellAgentPluginSaveAudio')
addOut('STRING', 'ShellAgentPluginOutputInteger')
addOut('STRING', 'ShellAgentPluginOutputFloat')
addOut('STRING', 'ShellAgentPluginOutputText')
},
getCustomWidgets() {
return {
SHELLAGENT_AUDIOUPLOAD(node, inputName) {
const audioWidget = node.widgets.find(
(w) => w.name === "default_value"
);
const audioUIWidget = node.widgets.find(
(w) => w.name === "audioUI"
);
const onAudioWidgetUpdate = /* @__PURE__ */ __name(() => {
audioUIWidget.element.src = api.apiURL(
getResourceURL(...splitFilePath(audioWidget.value))
);
}, "onAudioWidgetUpdate");
if (audioWidget.value) {
onAudioWidgetUpdate();
}
audioWidget.callback = onAudioWidgetUpdate;
const onGraphConfigured = node.onGraphConfigured;
node.onGraphConfigured = function() {
onGraphConfigured?.apply(this, arguments);
if (audioWidget.value) {
onAudioWidgetUpdate();
}
};
const fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.accept = "audio/*";
fileInput.style.display = "none";
fileInput.onchange = () => {
if (fileInput.files.length) {
uploadFileAudio(audioWidget, audioUIWidget, fileInput.files[0], true);
}
};
const uploadWidget = node.addWidget(
"button",
inputName,
/* value=*/
"",
() => {
fileInput.click();
},
{ serialize: false }
);
uploadWidget.label = "choose file to upload";
return { widget: uploadWidget };
}
};
}
});
function addMenuHandler(nodeType, cb) {
@@ -599,4 +817,55 @@ function addLoadVideoCommon(nodeType, nodeData) {
}
});
});
}
function getResourceURL(subfolder, filename, type = "input") {
const params = [
"filename=" + encodeURIComponent(filename),
"type=" + type,
"subfolder=" + subfolder,
app.getRandParam().substring(1)
].join("&");
return `/view?${params}`;
}
function splitFilePath(path) {
const folder_separator = path.lastIndexOf("/");
if (folder_separator === -1) {
return ["", path];
}
return [
path.substring(0, folder_separator),
path.substring(folder_separator + 1)
];
}
async function uploadFileAudio(audioWidget, audioUIWidget, file2, updateNode, pasted = false) {
try {
const body = new FormData();
body.append("image", file2);
if (pasted) body.append("subfolder", "pasted");
const resp = await api.fetchApi("/upload/image", {
method: "POST",
body
});
if (resp.status === 200) {
const data = await resp.json();
let path = data.name;
if (data.subfolder) path = data.subfolder + "/" + path;
if (!audioWidget.options.values.includes(path)) {
audioWidget.options.values.push(path);
}
if (updateNode) {
audioUIWidget.element.src = api.apiURL(
getResourceURL(...splitFilePath(path))
);
audioWidget.value = path;
}
} else {
window.alert(resp.status + " - " + resp.statusText);
}
} catch (error) {
window.alert(error);
}
}