2022-08-24 21:04:30 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Stable Diffusion WebUI</title>
|
|
|
|
<link rel="icon" href="data:,">
|
|
|
|
<style>
|
|
|
|
* {
|
|
|
|
font-family: 'Arial';
|
|
|
|
}
|
|
|
|
#header {
|
|
|
|
text-decoration: dotted underline;
|
|
|
|
}
|
|
|
|
#search {
|
|
|
|
margin-top: 20vh;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
fieldset {
|
|
|
|
border: none;
|
|
|
|
}
|
|
|
|
#prompt {
|
2022-08-24 21:26:22 +00:00
|
|
|
width: 500px;
|
2022-08-24 21:04:30 +00:00
|
|
|
border-radius: 20px 0px 0px 20px;
|
|
|
|
padding: 5px 10px 5px 10px;
|
|
|
|
border: 1px solid black;
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
#submit {
|
|
|
|
border-radius: 0px 20px 20px 0px;
|
|
|
|
padding: 5px 10px 5px 10px;
|
|
|
|
border: 1px solid black;
|
|
|
|
}
|
|
|
|
#results {
|
|
|
|
text-align: center;
|
|
|
|
padding-left: 20vw;
|
|
|
|
padding-right: 20vw;
|
|
|
|
padding-top: 10px;
|
|
|
|
}
|
|
|
|
img {
|
2022-08-24 21:26:22 +00:00
|
|
|
cursor: pointer;
|
|
|
|
height: 30vh;
|
|
|
|
border-radius: 5px;
|
|
|
|
margin: 10px;
|
2022-08-24 21:04:30 +00:00
|
|
|
}
|
|
|
|
input[type="number"] {
|
2022-08-24 21:26:22 +00:00
|
|
|
width: 60px;
|
|
|
|
}
|
|
|
|
#seed {
|
|
|
|
width: 150px;
|
2022-08-24 21:04:30 +00:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
function append_output(output) {
|
|
|
|
let output_node = document.createElement("img");
|
|
|
|
output_node.src = output[0];
|
|
|
|
|
|
|
|
let alt_text = output[1].toString() + " | " + output[2];
|
|
|
|
output_node.alt = alt_text;
|
|
|
|
output_node.title = alt_text;
|
2022-08-24 21:26:22 +00:00
|
|
|
// Update seed on click
|
|
|
|
output_node.addEventListener('click', () => {
|
|
|
|
document.querySelector("#seed").value = output[1];
|
|
|
|
});
|
2022-08-24 21:04:30 +00:00
|
|
|
|
|
|
|
document.querySelector("#results").prepend(output_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
function append_outputs(outputs) {
|
|
|
|
for (const output of outputs) {
|
|
|
|
append_output(output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function save_fields(form) {
|
|
|
|
for (const [k, v] of new FormData(form)) {
|
|
|
|
localStorage.setItem(k, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function load_fields(form) {
|
|
|
|
for (const [k, v] of new FormData(form)) {
|
|
|
|
const item = localStorage.getItem(k);
|
|
|
|
if (item != null) {
|
|
|
|
form.querySelector(`*[name=${k}]`).value = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onload = () => {
|
|
|
|
document.querySelector("#generate_form").addEventListener('submit', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const form = e.target;
|
2022-08-24 21:28:59 +00:00
|
|
|
const prompt = document.querySelector("#prompt").value;
|
2022-08-24 21:04:30 +00:00
|
|
|
|
|
|
|
// Post as JSON
|
|
|
|
fetch(form.action, {
|
|
|
|
method: form.method,
|
|
|
|
body: JSON.stringify(Object.fromEntries(new FormData(form))),
|
|
|
|
}).then((result) => {
|
|
|
|
result.json().then((data) => {
|
|
|
|
// Re-enable form, remove no-results-message
|
|
|
|
form.querySelector('fieldset').removeAttribute('disabled');
|
2022-08-24 21:28:59 +00:00
|
|
|
document.querySelector("#prompt").value = prompt;
|
2022-08-24 21:04:30 +00:00
|
|
|
|
|
|
|
if (data.outputs.length != 0) {
|
|
|
|
document.querySelector("#no_results_message")?.remove();
|
|
|
|
append_outputs(data.outputs);
|
|
|
|
} else {
|
|
|
|
alert("Error occurred while generating.");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Disable form
|
|
|
|
form.querySelector('fieldset').setAttribute('disabled','');
|
2022-08-24 21:28:59 +00:00
|
|
|
document.querySelector("#prompt").value = `Generating: "${prompt}"`;
|
2022-08-24 21:04:30 +00:00
|
|
|
});
|
|
|
|
document.querySelector("#generate_form").addEventListener('change', (e) => {
|
|
|
|
save_fields(e.target.form);
|
|
|
|
});
|
|
|
|
load_fields(document.querySelector("#generate_form"));
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="search">
|
|
|
|
<h2 id="header">Stable Diffusion</h2>
|
|
|
|
|
|
|
|
<form id="generate_form" method="post" action="#">
|
|
|
|
<fieldset>
|
|
|
|
<input type="text" id="prompt" name="prompt">
|
|
|
|
<input type="submit" id="submit" value="Generate">
|
|
|
|
</fieldset>
|
|
|
|
<fieldset>
|
|
|
|
<label for="batch">Batch Size:</label>
|
|
|
|
<input value="1" type="number" id="batch" name="batch">
|
|
|
|
<label for="steps">Steps:</label>
|
|
|
|
<input value="50" type="number" id="steps" name="steps">
|
|
|
|
<label for="cfgscale">Cfg Scale:</label>
|
|
|
|
<input value="7.5" type="number" id="cfgscale" name="cfgscale" step="any">
|
|
|
|
<span>•</span>
|
|
|
|
<label title="Set to multiple of 64" for="width">Width:</label>
|
|
|
|
<input value="512" type="number" id="width" name="width">
|
|
|
|
<label title="Set to multiple of 64" for="height">Height:</label>
|
|
|
|
<input value="512" type="number" id="height" name="height">
|
|
|
|
<span>•</span>
|
|
|
|
<label title="Set to -1 for random seed" for="seed">Seed:</label>
|
|
|
|
<input value="-1" type="number" id="seed" name="seed">
|
|
|
|
</fieldset>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<hr style="width: 200px">
|
|
|
|
<div id="results">
|
|
|
|
<div id="no_results_message">
|
|
|
|
<i><p>No results...</p></i>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|