Giter VIP home page Giter VIP logo

Comments (5)

LeroyDaydreamer avatar LeroyDaydreamer commented on August 11, 2024 4

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.

Poukpalaova avatar Poukpalaova commented on August 11, 2024

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.

Muabf avatar Muabf commented on August 11, 2024

your fix worked thank you. but a final one that I could use your help on is the TranslateTextNode. that one is also missing.

image

from comfyui-artgallery.

LeroyDaydreamer avatar LeroyDaydreamer commented on August 11, 2024

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.

water110 avatar water110 commented on August 11, 2024

上面的方法成功帮我修复了文件名包含中文时GBK编码问题!

from comfyui-artgallery.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.