mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
[2.1.822] New Inpaint System
See related documents for more details.
This commit is contained in:
@@ -22,6 +22,11 @@ from modules.auth import auth_enabled, check_auth
|
||||
|
||||
|
||||
def generate_clicked(*args):
|
||||
import fcbh.model_management as model_management
|
||||
|
||||
with model_management.interrupt_processing_mutex:
|
||||
model_management.interrupt_processing = False
|
||||
|
||||
# outputs=[progress_html, progress_window, progress_gallery, gallery]
|
||||
|
||||
execution_start_time = time.perf_counter()
|
||||
@@ -178,11 +183,15 @@ with shared.gradio_root:
|
||||
outputs=ip_ad_cols + ip_types + ip_stops + ip_weights,
|
||||
queue=False, show_progress=False)
|
||||
|
||||
with gr.TabItem(label='Inpaint or Outpaint (beta)') as inpaint_tab:
|
||||
with gr.TabItem(label='Inpaint or Outpaint') as inpaint_tab:
|
||||
inpaint_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy', tool='sketch', height=500, brush_color="#FFFFFF", elem_id='inpaint_canvas')
|
||||
gr.HTML('Outpaint Expansion Direction:')
|
||||
outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint', show_label=False, container=False)
|
||||
gr.HTML('* Powered by Fooocus Inpaint Engine (beta) <a href="https://github.com/lllyasviel/Fooocus/discussions/414" target="_blank">\U0001F4D4 Document</a>')
|
||||
with gr.Row():
|
||||
inpaint_additional_prompt = gr.Textbox(placeholder="Describe what you want to inpaint.", elem_id='inpaint_additional_prompt', label='Inpaint Additional Prompt', visible=False)
|
||||
outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction')
|
||||
inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.flags.inpaint_option_default, label='Method')
|
||||
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)
|
||||
|
||||
switch_js = "(x) => {if(x){viewer_to_bottom(100);viewer_to_bottom(500);}else{viewer_to_top();} return x;}"
|
||||
down_js = "() => {viewer_to_bottom();}"
|
||||
@@ -297,15 +306,17 @@ with shared.gradio_root:
|
||||
with gr.Row():
|
||||
model_refresh = gr.Button(label='Refresh', value='\U0001f504 Refresh All Files', variant='secondary', elem_classes='refresh_button')
|
||||
with gr.Tab(label='Advanced'):
|
||||
sharpness = gr.Slider(label='Sampling Sharpness', minimum=0.0, maximum=30.0, step=0.001, value=modules.config.default_sample_sharpness,
|
||||
guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=30.0, step=0.01,
|
||||
value=modules.config.default_cfg_scale,
|
||||
info='Higher value means style is cleaner, vivider, and more artistic.')
|
||||
sharpness = gr.Slider(label='Image Sharpness', minimum=0.0, maximum=30.0, step=0.001,
|
||||
value=modules.config.default_sample_sharpness,
|
||||
info='Higher value means image and texture are sharper.')
|
||||
guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=30.0, step=0.01, value=modules.config.default_cfg_scale,
|
||||
info='Higher value means style is cleaner, vivider, and more artistic.')
|
||||
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/117" target="_blank">\U0001F4D4 Document</a>')
|
||||
dev_mode = gr.Checkbox(label='Developer Debug Mode', value=False, container=False)
|
||||
|
||||
with gr.Column(visible=False) as dev_tools:
|
||||
with gr.Tab(label='Developer Debug Tools'):
|
||||
with gr.Tab(label='Debug Tools'):
|
||||
adm_scaler_positive = gr.Slider(label='Positive ADM Guidance Scaler', minimum=0.1, maximum=3.0,
|
||||
step=0.001, value=1.5, info='The scaler multiplied to positive ADM (use 1.0 to disable). ')
|
||||
adm_scaler_negative = gr.Slider(label='Negative ADM Guidance Scaler', minimum=0.1, maximum=3.0,
|
||||
@@ -352,14 +363,10 @@ with shared.gradio_root:
|
||||
overwrite_upscale_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Upscale"',
|
||||
minimum=-1, maximum=1.0, step=0.001, value=-1,
|
||||
info='Set as negative number to disable. For developer debugging.')
|
||||
inpaint_engine = gr.Dropdown(label='Inpaint Engine',
|
||||
value=modules.config.default_inpaint_engine_version,
|
||||
choices=flags.inpaint_engine_versions,
|
||||
info='Version of Fooocus inpaint model')
|
||||
disable_preview = gr.Checkbox(label='Disable Preview', value=False,
|
||||
info='Disable preview during generation.')
|
||||
|
||||
with gr.Tab(label='Control Debug'):
|
||||
with gr.Tab(label='Control'):
|
||||
debugging_cn_preprocessor = gr.Checkbox(label='Debug Preprocessors', value=False,
|
||||
info='See the results from preprocessors.')
|
||||
skipping_cn_preprocessor = gr.Checkbox(label='Skip Preprocessors', value=False,
|
||||
@@ -380,6 +387,27 @@ with shared.gradio_root:
|
||||
canny_high_threshold = gr.Slider(label='Canny High Threshold', minimum=1, maximum=255,
|
||||
step=1, value=128)
|
||||
|
||||
with gr.Tab(label='Inpaint'):
|
||||
debugging_inpaint_preprocessor = gr.Checkbox(label='Debug Inpaint Preprocessing', value=False)
|
||||
inpaint_disable_initial_latent = gr.Checkbox(label='Disable initial latent in inpaint', value=False)
|
||||
inpaint_engine = gr.Dropdown(label='Inpaint Engine',
|
||||
value=modules.config.default_inpaint_engine_version,
|
||||
choices=flags.inpaint_engine_versions,
|
||||
info='Version of Fooocus inpaint model')
|
||||
inpaint_strength = gr.Slider(label='Inpaint Denoising Strength',
|
||||
minimum=0.0, maximum=1.0, step=0.001, value=1.0,
|
||||
info='Same as the denoising strength in A1111 inpaint. '
|
||||
'Only used in inpaint, not used in outpaint. '
|
||||
'(Outpaint always use 1.0)')
|
||||
inpaint_respective_field = gr.Slider(label='Inpaint Respective Field',
|
||||
minimum=0.0, maximum=1.0, step=0.001, value=0.618,
|
||||
info='The area to inpaint. '
|
||||
'Value 0 is same as "Only Masked" in A1111. '
|
||||
'Value 1 is same as "Whole Image" in A1111. '
|
||||
'Only used in inpaint, not used in outpaint. '
|
||||
'(Outpaint always use 1.0)')
|
||||
inpaint_ctrls = [debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field]
|
||||
|
||||
with gr.Tab(label='FreeU'):
|
||||
freeu_enabled = gr.Checkbox(label='Enabled', value=False)
|
||||
freeu_b1 = gr.Slider(label='B1', minimum=0, maximum=2, step=0.01, value=1.01)
|
||||
@@ -392,9 +420,10 @@ with shared.gradio_root:
|
||||
scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height,
|
||||
overwrite_vary_strength, overwrite_upscale_strength,
|
||||
mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint,
|
||||
debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold,
|
||||
inpaint_engine, refiner_swap_method]
|
||||
debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness,
|
||||
canny_low_threshold, canny_high_threshold, refiner_swap_method]
|
||||
adps += freeu_ctrls
|
||||
adps += inpaint_ctrls
|
||||
|
||||
def dev_mode_checked(r):
|
||||
return gr.update(visible=r)
|
||||
@@ -426,6 +455,39 @@ with shared.gradio_root:
|
||||
queue=False, show_progress=False) \
|
||||
.then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False)
|
||||
|
||||
def inpaint_mode_change(mode):
|
||||
assert mode in modules.flags.inpaint_options
|
||||
|
||||
# inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
|
||||
# inpaint_disable_initial_latent, inpaint_engine,
|
||||
# inpaint_strength, inpaint_respective_field
|
||||
|
||||
if mode == modules.flags.inpaint_option_detail:
|
||||
return [
|
||||
gr.update(visible=True), gr.update(visible=False, value=[]),
|
||||
gr.Dataset.update(visible=True, samples=modules.config.example_inpaint_prompts),
|
||||
False, 'None', 0.5, 0.0
|
||||
]
|
||||
|
||||
if mode == modules.flags.inpaint_option_modify:
|
||||
return [
|
||||
gr.update(visible=True), gr.update(visible=False, value=[]),
|
||||
gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts),
|
||||
True, modules.config.default_inpaint_engine_version, 1.0, 0.0
|
||||
]
|
||||
|
||||
return [
|
||||
gr.update(visible=False, value=''), gr.update(visible=True),
|
||||
gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts),
|
||||
False, modules.config.default_inpaint_engine_version, 1.0, 0.618
|
||||
]
|
||||
|
||||
inpaint_mode.input(inpaint_mode_change, inputs=inpaint_mode, outputs=[
|
||||
inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
|
||||
inpaint_disable_initial_latent, inpaint_engine,
|
||||
inpaint_strength, inpaint_respective_field
|
||||
], show_progress=False, queue=False)
|
||||
|
||||
ctrls = [
|
||||
prompt, negative_prompt, style_selections,
|
||||
performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale
|
||||
@@ -434,7 +496,7 @@ with shared.gradio_root:
|
||||
ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls
|
||||
ctrls += [input_image_checkbox, current_tab]
|
||||
ctrls += [uov_method, uov_input_image]
|
||||
ctrls += [outpaint_selections, inpaint_input_image]
|
||||
ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt]
|
||||
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]) \
|
||||
|
||||
Reference in New Issue
Block a user