support progress for img2img (#215)

WebGUI shows progress bar when an initial image is provided.
This commit is contained in:
Kevin Gibbons 2022-08-30 12:36:12 -07:00 committed by GitHub
parent a51e18ea98
commit 8ca4d6542d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions

View File

@ -145,7 +145,7 @@ class DreamServer(BaseHTTPRequestHandler):
step_writer.write_image(image, seed) # TODO PngWriter to return path
url = step_writer.filepath
self.wfile.write(bytes(json.dumps(
{'event':'step', 'step':step, 'url': url}
{'event':'step', 'step':step + 1, 'url': url}
) + '\n',"utf-8"))
try:

View File

@ -375,6 +375,7 @@ class DDIMSampler(object):
x_latent,
cond,
t_start,
img_callback=None,
unconditional_guidance_scale=1.0,
unconditional_conditioning=None,
use_original_steps=False,
@ -410,4 +411,7 @@ class DDIMSampler(object):
unconditional_guidance_scale=unconditional_guidance_scale,
unconditional_conditioning=unconditional_conditioning,
)
if img_callback:
img_callback(x_dec, i)
return x_dec

View File

@ -489,6 +489,7 @@ class T2I:
z_enc,
c,
t_enc,
img_callback=callback,
unconditional_guidance_scale=cfg_scale,
unconditional_conditioning=uc,
)

View File

@ -61,10 +61,13 @@ async function generateSubmit(form) {
let formData = Object.fromEntries(new FormData(form));
formData.initimg = formData.initimg.name !== '' ? await toBase64(formData.initimg) : null;
let strength = 0.75; // TODO let this be specified in the UI
let totalSteps = formData.initimg ? Math.floor(.75 * formData.steps) : formData.steps;
let progressSectionEle = document.querySelector('#progress-section');
progressSectionEle.style.display = 'initial';
let progressEle = document.querySelector('#progress-bar');
progressEle.setAttribute('max', formData.steps);
progressEle.setAttribute('max', totalSteps);
let progressImageEle = document.querySelector('#progress-image');
progressImageEle.src = BLANK_IMAGE_URL;
@ -94,7 +97,7 @@ async function generateSubmit(form) {
document.querySelector("#no-results-message")?.remove();
appendOutput(data.files[0],data.files[1],data.config);
progressEle.setAttribute('value', 0);
progressEle.setAttribute('max', formData.steps);
progressEle.setAttribute('max', totalSteps);
progressImageEle.src = BLANK_IMAGE_URL;
} else if (data.event === 'upscaling-started') {
document.getElementById("processing_cnt").textContent=data.processed_file_cnt;