better logic for clicking to make variations

This commit is contained in:
Denis Olshin 2022-09-08 01:51:47 +03:00
parent d1d044aa87
commit d7e67b62f0
2 changed files with 16 additions and 19 deletions

View File

@ -75,8 +75,8 @@ class DreamServer(BaseHTTPRequestHandler):
seamless = 'seamless' in post_data seamless = 'seamless' in post_data
cfgscale = float(post_data['cfgscale']) cfgscale = float(post_data['cfgscale'])
sampler_name = post_data['sampler'] sampler_name = post_data['sampler']
variation_amount = float(post_data['variation_amount']) variation_amount = float(post_data['variation_amount']) if int(post_data['seed']) == -1 else 0.0
with_variations = post_data['with_variations'] 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 gfpgan_strength = float(post_data['gfpgan_strength']) if gfpgan_model_exists else 0
upscale_level = post_data['upscale_level'] upscale_level = post_data['upscale_level']
upscale_strength = post_data['upscale_strength'] upscale_strength = post_data['upscale_strength']
@ -129,7 +129,8 @@ class DreamServer(BaseHTTPRequestHandler):
name = f'{prefix}.{seed}.png' name = f'{prefix}.{seed}.png'
path = pngwriter.save_image_and_prompt_to_png(image, f'{prompt} -S{seed}', name) 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! # Append post_data to log, but only once!
if not upscaled: if not upscaled:
with open(os.path.join(self.outdir, "dream_web_log.txt"), "a") as log: with open(os.path.join(self.outdir, "dream_web_log.txt"), "a") as log:

View File

@ -9,7 +9,13 @@ function toBase64(file) {
function appendOutput(src, seed, config) { function appendOutput(src, seed, config) {
let outputNode = document.createElement("figure"); 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 = ` const figureContents = `
<a href="${src}" target="_blank"> <a href="${src}" target="_blank">
@ -19,7 +25,7 @@ function appendOutput(src, seed, config) {
`; `;
outputNode.innerHTML = figureContents; outputNode.innerHTML = figureContents;
let figcaption = outputNode.querySelector('figcaption') let figcaption = outputNode.querySelector('figcaption');
// Reload image config // Reload image config
figcaption.addEventListener('click', () => { figcaption.addEventListener('click', () => {
@ -28,21 +34,11 @@ function appendOutput(src, seed, config) {
if (k == 'initimg') { continue; } if (k == 'initimg') { continue; }
form.querySelector(`*[name=${k}]`).value = config[k]; 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) { document.querySelector("#seed").value = baseseed;
let oldVarAmt = document.querySelector("#variation_amount").value document.querySelector("#with_variations").value = variations || '';
let oldVariations = document.querySelector("#with_variations").value if (document.querySelector("#variation_amount").value <= 0) {
let varSep = '' document.querySelector("#variation_amount").value = 0.2;
document.querySelector("#variation_amount").value = 0;
if (document.querySelector("#with_variations").value != '') {
varSep = ","
}
document.querySelector("#with_variations").value = oldVariations + varSep + seed + ':' + config.variation_amount
} }
saveFields(document.querySelector("#generate-form")); saveFields(document.querySelector("#generate-form"));