-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Fix postprocessing_enable_in_main_ui ScriptPostprocessing elem_id #16373
Conversation
Maybe there is a universal way to allow coping of Input According, i.e. allow existence of InputAccordions with the same id. I remember I copied soft inpaint ui ik my extension, and a was needed to recreate InputAccordion element. Even callbacks on after/before component couldn't help with this, because it copies elem_id in constructor moment somewhere I also tried to add on_before_component in init of input accordion, but it was a bad idea because it's not possible to pass arguments by reference to edit elem_id Maybe it's possible to avoid coping elem_id to somewhere, and use lambdas, but I don't remember global input accordions ids is in python or JavaScript Btw if do something, it goes into a new pr, because it helps with on_after_component, not with postprocessing in ui. But also if this is implemented, we can avoid using |
yes I consider that path, and yes if we only want to fix the issue for only
the whole reason behind a fixed elem_id is that it porvides a unambiguous way to "targeting" the element using JavaScrip / CSS and sometimes in python as well but that code the use the elem id can be anywhere,
there's no way we can know what code would be using the elem id for their own reason, and so there's no way we can retroactively modify that code to the correct element and so the only way we can truly fix this is at the source, "the ID should be unique in the first place" and this is why
I don't quite follow you |
I don't mean dynamic element ids, I suggest relay on ids which gradio components have after ui created. Not on what they have in constructor. E.g. allow x = InputAccordion()
x.elem_id = "my_elem_id"
For example this in my replacer's code. I don't suggest exactly the same, I mean similar logic needWatchControlNetUI = False
controlNetAccordion = None
def watchControlNetUI(component, **kwargs):
global needWatchControlNetUI, controlNetAccordion
if not needWatchControlNetUI:
return
elem_id = kwargs.get('elem_id', None)
if elem_id is None:
return
if elem_id == 'controlnet':
controlNetAccordion = component
return
if 'img2img' in elem_id:
component.elem_id = elem_id.replace('img2img', 'replacer')
...
script_callbacks.on_after_component(replacer_extensions.controlnet.watchControlNetUI) I can enable this code by setting up |
I mean delay this code inside self.accordion_id = kwargs.get('elem_id')
if self.accordion_id is None:
self.accordion_id = f"input-accordion-{InputAccordion.global_index}"
InputAccordion.global_index += 1
kwargs_checkbox = {
**kwargs,
"elem_id": f"{self.accordion_id}-checkbox",
"visible": False,
}
super().__init__(value, **kwargs_checkbox)
self.change(fn=None, _js='function(checked){ inputAccordionChecked("' + self.accordion_id + '", checked); }', inputs=[self])
kwargs_accordion = {
**kwargs,
"elem_id": self.accordion_id,
"label": kwargs.get('label', 'Accordion'),
"elem_classes": ['input-accordion'],
"open": value,
}
self.accordion = gr.Accordion(**kwargs_accordion) On the moment after ui created, but the app was not started |
yes I have also considered delaying the init of InputAccordion , in face that was one of my initial solutions, but as I have mentioned solving the issue for InputAccordion it's basically just postponing the root issue
this issue has existed ever since postprocessing_enable_in_main_ui is introduced but it wasn't causing major issues until switch to InputAccordion maybe having additional code for fixing it for InputAccordion, as it can improve compatibility of some extensions without change, but since it's not fixing the root issue, I belive the InputAccordion should not introduce extra complexity to the cloud base
if an element ID is set replace it with something unique after it's been created so the next time you run into duplicate ID issues, something similar to my current PR would need to be applied if you want additional fixes that makes duplicate elem_id InputAccordion compatible without modification on extension side, good I'm also considering that |
So you think elem_id_suffix() is still important because we need to avoid duplicating of ids for js, css etc? And my suggested solution is not applicable for this problem in a proper way. Do I understand correctly? |
that's basically it that's the reason why people want elem ids is to serve as an unique identifier for the element from "anywhere", they may have different use case we simply cannot account there's nothing wrong with makeing InputAccordion more compatible, it is just it's not solving the root issue, which is what does PR is trying to address |
Description
Fix
postprocessing_enable_in_main_ui
ScriptPostprocessing
duplicateelem_id
ScriptPostprocessing
(extras
tab) modules such asUpscale
can be use as a processing add on intxt2img
andimg2img
pipeline with the use ofScriptPostprocessingForMainUI
/opts.postprocessing_enable_in_main_ui
this causes an issue, due to the way
ScriptPostprocessingForMainUI
creates the UI for theScriptPostprocessing
UI is the same as Extra tab, if an element has a fixedelem_id
configured the element IDs will be duplicatedthis has always been an issue since the beginning but this has become a serious issue due to the switch to
InputAccordion
inScriptPostprocessing
as
InputAccordion
relies on the id being unique (if manually set)the issue can be reproduced by
Setting > Postprocessing > Enable postprocessing operations in txt2img and img2img tabs
addUpscale
Upscale
on extras tab, you should find that theInputAccordion
is not responsiveInputAccordion
ontxt2img
tab actually controls theInputAccordion
onextras
tabProposed solution
similer to
scripts.Script
elem_id
should be generated with theelem_id()
helper functiontab_name
will be append to the end of theelem_id
on
extras
tabtab_name
is blankbut before
ScriptPostprocessingForMainUI
creates the UI,tab_name
of the script should be set to_txt2img
or_img2img
issue with this approach any extension that wishes to make their
ScriptPostprocessing
should also be update to useelem_id()
to create thereelem_id
unfortunately I don't think there is a better solution that can be applied in automatic efficiently issue globally without change to extensions
reason being
elem_id
are mostly reference inside JavaScript, and there's really no unified method of modifying what function do they target within pythonalso additional inconvenience extension that wishes to use this function if they wish to maintain compatibility with old versions of web UI they need to test if this function exists
there are two variant of the create elem_id helper function
elem_id()
andfunc elem_id_suffix()
elem_id()
is for new extentions, they can use this to creat there elem_id, this create the ID withextras_
andscript name
prefix followed by the input string andtab_name
suffixfunc elem_id_suffix()
on the other hand only adds the suffix without modifying the rest of the IDthe reason is that it is possible that some other things extensions are already utilizing set ID to Target the specific elements and it would be bad to multiply the ID
Note invalid characters are still removed in both functions
Checklist: