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
199123e9
Commit
199123e9
authored
Aug 24, 2022
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add execution timings to output
change the text output element to HTML
parent
29f7e7ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
8 deletions
+34
-8
webui.py
webui.py
+34
-8
No files found.
webui.py
View file @
199123e9
...
@@ -12,6 +12,8 @@ from contextlib import contextmanager, nullcontext
...
@@ -12,6 +12,8 @@ from contextlib import contextmanager, nullcontext
import
mimetypes
import
mimetypes
import
random
import
random
import
math
import
math
import
html
import
time
import
k_diffusion
as
K
import
k_diffusion
as
K
from
ldm.util
import
instantiate_from_config
from
ldm.util
import
instantiate_from_config
...
@@ -160,6 +162,11 @@ def save_image(image, path, basename, seed, prompt, extension, info=None, short_
...
@@ -160,6 +162,11 @@ def save_image(image, path, basename, seed, prompt, extension, info=None, short_
image
.
save
(
os
.
path
.
join
(
path
,
filename
),
quality
=
opt
.
jpeg_quality
,
pnginfo
=
pnginfo
)
image
.
save
(
os
.
path
.
join
(
path
,
filename
),
quality
=
opt
.
jpeg_quality
,
pnginfo
=
pnginfo
)
def
plaintext_to_html
(
text
):
text
=
""
.
join
([
f
"<p>{html.escape(x)}</p>
\n
"
for
x
in
text
.
split
(
'
\n
'
)])
return
text
def
load_GFPGAN
():
def
load_GFPGAN
():
model_name
=
'GFPGANv1.3'
model_name
=
'GFPGANv1.3'
model_path
=
os
.
path
.
join
(
GFPGAN_dir
,
'experiments/pretrained_models'
,
model_name
+
'.pth'
)
model_path
=
os
.
path
.
join
(
GFPGAN_dir
,
'experiments/pretrained_models'
,
model_name
+
'.pth'
)
...
@@ -331,6 +338,20 @@ def check_prompt_length(prompt, comments):
...
@@ -331,6 +338,20 @@ def check_prompt_length(prompt, comments):
comments
.
append
(
f
"Warning: too many input tokens; some ({len(overflowing_words)}) have been truncated:
\n
{overflowing_text}
\n
"
)
comments
.
append
(
f
"Warning: too many input tokens; some ({len(overflowing_words)}) have been truncated:
\n
{overflowing_text}
\n
"
)
def
wrap_gradio_call
(
func
):
def
f
(
*
p1
,
**
p2
):
t
=
time
.
perf_counter
()
res
=
list
(
func
(
*
p1
,
**
p2
))
elapsed
=
time
.
perf_counter
()
-
t
# last item is always HTML
res
[
-
1
]
=
res
[
-
1
]
+
f
"<p class='performance'>Time taken: {elapsed:.2f}s</p>"
return
tuple
(
res
)
return
f
def
process_images
(
outpath
,
func_init
,
func_sample
,
prompt
,
seed
,
sampler_name
,
batch_size
,
n_iter
,
steps
,
cfg_scale
,
width
,
height
,
prompt_matrix
,
use_GFPGAN
,
do_not_save_grid
=
False
):
def
process_images
(
outpath
,
func_init
,
func_sample
,
prompt
,
seed
,
sampler_name
,
batch_size
,
n_iter
,
steps
,
cfg_scale
,
width
,
height
,
prompt_matrix
,
use_GFPGAN
,
do_not_save_grid
=
False
):
"""this is the main loop that both txt2img and img2img use; it calls func_init once inside all the scopes and func_sample once per batch"""
"""this is the main loop that both txt2img and img2img use; it calls func_init once inside all the scopes and func_sample once per batch"""
...
@@ -484,7 +505,7 @@ def txt2img(prompt: str, ddim_steps: int, sampler_name: str, use_GFPGAN: bool, p
...
@@ -484,7 +505,7 @@ def txt2img(prompt: str, ddim_steps: int, sampler_name: str, use_GFPGAN: bool, p
del
sampler
del
sampler
return
output_images
,
seed
,
info
return
output_images
,
seed
,
plaintext_to_html
(
info
)
class
Flagging
(
gr
.
FlaggingCallback
):
class
Flagging
(
gr
.
FlaggingCallback
):
...
@@ -529,7 +550,7 @@ class Flagging(gr.FlaggingCallback):
...
@@ -529,7 +550,7 @@ class Flagging(gr.FlaggingCallback):
txt2img_interface
=
gr
.
Interface
(
txt2img_interface
=
gr
.
Interface
(
txt2img
,
wrap_gradio_call
(
txt2img
)
,
inputs
=
[
inputs
=
[
gr
.
Textbox
(
label
=
"Prompt"
,
placeholder
=
"A corgi wearing a top hat as an oil painting."
,
lines
=
1
),
gr
.
Textbox
(
label
=
"Prompt"
,
placeholder
=
"A corgi wearing a top hat as an oil painting."
,
lines
=
1
),
gr
.
Slider
(
minimum
=
1
,
maximum
=
150
,
step
=
1
,
label
=
"Sampling Steps"
,
value
=
50
),
gr
.
Slider
(
minimum
=
1
,
maximum
=
150
,
step
=
1
,
label
=
"Sampling Steps"
,
value
=
50
),
...
@@ -547,7 +568,7 @@ txt2img_interface = gr.Interface(
...
@@ -547,7 +568,7 @@ txt2img_interface = gr.Interface(
outputs
=
[
outputs
=
[
gr
.
Gallery
(
label
=
"Images"
),
gr
.
Gallery
(
label
=
"Images"
),
gr
.
Number
(
label
=
'Seed'
),
gr
.
Number
(
label
=
'Seed'
),
gr
.
Textbox
(
label
=
"Copy-paste generation parameters"
),
gr
.
HTML
(
),
],
],
title
=
"Stable Diffusion Text-to-Image K"
,
title
=
"Stable Diffusion Text-to-Image K"
,
description
=
"Generate images from text with Stable Diffusion (using K-LMS)"
,
description
=
"Generate images from text with Stable Diffusion (using K-LMS)"
,
...
@@ -650,14 +671,14 @@ def img2img(prompt: str, init_img, ddim_steps: int, use_GFPGAN: bool, prompt_mat
...
@@ -650,14 +671,14 @@ def img2img(prompt: str, init_img, ddim_steps: int, use_GFPGAN: bool, prompt_mat
del
sampler
del
sampler
return
output_images
,
seed
,
info
return
output_images
,
seed
,
plaintext_to_html
(
info
)
sample_img2img
=
"assets/stable-samples/img2img/sketch-mountains-input.jpg"
sample_img2img
=
"assets/stable-samples/img2img/sketch-mountains-input.jpg"
sample_img2img
=
sample_img2img
if
os
.
path
.
exists
(
sample_img2img
)
else
None
sample_img2img
=
sample_img2img
if
os
.
path
.
exists
(
sample_img2img
)
else
None
img2img_interface
=
gr
.
Interface
(
img2img_interface
=
gr
.
Interface
(
img2img
,
wrap_gradio_call
(
img2img
)
,
inputs
=
[
inputs
=
[
gr
.
Textbox
(
placeholder
=
"A fantasy landscape, trending on artstation."
,
lines
=
1
),
gr
.
Textbox
(
placeholder
=
"A fantasy landscape, trending on artstation."
,
lines
=
1
),
gr
.
Image
(
value
=
sample_img2img
,
source
=
"upload"
,
interactive
=
True
,
type
=
"pil"
),
gr
.
Image
(
value
=
sample_img2img
,
source
=
"upload"
,
interactive
=
True
,
type
=
"pil"
),
...
@@ -677,7 +698,7 @@ img2img_interface = gr.Interface(
...
@@ -677,7 +698,7 @@ img2img_interface = gr.Interface(
outputs
=
[
outputs
=
[
gr
.
Gallery
(),
gr
.
Gallery
(),
gr
.
Number
(
label
=
'Seed'
),
gr
.
Number
(
label
=
'Seed'
),
gr
.
Textbox
(
label
=
"Copy-paste generation parameters"
),
gr
.
HTML
(
),
],
],
title
=
"Stable Diffusion Image-to-Image"
,
title
=
"Stable Diffusion Image-to-Image"
,
description
=
"Generate images from images with Stable Diffusion"
,
description
=
"Generate images from images with Stable Diffusion"
,
...
@@ -698,7 +719,7 @@ def run_GFPGAN(image, strength):
...
@@ -698,7 +719,7 @@ def run_GFPGAN(image, strength):
if
strength
<
1.0
:
if
strength
<
1.0
:
res
=
Image
.
blend
(
image
,
res
,
strength
)
res
=
Image
.
blend
(
image
,
res
,
strength
)
return
res
return
res
,
0
,
''
if
GFPGAN
is
not
None
:
if
GFPGAN
is
not
None
:
...
@@ -710,6 +731,8 @@ if GFPGAN is not None:
...
@@ -710,6 +731,8 @@ if GFPGAN is not None:
],
],
outputs
=
[
outputs
=
[
gr
.
Image
(
label
=
"Result"
),
gr
.
Image
(
label
=
"Result"
),
gr
.
Number
(
label
=
'Seed'
,
visible
=
False
),
gr
.
HTML
(),
],
],
title
=
"GFPGAN"
,
title
=
"GFPGAN"
,
description
=
"Fix faces on images"
,
description
=
"Fix faces on images"
,
...
@@ -719,7 +742,10 @@ if GFPGAN is not None:
...
@@ -719,7 +742,10 @@ if GFPGAN is not None:
demo
=
gr
.
TabbedInterface
(
demo
=
gr
.
TabbedInterface
(
interface_list
=
[
x
[
0
]
for
x
in
interfaces
],
interface_list
=
[
x
[
0
]
for
x
in
interfaces
],
tab_names
=
[
x
[
1
]
for
x
in
interfaces
],
tab_names
=
[
x
[
1
]
for
x
in
interfaces
],
css
=
(
""
if
opt
.
no_progressbar_hiding
else
css_hide_progressbar
)
css
=
(
""
if
opt
.
no_progressbar_hiding
else
css_hide_progressbar
)
+
"""
.output-html p {margin: 0 0.5em;}
.performance { font-size: 0.85em; color: #444; }
"""
)
)
demo
.
launch
()
demo
.
launch
()
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