Skip to content

Instantly share code, notes, and snippets.

@w-e-w
Last active June 8, 2024 21:45
Show Gist options
  • Save w-e-w/5849daf255faf73e8aaa4d7ee6369523 to your computer and use it in GitHub Desktop.
Save w-e-w/5849daf255faf73e8aaa4d7ee6369523 to your computer and use it in GitHub Desktop.
a example on how an webui extention can get the prompt from the ui
from modules import scripts
import gradio as gr
class DemoExt(scripts.Script):
def __init__(self):
super().__init__()
self.promp_elm = None
self.promp_n_elm = None
self.on_after_component_elem_id = [
('txt2img_prompt', self.save_prompt_box),
('txt2img_neg_prompt', self.save_prompt_box_np),
('img2img_prompt', self.save_prompt_box),
('img2img_neg_prompt', self.save_prompt_box_np),
]
def title(self):
return 'Prompt ext demo'
def show(self, is_img2img):
return scripts.AlwaysVisible
def ui(self, is_img2img):
button = gr.Button('get prompt and n_prompt and process')
res_textbox = gr.Textbox('process result')
button.click(
fn=self.do_process,
inputs=[self.promp_elm, self.promp_n_elm],
outputs=[res_textbox]
)
def do_process(self, p, np):
return f'the prompt is:\n{p}\n\nand the negative prompt is:\n{np}'
def save_prompt_box(self, on_component):
self.promp_elm = on_component.component
def save_prompt_box_np(self, on_component):
self.promp_n_elm = on_component.component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment