From 538b81021cbad085edd7bd05100284fc3d8f4dfd Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 5 Apr 2025 08:54:16 -0400 Subject: [PATCH] add generate context menu get server status Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 1 + TODO.md | 2 -- javascript/contextMenus.js | 28 ++++++++++++++++++++++++++-- modules/lora/extra_networks_lora.py | 10 ++++++---- scripts/xyz_grid_classes.py | 8 ++++---- scripts/xyz_grid_shared.py | 7 +++++++ 6 files changed, 44 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71bed0ee6..096231ce1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Logging: fix debug logging - Logging: logging cleanup - Params: Reset default guidance-rescale from 0.7 to 0.0 +- Diag: add get-server-status to ui generate context menu ## Update for 2025-04-03 diff --git a/TODO.md b/TODO.md index c6cef03da..9c03982ed 100644 --- a/TODO.md +++ b/TODO.md @@ -17,8 +17,6 @@ N/A - Video: API support - Video: STG: - Video: SmoothCache: https://github.com/huggingface/diffusers/issues/11135 -- SoftFill: https://github.com/zacheryvaughn/softfill-pipelines -- SISO: https://github.com/yairshp/SISO ## Code TODO diff --git a/javascript/contextMenus.js b/javascript/contextMenus.js index b15615a2a..271f5a9e4 100644 --- a/javascript/contextMenus.js +++ b/javascript/contextMenus.js @@ -117,11 +117,35 @@ const reprocessClick = (tabId, state) => { if (btn) btn.click(); }; +const getStatus = async () => { + const headers = new Headers(); + const body = JSON.stringify({ id_task: -1, id_live_preview: false }); + headers.set('Content-Type', 'application/json'); + const tab = getUICurrentTabContent()?.id.replace('tab_', '') || ''; + const el = gradioApp().querySelector(`#html_log_${tab} .performance p`); + + let res; + let data; + res = await fetch('./internal/progress', { method: 'POST', headers, body }); + if (res?.ok) { + data = await res.json(); + log('progressInternal:', data); + if (el) el.innerText += '\nProgress internal:\n' + JSON.stringify(data, null, 2); // eslint-disable-line prefer-template + } + res = await fetch('./sdapi/v1/progress?skip_current_image=true', { method: 'GET', headers }); + if (res?.ok) { + data = await res.json(); + log('progressAPI:', data); + if (el) el.innerText += '\nProgress API:\n' + JSON.stringify(data, null, 2); // eslint-disable-line prefer-template + } +}; + async function initContextMenu() { let id = ''; - for (const tab of ['txt2img', 'img2img', 'control']) { + for (const tab of ['txt2img', 'img2img', 'control', 'video']) { id = `#${tab}_generate`; - appendContextMenuOption(id, 'Copy to clipboard', () => navigator.clipboard.writeText(document.querySelector(`#${tab}_prompt > label > textarea`).value)); + appendContextMenuOption(id, 'Get server status', getStatus); + appendContextMenuOption(id, 'Copy prompt to clipboard', () => navigator.clipboard.writeText(document.querySelector(`#${tab}_prompt > label > textarea`).value)); appendContextMenuOption(id, 'Generate forever', () => generateForever(`#${tab}_generate`)); appendContextMenuOption(id, 'Apply selected style', quickApplyStyle); appendContextMenuOption(id, 'Quick save style', quickSaveStyle); diff --git a/modules/lora/extra_networks_lora.py b/modules/lora/extra_networks_lora.py index 0f981d93a..aad71c50e 100644 --- a/modules/lora/extra_networks_lora.py +++ b/modules/lora/extra_networks_lora.py @@ -174,21 +174,23 @@ class ExtraNetworkLora(extra_networks.ExtraNetwork): if force_diffusers: has_changed = False # diffusers handle their own loading if len(exclude) == 0: - shared.state.begin('LoRA') + job = shared.state.job + shared.state.job = 'LoRA' lora_load.network_load(names, te_multipliers, unet_multipliers, dyn_dims) # load only on first call - shared.state.end() + shared.state.job = job else: lora_load.network_load(names, te_multipliers, unet_multipliers, dyn_dims) # load has_changed = self.changed(requested, include, exclude) if has_changed: - shared.state.begin('LoRA') + job = shared.state.job + shared.state.job = 'LoRA' if len(l.previously_loaded_networks) > 0: shared.log.info(f'Network unload: type=LoRA apply={[n.name for n in l.previously_loaded_networks]} mode={"fuse" if shared.opts.lora_fuse_diffusers else "backup"}') networks.network_deactivate(include, exclude) networks.network_activate(include, exclude) if len(exclude) > 0: # only update on last activation l.previously_loaded_networks = l.loaded_networks.copy() - shared.state.end() + shared.state.job = job debug_log(f'Network load: type=LoRA previous={[n.name for n in l.previously_loaded_networks]} current={[n.name for n in l.loaded_networks]} changed') if len(l.loaded_networks) > 0 and (len(networks.applied_layers) > 0 or force_diffusers) and step == 0: diff --git a/scripts/xyz_grid_classes.py b/scripts/xyz_grid_classes.py index a1e00b129..33911afdf 100644 --- a/scripts/xyz_grid_classes.py +++ b/scripts/xyz_grid_classes.py @@ -1,4 +1,4 @@ -from scripts.xyz_grid_shared import apply_field, apply_task_args, apply_setting, apply_prompt_primary, apply_prompt_refine, apply_prompt_detailer, apply_prompt_all, apply_order, apply_sampler, apply_hr_sampler_name, confirm_samplers, apply_checkpoint, apply_refiner, apply_unet, apply_dict, apply_clip_skip, apply_vae, list_lora, apply_lora, apply_lora_strength, apply_te, apply_styles, apply_upscaler, apply_context, apply_detailer, apply_override, apply_processing, apply_options, apply_seed, format_value_add_label, format_value, format_value_join_list, do_nothing, format_nothing, str_permutations # pylint: disable=no-name-in-module, unused-import +from scripts.xyz_grid_shared import apply_field, apply_task_arg, apply_task_args, apply_setting, apply_prompt_primary, apply_prompt_refine, apply_prompt_detailer, apply_prompt_all, apply_order, apply_sampler, apply_hr_sampler_name, confirm_samplers, apply_checkpoint, apply_refiner, apply_unet, apply_dict, apply_clip_skip, apply_vae, list_lora, apply_lora, apply_lora_strength, apply_te, apply_styles, apply_upscaler, apply_context, apply_detailer, apply_override, apply_processing, apply_options, apply_seed, format_value_add_label, format_value, format_value_join_list, do_nothing, format_nothing, str_permutations # pylint: disable=no-name-in-module, unused-import from modules import shared, shared_items, sd_samplers, ipadapter, sd_models, sd_vae, sd_unet @@ -209,7 +209,7 @@ axis_options = [ AxisOption("[PAG] Attention scale", float, apply_field('pag_scale')), AxisOption("[PAG] Adaptive scaling", float, apply_field('pag_adaptive')), AxisOption("[PAG] Applied layers", str, apply_setting('pag_apply_layers')), - AxisOption("[IY] Scale", str, apply_task_args('infusenet_conditioning_scale')), - AxisOption("[IY] Start", str, apply_task_args('infusenet_guidance_start')), - AxisOption("[IY] End", str, apply_task_args('infusenet_guidance_end')), + AxisOption("[IY] Scale", float, apply_task_arg('infusenet_conditioning_scale')), + AxisOption("[IY] Start", float, apply_task_arg('infusenet_guidance_start')), + AxisOption("[IY] End", float, apply_task_arg('infusenet_guidance_end')), ] diff --git a/scripts/xyz_grid_shared.py b/scripts/xyz_grid_shared.py index f624458d6..6b1d814b3 100644 --- a/scripts/xyz_grid_shared.py +++ b/scripts/xyz_grid_shared.py @@ -17,6 +17,13 @@ def apply_field(field): return fun +def apply_task_arg(field): + def fun(p, x, xs): + shared.log.debug(f'XYZ grid apply task-arg: {field}={x}') + p.task_args[field] = x + return fun + + def apply_task_args(p, x, xs): for section in x.split(';'): k, v = section.split('=')