mirror of
https://github.com/anapnoe/stable-diffusion-webui-ux.git
synced 2026-09-08 05:58:45 +02:00
update to sdxl
This commit is contained in:
+115
-137
@@ -36,13 +36,13 @@ function pad2(x) {
|
||||
}
|
||||
|
||||
function formatTime(secs) {
|
||||
if (secs > 3600) {
|
||||
return pad2(Math.floor(secs / 60 / 60)) + ":" + pad2(Math.floor(secs / 60) % 60) + ":" + pad2(Math.floor(secs) % 60);
|
||||
} else if (secs > 60) {
|
||||
return pad2(Math.floor(secs / 60)) + ":" + pad2(Math.floor(secs) % 60);
|
||||
} else {
|
||||
return Math.floor(secs) + "s";
|
||||
}
|
||||
if (secs > 3600) {
|
||||
return pad2(Math.floor(secs / 60 / 60)) + ":" + pad2(Math.floor(secs / 60) % 60) + ":" + pad2(Math.floor(secs) % 60);
|
||||
} else if (secs > 60) {
|
||||
return pad2(Math.floor(secs / 60)) + ":" + pad2(Math.floor(secs) % 60);
|
||||
} else {
|
||||
return Math.floor(secs) + "s";
|
||||
}
|
||||
}
|
||||
|
||||
function setTitle(progress) {
|
||||
@@ -57,6 +57,7 @@ function setTitle(progress) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function randomId() {
|
||||
return "task(" + Math.random().toString(36).slice(2, 7) + Math.random().toString(36).slice(2, 7) + Math.random().toString(36).slice(2, 7) + ")";
|
||||
}
|
||||
@@ -64,145 +65,122 @@ function randomId() {
|
||||
// starts sending progress requests to "/internal/progress" uri, creating progressbar above progressbarContainer element and
|
||||
// preview inside gallery element. Cleans up all created stuff when the task is over and calls atEnd.
|
||||
// calls onProgress every time there is a progress update
|
||||
function requestProgress(
|
||||
id_task,
|
||||
progressbarContainer,
|
||||
gallery,
|
||||
atEnd,
|
||||
onProgress,
|
||||
inactivityTimeout = 40
|
||||
) {
|
||||
var dateStart = new Date();
|
||||
var wasEverActive = false;
|
||||
var parentProgressbar = progressbarContainer.parentNode;
|
||||
var parentGallery = gallery ? gallery.parentNode : null;
|
||||
function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgress, inactivityTimeout = 40) {
|
||||
var dateStart = new Date();
|
||||
var wasEverActive = false;
|
||||
var parentProgressbar = progressbarContainer.parentNode;
|
||||
|
||||
var divProgress = document.createElement("div");
|
||||
divProgress.className = "progressDiv";
|
||||
var divProgress = document.createElement('div');
|
||||
divProgress.className = 'progressDiv';
|
||||
divProgress.style.display = opts.show_progressbar ? "block" : "none";
|
||||
var divInner = document.createElement('div');
|
||||
divInner.className = 'progress';
|
||||
|
||||
divProgress.style.display = opts.show_progressbar ? "block" : "none";
|
||||
var divInner = document.createElement("div");
|
||||
divInner.className = "progress";
|
||||
divProgress.appendChild(divInner);
|
||||
parentProgressbar.insertBefore(divProgress, progressbarContainer);
|
||||
|
||||
divProgress.appendChild(divInner);
|
||||
parentProgressbar.insertBefore(divProgress, progressbarContainer);
|
||||
var livePreview = null;
|
||||
|
||||
if (parentGallery) {
|
||||
var livePreview = gradioApp().querySelector(".livePreview");
|
||||
if (!livePreview) {
|
||||
livePreview = document.createElement("div");
|
||||
livePreview.classList.add("livePreview", "init");
|
||||
parentGallery.insertBefore(livePreview, gallery);
|
||||
}
|
||||
livePreview.classList.remove("dropPreview");
|
||||
}
|
||||
var removeProgressBar = function() {
|
||||
if (!divProgress) return;
|
||||
|
||||
var removeProgressBar = function () {
|
||||
setTitle("");
|
||||
if (divProgress) {
|
||||
parentProgressbar.removeChild(divProgress);
|
||||
}
|
||||
setTitle("");
|
||||
parentProgressbar.removeChild(divProgress);
|
||||
if (gallery && livePreview) gallery.removeChild(livePreview);
|
||||
atEnd();
|
||||
|
||||
if (progressbarContainer.id == "txt2img_gallery_container") {
|
||||
showSubmitButtons("txt2img", true);
|
||||
} else if (progressbarContainer.id == "img2img_gallery_container") {
|
||||
showSubmitButtons("img2img", true);
|
||||
}
|
||||
if (livePreview) {
|
||||
if (parentGallery) parentGallery.removeChild(livePreview);
|
||||
}
|
||||
gradioApp()
|
||||
.querySelectorAll("#tabs + div, #tabs + div > *:not(ul)")
|
||||
.forEach(function (elem) {
|
||||
elem.style.setProperty("display", "block", "important");
|
||||
});
|
||||
atEnd();
|
||||
};
|
||||
divProgress = null;
|
||||
};
|
||||
|
||||
var fun = function (id_task, id_live_preview) {
|
||||
request(
|
||||
"./internal/progress",
|
||||
{ id_task: id_task, id_live_preview: id_live_preview },
|
||||
function (res) {
|
||||
if (res.completed) {
|
||||
removeProgressBar();
|
||||
return;
|
||||
}
|
||||
|
||||
var rect = progressbarContainer.getBoundingClientRect();
|
||||
|
||||
if (rect.width) {
|
||||
divProgress.style.width = rect.width + "px";
|
||||
}
|
||||
|
||||
let progressText = "";
|
||||
|
||||
divInner.style.width = (res.progress || 0) * 100.0 + "%";
|
||||
divInner.style.background = res.progress ? "" : "transparent";
|
||||
|
||||
if (res.progress > 0) {
|
||||
progressText = ((res.progress || 0) * 100.0).toFixed(0) + "%";
|
||||
}
|
||||
|
||||
if (res.eta) {
|
||||
progressText += " ETA: " + formatTime(res.eta);
|
||||
}
|
||||
|
||||
setTitle(progressText);
|
||||
|
||||
if (res.textinfo && res.textinfo.indexOf("\n") == -1) {
|
||||
progressText = res.textinfo + " " + progressText;
|
||||
}
|
||||
|
||||
divInner.textContent = progressText;
|
||||
|
||||
var elapsedFromStart = (new Date() - dateStart) / 1000;
|
||||
|
||||
if (res.active) wasEverActive = true;
|
||||
|
||||
if (!res.active && wasEverActive) {
|
||||
removeProgressBar();
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
elapsedFromStart > inactivityTimeout &&
|
||||
!res.queued &&
|
||||
!res.active
|
||||
) {
|
||||
removeProgressBar();
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.live_preview && gallery) {
|
||||
|
||||
livePreview.classList.remove("init");
|
||||
|
||||
var img = new Image();
|
||||
img.onload = function () {
|
||||
img.width = img.naturalWidth;
|
||||
img.height = img.naturalHeight;
|
||||
livePreview.appendChild(img);
|
||||
if (livePreview.childElementCount > 2) {
|
||||
livePreview.removeChild(livePreview.firstElementChild);
|
||||
var funProgress = function(id_task) {
|
||||
request("./internal/progress", {id_task: id_task, live_preview: false}, function(res) {
|
||||
if (res.completed) {
|
||||
removeProgressBar();
|
||||
return;
|
||||
}
|
||||
};
|
||||
img.src = res.live_preview;
|
||||
}
|
||||
|
||||
if (onProgress) {
|
||||
onProgress(res);
|
||||
}
|
||||
let progressText = "";
|
||||
|
||||
setTimeout(() => {
|
||||
fun(id_task, res.id_live_preview);
|
||||
}, opts.live_preview_refresh_period || 500);
|
||||
},
|
||||
function () {
|
||||
removeProgressBar();
|
||||
}
|
||||
);
|
||||
};
|
||||
divInner.style.width = ((res.progress || 0) * 100.0) + '%';
|
||||
divInner.style.background = res.progress ? "" : "transparent";
|
||||
|
||||
if (res.progress > 0) {
|
||||
progressText = ((res.progress || 0) * 100.0).toFixed(0) + '%';
|
||||
}
|
||||
|
||||
if (res.eta) {
|
||||
progressText += " ETA: " + formatTime(res.eta);
|
||||
}
|
||||
|
||||
setTitle(progressText);
|
||||
|
||||
if (res.textinfo && res.textinfo.indexOf("\n") == -1) {
|
||||
progressText = res.textinfo + " " + progressText;
|
||||
}
|
||||
|
||||
divInner.textContent = progressText;
|
||||
|
||||
var elapsedFromStart = (new Date() - dateStart) / 1000;
|
||||
|
||||
if (res.active) wasEverActive = true;
|
||||
|
||||
if (!res.active && wasEverActive) {
|
||||
removeProgressBar();
|
||||
return;
|
||||
}
|
||||
|
||||
if (elapsedFromStart > inactivityTimeout && !res.queued && !res.active) {
|
||||
removeProgressBar();
|
||||
return;
|
||||
}
|
||||
|
||||
if (onProgress) {
|
||||
onProgress(res);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
funProgress(id_task, res.id_live_preview);
|
||||
}, opts.live_preview_refresh_period || 500);
|
||||
}, function() {
|
||||
removeProgressBar();
|
||||
});
|
||||
};
|
||||
|
||||
var funLivePreview = function(id_task, id_live_preview) {
|
||||
request("./internal/progress", {id_task: id_task, id_live_preview: id_live_preview}, function(res) {
|
||||
if (!divProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.live_preview && gallery) {
|
||||
var img = new Image();
|
||||
img.onload = function() {
|
||||
if (!livePreview) {
|
||||
livePreview = document.createElement('div');
|
||||
livePreview.className = 'livePreview';
|
||||
gallery.insertBefore(livePreview, gallery.firstElementChild);
|
||||
}
|
||||
|
||||
livePreview.appendChild(img);
|
||||
if (livePreview.childElementCount > 2) {
|
||||
livePreview.removeChild(livePreview.firstElementChild);
|
||||
}
|
||||
};
|
||||
img.src = res.live_preview;
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
funLivePreview(id_task, res.id_live_preview);
|
||||
}, opts.live_preview_refresh_period || 500);
|
||||
}, function() {
|
||||
removeProgressBar();
|
||||
});
|
||||
};
|
||||
|
||||
funProgress(id_task, 0);
|
||||
|
||||
if (gallery) {
|
||||
funLivePreview(id_task, 0);
|
||||
}
|
||||
|
||||
fun(id_task, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user