Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: example: extension "sd-webui-birefnet" for removing background #16455

Open
1 task done
kalle07 opened this issue Sep 3, 2024 · 2 comments
Open
1 task done
Labels
enhancement New feature or request

Comments

@kalle07
Copy link

kalle07 commented Sep 3, 2024

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

so its a fast and great extension for removing background in very good qualitiy

it works so fare with a1111 and webui

but if i have file names usual "image(103).png" -> the file after removing background is "image103.png"
also upscale and all other stuff, the name is not the same if i have brackets !

Proposed workflow

grafik

Additional information

No response

@kalle07 kalle07 added the enhancement New feature or request label Sep 3, 2024
@kalle07 kalle07 changed the title [Feature Request]: extension "sd-webui-birefnet" for removing background [Feature Request]: example: extension "sd-webui-birefnet" for removing background Sep 3, 2024
@dimitribarbot
Copy link

dimitribarbot commented Sep 4, 2024

Hi,
This issue occurs for any extra in "Extras" tab when using the "Batch Process" sub-tab:

image

Here, the file image(123).jpg will be renamed to image123.png in the extra output folder.

I think this is related to the way Gradio 3.41 handles file uploads where it strips so-called "invalid filename characters" (see function "gradio-client -> utils.py -> strip_invalid_filename_characters") and where only alphanumeric characters, spaces, ., - and _ are accepted. For me, there is an issue in the preprocess function of the Gradio Files component where orig_name is filled with this stripped filename instead of the real original filename.

A potential fix would be to override this preprocess function in an inherited component (in modules/ui_components.py ?) such as:

class Files(gr.Files):
    """Same as gr.Files but fixes an issue with wrong 'orig_name'
    by adding a 'real_orig_name' with the real 'orig_name'
    """

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        
    def patch_file_orig_name(self, f):
        file = super().preprocess(f)
        file.real_orig_name = f.get("orig_name")
        return file

    def preprocess(self, x):
        if x is None:
            return None

        if isinstance(x, list):
            return [self.patch_file_orig_name(f) for f in x]

        return self.patch_file_orig_name(x)

    def get_block_name(self):
        return "file"

And use this component instead of gr.Files in modules/ui_postprocessing.py.

Finally in the run_postprocessing of the modules/postprocessing.py file, replace:

fn = os.path.splitext(img.orig_name)[0]

with:

fn = os.path.splitext(img.real_orig_name or img.orig_name)[0]

...or wait for the Gradio 4 migration which might fix this issue (see #14068).

@kalle07
Copy link
Author

kalle07 commented Sep 4, 2024

i see iam not a coder/programmer

but i mean usualy all images i save at least in webui and fooocus are called "image(123).png"
what an error ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants