2022-09-18 06:00:06 +00:00
// various functions for interation with ui.py not large enough to warrant putting them in separate files
2022-09-02 20:25:29 +00: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 08:10:00 +00:00
return [ null ]
2022-09-02 20:25:29 +00:00
}
return gallery [ index ] ;
2022-09-10 21:17:34 +00: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-02 20:25:29 +00:00
}
2022-09-05 23:09:01 +00:00
function submit ( ) {
2022-09-18 06:00:06 +00:00
// this calls a function from progressbar.js
2022-09-18 08:14:42 +00:00
requestProgress ( )
2022-09-05 23:09:01 +00:00
res = [ ]
2022-09-17 05:03:47 +00:00
for ( var i = 0 ; i < arguments . length ; i ++ ) {
2022-09-05 23:09:01 +00:00
res . push ( arguments [ i ] )
}
2022-09-17 05:03:47 +00: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-05 23:09:01 +00:00
return res
2022-09-07 18:26:19 +00:00
}
2022-09-07 19:58:11 +00:00
2022-09-11 14:35:12 +00: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-09 20:16:02 +00:00
}