mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-04-27 04:48:23 +02:00
Show the approximate time remaining
This commit is contained in:
parent
74a9c46f08
commit
1d88a5b42e
@ -657,13 +657,18 @@ async function doMakeImage(reqBody, batchCount) {
|
|||||||
let reader = res.body.getReader()
|
let reader = res.body.getReader()
|
||||||
let textDecoder = new TextDecoder()
|
let textDecoder = new TextDecoder()
|
||||||
let finalJSON = ''
|
let finalJSON = ''
|
||||||
|
let prevTime = -1
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
|
let t = new Date().getTime()
|
||||||
|
|
||||||
const {value, done} = await reader.read()
|
const {value, done} = await reader.read()
|
||||||
if (done) {
|
if (done) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let timeTaken = (prevTime === -1 ? -1 : t - prevTime)
|
||||||
|
|
||||||
let jsonStr = textDecoder.decode(value)
|
let jsonStr = textDecoder.decode(value)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -677,13 +682,23 @@ async function doMakeImage(reqBody, batchCount) {
|
|||||||
let totalSteps = batchCount * batchSize
|
let totalSteps = batchCount * batchSize
|
||||||
let percent = 100 * (overallStepCount / totalSteps)
|
let percent = 100 * (overallStepCount / totalSteps)
|
||||||
percent = percent.toFixed(0)
|
percent = percent.toFixed(0)
|
||||||
|
|
||||||
|
stepsRemaining = totalSteps - overallStepCount
|
||||||
|
timeRemaining = (timeTaken === -1 ? '' : stepsRemaining * timeTaken) // ms
|
||||||
|
|
||||||
outputMsg.innerHTML = `Batch ${batchesDone+1} of ${batchCount}`
|
outputMsg.innerHTML = `Batch ${batchesDone+1} of ${batchCount}`
|
||||||
progressBar.innerHTML = `Generating image(s): ${percent}%`
|
progressBar.innerHTML = `Generating image(s): ${percent}%`
|
||||||
|
|
||||||
|
if (timeTaken !== -1) {
|
||||||
|
progressBar.innerHTML += `<br>Time remaining (approx): ${millisecondsToStr(timeRemaining)}`
|
||||||
|
}
|
||||||
progressBar.style.display = 'block'
|
progressBar.style.display = 'block'
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
finalJSON += jsonStr
|
finalJSON += jsonStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prevTime = t
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError('Stable Diffusion had an error. Please check the logs in the command-line window. This happens sometimes. Maybe modify the prompt or seed a little bit?', res)
|
logError('Stable Diffusion had an error. Please check the logs in the command-line window. This happens sometimes. Maybe modify the prompt or seed a little bit?', res)
|
||||||
res = undefined
|
res = undefined
|
||||||
@ -1209,6 +1224,30 @@ initImageClearBtn.addEventListener('click', function() {
|
|||||||
// maskImagePreview.src = ''
|
// maskImagePreview.src = ''
|
||||||
// maskImagePreviewContainer.style.display = 'none'
|
// maskImagePreviewContainer.style.display = 'none'
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/8212878
|
||||||
|
function millisecondsToStr(milliseconds) {
|
||||||
|
function numberEnding (number) {
|
||||||
|
return (number > 1) ? 's' : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var temp = Math.floor(milliseconds / 1000);
|
||||||
|
var hours = Math.floor((temp %= 86400) / 3600);
|
||||||
|
var s = ''
|
||||||
|
if (hours) {
|
||||||
|
s += hours + ' hour' + numberEnding(hours) + ' ';
|
||||||
|
}
|
||||||
|
var minutes = Math.floor((temp %= 3600) / 60);
|
||||||
|
if (minutes) {
|
||||||
|
s += minutes + ' minute' + numberEnding(minutes) + ' ';
|
||||||
|
}
|
||||||
|
var seconds = temp % 60;
|
||||||
|
if (!hours && minutes < 4 && seconds) {
|
||||||
|
s += seconds + ' second' + numberEnding(seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
function createCollapsibles(node) {
|
function createCollapsibles(node) {
|
||||||
|
Loading…
Reference in New Issue
Block a user