不能加载
liujintiger opened this issue · 10 comments
Cannot import D:\ComfyUI\custom_nodes\ComfyUI-ArtGallery module for custom nodes: [Errno 2] No such file or directory: 'D:\ComfyUI\custom_nodes\ComfyUI-ArtGallery\../../web/extensions/core/uploadImage.js'
https://github.com/alanhzh/ComfyUI-ArtGallery-updates/tree/main
ONLY to make it still work, can not preview with old manager, you have to switch to new:
"[Beta] Use new menu and workflow management. Note: On small screens the menu will always be at the top."
ONCE you switch you can no longer switch back easily
我改了下,能跑,但要设置里切换到新的UI后才能完全恢复功能(preview):
"[Beta] Use new menu and workflow management. Note: On small screens the menu will always be at the top."
最后估计要重构,前端都改了,如果后面改ts,还得改!
same
same problem
https://github.com/alanhzh/ComfyUI-ArtGallery-updates/tree/main ONLY to make it still work, can not preview with old manager, you have to switch to new: "[Beta] Use new menu and workflow management. Note: On small screens the menu will always be at the top." ONCE you switch you can no longer switch back easily 我改了下,能跑,但要设置里切换到新的UI后才能完全恢复功能(preview): "[Beta] Use new menu and workflow management. Note: On small screens the menu will always be at the top." 最后估计要重构,前端都改了,如果后面改ts,还得改!
覆盖,安装新的更新,用了新的工作流,还是ZHO结尾的5个红色图片,跟原来一样......希望大佬早点更新,谢谢!
复制粘贴,替换custom_nodes\ComfyUI-ArtGallery_init_.py文件,就能解决报错问题;兼容新版comfyUI界面
import os
修改 JS 文件
def modify_js_file(file_path, new_content):
with open(file_path, 'r') as file:
content = file.read()
# 检查文件中是否已包含需要添加的内容
if "image_upload_artist" not in content:
# 找到原始代码的位置
insert_position = content.find('nodeData.input.required.upload = ["IMAGEUPLOAD"];')
if insert_position != -1:
# 在原始代码后插入新的代码
insert_position += len('nodeData.input.required.upload = ["IMAGEUPLOAD"];')
content = content[:insert_position] + new_content + content[insert_position:]
# 写回文件
with open(file_path, 'w') as file:
file.write(content)
print(f"File '{file_path}' updated successfully.✅")
else:
print("Original code block not found.❌")
else:
print("File already contains the necessary modifications.✅")
要插入的新内容
new_js_content = """
}
// ComfyUI-ArtGallery
if (((_d = (_c = (_b = (_a = nodeData == null ? void 0 : nodeData.input) == null ? void 0 : _a.required) == null ? void 0 : _b.image) == null ? void 0 : _c[1]) == null ? void 0 : _d.image_upload_artist) === true) {
nodeData.input.required.upload = ["ARTISTS_IMAGEUPLOAD"];
}
if (((_d = (_c = (_b = (_a = nodeData == null ? void 0 : nodeData.input) == null ? void 0 : _a.required) == null ? void 0 : _b.image) == null ? void 0 : _c[1]) == null ? void 0 : _d.image_upload_camera) === true) {
nodeData.input.required.upload = ["CAMERAS_IMAGEUPLOAD"];
}
if (((_d = (_c = (_b = (_a = nodeData == null ? void 0 : nodeData.input) == null ? void 0 : _a.required) == null ? void 0 : _b.image) == null ? void 0 : _c[1]) == null ? void 0 : _d.image_upload_film) === true) {
nodeData.input.required.upload = ["FILMS_IMAGEUPLOAD"];
}
if (((_d = (_c = (_b = (_a = nodeData == null ? void 0 : nodeData.input) == null ? void 0 : _a.required) == null ? void 0 : _b.image) == null ? void 0 : _c[1]) == null ? void 0 : _d.image_upload_movement) === true) {
nodeData.input.required.upload = ["MOVEMENTS_IMAGEUPLOAD"];
}
if (((_d = (_c = (_b = (_a = nodeData == null ? void 0 : nodeData.input) == null ? void 0 : _a.required) == null ? void 0 : _b.image) == null ? void 0 : _c[1]) == null ? void 0 : _d.image_upload_style) === true) {
nodeData.input.required.upload = ["STYLES_IMAGEUPLOAD"];
"""
文件路径
current_dir = os.path.dirname(os.path.abspath(file))
uploadimg_js_file_path = os.path.join(current_dir, '../../web/assets/index--0nRVkuV.js')
打印文件路径(可选)
print(uploadimg_js_file_path)
调用函数修改JS文件
modify_js_file(uploadimg_js_file_path, new_js_content)
################################################################
#folderpath
def modify_py_file(file_path, new_content, search_line, function_content, search_function):
with open(file_path, 'r') as file:
lines = file.readlines()
# 准备新内容和函数内容的关键行用于比较
new_content_key_line = new_content.strip().split('\n')[0]
function_content_key_line = function_content.strip().split('\n')[0]
# 检查新内容是否已存在
if new_content_key_line not in "".join(lines):
for index, line in enumerate(lines):
if search_line in line:
lines.insert(index + 1, new_content)
break
# 检查函数修改是否已存在
if function_content_key_line not in "".join(lines):
function_start = False
for index, line in enumerate(lines):
if search_function in line:
function_start = True
if function_start and "return None" in line:
lines.insert(index, function_content)
break
# 写回文件
with open(file_path, 'w') as file:
file.writelines(lines)
print(f"File '{file_path}' updated successfully.✅")
要插入的新内容
new_py_content = """
supported_artist_extensions = [".jpg", ".png", ".jpeg"]
artists_dir = os.path.join(base_path, "custom_nodes", "ComfyUI-ArtGallery", "img_lists", "artists")
folder_names_and_paths["artists"] = ([artists_dir], supported_artist_extensions)
cameras_dir = os.path.join(base_path, "custom_nodes", "ComfyUI-ArtGallery", "img_lists", "cameras")
folder_names_and_paths["cameras"] = ([cameras_dir], supported_artist_extensions)
films_dir = os.path.join(base_path, "custom_nodes", "ComfyUI-ArtGallery", "img_lists", "films")
folder_names_and_paths["films"] = ([films_dir], supported_artist_extensions)
movements_dir = os.path.join(base_path, "custom_nodes", "ComfyUI-ArtGallery", "img_lists", "movements")
folder_names_and_paths["movements"] = ([movements_dir], supported_artist_extensions)
styles_dir = os.path.join(base_path, "custom_nodes", "ComfyUI-ArtGallery", "img_lists", "styles")
folder_names_and_paths["styles"] = ([styles_dir], supported_artist_extensions)
"""
要修改的函数内容
function_py_content = '''
if type_name == "artists":
return folder_names_and_paths["artists"][0][0]
if type_name == "cameras":
return folder_names_and_paths["cameras"][0][0]
if type_name == "films":
return folder_names_and_paths["films"][0][0]
if type_name == "movements":
return folder_names_and_paths["movements"][0][0]
if type_name == "styles":
return folder_names_and_paths["styles"][0][0]
'''
文件路径
py_file_path = os.path.join(current_dir, '../../folder_paths.py')
modify_py_file(py_file_path, new_py_content, 'folder_names_and_paths["classifiers"]', function_py_content, 'def get_directory_by_type(type_name: str) -> str | None:')
#################################################
#wedget
def modify_wedgets_js_file(file_path, new_content_1, new_content_2):
# 使用 utf-8 编码读取文件
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# 检查文件中是否已包含需要添加的内容
if "ARTISTS_IMAGEUPLOAD" not in content:
# 找到原始代码的位置
insert_position = content.find('return display === "slider" ? "slider" : "number";')
if insert_position != -1:
# 在原始代码后插入新的代码
insert_position += len('return display === "slider" ? "slider" : "number";')
content = content[:insert_position] + new_content_1 + content[insert_position:]
insert_position_2 = content.find('return { widget: uploadWidget };')
if insert_position_2 != -1:
# 在原始代码后插入新的代码
insert_position_2 += len('return { widget: uploadWidget };')
content = content[:insert_position_2] + new_content_2 + content[insert_position_2:]
# 写回文件
with open(file_path, 'w', encoding='utf-8') as file:
file.write(content)
print(f"File '{file_path}' updated successfully.✅")
else:
print("Original code block not found.❌")
else:
print("File already contains the necessary modifications.✅")
要插入的新内容
new_wedgets_js_content = """
}
//ComfyUI-ArtGallery
function createImageUploadWidget(node, inputName, inputData, imageType, app) {
console.log('createImageUploadWidget called with parameters:', {
node,
inputName,
inputData,
imageType,
app
});
const imageWidget = node.widgets.find((w) => w.name === (inputData[1]?.widget ?? "image"));
let AuploadWidget;
function showImage(name, type) {
const img = new Image();
img.onload = () => {
node.imgs = [img];
app.graph.setDirtyCanvas(true);
};
let folder_separator = name.lastIndexOf("/");
let subfolder = "";
if (folder_separator > -1) {
subfolder = name.substring(0, folder_separator);
name = name.substring(folder_separator + 1);
}
img.src = api.apiURL(`/view?filename=${encodeURIComponent(name)}&type=${type}&subfolder=${subfolder}${app.getPreviewFormatParam()}${app.getRandParam()}`);
node.setSizeForImage?.();
}
var default_value = imageWidget.value;
Object.defineProperty(imageWidget, "value", {
set: function (value) {
this._real_value = value;
},
get: function () {
let value = "";
if (this._real_value) {
value = this._real_value;
} else {
return default_value;
}
if (value.filename) {
let real_value = value;
value = "";
if (real_value.subfolder) {
value = real_value.subfolder + "/";
}
value += real_value.filename;
if (real_value.type && real_value.type !== "input")
value += ` [${real_value.type}]`;
}
return value;
}
});
const cb = node.callback;
imageWidget.callback = function () {
showImage(imageWidget.value, imageType);
if (cb) {
return cb.apply(this, arguments);
}
};
requestAnimationFrame(() => {
if (imageWidget.value) {
showImage(imageWidget.value, imageType);
}
});
return { widget: AuploadWidget };
"""
new_wedgets_js_content_2 = """
},
ARTISTS_IMAGEUPLOAD(node, inputName, inputData, app) {
return createImageUploadWidget(node, inputName, inputData, 'artists', app);
},
CAMERAS_IMAGEUPLOAD(node, inputName, inputData, app) {
return createImageUploadWidget(node, inputName, inputData, 'cameras', app);
},
FILMS_IMAGEUPLOAD(node, inputName, inputData, app) {
return createImageUploadWidget(node, inputName, inputData, 'films', app);
},
MOVEMENTS_IMAGEUPLOAD(node, inputName, inputData, app) {
return createImageUploadWidget(node, inputName, inputData, 'movements', app);
},
STYLES_IMAGEUPLOAD(node, inputName, inputData, app) {
return createImageUploadWidget(node, inputName, inputData, 'styles', app);
"""
PATH
wedgets_js_file_path = os.path.join(current_dir, '../../web/assets/index-D8Zp4vRl.js')
modify_wedgets_js_file(wedgets_js_file_path, new_wedgets_js_content, new_wedgets_js_content_2)
from .ArtGallery import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
all = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
simply modify init.py
uploadimg_js_file_path = os.path.join(current_dir, '../../web/extensions/core/uploadImage.js')
to
uploadimg_js_file_path = os.path.join(current_dir, '../../web/assets/index-BX11rJu2.js')
wedgets_js_file_path = os.path.join(current_dir, '../../web/scripts/widgets.js')
to
wedgets_js_file_path = os.path.join(current_dir, '../../web/assets/index-exUB01hM.js')
it will work now.
新版comfyui,要修改
use "git pull" to upgrade comfyui , and modify artgallery node init.py:
uploadimg_js_file_path = os.path.join(current_dir, '../../web/assets/index-BMC1ey-i.js')
wedgets_js_file_path = os.path.join(current_dir, '../../web/assets/index-DGAbdBYF.js')
it will work now.
新版comfyui,要修改 use "git pull" to upgrade comfyui , and modify artgallery node init.py:
uploadimg_js_file_path = os.path.join(current_dir, '../../web/assets/index-BMC1ey-i.js')
wedgets_js_file_path = os.path.join(current_dir, '../../web/assets/index-DGAbdBYF.js')
it will work now.
大神,启动加载一切正常,可是一些节点还是没法用,还是红色的方框,搜索对应节点名重新添加,添加没反应!
安装 ComfyUI-Gemini 试试,要配合这个节点的 https://github.com/ZHO-ZHO-ZHO/ComfyUI-Gemini
另外,如果遇到gbk错误,可以给openfile 函数加上 encoding='utf-8'。