Skip to content

Commit

Permalink
better logic for clicking to make variations
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Olshin committed Sep 7, 2022
1 parent d1d044a commit d7e67b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
7 changes: 4 additions & 3 deletions ldm/dream/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def do_POST(self):
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']
variation_amount = float(post_data['variation_amount']) if int(post_data['seed']) == -1 else 0.0
with_variations = post_data['with_variations'] if int(post_data['seed']) == -1 else ''
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']
Expand Down Expand Up @@ -129,7 +129,8 @@ def image_done(image, seed, upscaled=False):
name = f'{prefix}.{seed}.png'
path = pngwriter.save_image_and_prompt_to_png(image, f'{prompt} -S{seed}', name)

config['seed'] = seed
if int(config['seed']) == -1:
config['seed'] = seed
# Append post_data to log, but only once!
if not upscaled:
with open(os.path.join(self.outdir, "dream_web_log.txt"), "a") as log:
Expand Down
28 changes: 12 additions & 16 deletions static/dream_web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ function toBase64(file) {

function appendOutput(src, seed, config) {
let outputNode = document.createElement("figure");
let altText = seed.toString() + " | " + config.prompt;

let variations = config.with_variations;
if (config.variation_amount > 0) {
variations = (variations ? variations + ',' : '') + seed + ':' + config.variation_amount;
}
let baseseed = (config.with_variations || config.variation_amount > 0) ? config.seed : seed;
let altText = baseseed + ' | ' + (variations ? variations + ' | ' : '') + config.prompt;

const figureContents = `
<a href="${src}" target="_blank">
Expand All @@ -19,7 +25,7 @@ function appendOutput(src, seed, config) {
`;

outputNode.innerHTML = figureContents;
let figcaption = outputNode.querySelector('figcaption')
let figcaption = outputNode.querySelector('figcaption');

// Reload image config
figcaption.addEventListener('click', () => {
Expand All @@ -28,21 +34,11 @@ function appendOutput(src, seed, config) {
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 = baseseed;
document.querySelector("#with_variations").value = variations || '';
if (document.querySelector("#variation_amount").value <= 0) {
document.querySelector("#variation_amount").value = 0.2;
}

saveFields(document.querySelector("#generate-form"));
Expand Down

0 comments on commit d7e67b6

Please sign in to comment.