Read prompts from a text file; Allow specifying multiple prompts in the textbox by separating them by new lines

This commit is contained in:
cmdr2 2022-10-07 23:46:56 +05:30
parent bccf7e3f69
commit 66f39e070b
3 changed files with 48 additions and 8 deletions

View File

@ -4,7 +4,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="/media/favicon-16x16.png" sizes="16x16"> <link rel="icon" type="image/png" href="/media/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="/media/favicon-32x32.png" sizes="32x32"> <link rel="icon" type="image/png" href="/media/favicon-32x32.png" sizes="32x32">
<link rel="stylesheet" href="/media/main.css?v=21"> <link rel="stylesheet" href="/media/main.css?v=22">
<link rel="stylesheet" href="/media/modifier-thumbnails.css?v=1"> <link rel="stylesheet" href="/media/modifier-thumbnails.css?v=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">
<link rel="stylesheet" href="/media/drawingboard.min.css"> <link rel="stylesheet" href="/media/drawingboard.min.css">
@ -15,7 +15,7 @@
<div id="container"> <div id="container">
<div id="top-nav"> <div id="top-nav">
<div id="logo"> <div id="logo">
<h1>Stable Diffusion UI <small>v2.2 <span id="updateBranchLabel"></span></small></h1> <h1>Stable Diffusion UI <small>v2.21 <span id="updateBranchLabel"></span></small></h1>
</div> </div>
<ul id="top-nav-items"> <ul id="top-nav-items">
<li class="dropdown"> <li class="dropdown">
@ -57,10 +57,12 @@
<div id="editor-inputs-prompt" class="row"> <div id="editor-inputs-prompt" class="row">
<label for="prompt">Prompt</label> <label for="prompt">Prompt</label>
<textarea id="prompt" class="col-free">a photograph of an astronaut riding a horse</textarea> <textarea id="prompt" class="col-free">a photograph of an astronaut riding a horse</textarea>
<small>(or)</small> <button id="promptsFromFileBtn">Load prompts from a file</button> <small>(one prompt per line)</small>
<input id="prompt_from_file" name="prompt_from_file" type="file" /> <!-- hidden -->
</div> </div>
<div id="editor-inputs-init-image" class="row"> <div id="editor-inputs-init-image" class="row">
<label for="init_image"><b>Initial Image:</b> (optional) </label> <input id="init_image" name="init_image" type="file" /><br/> <label for="init_image"><b>Initial Image (img2img):</b> (optional) </label> <input id="init_image" name="init_image" type="file" /><br/>
<div id="init_image_preview_container" class="image_preview_container"> <div id="init_image_preview_container" class="image_preview_container">
<img id="init_image_preview" src="" width="100" height="100" /> <img id="init_image_preview" src="" width="100" height="100" />
@ -224,7 +226,7 @@
</div> </div>
</body> </body>
<script src="media/main.js?v=31"></script> <script src="media/main.js?v=32"></script>
<script> <script>
async function init() { async function init() {
await loadModifiers() await loadModifiers()

View File

@ -410,4 +410,7 @@ img {
} }
.img-batch { .img-batch {
display: inline; display: inline;
}
#prompt_from_file {
display: none;
} }

View File

@ -18,6 +18,8 @@ const IMAGE_REGEX = new RegExp('data:image/[A-Za-z]+;base64')
let sessionId = new Date().getTime() let sessionId = new Date().getTime()
let promptField = document.querySelector('#prompt') let promptField = document.querySelector('#prompt')
let promptsFromFileSelector = document.querySelector('#prompt_from_file')
let promptsFromFileBtn = document.querySelector('#promptsFromFileBtn')
let negativePromptField = document.querySelector('#negative_prompt') let negativePromptField = document.querySelector('#negative_prompt')
let numOutputsTotalField = document.querySelector('#num_outputs_total') let numOutputsTotalField = document.querySelector('#num_outputs_total')
let numOutputsParallelField = document.querySelector('#num_outputs_parallel') let numOutputsParallelField = document.querySelector('#num_outputs_parallel')
@ -588,12 +590,27 @@ async function checkTasks() {
} }
setTimeout(checkTasks, 0) setTimeout(checkTasks, 0)
async function makeImage() { function makeImage() {
if (serverStatus !== 'online') { if (serverStatus !== 'online') {
alert('The server is still starting up..') alert('The server is still starting up..')
return return
} }
let prompts = promptField.value
prompts = prompts.split('\n')
prompts.forEach(prompt => {
prompt = prompt.trim()
if (prompt === '') {
return
}
createTask(prompt)
})
initialText.style.display = 'none'
}
function createTask(prompt) {
let task = { let task = {
stopped: false, stopped: false,
batchesDone: 0 batchesDone: 0
@ -607,7 +624,6 @@ async function makeImage() {
let streamImageProgress = (numOutputsTotal > 50 ? false : streamImageProgressField.checked) let streamImageProgress = (numOutputsTotal > 50 ? false : streamImageProgressField.checked)
let prompt = promptField.value
if (activeTags.length > 0) { if (activeTags.length > 0) {
let promptTags = activeTags.map(x => x.name).join(", ") let promptTags = activeTags.map(x => x.name).join(", ")
prompt += ", " + promptTags prompt += ", " + promptTags
@ -729,8 +745,6 @@ async function makeImage() {
task['previewPrompt'].innerText = prompt task['previewPrompt'].innerText = prompt
taskQueue.unshift(task) taskQueue.unshift(task)
initialText.style.display = 'none'
} }
// create a file name with embedded prompt and metadata // create a file name with embedded prompt and metadata
@ -1032,6 +1046,27 @@ maskSetting.addEventListener('click', function() {
inpaintingEditorContainer.style.display = (this.checked ? 'block' : 'none') inpaintingEditorContainer.style.display = (this.checked ? 'block' : 'none')
}) })
promptsFromFileBtn.addEventListener('click', function() {
promptsFromFileSelector.click()
})
promptsFromFileSelector.addEventListener('change', function() {
if (promptsFromFileSelector.files.length === 0) {
return
}
let reader = new FileReader()
let file = promptsFromFileSelector.files[0]
reader.addEventListener('load', function() {
promptField.value = reader.result
})
if (file) {
reader.readAsText(file)
}
})
// function showMaskImagePreview() { // function showMaskImagePreview() {
// if (maskImageSelector.files.length === 0) { // if (maskImageSelector.files.length === 0) {
// // maskImagePreviewContainer.style.display = 'none' // // maskImagePreviewContainer.style.display = 'none'