mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
fix api scripts callbacks
Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
+2
-1
@@ -37,7 +37,8 @@
|
||||
"object-curly-newline":"off",
|
||||
"prefer-rest-params":"off",
|
||||
"prefer-destructuring":"off",
|
||||
"radix":"off"
|
||||
"radix":"off",
|
||||
"node/shebang": "off"
|
||||
},
|
||||
"globals": {
|
||||
// asssets
|
||||
|
||||
+3
-2
@@ -1,6 +1,6 @@
|
||||
# Change Log for SD.Next
|
||||
|
||||
## Update for 2024-11-26
|
||||
## Update for 2024-11-27
|
||||
|
||||
### New models and integrations
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
- **Sampler** improvements
|
||||
- update DPM FlowMatch samplers
|
||||
|
||||
### Fixes:
|
||||
### Fixes
|
||||
|
||||
- update `diffusers`
|
||||
- fix README links
|
||||
@@ -60,6 +60,7 @@
|
||||
- avoid live-preview if vae-decode is running
|
||||
- allow xyz-grid with multi-axis s&r
|
||||
- fix xyz-grid with lora
|
||||
- fix api script callbacks
|
||||
|
||||
## Update for 2024-11-21
|
||||
|
||||
|
||||
+17
-7
@@ -10,12 +10,13 @@ const argparse = require('argparse');
|
||||
const sd_url = process.env.SDAPI_URL || 'http://127.0.0.1:7860';
|
||||
const sd_username = process.env.SDAPI_USR;
|
||||
const sd_password = process.env.SDAPI_PWD;
|
||||
let args = {};
|
||||
|
||||
function b64(file) {
|
||||
const data = fs.readFileSync(file);
|
||||
const b64 = Buffer.from(data).toString('base64');
|
||||
const b64str = Buffer.from(data).toString('base64');
|
||||
const ext = path.extname(file).replace('.', '');
|
||||
str = `data:image/${ext};base64,${b64}`;
|
||||
const str = `data:image/${ext};base64,${b64str}`;
|
||||
// console.log('b64:', ext, b64.length);
|
||||
return str;
|
||||
}
|
||||
@@ -39,7 +40,16 @@ function options() {
|
||||
if (args.pulid) {
|
||||
const b64image = b64(args.pulid);
|
||||
opt.script_name = 'pulid';
|
||||
opt.script_args = [b64image, 0.9];
|
||||
opt.script_args = [
|
||||
b64image, // b64 encoded image, required param
|
||||
0.9, // strength, optional
|
||||
20, // zero, optional
|
||||
'dpmpp_sde', // sampler, optional
|
||||
'v2', // ortho, optional
|
||||
true, // restore (disable pulid after run), optional
|
||||
true, // offload, optional
|
||||
'v1.1', // version, optional
|
||||
];
|
||||
}
|
||||
// console.log('options:', opt);
|
||||
return opt;
|
||||
@@ -53,8 +63,8 @@ function init() {
|
||||
parser.add_argument('--height', { type: 'int', help: 'height' });
|
||||
parser.add_argument('--pulid', { type: 'str', help: 'pulid init image' });
|
||||
parser.add_argument('--output', { type: 'str', help: 'output path' });
|
||||
const args = parser.parse_args();
|
||||
return args
|
||||
const parsed = parser.parse_args();
|
||||
return parsed;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
@@ -73,12 +83,12 @@ async function main() {
|
||||
console.log('result:', json.info);
|
||||
for (const i in json.images) { // eslint-disable-line guard-for-in
|
||||
const file = args.output || `/tmp/test-${i}.jpg`;
|
||||
const data = atob(json.images[i])
|
||||
const data = atob(json.images[i]);
|
||||
fs.writeFileSync(file, data, 'binary');
|
||||
console.log('image saved:', file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const args = init();
|
||||
args = init();
|
||||
main();
|
||||
|
||||
@@ -159,6 +159,8 @@ class APIControl():
|
||||
output_images = []
|
||||
output_processed = []
|
||||
output_info = ''
|
||||
# TODO control script process
|
||||
# init script args, call scripts.script_control.run, call scripts.script_control.after
|
||||
run.control_set({ 'do_not_save_grid': not req.save_images, 'do_not_save_samples': not req.save_images, **self.prepare_ip_adapter(req) })
|
||||
run.control_set(getattr(req, "extra", {}))
|
||||
res = run.control_run(**args)
|
||||
|
||||
@@ -116,6 +116,8 @@ class APIGenerate():
|
||||
processed = scripts.scripts_txt2img.run(p, *script_args) # Need to pass args as list here
|
||||
else:
|
||||
processed = process_images(p)
|
||||
processed = scripts.scripts_txt2img.after(p, processed, *script_args)
|
||||
p.close()
|
||||
shared.state.end(api=False)
|
||||
if processed is None or processed.images is None or len(processed.images) == 0:
|
||||
b64images = []
|
||||
@@ -166,6 +168,8 @@ class APIGenerate():
|
||||
processed = scripts.scripts_img2img.run(p, *script_args) # Need to pass args as list here
|
||||
else:
|
||||
processed = process_images(p)
|
||||
processed = scripts.scripts_img2img.after(p, processed, *script_args)
|
||||
p.close()
|
||||
shared.state.end(api=False)
|
||||
if processed is None or processed.images is None or len(processed.images) == 0:
|
||||
b64images = []
|
||||
|
||||
@@ -87,7 +87,6 @@ def control_run(state: str = '',
|
||||
u.process.override = u.override
|
||||
|
||||
global instance, pipe, original_pipeline # pylint: disable=global-statement
|
||||
t_start = time.time()
|
||||
debug(f'Control: type={unit_type} input={inputs} init={inits} type={input_type}')
|
||||
if inputs is None or (type(inputs) is list and len(inputs) == 0):
|
||||
inputs = [None]
|
||||
|
||||
+2
-2
@@ -559,8 +559,8 @@ options_templates.update(options_section(('diffusers', "Diffusers Settings"), {
|
||||
"diffusers_extract_ema": OptionInfo(False, "Use model EMA weights when possible"),
|
||||
"diffusers_generator_device": OptionInfo("GPU", "Generator device", gr.Radio, {"choices": ["GPU", "CPU", "Unset"]}),
|
||||
"diffusers_offload_mode": OptionInfo(startup_offload_mode, "Model offload mode", gr.Radio, {"choices": ['none', 'balanced', 'model', 'sequential']}),
|
||||
"diffusers_offload_max_gpu_memory": OptionInfo(round(gpu_memory * 0.75, 1), "Max GPU memory for balanced offload mode in GB", gr.Slider, {"minimum": 0, "maximum": gpu_memory, "step": 0.01,}),
|
||||
"diffusers_offload_max_cpu_memory": OptionInfo(round(cpu_memory * 0.75, 1), "Max CPU memory for balanced offload mode in GB", gr.Slider, {"minimum": 0, "maximum": cpu_memory, "step": 0.01,}),
|
||||
"diffusers_offload_max_gpu_memory": OptionInfo(round(gpu_memory * 0.75, 1), "Max GPU memory before balanced offload", gr.Slider, {"minimum": 0, "maximum": gpu_memory, "step": 0.01, "visible": True }),
|
||||
"diffusers_offload_max_cpu_memory": OptionInfo(round(cpu_memory * 0.75, 1), "Max CPU memory before balanced offload", gr.Slider, {"minimum": 0, "maximum": cpu_memory, "step": 0.01, "visible": False }),
|
||||
"diffusers_vae_upcast": OptionInfo("default", "VAE upcasting", gr.Radio, {"choices": ['default', 'true', 'false']}),
|
||||
"diffusers_vae_slicing": OptionInfo(True, "VAE slicing"),
|
||||
"diffusers_vae_tiling": OptionInfo(cmd_opts.lowvram or cmd_opts.medvram, "VAE tiling"),
|
||||
|
||||
@@ -164,11 +164,13 @@ class Script(scripts.Script):
|
||||
p.batch_size = 1
|
||||
|
||||
sdp = shared.opts.cross_attention_optimization == "Scaled-Dot-Product"
|
||||
sampler_fn = getattr(self.pulid.sampling, f'sample_{sampler}', None)
|
||||
strength = getattr(p, 'pulid_strength', strength)
|
||||
zero = getattr(p, 'pulid_zero', zero)
|
||||
ortho = getattr(p, 'pulid_ortho', ortho)
|
||||
sampler = getattr(p, 'pulid_sampler', sampler)
|
||||
sampler_fn = getattr(self.pulid.sampling, f'sample_{sampler}', None)
|
||||
restore = getattr(p, 'pulid_restore', restore)
|
||||
p.pulid_restore = restore
|
||||
if sampler_fn is None:
|
||||
sampler_fn = self.pulid.sampling.sample_dpmpp_2m_sde
|
||||
|
||||
@@ -199,7 +201,7 @@ class Script(scripts.Script):
|
||||
return None
|
||||
|
||||
shared.sd_model.sampler = sampler_fn
|
||||
shared.log.info(f'PuLID: class={shared.sd_model.__class__.__name__} version="{version}" sdp={sdp} strength={strength} zero={zero} ortho={ortho} sampler={sampler_fn} images={[i.shape for i in images]} offload={offload}')
|
||||
shared.log.info(f'PuLID: class={shared.sd_model.__class__.__name__} version="{version}" sdp={sdp} strength={strength} zero={zero} ortho={ortho} sampler={sampler_fn} images={[i.shape for i in images]} offload={offload} restore={restore}')
|
||||
self.pulid.attention.NUM_ZERO = zero
|
||||
self.pulid.attention.ORTHO = ortho == 'v1'
|
||||
self.pulid.attention.ORTHO_v2 = ortho == 'v2'
|
||||
|
||||
Reference in New Issue
Block a user