Comments (5)
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}")
from comfyui-artgallery.
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.
from comfyui-artgallery.
your fix worked thank you. but a final one that I could use your help on is the TranslateTextNode. that one is also missing.
from comfyui-artgallery.
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.
from comfyui-artgallery.
上面的方法成功帮我修复了文件名包含中文时GBK编码问题!
from comfyui-artgallery.
Related Issues (11)
- 【建议】浏览图片列表时希望能够实时显示图片
- [建议] 项目容易克隆失败:预览图片能否再压缩一下,或者另外放置到云端网盘 HOT 2
- 更新Comfy-UI到最新版后, 图片无法显示.
- 无法加载图片显示400错误
- Cant install it correctly HOT 7
- Error does not work HOT 6
- Original code block not found - uploadImage.js is empty HOT 9
- 'gbk' codec can't decode byte 0x80 in position 336: illegal multibyte sequence HOT 5
- Can't Install at all
- Where is "ConcatText_Zho"?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comfyui-artgallery.