add a button to restore the current progress

This commit is contained in:
siutin
2023-02-06 03:55:31 +08:00
parent 9407f1731a
commit 4242e194e4
4 changed files with 80 additions and 8 deletions

View File

@@ -163,7 +163,7 @@ function submit(){
rememberGallerySelection('txt2img_gallery')
showSubmitButtons('txt2img', false)
var id = randomId()
var id = randomId("txt2img")
requestProgress(id, gradioApp().getElementById('txt2img_gallery_container'), gradioApp().getElementById('txt2img_gallery'), function(){
showSubmitButtons('txt2img', true)
@@ -180,7 +180,7 @@ function submit_img2img(){
rememberGallerySelection('img2img_gallery')
showSubmitButtons('img2img', false)
var id = randomId()
var id = randomId("img2img")
requestProgress(id, gradioApp().getElementById('img2img_gallery_container'), gradioApp().getElementById('img2img_gallery'), function(){
showSubmitButtons('img2img', true)
})
@@ -361,3 +361,35 @@ function selectCheckpoint(name){
desiredCheckpointName = name;
gradioApp().getElementById('change_checkpoint').click()
}
function restoreProgress (task_tag) {
if (task_tag) {
let successHandler = ({ current_task }) => {
if (current_task) {
let _task_tag = ["txt2img", "img2img"].find(t => current_task.startsWith(`task(${t}_`) && current_task.endsWith(")"))
if (!_task_tag) {
console.warn(`task tag ${current_task} not implemented yet`)
return
}
if (task_tag != _task_tag) return
showSubmitButtons(task_tag, false)
requestProgress(current_task, gradioApp().getElementById(`${task_tag}_gallery_container`), gradioApp().getElementById(`${task_tag}_gallery`), function(){
showSubmitButtons(task_tag, true)
})
}
}
let errorHandler = e => window.alert(`invalid internal api respsonse. message: ${e}`)
fetch("./internal/current_task")
.then(res => res.json())
.then(successHandler)
.catch(errorHandler)
}
var res = create_submit_args(arguments)
res[0] = 0
return res
}