ComfyUI-ArtGallery
ComfyUI-ArtGallery copied to clipboard
Import Failed - No Matter What I Do?
C:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-ArtGallery../../web/extensions/core/uploadImage.js
Original code block not found.❌
File 'C:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-ArtGallery../../folder_paths.py' updated successfully.✅
Traceback (most recent call last):
File "C:\ComfyUI_windows_portable\ComfyUI\nodes.py", line 1800, in load_custom_node
module_spec.loader.exec_module(module)
File "
Cannot import C:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-ArtGallery module for custom nodes: 'charmap' codec can't encode characters in position 6973-6981: character maps to
Same problem here. non ascii char at 6973-6981, maybe some chinese char in the file. I found some but didn't helped me to rename it.
I had ChatGPT helping me to fix the code and translate the comments. Bascially utf-8 support must be added to the file operations. Error handling was added too because some ComfyUI core files are modified and if this fails, they'll be wiped. So before you start, update ComfyUI so it can restore the files that got broken so far. Then the following 3 methods in the init.py of the node must be changed: modify_js_file modify_wedgets_js_file modify_py_file
You can just replace them with the code below accordingly:
modify_js_file
def modify_js_file(file_path, new_content):
try:
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# Check if new content is already included
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:]
# Backup the original file
backup_path = file_path + '.backup'
with open(backup_path, 'w', encoding='utf-8') as backup_file:
backup_file.write(content)
# Write modified content back to file
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.✅")
except Exception as e:
print(f"An error occurred: {e}")
modify_wedgets_js_file
def modify_wedgets_js_file(file_path, new_content, new_content_2):
try:
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# Check if the file already contains the content to be added
if "ARTISTS_IMAGEUPLOAD" not in content:
# Find the position of the original code
insert_position = content.find('return (display==="slider") ? "slider" : "number"')
if insert_position != -1:
# Insert new code after the original code
insert_position += len('return (display==="slider") ? "slider" : "number"')
content = content[:insert_position] + new_content + content[insert_position:]
insert_position_2 = content.find('return { widget: uploadWidget };')
if insert_position_2 != -1:
# Insert new code after the original code
insert_position_2 += len('return { widget: uploadWidget };')
content = content[:insert_position_2] + new_content_2 + content[insert_position_2:]
# Backup the original file
backup_path = file_path + '.backup'
with open(backup_path, 'w', encoding='utf-8') as backup_file:
backup_file.write(content)
# Write back the file
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.✅")
except Exception as e:
print(f"An error occurred: {e}")
modify_py_file
def modify_py_file(file_path, new_content, search_line, function_content, search_function):
try:
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
# Prepare key lines of new content and function content for comparison
new_content_key_line = new_content.strip().split('\n')[0]
function_content_key_line = function_content.strip().split('\n')[0]
# Check if new content already exists
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
# Check if function modification already exists
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
# Backup the original file
backup_path = file_path + '.backup'
with open(backup_path, 'w', encoding='utf-8') as backup_file:
backup_file.writelines(lines)
# Write back the modified content
with open(file_path, 'w', encoding='utf-8') as file:
file.writelines(lines)
print(f"File '{file_path}' updated successfully.✅")
except Exception as e:
print(f"An error occurred: {e}")
your fix worked thank you. but a final one that I could use your help on is the TranslateTextNode. that one is also missing.
This doesn't seem to be related to this repository. There's a package in ComfyUIs manager showing up though that contains a node named TranslateText. If you got it from that pack, update/fix it using the manager. If it doesn't work uninstall the package that contains it also using the manager and then reinstall it.
上面的方法成功帮我修复了文件名包含中文时GBK编码问题!
Thanks @LeroyDaydreamer !! Your code changes fixed it for me!
I had ChatGPT helping me to fix the code and translate the comments. Bascially utf-8 support must be added to the file operations. Error handling was added too because some ComfyUI core files are modified and if this fails, they'll be wiped. So before you start, update ComfyUI so it can restore the files that got broken so far. Then the following 3 methods in the init.py of the node must be changed: modify_js_file modify_wedgets_js_file modify_py_file
You can just replace them with the code below accordingly:
modify_js_file
def modify_js_file(file_path, new_content): try: with open(file_path, 'r', encoding='utf-8') as file: content = file.read() # Check if new content is already included 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:] # Backup the original file backup_path = file_path + '.backup' with open(backup_path, 'w', encoding='utf-8') as backup_file: backup_file.write(content) # Write modified content back to file 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.✅") except Exception as e: print(f"An error occurred: {e}")
modify_wedgets_js_file
def modify_wedgets_js_file(file_path, new_content, new_content_2): try: with open(file_path, 'r', encoding='utf-8') as file: content = file.read() # Check if the file already contains the content to be added if "ARTISTS_IMAGEUPLOAD" not in content: # Find the position of the original code insert_position = content.find('return (display==="slider") ? "slider" : "number"') if insert_position != -1: # Insert new code after the original code insert_position += len('return (display==="slider") ? "slider" : "number"') content = content[:insert_position] + new_content + content[insert_position:] insert_position_2 = content.find('return { widget: uploadWidget };') if insert_position_2 != -1: # Insert new code after the original code insert_position_2 += len('return { widget: uploadWidget };') content = content[:insert_position_2] + new_content_2 + content[insert_position_2:] # Backup the original file backup_path = file_path + '.backup' with open(backup_path, 'w', encoding='utf-8') as backup_file: backup_file.write(content) # Write back the file 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.✅") except Exception as e: print(f"An error occurred: {e}")
modify_py_file
def modify_py_file(file_path, new_content, search_line, function_content, search_function): try: with open(file_path, 'r', encoding='utf-8') as file: lines = file.readlines() # Prepare key lines of new content and function content for comparison new_content_key_line = new_content.strip().split('\n')[0] function_content_key_line = function_content.strip().split('\n')[0] # Check if new content already exists 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 # Check if function modification already exists 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 # Backup the original file backup_path = file_path + '.backup' with open(backup_path, 'w', encoding='utf-8') as backup_file: backup_file.writelines(lines) # Write back the modified content with open(file_path, 'w', encoding='utf-8') as file: file.writelines(lines) print(f"File '{file_path}' updated successfully.✅") except Exception as e: print(f"An error occurred: {e}")
THX for Ur great work. but the preview images in the blocks are still missed.
File /web/extensions/core/uploadImage.js doesn`t exist really in ComfyUI!