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

add lcm realtime canvas painting #1043

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Next Next commit
add lcm realtime canvas painting
  • Loading branch information
mashb1t committed Nov 26, 2023
commit e097a5d2ca35a953d49344b706de2bf38a78c24b
5 changes: 5 additions & 0 deletions modules/async_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def handler(async_task):
outpaint_selections = args.pop()
inpaint_input_image = args.pop()
inpaint_additional_prompt = args.pop()
realtime_input_image = args.pop()

cn_tasks = {x: [] for x in flags.ip_list}
for _ in range(4):
Expand Down Expand Up @@ -310,6 +311,10 @@ def handler(async_task):
clip_vision_path, ip_negative_path, ip_adapter_face_path = modules.config.downloading_ip_adapters(
'face')
progressbar(async_task, 1, 'Loading control models ...')
if current_tab == 'paint' and realtime_input_image is not None:
uov_input_image = HWC3(realtime_input_image)
goals.append('vary')
uov_method = 'strong'

# Load or unload CNs
pipeline.refresh_controlnets([controlnet_canny_path, controlnet_cpds_path])
Expand Down
8 changes: 8 additions & 0 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ def ip_advance_checked(x):
example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts, label='Additional Prompt Quick List', components=[inpaint_additional_prompt], visible=False)
gr.HTML('* Powered by Fooocus Inpaint Engine <a href="https://github.com/lllyasviel/Fooocus/discussions/414" target="_blank">\U0001F4D4 Document</a>')
example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False)
with gr.TabItem(label='Realtime Canvas') as paint_tab:
with gr.Row(equal_height=True):
canvas_size = 512
realtime_input_image = gr.Image(source="canvas", tool="color-sketch", shape=(canvas_size, canvas_size), width=canvas_size, height=canvas_size)

switch_js = "(x) => {if(x){viewer_to_bottom(100);viewer_to_bottom(500);}else{viewer_to_top();} return x;}"
down_js = "() => {viewer_to_bottom();}"
Expand All @@ -204,6 +208,7 @@ def ip_advance_checked(x):
uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
paint_tab.select(lambda: 'paint', outputs=current_tab, queue=False, _js=down_js, show_progress=False)

with gr.Column(scale=1, visible=modules.config.default_advanced_checkbox) as advanced_column:
with gr.Tab(label='Setting'):
Expand Down Expand Up @@ -488,6 +493,8 @@ def inpaint_mode_change(mode):
inpaint_strength, inpaint_respective_field
], show_progress=False, queue=False)

realtime_input_image.change(lambda: gr.update(value='Extreme Speed'), outputs=performance_selection, queue=False, show_progress=False, _js="() => {document.getElementById('generate_button').click();}")

ctrls = [
prompt, negative_prompt, style_selections,
performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale
Expand All @@ -497,6 +504,7 @@ def inpaint_mode_change(mode):
ctrls += [input_image_checkbox, current_tab]
ctrls += [uov_method, uov_input_image]
ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt]
ctrls += [realtime_input_image]
ctrls += ip_ctrls

generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False), []), outputs=[stop_button, skip_button, generate_button, gallery]) \
Expand Down