mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
feat: advanced params refactoring + prevent users from skipping/stopping other users tasks in queue (#981)
* only make stop_button and skip_button interactive when rendering process starts
fix inconsistency in behaviour of stop_button and skip_button as it was possible to skip or stop other users processes while still being in queue
* use AsyncTask for last_stop handling instead of shared
* Revert "only make stop_button and skip_button interactive when rendering process starts"
This reverts commit d3f9156854.
* introduce state for task skipping/stopping
* fix return parameters of stop_clicked
* code cleanup, do not disable skip/stop on stop_clicked
* reset last_stop when skipping for further processing
* fix: replace fcbh with ldm_patched
* fix: use currentTask instead of ctrls after merging upstream
* feat: extract attribute disable_preview
* feat: extract attribute adm_scaler_positive
* feat: extract attribute adm_scaler_negative
* feat: extract attribute adm_scaler_end
* feat: extract attribute adaptive_cfg
* feat: extract attribute sampler_name
* feat: extract attribute scheduler_name
* feat: extract attribute generate_image_grid
* feat: extract attribute overwrite_step
* feat: extract attribute overwrite_switch
* feat: extract attribute overwrite_width
* feat: extract attribute overwrite_height
* feat: extract attribute overwrite_vary_strength
* feat: extract attribute overwrite_upscale_strength
* feat: extract attribute mixing_image_prompt_and_vary_upscale
* feat: extract attribute mixing_image_prompt_and_inpaint
* feat: extract attribute debugging_cn_preprocessor
* feat: extract attribute skipping_cn_preprocessor
* feat: extract attribute canny_low_threshold
* feat: extract attribute canny_high_threshold
* feat: extract attribute refiner_swap_method
* feat: extract freeu_ctrls attributes
freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2
* feat: extract inpaint_ctrls attributes
debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate
* wip: add TODOs
* chore: cleanup code
* feat: extract attribute controlnet_softness
* feat: extract remaining attributes, do not use globals in patch
* fix: resolve circular import, patch_all now in async_worker
* chore: cleanup pid code
This commit is contained in:
@@ -11,7 +11,6 @@ import modules.async_worker as worker
|
||||
import modules.constants as constants
|
||||
import modules.flags as flags
|
||||
import modules.gradio_hijack as grh
|
||||
import modules.advanced_parameters as advanced_parameters
|
||||
import modules.style_sorter as style_sorter
|
||||
import modules.meta_parser
|
||||
import args_manager
|
||||
@@ -22,17 +21,19 @@ from modules.private_logger import get_current_html_path
|
||||
from modules.ui_gradio_extensions import reload_javascript
|
||||
from modules.auth import auth_enabled, check_auth
|
||||
|
||||
def get_task(*args):
|
||||
args = list(args)
|
||||
args.pop(0)
|
||||
|
||||
def generate_clicked(*args):
|
||||
return worker.AsyncTask(args=args)
|
||||
|
||||
def generate_clicked(task):
|
||||
import ldm_patched.modules.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()
|
||||
task = worker.AsyncTask(args=list(args))
|
||||
finished = False
|
||||
|
||||
yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \
|
||||
@@ -88,6 +89,7 @@ shared.gradio_root = gr.Blocks(
|
||||
css=modules.html.css).queue()
|
||||
|
||||
with shared.gradio_root:
|
||||
currentTask = gr.State(worker.AsyncTask(args=[]))
|
||||
with gr.Row():
|
||||
with gr.Column(scale=2):
|
||||
with gr.Row():
|
||||
@@ -115,21 +117,22 @@ with shared.gradio_root:
|
||||
skip_button = gr.Button(label="Skip", value="Skip", elem_classes='type_row_half', visible=False)
|
||||
stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row_half', elem_id='stop_button', visible=False)
|
||||
|
||||
def stop_clicked():
|
||||
def stop_clicked(currentTask):
|
||||
import ldm_patched.modules.model_management as model_management
|
||||
shared.last_stop = 'stop'
|
||||
model_management.interrupt_current_processing()
|
||||
return [gr.update(interactive=False)] * 2
|
||||
currentTask.last_stop = 'stop'
|
||||
if (currentTask.processing):
|
||||
model_management.interrupt_current_processing()
|
||||
return currentTask
|
||||
|
||||
def skip_clicked():
|
||||
def skip_clicked(currentTask):
|
||||
import ldm_patched.modules.model_management as model_management
|
||||
shared.last_stop = 'skip'
|
||||
model_management.interrupt_current_processing()
|
||||
return
|
||||
currentTask.last_stop = 'skip'
|
||||
if (currentTask.processing):
|
||||
model_management.interrupt_current_processing()
|
||||
return currentTask
|
||||
|
||||
stop_button.click(stop_clicked, outputs=[skip_button, stop_button],
|
||||
queue=False, show_progress=False, _js='cancelGenerateForever')
|
||||
skip_button.click(skip_clicked, queue=False, show_progress=False)
|
||||
stop_button.click(stop_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False, _js='cancelGenerateForever')
|
||||
skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False)
|
||||
with gr.Row(elem_classes='advanced_check_row'):
|
||||
input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check')
|
||||
advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check')
|
||||
@@ -435,7 +438,7 @@ with shared.gradio_root:
|
||||
'(default is 0, always process before any mask invert)')
|
||||
inpaint_mask_upload_checkbox = gr.Checkbox(label='Enable Mask Upload', value=False)
|
||||
invert_mask_checkbox = gr.Checkbox(label='Invert Mask', value=False)
|
||||
|
||||
|
||||
inpaint_ctrls = [debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine,
|
||||
inpaint_strength, inpaint_respective_field,
|
||||
inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate]
|
||||
@@ -452,15 +455,6 @@ with shared.gradio_root:
|
||||
freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95)
|
||||
freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2]
|
||||
|
||||
adps = [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name,
|
||||
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, refiner_swap_method]
|
||||
adps += freeu_ctrls
|
||||
adps += inpaint_ctrls
|
||||
|
||||
def dev_mode_checked(r):
|
||||
return gr.update(visible=r)
|
||||
|
||||
@@ -525,7 +519,8 @@ with shared.gradio_root:
|
||||
inpaint_strength, inpaint_respective_field
|
||||
], show_progress=False, queue=False)
|
||||
|
||||
ctrls = [
|
||||
ctrls = [currentTask, generate_image_grid]
|
||||
ctrls += [
|
||||
prompt, negative_prompt, style_selections,
|
||||
performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale
|
||||
]
|
||||
@@ -534,6 +529,14 @@ with shared.gradio_root:
|
||||
ctrls += [input_image_checkbox, current_tab]
|
||||
ctrls += [uov_method, uov_input_image]
|
||||
ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image]
|
||||
ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg]
|
||||
ctrls += [sampler_name, scheduler_name]
|
||||
ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength]
|
||||
ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint]
|
||||
ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold, canny_high_threshold]
|
||||
ctrls += [refiner_swap_method, controlnet_softness]
|
||||
ctrls += freeu_ctrls
|
||||
ctrls += inpaint_ctrls
|
||||
ctrls += ip_ctrls
|
||||
|
||||
state_is_generating = gr.State(False)
|
||||
@@ -588,8 +591,8 @@ with shared.gradio_root:
|
||||
generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), [], True),
|
||||
outputs=[stop_button, skip_button, generate_button, gallery, state_is_generating]) \
|
||||
.then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \
|
||||
.then(advanced_parameters.set_all_advanced_parameters, inputs=adps) \
|
||||
.then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery]) \
|
||||
.then(fn=get_task, inputs=ctrls, outputs=currentTask) \
|
||||
.then(fn=generate_clicked, inputs=currentTask, outputs=[progress_html, progress_window, progress_gallery, gallery]) \
|
||||
.then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), gr.update(visible=False, interactive=False), False),
|
||||
outputs=[generate_button, stop_button, skip_button, state_is_generating]) \
|
||||
.then(fn=update_history_link, outputs=history_link) \
|
||||
|
||||
Reference in New Issue
Block a user