Skip to content

Commit f628477

Browse files
committed
Squashed commit of the following:
commit 7d1344282d942a33dcecda4d5144fc154ec82915 Merge: caf4ea3 ebeb556 Author: Lincoln Stein <[email protected]> Date: Mon Sep 5 10:07:27 2022 -0400 Merge branch 'development' of github.com:WebDev9000/stable-diffusion into WebDev9000-development commit ebeb556 Author: Web Dev 9000 <[email protected]> Date: Sun Sep 4 18:05:15 2022 -0700 Fixed unintentionally removed lines commit ff2c4b9 Author: Web Dev 9000 <[email protected]> Date: Sun Sep 4 17:50:13 2022 -0700 Add ability to recreate variations via image click commit c012929 Author: Web Dev 9000 <[email protected]> Date: Sun Sep 4 14:35:33 2022 -0700 Add files via upload commit 02a6018 Author: Web Dev 9000 <[email protected]> Date: Sun Sep 4 14:35:07 2022 -0700 Add files via upload
1 parent eef7889 commit f628477

File tree

4 files changed

+72
-19
lines changed

4 files changed

+72
-19
lines changed

ldm/dream/server.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,39 @@ def do_POST(self):
7575
seamless = 'seamless' in post_data
7676
cfgscale = float(post_data['cfgscale'])
7777
sampler_name = post_data['sampler']
78+
variation_amount = float(post_data['variation_amount'])
79+
with_variations = post_data['with_variations']
7880
gfpgan_strength = float(post_data['gfpgan_strength']) if gfpgan_model_exists else 0
7981
upscale_level = post_data['upscale_level']
8082
upscale_strength = post_data['upscale_strength']
8183
upscale = [int(upscale_level),float(upscale_strength)] if upscale_level != '' else None
8284
progress_images = 'progress_images' in post_data
8385
seed = self.model.seed if int(post_data['seed']) == -1 else int(post_data['seed'])
8486

87+
if with_variations != '':
88+
parts = []
89+
broken = False
90+
for part in with_variations.split(','):
91+
seed_and_weight = part.split(':')
92+
if len(seed_and_weight) != 2:
93+
print(f'could not parse with_variation part "{part}"')
94+
broken = True
95+
break
96+
try:
97+
vseed = int(seed_and_weight[0])
98+
vweight = float(seed_and_weight[1])
99+
except ValueError:
100+
print(f'could not parse with_variation part "{part}"')
101+
broken = True
102+
break
103+
parts.append([vseed, vweight])
104+
if broken:
105+
raise CanceledException
106+
if len(parts) > 0:
107+
with_variations = parts
108+
else:
109+
with_variations = None
110+
85111
self.canceled.clear()
86112
print(f">> Request to generate with prompt: {prompt}")
87113
# In order to handle upscaled images, the PngWriter needs to maintain state
@@ -163,6 +189,8 @@ def image_progress(sample, step):
163189
height = height,
164190
seed = seed,
165191
steps = steps,
192+
variation_amount = variation_amount,
193+
with_variations = with_variations,
166194
gfpgan_strength = gfpgan_strength,
167195
upscale = upscale,
168196
sampler_name = sampler_name,
@@ -184,6 +212,8 @@ def image_progress(sample, step):
184212
cfg_scale = cfgscale,
185213
seed = seed,
186214
steps = steps,
215+
variation_amount = variation_amount,
216+
with_variations = with_variations,
187217
sampler_name = sampler_name,
188218
width = width,
189219
height = height,

static/dream_web/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ label {
125125
#txt2img {
126126
background-color: #DCDCDC;
127127
}
128+
#variations {
129+
background-color: #EEEEEE;
130+
}
128131
#img2img {
129132
background-color: #F5F5F5;
130133
}

static/dream_web/index.html

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h1>Stable Diffusion Dream Server</h1>
2323
<div id="search-box">
2424
<textarea rows="3" id="prompt" name="prompt"></textarea>
2525
<input type="submit" id="submit" value="Generate">
26-
</div>
26+
</div>
2727
</fieldset>
2828
<fieldset id="fieldset-config">
2929
<label for="iterations">Images to generate:</label>
@@ -40,7 +40,7 @@ <h1>Stable Diffusion Dream Server</h1>
4040
<option value="k_dpm_2">KDPM_2</option>
4141
<option value="k_dpm_2_a">KDPM_2A</option>
4242
<option value="k_euler">KEULER</option>
43-
<option value="k_euler_a">KEULER_A</option>
43+
<option value="k_euler_a">KEULER_A</option>
4444
<option value="k_heun">KHEUN</option>
4545
</select>
4646
<input type="checkbox" name="seamless" id="seamless">
@@ -68,23 +68,28 @@ <h1>Stable Diffusion Dream Server</h1>
6868
<option value="832">832</option> <option value="896">896</option>
6969
<option value="960">960</option> <option value="1024">1024</option>
7070
</select>
71-
7271
<label title="Set to -1 for random seed" for="seed">Seed:</label>
7372
<input value="-1" type="number" id="seed" name="seed">
7473
<button type="button" id="reset-seed">&olarr;</button>
7574
<input type="checkbox" name="progress_images" id="progress_images">
76-
<label for="progress_images">Display in-progress images (slower):</label>
77-
<button type="button" id="reset-all">Reset to Defaults</button>
78-
</fieldset>
79-
<fieldset id="img2img">
80-
<label title="Upload an image to use img2img" for="initimg">Initial image:</label>
81-
<input type="file" id="initimg" name="initimg" accept=".jpg, .jpeg, .png">
82-
<button type="button" id="remove-image">Remove Image</button>
83-
<br>
84-
<label for="strength">Img2Img Strength:</label>
85-
<input value="0.75" type="number" id="strength" name="strength" step="0.01" min="0" max="1">
86-
<input type="checkbox" id="fit" name="fit" checked>
87-
<label title="Rescale image to fit within requested width and height" for="fit">Fit to width/height:</label>
75+
<label for="progress_images">Display in-progress images (slower)</label>
76+
<button type="button" id="reset-all">Reset to Defaults</button>
77+
<div id="variations">
78+
<label title="If > 0, generates variations on the initial seed instead of random seeds per iteration. Must be between 0 and 1. Higher values will be more different." for="variation_amount">Variation amount (0 to disable):</label>
79+
<input value="0" type="number" id="variation_amount" name="variation_amount" step="0.01" min="0" max="1">
80+
<label title="list of variations to apply, in the format `seed:weight,seed:weight,..." for="with_variations">With variations (seed:weight,seed:weight,...):</label>
81+
<input value="" type="text" id="with_variations" name="with_variations">
82+
</div>
83+
<div id="img2img">
84+
<label title="Upload an image to use img2img" for="initimg">Initial image:</label>
85+
<input type="file" id="initimg" name="initimg" accept=".jpg, .jpeg, .png">
86+
<button type="button" id="remove-image">Remove Image</button>
87+
<br>
88+
<label for="strength">Img2Img Strength:</label>
89+
<input value="0.75" type="number" id="strength" name="strength" step="0.01" min="0" max="1">
90+
<input type="checkbox" id="fit" name="fit" checked>
91+
<label title="Rescale image to fit within requested width and height" for="fit">Fit to width/height:</label>
92+
</div>
8893
</fieldset>
8994
<fieldset id="gfpgan">
9095
<label title="Strength of the gfpgan (face fixing) algorithm." for="gfpgan_strength">GPFGAN Strength (0 to disable):</label>
@@ -105,7 +110,7 @@ <h1>Stable Diffusion Dream Server</h1>
105110
<progress id="progress-bar" value="0" max="1"></progress>
106111
<span id="cancel-button" title="Cancel">&#10006;</span>
107112
<br>
108-
<img id="progress-image" src='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"/>'></img>
113+
<img id="progress-image" src='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"/>'>
109114
<div id="scaling-inprocess-message">
110115
<i><span>Postprocessing...</span><span id="processing_cnt">1/3</span></i>
111116
</div>

static/dream_web/index.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,25 @@ function appendOutput(src, seed, config) {
2525
figcaption.addEventListener('click', () => {
2626
let form = document.querySelector("#generate-form");
2727
for (const [k, v] of new FormData(form)) {
28-
if (k == 'initimg') { continue; }
29-
form.querySelector(`*[name=${k}]`).value = config[k];
28+
if (k == 'initimg') { continue; }
29+
form.querySelector(`*[name=${k}]`).value = config[k];
30+
}
31+
if (config.variation_amount > 0 || config.with_variations != '') {
32+
document.querySelector("#seed").value = config.seed;
33+
} else {
34+
document.querySelector("#seed").value = seed;
35+
}
36+
37+
if (config.variation_amount > 0) {
38+
let oldVarAmt = document.querySelector("#variation_amount").value
39+
let oldVariations = document.querySelector("#with_variations").value
40+
let varSep = ''
41+
document.querySelector("#variation_amount").value = 0;
42+
if (document.querySelector("#with_variations").value != '') {
43+
varSep = ","
44+
}
45+
document.querySelector("#with_variations").value = oldVariations + varSep + seed + ':' + config.variation_amount
3046
}
31-
document.querySelector("#seed").value = seed;
3247

3348
saveFields(document.querySelector("#generate-form"));
3449
});

0 commit comments

Comments
 (0)