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
|
|
|
}
|
2022-08-25 03:03:02 +00:00
|
|
|
#generate-config {
|
|
|
|
line-height:2em;
|
|
|
|
}
|
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>
|
2022-08-25 03:03:02 +00:00
|
|
|
function toBase64(file) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const r = new FileReader();
|
|
|
|
r.readAsDataURL(file);
|
|
|
|
r.onload = () => resolve(r.result);
|
|
|
|
r.onerror = (error) => reject(error);
|
|
|
|
});
|
|
|
|
}
|
2022-08-24 21:04:30 +00:00
|
|
|
|
2022-08-25 03:03:02 +00:00
|
|
|
function appendOutput(output) {
|
|
|
|
let outputNode = document.createElement("img");
|
|
|
|
outputNode.src = output[0];
|
|
|
|
|
|
|
|
let outputConfig = output[2];
|
|
|
|
let altText = output[1].toString() + " | " + outputConfig.prompt;
|
|
|
|
outputNode.alt = altText;
|
|
|
|
outputNode.title = altText;
|
2022-08-25 01:38:47 +00:00
|
|
|
|
|
|
|
// Reload image config
|
2022-08-25 03:03:02 +00:00
|
|
|
outputNode.addEventListener('click', () => {
|
|
|
|
let form = document.querySelector("#generate-form");
|
2022-08-25 01:38:47 +00:00
|
|
|
for (const [k, v] of new FormData(form)) {
|
2022-08-25 03:03:02 +00:00
|
|
|
form.querySelector(`*[name=${k}]`).value = outputConfig[k];
|
2022-08-25 01:38:47 +00:00
|
|
|
}
|
2022-08-24 21:26:22 +00:00
|
|
|
document.querySelector("#seed").value = output[1];
|
2022-08-25 01:38:47 +00:00
|
|
|
|
2022-08-25 03:03:02 +00:00
|
|
|
saveFields(document.querySelector("#generate-form"));
|
2022-08-24 21:26:22 +00:00
|
|
|
});
|
2022-08-24 21:04:30 +00:00
|
|
|
|
2022-08-25 03:03:02 +00:00
|
|
|
document.querySelector("#results").prepend(outputNode);
|
2022-08-24 21:04:30 +00:00
|
|
|
}
|
|
|
|
|
2022-08-25 03:03:02 +00:00
|
|
|
function appendOutputs(outputs) {
|
2022-08-24 21:04:30 +00:00
|
|
|
for (const output of outputs) {
|
2022-08-25 03:03:02 +00:00
|
|
|
appendOutput(output);
|
2022-08-24 21:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-25 03:03:02 +00:00
|
|
|
function saveFields(form) {
|
2022-08-24 21:04:30 +00:00
|
|
|
for (const [k, v] of new FormData(form)) {
|
2022-08-25 03:03:02 +00:00
|
|
|
if (typeof v !== 'object') { // Don't save 'file' type
|
|
|
|
localStorage.setItem(k, v);
|
|
|
|
}
|
2022-08-24 21:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-25 03:03:02 +00:00
|
|
|
function loadFields(form) {
|
2022-08-24 21:04:30 +00:00
|
|
|
for (const [k, v] of new FormData(form)) {
|
|
|
|
const item = localStorage.getItem(k);
|
|
|
|
if (item != null) {
|
|
|
|
form.querySelector(`*[name=${k}]`).value = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-25 03:03:02 +00:00
|
|
|
|
|
|
|
async function generateSubmit(form) {
|
|
|
|
const prompt = document.querySelector("#prompt").value;
|
|
|
|
|
|
|
|
// Convert file data to base64
|
|
|
|
let formData = Object.fromEntries(new FormData(form));
|
|
|
|
formData.initimg = formData.initimg.name !== '' ? await toBase64(formData.initimg) : null;
|
|
|
|
|
|
|
|
// Post as JSON
|
|
|
|
fetch(form.action, {
|
|
|
|
method: form.method,
|
|
|
|
body: JSON.stringify(formData),
|
|
|
|
}).then(async (result) => {
|
|
|
|
let data = await result.json();
|
|
|
|
|
|
|
|
// Re-enable form, remove no-results-message
|
|
|
|
form.querySelector('fieldset').removeAttribute('disabled');
|
|
|
|
document.querySelector("#prompt").value = prompt;
|
|
|
|
|
|
|
|
if (data.outputs.length != 0) {
|
|
|
|
document.querySelector("#no-results-message")?.remove();
|
|
|
|
appendOutputs(data.outputs);
|
|
|
|
} else {
|
|
|
|
alert("Error occurred while generating.");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Disable form while generating
|
|
|
|
form.querySelector('fieldset').setAttribute('disabled','');
|
|
|
|
document.querySelector("#prompt").value = `Generating: "${prompt}"`;
|
|
|
|
}
|
2022-08-24 21:04:30 +00:00
|
|
|
|
|
|
|
window.onload = () => {
|
2022-08-25 03:03:02 +00:00
|
|
|
document.querySelector("#generate-form").addEventListener('submit', (e) => {
|
2022-08-24 21:04:30 +00:00
|
|
|
e.preventDefault();
|
|
|
|
const form = e.target;
|
|
|
|
|
2022-08-25 03:03:02 +00:00
|
|
|
generateSubmit(form);
|
2022-08-24 21:04:30 +00:00
|
|
|
});
|
2022-08-25 03:03:02 +00:00
|
|
|
document.querySelector("#generate-form").addEventListener('change', (e) => {
|
|
|
|
saveFields(e.target.form);
|
2022-08-24 21:04:30 +00:00
|
|
|
});
|
2022-08-25 01:38:47 +00:00
|
|
|
document.querySelector("#reset").addEventListener('click', (e) => {
|
|
|
|
document.querySelector("#seed").value = -1;
|
2022-08-25 03:03:02 +00:00
|
|
|
saveFields(e.target.form);
|
2022-08-25 01:38:47 +00:00
|
|
|
});
|
2022-08-25 03:03:02 +00:00
|
|
|
loadFields(document.querySelector("#generate-form"));
|
2022-08-24 21:04:30 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="search">
|
|
|
|
<h2 id="header">Stable Diffusion</h2>
|
|
|
|
|
2022-08-25 03:03:02 +00:00
|
|
|
<form id="generate-form" method="post" action="#">
|
2022-08-24 21:04:30 +00:00
|
|
|
<fieldset>
|
|
|
|
<input type="text" id="prompt" name="prompt">
|
|
|
|
<input type="submit" id="submit" value="Generate">
|
|
|
|
</fieldset>
|
2022-08-25 03:03:02 +00:00
|
|
|
<fieldset id="generate-config">
|
2022-08-24 21:04:30 +00:00
|
|
|
<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">
|
2022-08-25 03:03:02 +00:00
|
|
|
<br>
|
|
|
|
<label title="Upload an image to use img2img" for="initimg">Img2Img Init:</label>
|
|
|
|
<input type="file" id="initimg" name="initimg" accept=".jpg, .jpeg, .png">
|
2022-08-24 21:04:30 +00:00
|
|
|
<label title="Set to -1 for random seed" for="seed">Seed:</label>
|
|
|
|
<input value="-1" type="number" id="seed" name="seed">
|
2022-08-25 01:38:47 +00:00
|
|
|
<button type="button" id="reset">↺</button>
|
2022-08-24 21:04:30 +00:00
|
|
|
</fieldset>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<hr style="width: 200px">
|
|
|
|
<div id="results">
|
2022-08-25 03:03:02 +00:00
|
|
|
<div id="no-results-message">
|
2022-08-24 21:04:30 +00:00
|
|
|
<i><p>No results...</p></i>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|