diff --git a/ldm/dream/server.py b/ldm/dream/server.py index 10cd7d722e..f22c5847e2 100644 --- a/ldm/dream/server.py +++ b/ldm/dream/server.py @@ -75,6 +75,8 @@ class DreamServer(BaseHTTPRequestHandler): seamless = 'seamless' in post_data cfgscale = float(post_data['cfgscale']) sampler_name = post_data['sampler'] + variation_amount = float(post_data['variation_amount']) + with_variations = post_data['with_variations'] gfpgan_strength = float(post_data['gfpgan_strength']) if gfpgan_model_exists else 0 upscale_level = post_data['upscale_level'] upscale_strength = post_data['upscale_strength'] @@ -82,6 +84,30 @@ class DreamServer(BaseHTTPRequestHandler): progress_images = 'progress_images' in post_data seed = self.model.seed if int(post_data['seed']) == -1 else int(post_data['seed']) + if with_variations != '': + parts = [] + broken = False + for part in with_variations.split(','): + seed_and_weight = part.split(':') + if len(seed_and_weight) != 2: + print(f'could not parse with_variation part "{part}"') + broken = True + break + try: + vseed = int(seed_and_weight[0]) + vweight = float(seed_and_weight[1]) + except ValueError: + print(f'could not parse with_variation part "{part}"') + broken = True + break + parts.append([vseed, vweight]) + if broken: + raise CanceledException + if len(parts) > 0: + with_variations = parts + else: + with_variations = None + self.canceled.clear() print(f">> Request to generate with prompt: {prompt}") # In order to handle upscaled images, the PngWriter needs to maintain state @@ -163,6 +189,8 @@ class DreamServer(BaseHTTPRequestHandler): height = height, seed = seed, steps = steps, + variation_amount = variation_amount, + with_variations = with_variations, gfpgan_strength = gfpgan_strength, upscale = upscale, sampler_name = sampler_name, @@ -184,6 +212,8 @@ class DreamServer(BaseHTTPRequestHandler): cfg_scale = cfgscale, seed = seed, steps = steps, + variation_amount = variation_amount, + with_variations = with_variations, sampler_name = sampler_name, width = width, height = height, diff --git a/static/dream_web/index.css b/static/dream_web/index.css index aa5e349770..117db7b5fb 100644 --- a/static/dream_web/index.css +++ b/static/dream_web/index.css @@ -125,6 +125,9 @@ label { #txt2img { background-color: #DCDCDC; } +#variations { + background-color: #EEEEEE; +} #img2img { background-color: #F5F5F5; } diff --git a/static/dream_web/index.html b/static/dream_web/index.html index 980bd0fcc5..466e165ffd 100644 --- a/static/dream_web/index.html +++ b/static/dream_web/index.html @@ -23,7 +23,7 @@ +
@@ -40,7 +40,7 @@ - + @@ -68,23 +68,28 @@ - - - -
-
- - - -
- - - - + + +
+ + + + +
+
+ + + +
+ + + + +
@@ -105,7 +110,7 @@
- +
Postprocessing...1/3
diff --git a/static/dream_web/index.js b/static/dream_web/index.js index e2806d4d10..4d1fbe3778 100644 --- a/static/dream_web/index.js +++ b/static/dream_web/index.js @@ -25,10 +25,25 @@ function appendOutput(src, seed, config) { figcaption.addEventListener('click', () => { let form = document.querySelector("#generate-form"); for (const [k, v] of new FormData(form)) { - if (k == 'initimg') { continue; } - form.querySelector(`*[name=${k}]`).value = config[k]; + if (k == 'initimg') { continue; } + form.querySelector(`*[name=${k}]`).value = config[k]; + } + if (config.variation_amount > 0 || config.with_variations != '') { + document.querySelector("#seed").value = config.seed; + } else { + document.querySelector("#seed").value = seed; + } + + if (config.variation_amount > 0) { + let oldVarAmt = document.querySelector("#variation_amount").value + let oldVariations = document.querySelector("#with_variations").value + let varSep = '' + document.querySelector("#variation_amount").value = 0; + if (document.querySelector("#with_variations").value != '') { + varSep = "," + } + document.querySelector("#with_variations").value = oldVariations + varSep + seed + ':' + config.variation_amount } - document.querySelector("#seed").value = seed; saveFields(document.querySelector("#generate-form")); });