2022-09-18 14:00:06 +08:00
// various functions for interation with ui.py not large enough to warrant putting them in separate files
2022-09-03 04:25:29 +08:00
function selected _gallery _index ( ) {
var gr = gradioApp ( )
var buttons = gradioApp ( ) . querySelectorAll ( ".gallery-item" )
var button = gr . querySelector ( ".gallery-item.\\!ring-2" )
var result = - 1
buttons . forEach ( function ( v , i ) { if ( v == button ) { result = i } } )
return result
}
function extract _image _from _gallery ( gallery ) {
if ( gallery . length == 1 ) {
return gallery [ 0 ]
}
index = selected _gallery _index ( )
if ( index < 0 || index >= gallery . length ) {
2022-09-10 16:10:00 +08:00
return [ null ]
2022-09-03 04:25:29 +08:00
}
return gallery [ index ] ;
2022-09-11 05:17:34 +08:00
}
function extract _image _from _gallery _img2img ( gallery ) {
gradioApp ( ) . querySelectorAll ( 'button' ) [ 1 ] . click ( ) ;
return extract _image _from _gallery ( gallery ) ;
}
function extract _image _from _gallery _extras ( gallery ) {
gradioApp ( ) . querySelectorAll ( 'button' ) [ 2 ] . click ( ) ;
return extract _image _from _gallery ( gallery ) ;
2022-09-03 04:25:29 +08:00
}
2022-09-06 07:09:01 +08:00
function submit ( ) {
2022-09-18 14:00:06 +08:00
// this calls a function from progressbar.js
2022-09-18 16:14:42 +08:00
requestProgress ( )
2022-09-06 07:09:01 +08:00
res = [ ]
2022-09-17 13:03:47 +08:00
for ( var i = 0 ; i < arguments . length ; i ++ ) {
2022-09-06 07:09:01 +08:00
res . push ( arguments [ i ] )
}
2022-09-17 13:03:47 +08:00
// As it is currently, txt2img and img2img send back the previous output args (txt2img_gallery, generation_info, html_info) whenever you generate a new image.
// This can lead to uploading a huge gallery of previously generated images, which leads to an unnecessary delay between submitting and beginning to generate.
// I don't know why gradio is seding outputs along with inputs, but we can prevent sending the image gallery here, which seems to be an issue for some.
// If gradio at some point stops sending outputs, this may break something
if ( Array . isArray ( res [ res . length - 3 ] ) ) {
res [ res . length - 3 ] = null
}
2022-09-06 07:09:01 +08:00
return res
2022-09-08 02:26:19 +08:00
}
2022-09-08 03:58:11 +08:00
2022-09-11 22:35:12 +08:00
function ask _for _style _name ( _ , prompt _text , negative _prompt _text ) {
name _ = prompt ( 'Style name:' )
return name _ === null ? [ null , null , null ] : [ name _ , prompt _text , negative _prompt _text ]
2022-09-10 04:16:02 +08:00
}