Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
54a097a8
Commit
54a097a8
authored
Sep 20, 2022
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
ab383921
d7f36dac
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
5 deletions
+55
-5
javascript/notification.js
javascript/notification.js
+34
-0
modules/images.py
modules/images.py
+13
-5
modules/ui.py
modules/ui.py
+8
-0
No files found.
javascript/notification.js
0 → 100644
View file @
54a097a8
// Monitors the gallery and sends a browser notification when the leading image is new.
let
lastHeadImg
=
null
;
onUiUpdate
(
function
(){
const
galleryPreviews
=
gradioApp
().
querySelectorAll
(
'
img.h-full.w-full.overflow-hidden
'
);
if
(
galleryPreviews
==
null
)
return
;
const
headImg
=
galleryPreviews
[
0
]?.
src
;
if
(
headImg
==
null
||
headImg
==
lastHeadImg
)
return
;
lastHeadImg
=
headImg
;
if
(
document
.
hasFocus
())
return
;
// Multiple copies of the images are in the DOM when one is selected. Dedup with a Set to get the real number generated.
const
imgs
=
new
Set
(
Array
.
from
(
galleryPreviews
).
map
(
img
=>
img
.
src
));
const
notification
=
new
Notification
(
'
Stable Diffusion
'
,
{
body
:
`Generated
${
imgs
.
size
>
1
?
imgs
.
size
-
1
:
1
}
image
${
imgs
.
size
>
1
?
'
s
'
:
''
}
`
,
icon
:
headImg
,
image
:
headImg
,
}
);
notification
.
onclick
=
function
(
_
){
parent
.
focus
();
this
.
close
();
};
});
modules/images.py
View file @
54a097a8
...
...
@@ -245,34 +245,42 @@ def resize_image(resize_mode, im, width, height):
invalid_filename_chars
=
'<>:"/
\\
|?*
\n
'
invalid_filename_prefix
=
' '
invalid_filename_postfix
=
' .'
re_nonletters
=
re
.
compile
(
r'[\s'
+
string
.
punctuation
+
']+'
)
max_filename_part_length
=
128
max_prompt_words
=
8
def
sanitize_filename_part
(
text
,
replace_spaces
=
True
):
if
replace_spaces
:
text
=
text
.
replace
(
' '
,
'_'
)
return
text
.
translate
({
ord
(
x
):
'_'
for
x
in
invalid_filename_chars
})[:
128
]
text
=
text
.
translate
({
ord
(
x
):
'_'
for
x
in
invalid_filename_chars
})
text
=
text
.
lstrip
(
invalid_filename_prefix
)[:
max_filename_part_length
]
text
=
text
.
rstrip
(
invalid_filename_postfix
)
return
text
def
apply_filename_pattern
(
x
,
p
,
seed
,
prompt
):
if
seed
is
not
None
:
x
=
x
.
replace
(
"[seed]"
,
str
(
seed
))
if
prompt
is
not
None
:
x
=
x
.
replace
(
"[prompt]"
,
sanitize_filename_part
(
prompt
)
[:
128
]
)
x
=
x
.
replace
(
"[prompt_spaces]"
,
sanitize_filename_part
(
prompt
,
replace_spaces
=
False
)
[:
128
]
)
x
=
x
.
replace
(
"[prompt]"
,
sanitize_filename_part
(
prompt
))
x
=
x
.
replace
(
"[prompt_spaces]"
,
sanitize_filename_part
(
prompt
,
replace_spaces
=
False
))
if
"[prompt_words]"
in
x
:
words
=
[
x
for
x
in
re_nonletters
.
split
(
prompt
or
""
)
if
len
(
x
)
>
0
]
if
len
(
words
)
==
0
:
words
=
[
"empty"
]
x
=
x
.
replace
(
"[prompt_words]"
,
sanitize_filename_part
(
" "
.
join
(
words
[
0
:
max_prompt_words
]),
replace_spaces
=
False
))
x
=
x
.
replace
(
"[prompt_words]"
,
" "
.
join
(
words
[
0
:
8
])
.
strip
())
if
p
is
not
None
:
x
=
x
.
replace
(
"[steps]"
,
str
(
p
.
steps
))
x
=
x
.
replace
(
"[cfg]"
,
str
(
p
.
cfg_scale
))
x
=
x
.
replace
(
"[width]"
,
str
(
p
.
width
))
x
=
x
.
replace
(
"[height]"
,
str
(
p
.
height
))
x
=
x
.
replace
(
"[sampler]"
,
s
d_samplers
.
samplers
[
p
.
sampler_index
]
.
name
)
x
=
x
.
replace
(
"[sampler]"
,
s
anitize_filename_part
(
sd_samplers
.
samplers
[
p
.
sampler_index
]
.
name
,
replace_spaces
=
False
)
)
x
=
x
.
replace
(
"[model_hash]"
,
shared
.
sd_model
.
sd_model_hash
)
x
=
x
.
replace
(
"[date]"
,
datetime
.
date
.
today
()
.
isoformat
())
...
...
modules/ui.py
View file @
54a097a8
...
...
@@ -875,6 +875,14 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
outputs
=
[
result
]
)
request_notifications
=
gr
.
Button
(
value
=
'Request browser notifications'
)
request_notifications
.
click
(
fn
=
lambda
:
None
,
inputs
=
[],
outputs
=
[],
_js
=
'() => Notification.requestPermission()'
)
interfaces
=
[
(
txt2img_interface
,
"txt2img"
,
"txt2img"
),
(
img2img_interface
,
"img2img"
,
"img2img"
),
...
...
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