Skip to content

Adding after_ui_callback for script ui modification#8380

Closed
ashen-sensored wants to merge 1 commit into
AUTOMATIC1111:masterfrom
ashen-sensored:after_ui_callback
Closed

Adding after_ui_callback for script ui modification#8380
ashen-sensored wants to merge 1 commit into
AUTOMATIC1111:masterfrom
ashen-sensored:after_ui_callback

Conversation

@ashen-sensored

Copy link
Copy Markdown

Describe what this pull request is trying to achieve.

Adding after_ui_callback for easier gradio component access for extensions during ui creation

Additional notes and description of your changes

Used for opparco/stable-diffusion-webui-two-shot#23
for realizing prompt auto pasting
opparco/stable-diffusion-webui-two-shot@d0163f2

@AUTOMATIC1111

Copy link
Copy Markdown
Owner

why is it called twice

@ashen-sensored

ashen-sensored commented Mar 11, 2023

Copy link
Copy Markdown
Author

It is called once inside txt2img block, once inside img2img block, so I can do the following.
gradio does not allow calling button.click outside current block context.

def on_after_ui(self):
    if self.prompt_paste_initialized:
        return
    def paste_prompt(*input_prompts):
        finalprompts = input_prompts[:len(self.area_colors)]
        final_prompt_str = '\nAND '.join(finalprompts)
        return final_prompt_str

    prompt_target = self.ui_root.parent.parent.parent.parent.parent.children[0].children[0].children[0].children[0].children[0].children[0].children[0]
    self.prompt_update_button.click(fn=paste_prompt, inputs=self.source_prompts, outputs=prompt_target)

    self.prompt_paste_initialized = True

why is it called twice

@AUTOMATIC1111

Copy link
Copy Markdown
Owner

Can you not do that using on_before_component/on_after_component?

@ashen-sensored

Copy link
Copy Markdown
Author

Can you not do that using on_before_component/on_after_component?

I just looked up the implementation in controlnet plugin. I think you're right. Sorry for the trouble caused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants