Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
a1a94b8b
Commit
a1a94b8b
authored
Oct 12, 2022
by
yfszzx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
images history improvement
parent
c87c3b9c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
84 deletions
+88
-84
images_history.js
javascript/images_history.js
+65
-60
images_history.py
modules/images_history.py
+4
-3
ui.py
modules/ui.py
+19
-21
No files found.
javascript/images_history.js
View file @
a1a94b8b
...
@@ -30,6 +30,12 @@ var images_history_close_full_view = function(){
...
@@ -30,6 +30,12 @@ var images_history_close_full_view = function(){
box
.
querySelector
(
".images_history_del_button"
).
setAttribute
(
"disabled"
,
"disabled"
);
box
.
querySelector
(
".images_history_del_button"
).
setAttribute
(
"disabled"
,
"disabled"
);
}
}
function
images_history_disabled_del
(){
gradioApp
().
querySelectorAll
(
".images_history_del_button"
).
forEach
(
function
(
btn
){
btn
.
setAttribute
(
'disabled'
,
'disabled'
);
});
}
function
images_history_get_parent_by_class
(
item
,
class_name
){
function
images_history_get_parent_by_class
(
item
,
class_name
){
var
parent
=
item
.
parentElement
;
var
parent
=
item
.
parentElement
;
while
(
!
parent
.
classList
.
contains
(
class_name
)){
while
(
!
parent
.
classList
.
contains
(
class_name
)){
...
@@ -47,6 +53,7 @@ function images_history_get_parent_by_tagname(item, tagname){
...
@@ -47,6 +53,7 @@ function images_history_get_parent_by_tagname(item, tagname){
}
}
return
parent
;
return
parent
;
}
}
function
images_history_hide_buttons
(
hidden_list
,
gallery
){
function
images_history_hide_buttons
(
hidden_list
,
gallery
){
var
buttons
=
gallery
.
querySelectorAll
(
".gallery-item"
);
var
buttons
=
gallery
.
querySelectorAll
(
".gallery-item"
);
var
num
=
0
;
var
num
=
0
;
...
@@ -54,7 +61,7 @@ function images_history_hide_buttons(hidden_list, gallery){
...
@@ -54,7 +61,7 @@ function images_history_hide_buttons(hidden_list, gallery){
if
(
e
.
style
.
display
==
"none"
){
if
(
e
.
style
.
display
==
"none"
){
num
+=
1
;
num
+=
1
;
}
}
})
})
;
if
(
num
==
hidden_list
.
length
){
if
(
num
==
hidden_list
.
length
){
setTimeout
(
images_history_hide_buttons
,
10
,
hidden_list
,
gallery
);
setTimeout
(
images_history_hide_buttons
,
10
,
hidden_list
,
gallery
);
}
}
...
@@ -74,14 +81,15 @@ function images_history_set_image_info(button){
...
@@ -74,14 +81,15 @@ function images_history_set_image_info(button){
if
(
e
.
style
.
display
!=
"none"
){
if
(
e
.
style
.
display
!=
"none"
){
i
+=
1
;
i
+=
1
;
}
}
})
})
;
var
gallery
=
images_history_get_parent_by_class
(
button
,
"images_history_cantainor"
);
var
gallery
=
images_history_get_parent_by_class
(
button
,
"images_history_cantainor"
);
var
set_btn
=
gallery
.
querySelector
(
".images_history_set_index"
);
var
set_btn
=
gallery
.
querySelector
(
".images_history_set_index"
);
var
curr_idx
=
set_btn
.
getAttribute
(
"img_index"
,
index
);
if
(
curr_idx
!=
index
)
{
set_btn
.
setAttribute
(
"img_index"
,
index
);
set_btn
.
setAttribute
(
"img_index"
,
index
);
images_history_disabled_del
();
}
set_btn
.
click
();
set_btn
.
click
();
gradioApp
().
querySelectorAll
(
".images_history_del_button"
).
forEach
(
function
(
btn
){
btn
.
setAttribute
(
'disabled'
,
'disabled'
);
})
}
}
...
@@ -103,7 +111,6 @@ function images_history_delete(tabname, img_path, img_file_name, page_index, fil
...
@@ -103,7 +111,6 @@ function images_history_delete(tabname, img_path, img_file_name, page_index, fil
buttons
.
push
(
e
);
buttons
.
push
(
e
);
}
}
});
});
var
img_num
=
buttons
.
length
/
2
;
var
img_num
=
buttons
.
length
/
2
;
if
(
img_num
===
1
){
if
(
img_num
===
1
){
setTimeout
(
function
(
tabname
){
setTimeout
(
function
(
tabname
){
...
@@ -120,6 +127,7 @@ function images_history_delete(tabname, img_path, img_file_name, page_index, fil
...
@@ -120,6 +127,7 @@ function images_history_delete(tabname, img_path, img_file_name, page_index, fil
}
}
setTimeout
(
function
(
btn
){
btn
.
click
()},
30
,
btn
);
setTimeout
(
function
(
btn
){
btn
.
click
()},
30
,
btn
);
}
}
images_history_disabled_del
();
return
[
tabname
,
img_path
,
img_file_name
,
page_index
,
filenames
,
image_index
];
return
[
tabname
,
img_path
,
img_file_name
,
page_index
,
filenames
,
image_index
];
}
}
...
@@ -138,9 +146,8 @@ function images_history_enable_del_buttons(){
...
@@ -138,9 +146,8 @@ function images_history_enable_del_buttons(){
}
}
function
images_history_init
(){
function
images_history_init
(){
if
(
gradioApp
().
getElementById
(
'txt2img_images_history_renew_page'
)
==
null
)
{
var
load_txt2img_button
=
gradioApp
().
getElementById
(
'txt2img_images_history_renew_page'
)
setTimeout
(
images_history_init
,
500
);
if
(
load_txt2img_button
){
}
else
{
for
(
var
i
in
images_history_tab_list
){
for
(
var
i
in
images_history_tab_list
){
tab
=
images_history_tab_list
[
i
];
tab
=
images_history_tab_list
[
i
];
gradioApp
().
getElementById
(
tab
+
'_images_history'
).
classList
.
add
(
"images_history_cantainor"
);
gradioApp
().
getElementById
(
tab
+
'_images_history'
).
classList
.
add
(
"images_history_cantainor"
);
...
@@ -148,34 +155,31 @@ function images_history_init(){
...
@@ -148,34 +155,31 @@ function images_history_init(){
gradioApp
().
getElementById
(
tab
+
'_images_history_del_button'
).
classList
.
add
(
"images_history_del_button"
);
gradioApp
().
getElementById
(
tab
+
'_images_history_del_button'
).
classList
.
add
(
"images_history_del_button"
);
gradioApp
().
getElementById
(
tab
+
'_images_history_gallery'
).
classList
.
add
(
"images_history_gallery"
);
gradioApp
().
getElementById
(
tab
+
'_images_history_gallery'
).
classList
.
add
(
"images_history_gallery"
);
}
}
var
tabs_box
=
gradioApp
().
getElementById
(
"tab_images_history"
).
querySelector
(
"div"
).
querySelector
(
"div"
).
querySelector
(
"div"
);
var
tabs_box
=
gradioApp
().
getElementById
(
"tab_images_history"
).
querySelector
(
"div"
).
querySelector
(
"div"
).
querySelector
(
"div"
);
tabs_box
.
setAttribute
(
"id"
,
"images_history_tab"
);
tabs_box
.
setAttribute
(
"id"
,
"images_history_tab"
);
var
tab_btns
=
tabs_box
.
querySelectorAll
(
"button"
);
for
(
var
i
in
images_history_tab_list
){
var
tabname
=
images_history_tab_list
[
i
]
tab_btns
[
i
].
setAttribute
(
"tabname"
,
tabname
);
tab_btns
[
i
].
addEventListener
(
'click'
,
images_history_click_tab
);
}
tabs_box
.
classList
.
add
(
images_history_tab_list
[
0
]);
tabs_box
.
classList
.
add
(
images_history_tab_list
[
0
]);
gradioApp
().
getElementById
(
"txt2img_images_history_renew_page"
).
click
();
load_txt2img_button
.
click
();
}
else
{
setTimeout
(
images_history_init
,
500
);
}
}
}
}
var
images_history_tab_list
=
[
"txt2img"
,
"img2img"
,
"extras"
];
var
images_history_tab_list
=
[
"txt2img"
,
"img2img"
,
"extras"
];
var
images_history_start_flag
=
false
;
setTimeout
(
images_history_init
,
500
)
document
.
addEventListener
(
"DOMContentLoaded"
,
function
()
{
onUiUpdate
(
function
(){
var
mutationObserver
=
new
MutationObserver
(
function
(
m
){
var
tab
=
gradioApp
().
getElementById
(
"images_history_tab"
);
if
(
tab
)
{
if
(
!
images_history_start_flag
){
images_history_init
();
images_history_start_flag
=
true
;
}
var
tab_btns
=
gradioApp
().
getElementById
(
"images_history_tab"
).
querySelectorAll
(
"button"
);
for
(
var
i
in
images_history_tab_list
){
for
(
var
i
in
images_history_tab_list
){
var
buttons
=
gradioApp
().
querySelectorAll
(
'#'
+
images_history_tab_list
[
i
]
+
'_images_history .gallery-item'
);
var
buttons
=
gradioApp
().
querySelectorAll
(
'#'
+
images_history_tab_list
[
i
]
+
'_images_history .gallery-item'
);
buttons
.
forEach
(
function
(
bnt
){
buttons
.
forEach
(
function
(
bnt
){
bnt
.
addEventListener
(
'click'
,
images_history_click_image
,
true
);
bnt
.
addEventListener
(
'click'
,
images_history_click_image
,
true
);
});
});
var
tabname
=
images_history_tab_list
[
i
]
tab_btns
[
i
].
setAttribute
(
"tabname"
,
tabname
);
tab_btns
[
i
].
addEventListener
(
'click'
,
images_history_click_tab
,
true
);
// var cls_btn = gradioApp().getElementById(tabname + '_images_history_gallery').querySelector("svg");
// var cls_btn = gradioApp().getElementById(tabname + '_images_history_gallery').querySelector("svg");
// if (cls_btn){
// if (cls_btn){
// cls_btn.addEventListener('click', images_history_close_full_view, false);
// cls_btn.addEventListener('click', images_history_close_full_view, false);
...
@@ -184,9 +188,10 @@ onUiUpdate(function(){
...
@@ -184,9 +188,10 @@ onUiUpdate(function(){
// if (cls_btn) {
// if (cls_btn) {
// cls_btn = images_history_get_parent_by_tagname(cls_btn, "BUTTON");
// cls_btn = images_history_get_parent_by_tagname(cls_btn, "BUTTON");
// cls_btn.addEventListener('click', images_history_close_full_view, true);
// cls_btn.addEventListener('click', images_history_close_full_view, true);
// }
}
}
});
mutationObserver
.
observe
(
gradioApp
(),
{
childList
:
true
,
subtree
:
true
});
}
});
});
modules/images_history.py
View file @
a1a94b8b
...
@@ -126,9 +126,10 @@ def show_images_history(gr, opts, tabname, run_pnginfo, switch_dict):
...
@@ -126,9 +126,10 @@ def show_images_history(gr, opts, tabname, run_pnginfo, switch_dict):
#other funcitons
#other funcitons
set_index
.
click
(
show_image_info
,
_js
=
"images_history_get_current_img"
,
inputs
=
[
tabname_box
,
img_path
,
filenames
],
outputs
=
[
img_file_name
,
image_index
,
hide_image
])
set_index
.
click
(
show_image_info
,
_js
=
"images_history_get_current_img"
,
inputs
=
[
tabname_box
,
img_path
,
filenames
],
outputs
=
[
img_file_name
,
image_index
,
hide_image
])
img_file_name
.
change
(
fn
=
None
,
_js
=
"images_history_enable_del_buttons"
,
inputs
=
None
,
outputs
=
None
)
delete
.
click
(
delete_image
,
_js
=
"images_history_delete"
,
inputs
=
[
tabname_box
,
img_path
,
img_file_name
,
page_index
,
filenames
,
image_index
],
outputs
=
[
page_index
,
filenames
])
delete
.
click
(
delete_image
,
_js
=
"images_history_delete"
,
inputs
=
[
tabname_box
,
img_path
,
img_file_name
,
page_index
,
filenames
,
image_index
],
outputs
=
[
page_index
,
filenames
])
hide_image
.
change
(
fn
=
run_pnginfo
,
inputs
=
[
hide_image
],
outputs
=
[
info1
,
img_file_info
,
info2
])
hide_image
.
change
(
fn
=
run_pnginfo
,
inputs
=
[
hide_image
],
outputs
=
[
info1
,
img_file_info
,
info2
])
hide_image
.
change
(
fn
=
None
,
_js
=
"images_history_enable_del_buttons"
,
inputs
=
None
,
outputs
=
None
)
#pnginfo.click(fn=run_pnginfo, inputs=[hide_image], outputs=[info1, img_file_info, info2])
#pnginfo.click(fn=run_pnginfo, inputs=[hide_image], outputs=[info1, img_file_info, info2])
switch_dict
[
"fn"
](
pnginfo_send_to_txt2img
,
switch_dict
[
"t2i"
],
img_file_info
,
'switch_to_txt2img'
)
switch_dict
[
"fn"
](
pnginfo_send_to_txt2img
,
switch_dict
[
"t2i"
],
img_file_info
,
'switch_to_txt2img'
)
switch_dict
[
"fn"
](
pnginfo_send_to_img2img
,
switch_dict
[
"i2i"
],
img_file_info
,
'switch_to_img2img_img2img'
)
switch_dict
[
"fn"
](
pnginfo_send_to_img2img
,
switch_dict
[
"i2i"
],
img_file_info
,
'switch_to_img2img_img2img'
)
...
...
modules/ui.py
View file @
a1a94b8b
...
@@ -39,7 +39,7 @@ import modules.generation_parameters_copypaste
...
@@ -39,7 +39,7 @@ import modules.generation_parameters_copypaste
from
modules
import
prompt_parser
from
modules
import
prompt_parser
from
modules.images
import
save_image
from
modules.images
import
save_image
import
modules.textual_inversion.ui
import
modules.textual_inversion.ui
import
modules.hypernetwork.ui
import
modules.hypernetwork
s
.ui
import
modules.images_history
as
img_his
import
modules.images_history
as
img_his
# this is a fix for Windows users. Without it, javascript files will be served with text/html content-type and the browser will not show any UI
# this is a fix for Windows users. Without it, javascript files will be served with text/html content-type and the browser will not show any UI
...
@@ -554,6 +554,7 @@ def create_ui(wrap_gradio_gpu_call):
...
@@ -554,6 +554,7 @@ def create_ui(wrap_gradio_gpu_call):
custom_inputs
=
modules
.
scripts
.
scripts_txt2img
.
setup_ui
(
is_img2img
=
False
)
custom_inputs
=
modules
.
scripts
.
scripts_txt2img
.
setup_ui
(
is_img2img
=
False
)
with
gr
.
Column
(
variant
=
'panel'
):
with
gr
.
Column
(
variant
=
'panel'
):
with
gr
.
Group
():
with
gr
.
Group
():
txt2img_preview
=
gr
.
Image
(
elem_id
=
'txt2img_preview'
,
visible
=
False
)
txt2img_preview
=
gr
.
Image
(
elem_id
=
'txt2img_preview'
,
visible
=
False
)
txt2img_gallery
=
gr
.
Gallery
(
label
=
'Output'
,
show_label
=
False
,
elem_id
=
'txt2img_gallery'
)
.
style
(
grid
=
4
)
txt2img_gallery
=
gr
.
Gallery
(
label
=
'Output'
,
show_label
=
False
,
elem_id
=
'txt2img_gallery'
)
.
style
(
grid
=
4
)
...
@@ -670,7 +671,6 @@ def create_ui(wrap_gradio_gpu_call):
...
@@ -670,7 +671,6 @@ def create_ui(wrap_gradio_gpu_call):
modules
.
generation_parameters_copypaste
.
connect_paste
(
paste
,
txt2img_paste_fields
,
txt2img_prompt
)
modules
.
generation_parameters_copypaste
.
connect_paste
(
paste
,
txt2img_paste_fields
,
txt2img_prompt
)
token_button
.
click
(
fn
=
update_token_counter
,
inputs
=
[
txt2img_prompt
,
steps
],
outputs
=
[
token_counter
])
token_button
.
click
(
fn
=
update_token_counter
,
inputs
=
[
txt2img_prompt
,
steps
],
outputs
=
[
token_counter
])
with
gr
.
Blocks
(
analytics_enabled
=
False
)
as
img2img_interface
:
with
gr
.
Blocks
(
analytics_enabled
=
False
)
as
img2img_interface
:
img2img_prompt
,
roll
,
img2img_prompt_style
,
img2img_negative_prompt
,
img2img_prompt_style2
,
submit
,
img2img_interrogate
,
img2img_deepbooru
,
img2img_prompt_style_apply
,
img2img_save_style
,
paste
,
token_counter
,
token_button
=
create_toprow
(
is_img2img
=
True
)
img2img_prompt
,
roll
,
img2img_prompt_style
,
img2img_negative_prompt
,
img2img_prompt_style2
,
submit
,
img2img_interrogate
,
img2img_deepbooru
,
img2img_prompt_style_apply
,
img2img_save_style
,
paste
,
token_counter
,
token_button
=
create_toprow
(
is_img2img
=
True
)
...
@@ -1016,6 +1016,13 @@ def create_ui(wrap_gradio_gpu_call):
...
@@ -1016,6 +1016,13 @@ def create_ui(wrap_gradio_gpu_call):
inputs
=
[
image
],
inputs
=
[
image
],
outputs
=
[
html
,
generation_info
,
html2
],
outputs
=
[
html
,
generation_info
,
html2
],
)
)
#images history
images_history_switch_dict
=
{
"fn"
:
modules
.
generation_parameters_copypaste
.
connect_paste
,
"t2i"
:
txt2img_paste_fields
,
"i2i"
:
img2img_paste_fields
}
images_history
=
img_his
.
create_history_tabs
(
gr
,
opts
,
wrap_gradio_call
(
modules
.
extras
.
run_pnginfo
),
images_history_switch_dict
)
with
gr
.
Blocks
()
as
modelmerger_interface
:
with
gr
.
Blocks
()
as
modelmerger_interface
:
with
gr
.
Row
()
.
style
(
equal_height
=
False
):
with
gr
.
Row
()
.
style
(
equal_height
=
False
):
...
@@ -1287,15 +1294,6 @@ Requested path was: {f}
...
@@ -1287,15 +1294,6 @@ Requested path was: {f}
return
f
'{changed} settings changed.'
,
opts
.
dumpjson
()
return
f
'{changed} settings changed.'
,
opts
.
dumpjson
()
#images history
images_history_switch_dict
=
{
"fn"
:
modules
.
generation_parameters_copypaste
.
connect_paste
,
"t2i"
:
txt2img_paste_fields
,
"i2i"
:
img2img_paste_fields
}
images_history
=
img_his
.
create_history_tabs
(
gr
,
opts
,
wrap_gradio_call
(
modules
.
extras
.
run_pnginfo
),
images_history_switch_dict
)
def
run_settings_single
(
value
,
key
):
def
run_settings_single
(
value
,
key
):
if
not
opts
.
same_type
(
value
,
opts
.
data_labels
[
key
]
.
default
):
if
not
opts
.
same_type
(
value
,
opts
.
data_labels
[
key
]
.
default
):
return
gr
.
update
(
visible
=
True
),
opts
.
dumpjson
()
return
gr
.
update
(
visible
=
True
),
opts
.
dumpjson
()
...
@@ -1393,11 +1391,10 @@ Requested path was: {f}
...
@@ -1393,11 +1391,10 @@ Requested path was: {f}
(
img2img_interface
,
"img2img"
,
"img2img"
),
(
img2img_interface
,
"img2img"
,
"img2img"
),
(
extras_interface
,
"Extras"
,
"extras"
),
(
extras_interface
,
"Extras"
,
"extras"
),
(
pnginfo_interface
,
"PNG Info"
,
"pnginfo"
),
(
pnginfo_interface
,
"PNG Info"
,
"pnginfo"
),
(
modelmerger_interface
,
"Checkpoint Merger"
,
"modelmerger"
),
(
images_history
,
"History"
,
"images_history"
),
(
images_history
,
"History"
,
"images_history"
),
(
modelmerger_interface
,
"Checkpoint Merger"
,
"modelmerger"
),
(
train_interface
,
"Train"
,
"ti"
),
(
train_interface
,
"Train"
,
"ti"
),
(
settings_interface
,
"Settings"
,
"settings"
),
(
settings_interface
,
"Settings"
,
"settings"
),
]
]
with
open
(
os
.
path
.
join
(
script_path
,
"style.css"
),
"r"
,
encoding
=
"utf8"
)
as
file
:
with
open
(
os
.
path
.
join
(
script_path
,
"style.css"
),
"r"
,
encoding
=
"utf8"
)
as
file
:
...
@@ -1616,3 +1613,4 @@ if 'gradio_routes_templates_response' not in globals():
...
@@ -1616,3 +1613,4 @@ if 'gradio_routes_templates_response' not in globals():
gradio_routes_templates_response
=
gradio
.
routes
.
templates
.
TemplateResponse
gradio_routes_templates_response
=
gradio
.
routes
.
templates
.
TemplateResponse
gradio
.
routes
.
templates
.
TemplateResponse
=
template_response
gradio
.
routes
.
templates
.
TemplateResponse
=
template_response
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment