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
336c341a
Commit
336c341a
authored
Nov 19, 2022
by
Maiko Sinkyaet Tan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into api-authorization
parents
8f2ff861
84a6f211
Changes
28
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
187 additions
and
144 deletions
+187
-144
modules/api/api.py
modules/api/api.py
+17
-25
modules/api/models.py
modules/api/models.py
+3
-3
modules/extensions.py
modules/extensions.py
+5
-2
modules/generation_parameters_copypaste.py
modules/generation_parameters_copypaste.py
+1
-0
modules/hypernetworks/hypernetwork.py
modules/hypernetworks/hypernetwork.py
+2
-2
modules/images.py
modules/images.py
+1
-1
modules/img2img.py
modules/img2img.py
+2
-2
modules/processing.py
modules/processing.py
+60
-51
modules/sd_hijack.py
modules/sd_hijack.py
+1
-1
modules/sd_models.py
modules/sd_models.py
+2
-8
modules/sd_samplers.py
modules/sd_samplers.py
+10
-3
modules/sd_vae.py
modules/sd_vae.py
+22
-14
modules/shared.py
modules/shared.py
+2
-1
modules/styles.py
modules/styles.py
+0
-11
modules/textual_inversion/textual_inversion.py
modules/textual_inversion/textual_inversion.py
+2
-2
modules/textual_inversion/ui.py
modules/textual_inversion/ui.py
+1
-1
modules/txt2img.py
modules/txt2img.py
+2
-1
modules/ui.py
modules/ui.py
+13
-2
modules/ui_extensions.py
modules/ui_extensions.py
+2
-2
requirements.txt
requirements.txt
+1
-0
requirements_versions.txt
requirements_versions.txt
+1
-0
scripts/img2imgalt.py
scripts/img2imgalt.py
+2
-2
scripts/xy_grid.py
scripts/xy_grid.py
+6
-6
webui-user.bat
webui-user.bat
+1
-0
webui-user.sh
webui-user.sh
+3
-0
webui.bat
webui.bat
+12
-0
webui.py
webui.py
+1
-0
webui.sh
webui.sh
+12
-4
No files found.
modules/api/api.py
View file @
336c341a
...
@@ -9,9 +9,9 @@ from fastapi.security import HTTPBasic, HTTPBasicCredentials
...
@@ -9,9 +9,9 @@ from fastapi.security import HTTPBasic, HTTPBasicCredentials
from
secrets
import
compare_digest
from
secrets
import
compare_digest
import
modules.shared
as
shared
import
modules.shared
as
shared
from
modules
import
sd_samplers
from
modules.api.models
import
*
from
modules.api.models
import
*
from
modules.processing
import
StableDiffusionProcessingTxt2Img
,
StableDiffusionProcessingImg2Img
,
process_images
from
modules.processing
import
StableDiffusionProcessingTxt2Img
,
StableDiffusionProcessingImg2Img
,
process_images
from
modules.sd_samplers
import
all_samplers
from
modules.extras
import
run_extras
,
run_pnginfo
from
modules.extras
import
run_extras
,
run_pnginfo
from
PIL
import
PngImagePlugin
from
PIL
import
PngImagePlugin
from
modules.sd_models
import
checkpoints_list
from
modules.sd_models
import
checkpoints_list
...
@@ -28,8 +28,12 @@ def upscaler_to_index(name: str):
...
@@ -28,8 +28,12 @@ def upscaler_to_index(name: str):
raise
HTTPException
(
status_code
=
400
,
detail
=
f
"Invalid upscaler, needs to be on of these: {' , '.join([x.name for x in sd_upscalers])}"
)
raise
HTTPException
(
status_code
=
400
,
detail
=
f
"Invalid upscaler, needs to be on of these: {' , '.join([x.name for x in sd_upscalers])}"
)
sampler_to_index
=
lambda
name
:
next
(
filter
(
lambda
row
:
name
.
lower
()
==
row
[
1
]
.
name
.
lower
(),
enumerate
(
all_samplers
)),
None
)
def
validate_sampler_name
(
name
):
config
=
sd_samplers
.
all_samplers_map
.
get
(
name
,
None
)
if
config
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"Sampler not found"
)
return
name
def
setUpscalers
(
req
:
dict
):
def
setUpscalers
(
req
:
dict
):
reqDict
=
vars
(
req
)
reqDict
=
vars
(
req
)
...
@@ -77,6 +81,7 @@ class Api:
...
@@ -77,6 +81,7 @@ class Api:
self
.
add_api_route
(
"/sdapi/v1/progress"
,
self
.
progressapi
,
methods
=
[
"GET"
],
response_model
=
ProgressResponse
)
self
.
add_api_route
(
"/sdapi/v1/progress"
,
self
.
progressapi
,
methods
=
[
"GET"
],
response_model
=
ProgressResponse
)
self
.
add_api_route
(
"/sdapi/v1/interrogate"
,
self
.
interrogateapi
,
methods
=
[
"POST"
])
self
.
add_api_route
(
"/sdapi/v1/interrogate"
,
self
.
interrogateapi
,
methods
=
[
"POST"
])
self
.
add_api_route
(
"/sdapi/v1/interrupt"
,
self
.
interruptapi
,
methods
=
[
"POST"
])
self
.
add_api_route
(
"/sdapi/v1/interrupt"
,
self
.
interruptapi
,
methods
=
[
"POST"
])
self
.
add_api_route
(
"/sdapi/v1/skip"
,
self
.
skip
,
methods
=
[
"POST"
])
self
.
add_api_route
(
"/sdapi/v1/options"
,
self
.
get_config
,
methods
=
[
"GET"
],
response_model
=
OptionsModel
)
self
.
add_api_route
(
"/sdapi/v1/options"
,
self
.
get_config
,
methods
=
[
"GET"
],
response_model
=
OptionsModel
)
self
.
add_api_route
(
"/sdapi/v1/options"
,
self
.
set_config
,
methods
=
[
"POST"
])
self
.
add_api_route
(
"/sdapi/v1/options"
,
self
.
set_config
,
methods
=
[
"POST"
])
self
.
add_api_route
(
"/sdapi/v1/cmd-flags"
,
self
.
get_cmd_flags
,
methods
=
[
"GET"
],
response_model
=
FlagsModel
)
self
.
add_api_route
(
"/sdapi/v1/cmd-flags"
,
self
.
get_cmd_flags
,
methods
=
[
"GET"
],
response_model
=
FlagsModel
)
...
@@ -103,14 +108,9 @@ class Api:
...
@@ -103,14 +108,9 @@ class Api:
raise
HTTPException
(
status_code
=
401
,
detail
=
"Incorrect username or password"
,
headers
=
{
"WWW-Authenticate"
:
"Basic"
})
raise
HTTPException
(
status_code
=
401
,
detail
=
"Incorrect username or password"
,
headers
=
{
"WWW-Authenticate"
:
"Basic"
})
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionTxt2ImgProcessingAPI
):
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionTxt2ImgProcessingAPI
):
sampler_index
=
sampler_to_index
(
txt2imgreq
.
sampler_index
)
if
sampler_index
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"Sampler not found"
)
populate
=
txt2imgreq
.
copy
(
update
=
{
# Override __init__ params
populate
=
txt2imgreq
.
copy
(
update
=
{
# Override __init__ params
"sd_model"
:
shared
.
sd_model
,
"sd_model"
:
shared
.
sd_model
,
"sampler_
index"
:
sampler_index
[
0
]
,
"sampler_
name"
:
validate_sampler_name
(
txt2imgreq
.
sampler_index
)
,
"do_not_save_samples"
:
True
,
"do_not_save_samples"
:
True
,
"do_not_save_grid"
:
True
"do_not_save_grid"
:
True
}
}
...
@@ -130,12 +130,6 @@ class Api:
...
@@ -130,12 +130,6 @@ class Api:
return
TextToImageResponse
(
images
=
b64images
,
parameters
=
vars
(
txt2imgreq
),
info
=
processed
.
js
())
return
TextToImageResponse
(
images
=
b64images
,
parameters
=
vars
(
txt2imgreq
),
info
=
processed
.
js
())
def
img2imgapi
(
self
,
img2imgreq
:
StableDiffusionImg2ImgProcessingAPI
):
def
img2imgapi
(
self
,
img2imgreq
:
StableDiffusionImg2ImgProcessingAPI
):
sampler_index
=
sampler_to_index
(
img2imgreq
.
sampler_index
)
if
sampler_index
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"Sampler not found"
)
init_images
=
img2imgreq
.
init_images
init_images
=
img2imgreq
.
init_images
if
init_images
is
None
:
if
init_images
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"Init image not found"
)
raise
HTTPException
(
status_code
=
404
,
detail
=
"Init image not found"
)
...
@@ -144,10 +138,9 @@ class Api:
...
@@ -144,10 +138,9 @@ class Api:
if
mask
:
if
mask
:
mask
=
decode_base64_to_image
(
mask
)
mask
=
decode_base64_to_image
(
mask
)
populate
=
img2imgreq
.
copy
(
update
=
{
# Override __init__ params
populate
=
img2imgreq
.
copy
(
update
=
{
# Override __init__ params
"sd_model"
:
shared
.
sd_model
,
"sd_model"
:
shared
.
sd_model
,
"sampler_
index"
:
sampler_index
[
0
]
,
"sampler_
name"
:
validate_sampler_name
(
img2imgreq
.
sampler_index
)
,
"do_not_save_samples"
:
True
,
"do_not_save_samples"
:
True
,
"do_not_save_grid"
:
True
,
"do_not_save_grid"
:
True
,
"mask"
:
mask
"mask"
:
mask
...
@@ -266,6 +259,9 @@ class Api:
...
@@ -266,6 +259,9 @@ class Api:
return
{}
return
{}
def
skip
(
self
):
shared
.
state
.
skip
()
def
get_config
(
self
):
def
get_config
(
self
):
options
=
{}
options
=
{}
for
key
in
shared
.
opts
.
data
.
keys
():
for
key
in
shared
.
opts
.
data
.
keys
():
...
@@ -277,14 +273,10 @@ class Api:
...
@@ -277,14 +273,10 @@ class Api:
return
options
return
options
def
set_config
(
self
,
req
:
OptionsModel
):
def
set_config
(
self
,
req
:
Dict
[
str
,
Any
]):
# currently req has all options fields even if you send a dict like { "send_seed": false }, which means it will
# overwrite all options with default values.
for
o
in
req
:
raise
RuntimeError
(
'Setting options via API is not supported'
)
setattr
(
shared
.
opts
,
o
,
req
[
o
])
reqDict
=
vars
(
req
)
for
o
in
reqDict
:
setattr
(
shared
.
opts
,
o
,
reqDict
[
o
])
shared
.
opts
.
save
(
shared
.
config_filename
)
shared
.
opts
.
save
(
shared
.
config_filename
)
return
return
...
@@ -293,7 +285,7 @@ class Api:
...
@@ -293,7 +285,7 @@ class Api:
return
vars
(
shared
.
cmd_opts
)
return
vars
(
shared
.
cmd_opts
)
def
get_samplers
(
self
):
def
get_samplers
(
self
):
return
[{
"name"
:
sampler
[
0
],
"aliases"
:
sampler
[
2
],
"options"
:
sampler
[
3
]}
for
sampler
in
all_samplers
]
return
[{
"name"
:
sampler
[
0
],
"aliases"
:
sampler
[
2
],
"options"
:
sampler
[
3
]}
for
sampler
in
sd_samplers
.
all_samplers
]
def
get_upscalers
(
self
):
def
get_upscalers
(
self
):
upscalers
=
[]
upscalers
=
[]
...
...
modules/api/models.py
View file @
336c341a
...
@@ -176,9 +176,9 @@ class InterrogateResponse(BaseModel):
...
@@ -176,9 +176,9 @@ class InterrogateResponse(BaseModel):
caption
:
str
=
Field
(
default
=
None
,
title
=
"Caption"
,
description
=
"The generated caption for the image."
)
caption
:
str
=
Field
(
default
=
None
,
title
=
"Caption"
,
description
=
"The generated caption for the image."
)
fields
=
{}
fields
=
{}
for
key
,
value
in
opts
.
data
.
items
():
for
key
,
metadata
in
opts
.
data_labels
.
items
():
metadata
=
opts
.
data_labels
.
get
(
key
)
value
=
opts
.
data
.
get
(
key
)
optType
=
opts
.
typemap
.
get
(
type
(
value
),
type
(
value
))
optType
=
opts
.
typemap
.
get
(
type
(
metadata
.
default
),
type
(
value
))
if
(
metadata
is
not
None
):
if
(
metadata
is
not
None
):
fields
.
update
({
key
:
(
Optional
[
optType
],
Field
(
fields
.
update
({
key
:
(
Optional
[
optType
],
Field
(
...
...
modules/extensions.py
View file @
336c341a
...
@@ -65,9 +65,12 @@ class Extension:
...
@@ -65,9 +65,12 @@ class Extension:
self
.
can_update
=
False
self
.
can_update
=
False
self
.
status
=
"latest"
self
.
status
=
"latest"
def
pull
(
self
):
def
fetch_and_reset_hard
(
self
):
repo
=
git
.
Repo
(
self
.
path
)
repo
=
git
.
Repo
(
self
.
path
)
repo
.
remotes
.
origin
.
pull
()
# Fix: `error: Your local changes to the following files would be overwritten by merge`,
# because WSL2 Docker set 755 file permissions instead of 644, this results to the error.
repo
.
git
.
fetch
(
'--all'
)
repo
.
git
.
reset
(
'--hard'
,
'origin'
)
def
list_extensions
():
def
list_extensions
():
...
...
modules/generation_parameters_copypaste.py
View file @
336c341a
...
@@ -73,6 +73,7 @@ def integrate_settings_paste_fields(component_dict):
...
@@ -73,6 +73,7 @@ def integrate_settings_paste_fields(component_dict):
'sd_hypernetwork'
:
'Hypernet'
,
'sd_hypernetwork'
:
'Hypernet'
,
'sd_hypernetwork_strength'
:
'Hypernet strength'
,
'sd_hypernetwork_strength'
:
'Hypernet strength'
,
'CLIP_stop_at_last_layers'
:
'Clip skip'
,
'CLIP_stop_at_last_layers'
:
'Clip skip'
,
'inpainting_mask_weight'
:
'Conditional mask weight'
,
'sd_model_checkpoint'
:
'Model hash'
,
'sd_model_checkpoint'
:
'Model hash'
,
}
}
settings_paste_fields
=
[
settings_paste_fields
=
[
...
...
modules/hypernetworks/hypernetwork.py
View file @
336c341a
...
@@ -12,7 +12,7 @@ import torch
...
@@ -12,7 +12,7 @@ import torch
import
tqdm
import
tqdm
from
einops
import
rearrange
,
repeat
from
einops
import
rearrange
,
repeat
from
ldm.util
import
default
from
ldm.util
import
default
from
modules
import
devices
,
processing
,
sd_models
,
shared
from
modules
import
devices
,
processing
,
sd_models
,
shared
,
sd_samplers
from
modules.textual_inversion
import
textual_inversion
from
modules.textual_inversion
import
textual_inversion
from
modules.textual_inversion.learn_schedule
import
LearnRateScheduler
from
modules.textual_inversion.learn_schedule
import
LearnRateScheduler
from
torch
import
einsum
from
torch
import
einsum
...
@@ -535,7 +535,7 @@ def train_hypernetwork(hypernetwork_name, learn_rate, batch_size, data_root, log
...
@@ -535,7 +535,7 @@ def train_hypernetwork(hypernetwork_name, learn_rate, batch_size, data_root, log
p
.
prompt
=
preview_prompt
p
.
prompt
=
preview_prompt
p
.
negative_prompt
=
preview_negative_prompt
p
.
negative_prompt
=
preview_negative_prompt
p
.
steps
=
preview_steps
p
.
steps
=
preview_steps
p
.
sampler_
index
=
preview_sampler_index
p
.
sampler_
name
=
sd_samplers
.
samplers
[
preview_sampler_index
]
.
name
p
.
cfg_scale
=
preview_cfg_scale
p
.
cfg_scale
=
preview_cfg_scale
p
.
seed
=
preview_seed
p
.
seed
=
preview_seed
p
.
width
=
preview_width
p
.
width
=
preview_width
...
...
modules/images.py
View file @
336c341a
...
@@ -303,7 +303,7 @@ class FilenameGenerator:
...
@@ -303,7 +303,7 @@ class FilenameGenerator:
'width'
:
lambda
self
:
self
.
image
.
width
,
'width'
:
lambda
self
:
self
.
image
.
width
,
'height'
:
lambda
self
:
self
.
image
.
height
,
'height'
:
lambda
self
:
self
.
image
.
height
,
'styles'
:
lambda
self
:
self
.
p
and
sanitize_filename_part
(
", "
.
join
([
style
for
style
in
self
.
p
.
styles
if
not
style
==
"None"
])
or
"None"
,
replace_spaces
=
False
),
'styles'
:
lambda
self
:
self
.
p
and
sanitize_filename_part
(
", "
.
join
([
style
for
style
in
self
.
p
.
styles
if
not
style
==
"None"
])
or
"None"
,
replace_spaces
=
False
),
'sampler'
:
lambda
self
:
self
.
p
and
sanitize_filename_part
(
s
d_samplers
.
samplers
[
self
.
p
.
sampler_index
]
.
name
,
replace_spaces
=
False
),
'sampler'
:
lambda
self
:
self
.
p
and
sanitize_filename_part
(
s
elf
.
p
.
sampler_
name
,
replace_spaces
=
False
),
'model_hash'
:
lambda
self
:
getattr
(
self
.
p
,
"sd_model_hash"
,
shared
.
sd_model
.
sd_model_hash
),
'model_hash'
:
lambda
self
:
getattr
(
self
.
p
,
"sd_model_hash"
,
shared
.
sd_model
.
sd_model_hash
),
'date'
:
lambda
self
:
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d'
),
'date'
:
lambda
self
:
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d'
),
'datetime'
:
lambda
self
,
*
args
:
self
.
datetime
(
*
args
),
# accepts formats: [datetime], [datetime<Format>], [datetime<Format><Time Zone>]
'datetime'
:
lambda
self
,
*
args
:
self
.
datetime
(
*
args
),
# accepts formats: [datetime], [datetime<Format>], [datetime<Format><Time Zone>]
...
...
modules/img2img.py
View file @
336c341a
...
@@ -6,7 +6,7 @@ import traceback
...
@@ -6,7 +6,7 @@ import traceback
import
numpy
as
np
import
numpy
as
np
from
PIL
import
Image
,
ImageOps
,
ImageChops
from
PIL
import
Image
,
ImageOps
,
ImageChops
from
modules
import
devices
from
modules
import
devices
,
sd_samplers
from
modules.processing
import
Processed
,
StableDiffusionProcessingImg2Img
,
process_images
from
modules.processing
import
Processed
,
StableDiffusionProcessingImg2Img
,
process_images
from
modules.shared
import
opts
,
state
from
modules.shared
import
opts
,
state
import
modules.shared
as
shared
import
modules.shared
as
shared
...
@@ -99,7 +99,7 @@ def img2img(mode: int, prompt: str, negative_prompt: str, prompt_style: str, pro
...
@@ -99,7 +99,7 @@ def img2img(mode: int, prompt: str, negative_prompt: str, prompt_style: str, pro
seed_resize_from_h
=
seed_resize_from_h
,
seed_resize_from_h
=
seed_resize_from_h
,
seed_resize_from_w
=
seed_resize_from_w
,
seed_resize_from_w
=
seed_resize_from_w
,
seed_enable_extras
=
seed_enable_extras
,
seed_enable_extras
=
seed_enable_extras
,
sampler_index
=
s
ampler_index
,
sampler_index
=
s
d_samplers
.
samplers_for_img2img
[
sampler_index
]
.
name
,
batch_size
=
batch_size
,
batch_size
=
batch_size
,
n_iter
=
n_iter
,
n_iter
=
n_iter
,
steps
=
steps
,
steps
=
steps
,
...
...
modules/processing.py
View file @
336c341a
This diff is collapsed.
Click to expand it.
modules/sd_hijack.py
View file @
336c341a
...
@@ -96,8 +96,8 @@ class StableDiffusionModelHijack:
...
@@ -96,8 +96,8 @@ class StableDiffusionModelHijack:
if
type
(
model_embeddings
.
token_embedding
)
==
EmbeddingsWithFixes
:
if
type
(
model_embeddings
.
token_embedding
)
==
EmbeddingsWithFixes
:
model_embeddings
.
token_embedding
=
model_embeddings
.
token_embedding
.
wrapped
model_embeddings
.
token_embedding
=
model_embeddings
.
token_embedding
.
wrapped
self
.
apply_circular
(
False
)
self
.
layers
=
None
self
.
layers
=
None
self
.
circular_enabled
=
False
self
.
clip
=
None
self
.
clip
=
None
def
apply_circular
(
self
,
enable
):
def
apply_circular
(
self
,
enable
):
...
...
modules/sd_models.py
View file @
336c341a
...
@@ -165,16 +165,9 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
...
@@ -165,16 +165,9 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
cache_enabled
=
shared
.
opts
.
sd_checkpoint_cache
>
0
cache_enabled
=
shared
.
opts
.
sd_checkpoint_cache
>
0
if
cache_enabled
:
sd_vae
.
restore_base_vae
(
model
)
vae_file
=
sd_vae
.
resolve_vae
(
checkpoint_file
,
vae_file
=
vae_file
)
if
cache_enabled
and
checkpoint_info
in
checkpoints_loaded
:
if
cache_enabled
and
checkpoint_info
in
checkpoints_loaded
:
# use checkpoint cache
# use checkpoint cache
vae_name
=
sd_vae
.
get_filename
(
vae_file
)
if
vae_file
else
None
print
(
f
"Loading weights [{sd_model_hash}] from cache"
)
vae_message
=
f
" with {vae_name} VAE"
if
vae_name
else
""
print
(
f
"Loading weights [{sd_model_hash}]{vae_message} from cache"
)
model
.
load_state_dict
(
checkpoints_loaded
[
checkpoint_info
])
model
.
load_state_dict
(
checkpoints_loaded
[
checkpoint_info
])
else
:
else
:
# load from file
# load from file
...
@@ -220,6 +213,7 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
...
@@ -220,6 +213,7 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
model
.
sd_model_checkpoint
=
checkpoint_file
model
.
sd_model_checkpoint
=
checkpoint_file
model
.
sd_checkpoint_info
=
checkpoint_info
model
.
sd_checkpoint_info
=
checkpoint_info
vae_file
=
sd_vae
.
resolve_vae
(
checkpoint_file
,
vae_file
=
vae_file
)
sd_vae
.
load_vae
(
model
,
vae_file
)
sd_vae
.
load_vae
(
model
,
vae_file
)
...
...
modules/sd_samplers.py
View file @
336c341a
...
@@ -46,16 +46,23 @@ all_samplers = [
...
@@ -46,16 +46,23 @@ all_samplers = [
SamplerData
(
'DDIM'
,
lambda
model
:
VanillaStableDiffusionSampler
(
ldm
.
models
.
diffusion
.
ddim
.
DDIMSampler
,
model
),
[],
{}),
SamplerData
(
'DDIM'
,
lambda
model
:
VanillaStableDiffusionSampler
(
ldm
.
models
.
diffusion
.
ddim
.
DDIMSampler
,
model
),
[],
{}),
SamplerData
(
'PLMS'
,
lambda
model
:
VanillaStableDiffusionSampler
(
ldm
.
models
.
diffusion
.
plms
.
PLMSSampler
,
model
),
[],
{}),
SamplerData
(
'PLMS'
,
lambda
model
:
VanillaStableDiffusionSampler
(
ldm
.
models
.
diffusion
.
plms
.
PLMSSampler
,
model
),
[],
{}),
]
]
all_samplers_map
=
{
x
.
name
:
x
for
x
in
all_samplers
}
samplers
=
[]
samplers
=
[]
samplers_for_img2img
=
[]
samplers_for_img2img
=
[]
def
create_sampler_with_index
(
list_of_configs
,
index
,
model
):
def
create_sampler
(
name
,
model
):
config
=
list_of_configs
[
index
]
if
name
is
not
None
:
config
=
all_samplers_map
.
get
(
name
,
None
)
else
:
config
=
all_samplers
[
0
]
assert
config
is
not
None
,
f
'bad sampler name: {name}'
sampler
=
config
.
constructor
(
model
)
sampler
=
config
.
constructor
(
model
)
sampler
.
config
=
config
sampler
.
config
=
config
return
sampler
return
sampler
...
...
modules/sd_vae.py
View file @
336c341a
...
@@ -83,47 +83,54 @@ def refresh_vae_list(vae_path=vae_path, model_path=model_path):
...
@@ -83,47 +83,54 @@ def refresh_vae_list(vae_path=vae_path, model_path=model_path):
return
vae_list
return
vae_list
def
resolve_vae
(
checkpoint_file
,
vae_file
=
"auto"
):
def
get_vae_from_settings
(
vae_file
=
"auto"
):
# else, we load from settings, if not set to be default
if
vae_file
==
"auto"
and
shared
.
opts
.
sd_vae
is
not
None
:
# if saved VAE settings isn't recognized, fallback to auto
vae_file
=
vae_dict
.
get
(
shared
.
opts
.
sd_vae
,
"auto"
)
# if VAE selected but not found, fallback to auto
if
vae_file
not
in
default_vae_values
and
not
os
.
path
.
isfile
(
vae_file
):
vae_file
=
"auto"
print
(
f
"Selected VAE doesn't exist: {vae_file}"
)
return
vae_file
def
resolve_vae
(
checkpoint_file
=
None
,
vae_file
=
"auto"
):
global
first_load
,
vae_dict
,
vae_list
global
first_load
,
vae_dict
,
vae_list
# if vae_file argument is provided, it takes priority, but not saved
# if vae_file argument is provided, it takes priority, but not saved
if
vae_file
and
vae_file
not
in
default_vae_list
:
if
vae_file
and
vae_file
not
in
default_vae_list
:
if
not
os
.
path
.
isfile
(
vae_file
):
if
not
os
.
path
.
isfile
(
vae_file
):
print
(
f
"VAE provided as function argument doesn't exist: {vae_file}"
)
vae_file
=
"auto"
vae_file
=
"auto"
print
(
"VAE provided as function argument doesn't exist"
)
# for the first load, if vae-path is provided, it takes priority, saved, and failure is reported
# for the first load, if vae-path is provided, it takes priority, saved, and failure is reported
if
first_load
and
shared
.
cmd_opts
.
vae_path
is
not
None
:
if
first_load
and
shared
.
cmd_opts
.
vae_path
is
not
None
:
if
os
.
path
.
isfile
(
shared
.
cmd_opts
.
vae_path
):
if
os
.
path
.
isfile
(
shared
.
cmd_opts
.
vae_path
):
vae_file
=
shared
.
cmd_opts
.
vae_path
vae_file
=
shared
.
cmd_opts
.
vae_path
shared
.
opts
.
data
[
'sd_vae'
]
=
get_filename
(
vae_file
)
shared
.
opts
.
data
[
'sd_vae'
]
=
get_filename
(
vae_file
)
else
:
else
:
print
(
"VAE provided as command line argument doesn't exist"
)
print
(
f
"VAE provided as command line argument doesn't exist: {vae_file}"
)
# else, we load from settings
# fallback to selector in settings, if vae selector not set to act as default fallback
if
vae_file
==
"auto"
and
shared
.
opts
.
sd_vae
is
not
None
:
if
not
shared
.
opts
.
sd_vae_as_default
:
# if saved VAE settings isn't recognized, fallback to auto
vae_file
=
get_vae_from_settings
(
vae_file
)
vae_file
=
vae_dict
.
get
(
shared
.
opts
.
sd_vae
,
"auto"
)
# if VAE selected but not found, fallback to auto
if
vae_file
not
in
default_vae_values
and
not
os
.
path
.
isfile
(
vae_file
):
vae_file
=
"auto"
print
(
"Selected VAE doesn't exist"
)
# vae-path cmd arg takes priority for auto
# vae-path cmd arg takes priority for auto
if
vae_file
==
"auto"
and
shared
.
cmd_opts
.
vae_path
is
not
None
:
if
vae_file
==
"auto"
and
shared
.
cmd_opts
.
vae_path
is
not
None
:
if
os
.
path
.
isfile
(
shared
.
cmd_opts
.
vae_path
):
if
os
.
path
.
isfile
(
shared
.
cmd_opts
.
vae_path
):
vae_file
=
shared
.
cmd_opts
.
vae_path
vae_file
=
shared
.
cmd_opts
.
vae_path
print
(
"Using VAE provided as command line argument
"
)
print
(
f
"Using VAE provided as command line argument: {vae_file}
"
)
# if still not found, try look for ".vae.pt" beside model
# if still not found, try look for ".vae.pt" beside model
model_path
=
os
.
path
.
splitext
(
checkpoint_file
)[
0
]
model_path
=
os
.
path
.
splitext
(
checkpoint_file
)[
0
]
if
vae_file
==
"auto"
:
if
vae_file
==
"auto"
:
vae_file_try
=
model_path
+
".vae.pt"
vae_file_try
=
model_path
+
".vae.pt"
if
os
.
path
.
isfile
(
vae_file_try
):
if
os
.
path
.
isfile
(
vae_file_try
):
vae_file
=
vae_file_try
vae_file
=
vae_file_try
print
(
"Using VAE found beside selected model
"
)
print
(
f
"Using VAE found similar to selected model: {vae_file}
"
)
# if still not found, try look for ".vae.ckpt" beside model
# if still not found, try look for ".vae.ckpt" beside model
if
vae_file
==
"auto"
:
if
vae_file
==
"auto"
:
vae_file_try
=
model_path
+
".vae.ckpt"
vae_file_try
=
model_path
+
".vae.ckpt"
if
os
.
path
.
isfile
(
vae_file_try
):
if
os
.
path
.
isfile
(
vae_file_try
):
vae_file
=
vae_file_try
vae_file
=
vae_file_try
print
(
"Using VAE found beside selected model
"
)
print
(
f
"Using VAE found similar to selected model: {vae_file}
"
)
# No more fallbacks for auto
# No more fallbacks for auto
if
vae_file
==
"auto"
:
if
vae_file
==
"auto"
:
vae_file
=
None
vae_file
=
None
...
@@ -139,6 +146,7 @@ def load_vae(model, vae_file=None):
...
@@ -139,6 +146,7 @@ def load_vae(model, vae_file=None):
# save_settings = False
# save_settings = False
if
vae_file
:
if
vae_file
:
assert
os
.
path
.
isfile
(
vae_file
),
f
"VAE file doesn't exist: {vae_file}"
print
(
f
"Loading VAE weights from: {vae_file}"
)
print
(
f
"Loading VAE weights from: {vae_file}"
)
vae_ckpt
=
torch
.
load
(
vae_file
,
map_location
=
shared
.
weight_load_location
)
vae_ckpt
=
torch
.
load
(
vae_file
,
map_location
=
shared
.
weight_load_location
)
vae_dict_1
=
{
k
:
v
for
k
,
v
in
vae_ckpt
[
"state_dict"
]
.
items
()
if
k
[
0
:
4
]
!=
"loss"
and
k
not
in
vae_ignore_keys
}
vae_dict_1
=
{
k
:
v
for
k
,
v
in
vae_ckpt
[
"state_dict"
]
.
items
()
if
k
[
0
:
4
]
!=
"loss"
and
k
not
in
vae_ignore_keys
}
...
...
modules/shared.py
View file @
336c341a
...
@@ -335,7 +335,8 @@ options_templates.update(options_section(('training', "Training"), {
...
@@ -335,7 +335,8 @@ options_templates.update(options_section(('training', "Training"), {
options_templates
.
update
(
options_section
((
'sd'
,
"Stable Diffusion"
),
{
options_templates
.
update
(
options_section
((
'sd'
,
"Stable Diffusion"
),
{
"sd_model_checkpoint"
:
OptionInfo
(
None
,
"Stable Diffusion checkpoint"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
modules
.
sd_models
.
checkpoint_tiles
()},
refresh
=
sd_models
.
list_models
),
"sd_model_checkpoint"
:
OptionInfo
(
None
,
"Stable Diffusion checkpoint"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
modules
.
sd_models
.
checkpoint_tiles
()},
refresh
=
sd_models
.
list_models
),
"sd_checkpoint_cache"
:
OptionInfo
(
0
,
"Checkpoints to cache in RAM"
,
gr
.
Slider
,
{
"minimum"
:
0
,
"maximum"
:
10
,
"step"
:
1
}),
"sd_checkpoint_cache"
:
OptionInfo
(
0
,
"Checkpoints to cache in RAM"
,
gr
.
Slider
,
{
"minimum"
:
0
,
"maximum"
:
10
,
"step"
:
1
}),
"sd_vae"
:
OptionInfo
(
"auto"
,
"SD VAE"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
list
(
sd_vae
.
vae_list
)},
refresh
=
sd_vae
.
refresh_vae_list
),
"sd_vae"
:
OptionInfo
(
"auto"
,
"SD VAE"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
sd_vae
.
vae_list
},
refresh
=
sd_vae
.
refresh_vae_list
),
"sd_vae_as_default"
:
OptionInfo
(
False
,
"Ignore selected VAE for stable diffusion checkpoints that have their own .vae.pt next to them"
),
"sd_hypernetwork"
:
OptionInfo
(
"None"
,
"Hypernetwork"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
[
"None"
]
+
[
x
for
x
in
hypernetworks
.
keys
()]},
refresh
=
reload_hypernetworks
),
"sd_hypernetwork"
:
OptionInfo
(
"None"
,
"Hypernetwork"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
[
"None"
]
+
[
x
for
x
in
hypernetworks
.
keys
()]},
refresh
=
reload_hypernetworks
),
"sd_hypernetwork_strength"
:
OptionInfo
(
1.0
,
"Hypernetwork strength"
,
gr
.
Slider
,
{
"minimum"
:
0.0
,
"maximum"
:
1.0
,
"step"
:
0.001
}),
"sd_hypernetwork_strength"
:
OptionInfo
(
1.0
,
"Hypernetwork strength"
,
gr
.
Slider
,
{
"minimum"
:
0.0
,
"maximum"
:
1.0
,
"step"
:
0.001
}),
"inpainting_mask_weight"
:
OptionInfo
(
1.0
,
"Inpainting conditioning mask strength"
,
gr
.
Slider
,
{
"minimum"
:
0.0
,
"maximum"
:
1.0
,
"step"
:
0.01
}),
"inpainting_mask_weight"
:
OptionInfo
(
1.0
,
"Inpainting conditioning mask strength"
,
gr
.
Slider
,
{
"minimum"
:
0.0
,
"maximum"
:
1.0
,
"step"
:
0.01
}),
...
...
modules/styles.py
View file @
336c341a
...
@@ -65,17 +65,6 @@ class StyleDatabase:
...
@@ -65,17 +65,6 @@ class StyleDatabase:
def
apply_negative_styles_to_prompt
(
self
,
prompt
,
styles
):
def
apply_negative_styles_to_prompt
(
self
,
prompt
,
styles
):
return
apply_styles_to_prompt
(
prompt
,
[
self
.
styles
.
get
(
x
,
self
.
no_style
)
.
negative_prompt
for
x
in
styles
])
return
apply_styles_to_prompt
(
prompt
,
[
self
.
styles
.
get
(
x
,
self
.
no_style
)
.
negative_prompt
for
x
in
styles
])
def
apply_styles
(
self
,
p
:
StableDiffusionProcessing
)
->
None
:
if
isinstance
(
p
.
prompt
,
list
):
p
.
prompt
=
[
self
.
apply_styles_to_prompt
(
prompt
,
p
.
styles
)
for
prompt
in
p
.
prompt
]
else
:
p
.
prompt
=
self
.
apply_styles_to_prompt
(
p
.
prompt
,
p
.
styles
)
if
isinstance
(
p
.
negative_prompt
,
list
):
p
.
negative_prompt
=
[
self
.
apply_negative_styles_to_prompt
(
prompt
,
p
.
styles
)
for
prompt
in
p
.
negative_prompt
]
else
:
p
.
negative_prompt
=
self
.
apply_negative_styles_to_prompt
(
p
.
negative_prompt
,
p
.
styles
)
def
save_styles
(
self
,
path
:
str
)
->
None
:
def
save_styles
(
self
,
path
:
str
)
->
None
:
# Write to temporary file first, so we don't nuke the file if something goes wrong
# Write to temporary file first, so we don't nuke the file if something goes wrong
fd
,
temp_path
=
tempfile
.
mkstemp
(
".csv"
)
fd
,
temp_path
=
tempfile
.
mkstemp
(
".csv"
)
...
...
modules/textual_inversion/textual_inversion.py
View file @
336c341a
...
@@ -10,7 +10,7 @@ import csv
...
@@ -10,7 +10,7 @@ import csv
from
PIL
import
Image
,
PngImagePlugin
from
PIL
import
Image
,
PngImagePlugin
from
modules
import
shared
,
devices
,
sd_hijack
,
processing
,
sd_models
,
images
from
modules
import
shared
,
devices
,
sd_hijack
,
processing
,
sd_models
,
images
,
sd_samplers
import
modules.textual_inversion.dataset
import
modules.textual_inversion.dataset
from
modules.textual_inversion.learn_schedule
import
LearnRateScheduler
from
modules.textual_inversion.learn_schedule
import
LearnRateScheduler
...
@@ -345,7 +345,7 @@ def train_embedding(embedding_name, learn_rate, batch_size, data_root, log_direc
...
@@ -345,7 +345,7 @@ def train_embedding(embedding_name, learn_rate, batch_size, data_root, log_direc
p
.
prompt
=
preview_prompt
p
.
prompt
=
preview_prompt
p
.
negative_prompt
=
preview_negative_prompt
p
.
negative_prompt
=
preview_negative_prompt
p
.
steps
=
preview_steps
p
.
steps
=
preview_steps
p
.
sampler_
index
=
preview_sampler_index
p
.
sampler_
name
=
sd_samplers
.
samplers
[
preview_sampler_index
]
.
name
p
.
cfg_scale
=
preview_cfg_scale
p
.
cfg_scale
=
preview_cfg_scale
p
.
seed
=
preview_seed
p
.
seed
=
preview_seed
p
.
width
=
preview_width
p
.
width
=
preview_width
...
...
modules/textual_inversion/ui.py
View file @
336c341a
...
@@ -18,7 +18,7 @@ def create_embedding(name, initialization_text, nvpt, overwrite_old):
...
@@ -18,7 +18,7 @@ def create_embedding(name, initialization_text, nvpt, overwrite_old):
def
preprocess
(
*
args
):
def
preprocess
(
*
args
):
modules
.
textual_inversion
.
preprocess
.
preprocess
(
*
args
)
modules
.
textual_inversion
.
preprocess
.
preprocess
(
*
args
)
return
"Preprocessing finished
."
,
""
return
f
"Preprocessing {'interrupted' if shared.state.interrupted else 'finished'}
."
,
""
def
train_embedding
(
*
args
):
def
train_embedding
(
*
args
):
...
...
modules/txt2img.py
View file @
336c341a
import
modules.scripts
import
modules.scripts
from
modules
import
sd_samplers
from
modules.processing
import
StableDiffusionProcessing
,
Processed
,
StableDiffusionProcessingTxt2Img
,
\
from
modules.processing
import
StableDiffusionProcessing
,
Processed
,
StableDiffusionProcessingTxt2Img
,
\
StableDiffusionProcessingImg2Img
,
process_images
StableDiffusionProcessingImg2Img
,
process_images
from
modules.shared
import
opts
,
cmd_opts
from
modules.shared
import
opts
,
cmd_opts
...
@@ -21,7 +22,7 @@ def txt2img(prompt: str, negative_prompt: str, prompt_style: str, prompt_style2:
...
@@ -21,7 +22,7 @@ def txt2img(prompt: str, negative_prompt: str, prompt_style: str, prompt_style2:
seed_resize_from_h
=
seed_resize_from_h
,
seed_resize_from_h
=
seed_resize_from_h
,
seed_resize_from_w
=
seed_resize_from_w
,
seed_resize_from_w
=
seed_resize_from_w
,
seed_enable_extras
=
seed_enable_extras
,
seed_enable_extras
=
seed_enable_extras
,
sampler_
index
=
sampler_index
,
sampler_
name
=
sd_samplers
.
samplers
[
sampler_index
]
.
name
,
batch_size
=
batch_size
,
batch_size
=
batch_size
,
n_iter
=
n_iter
,
n_iter
=
n_iter
,
steps
=
steps
,
steps
=
steps
,
...
...
modules/ui.py
View file @
336c341a
...
@@ -69,8 +69,11 @@ sample_img2img = sample_img2img if os.path.exists(sample_img2img) else None
...
@@ -69,8 +69,11 @@ sample_img2img = sample_img2img if os.path.exists(sample_img2img) else None
css_hide_progressbar
=
"""
css_hide_progressbar
=
"""
.wrap .m-12 svg { display:none!important; }
.wrap .m-12 svg { display:none!important; }
.wrap .m-12::before { content:"Loading..." }
.wrap .m-12::before { content:"Loading..." }
.wrap .z-20 svg { display:none!important; }
.wrap .z-20::before { content:"Loading..." }
.progress-bar { display:none!important; }
.progress-bar { display:none!important; }
.meta-text { display:none!important; }
.meta-text { display:none!important; }
.meta-text-center { display:none!important; }
"""
"""
# Using constants for these since the variation selector isn't visible.
# Using constants for these since the variation selector isn't visible.
...
@@ -142,7 +145,7 @@ def save_files(js_data, images, do_make_zip, index):
...
@@ -142,7 +145,7 @@ def save_files(js_data, images, do_make_zip, index):
filenames
.
append
(
os
.
path
.
basename
(
txt_fullfn
))
filenames
.
append
(
os
.
path
.
basename
(
txt_fullfn
))
fullfns
.
append
(
txt_fullfn
)
fullfns
.
append
(
txt_fullfn
)
writer
.
writerow
([
data
[
"prompt"
],
data
[
"seed"
],
data
[
"width"
],
data
[
"height"
],
data
[
"sampler"
],
data
[
"cfg_scale"
],
data
[
"steps"
],
filenames
[
0
],
data
[
"negative_prompt"
]])
writer
.
writerow
([
data
[
"prompt"
],
data
[
"seed"
],
data
[
"width"
],
data
[
"height"
],
data
[
"sampler
_name
"
],
data
[
"cfg_scale"
],
data
[
"steps"
],
filenames
[
0
],
data
[
"negative_prompt"
]])
# Make Zip
# Make Zip
if
do_make_zip
:
if
do_make_zip
:
...
@@ -1249,7 +1252,9 @@ def create_ui(wrap_gradio_gpu_call):
...
@@ -1249,7 +1252,9 @@ def create_ui(wrap_gradio_gpu_call):
gr
.
HTML
(
value
=
""
)
gr
.
HTML
(
value
=
""
)
with
gr
.
Column
():
with
gr
.
Column
():
run_preprocess
=
gr
.
Button
(
value
=
"Preprocess"
,
variant
=
'primary'
)
with
gr
.
Row
():
interrupt_preprocessing
=
gr
.
Button
(
"Interrupt"
)
run_preprocess
=
gr
.
Button
(
value
=
"Preprocess"
,
variant
=
'primary'
)
process_split
.
change
(
process_split
.
change
(
fn
=
lambda
show
:
gr_show
(
show
),
fn
=
lambda
show
:
gr_show
(
show
),
...
@@ -1422,6 +1427,12 @@ def create_ui(wrap_gradio_gpu_call):
...
@@ -1422,6 +1427,12 @@ def create_ui(wrap_gradio_gpu_call):
outputs
=
[],
outputs
=
[],
)
)
interrupt_preprocessing
.
click
(
fn
=
lambda
:
shared
.
state
.
interrupt
(),
inputs
=
[],
outputs
=
[],
)
def
create_setting_component
(
key
,
is_quicksettings
=
False
):
def
create_setting_component
(
key
,
is_quicksettings
=
False
):
def
fun
():
def
fun
():
return
opts
.
data
[
key
]
if
key
in
opts
.
data
else
opts
.
data_labels
[
key
]
.
default
return
opts
.
data
[
key
]
if
key
in
opts
.
data
else
opts
.
data_labels
[
key
]
.
default
...
...
modules/ui_extensions.py
View file @
336c341a
...
@@ -36,9 +36,9 @@ def apply_and_restart(disable_list, update_list):
...
@@ -36,9 +36,9 @@ def apply_and_restart(disable_list, update_list):
continue
continue
try
:
try
:
ext
.
pull
()
ext
.
fetch_and_reset_hard
()
except
Exception
:
except
Exception
:
print
(
f
"Error
pull
ing updates for {ext.name}:"
,
file
=
sys
.
stderr
)
print
(
f
"Error
gett
ing updates for {ext.name}:"
,
file
=
sys
.
stderr
)
print
(
traceback
.
format_exc
(),
file
=
sys
.
stderr
)
print
(
traceback
.
format_exc
(),
file
=
sys
.
stderr
)
shared
.
opts
.
disabled_extensions
=
disabled
shared
.
opts
.
disabled_extensions
=
disabled
...
...
requirements.txt
View file @
336c341a
accelerate
basicsr
basicsr
diffusers
diffusers
fairscale
==0.4.4
fairscale
==0.4.4
...
...
requirements_versions.txt
View file @
336c341a
transformers==4.19.2
transformers==4.19.2
diffusers==0.3.0
diffusers==0.3.0
accelerate==0.12.0
basicsr==1.4.2
basicsr==1.4.2
gfpgan==1.3.8
gfpgan==1.3.8
gradio==3.9
gradio==3.9
...
...
scripts/img2imgalt.py
View file @
336c341a
...
@@ -157,7 +157,7 @@ class Script(scripts.Script):
...
@@ -157,7 +157,7 @@ class Script(scripts.Script):
def
run
(
self
,
p
,
_
,
override_sampler
,
override_prompt
,
original_prompt
,
original_negative_prompt
,
override_steps
,
st
,
override_strength
,
cfg
,
randomness
,
sigma_adjustment
):
def
run
(
self
,
p
,
_
,
override_sampler
,
override_prompt
,
original_prompt
,
original_negative_prompt
,
override_steps
,
st
,
override_strength
,
cfg
,
randomness
,
sigma_adjustment
):
# Override
# Override
if
override_sampler
:
if
override_sampler
:
p
.
sampler_
index
=
[
sampler
.
name
for
sampler
in
sd_samplers
.
samplers
]
.
index
(
"Euler"
)
p
.
sampler_
name
=
"Euler"
if
override_prompt
:
if
override_prompt
:
p
.
prompt
=
original_prompt
p
.
prompt
=
original_prompt
p
.
negative_prompt
=
original_negative_prompt
p
.
negative_prompt
=
original_negative_prompt
...
@@ -191,7 +191,7 @@ class Script(scripts.Script):
...
@@ -191,7 +191,7 @@ class Script(scripts.Script):
combined_noise
=
((
1
-
randomness
)
*
rec_noise
+
randomness
*
rand_noise
)
/
((
randomness
**
2
+
(
1
-
randomness
)
**
2
)
**
0.5
)
combined_noise
=
((
1
-
randomness
)
*
rec_noise
+
randomness
*
rand_noise
)
/
((
randomness
**
2
+
(
1
-
randomness
)
**
2
)
**
0.5
)
sampler
=
sd_samplers
.
create_sampler
_with_index
(
sd_samplers
.
samplers
,
p
.
sampler_index
,
p
.
sd_model
)
sampler
=
sd_samplers
.
create_sampler
(
p
.
sampler_name
,
p
.
sd_model
)
sigmas
=
sampler
.
model_wrap
.
get_sigmas
(
p
.
steps
)
sigmas
=
sampler
.
model_wrap
.
get_sigmas
(
p
.
steps
)
...
...
scripts/xy_grid.py
View file @
336c341a
...
@@ -10,9 +10,9 @@ import numpy as np
...
@@ -10,9 +10,9 @@ import numpy as np
import
modules.scripts
as
scripts
import
modules.scripts
as
scripts
import
gradio
as
gr
import
gradio
as
gr
from
modules
import
images
from
modules
import
images
,
sd_samplers
from
modules.hypernetworks
import
hypernetwork
from
modules.hypernetworks
import
hypernetwork
from
modules.processing
import
process_images
,
Processed
,
get_correct_sampler
,
StableDiffusionProcessingTxt2Img
from
modules.processing
import
process_images
,
Processed
,
StableDiffusionProcessingTxt2Img
from
modules.shared
import
opts
,
cmd_opts
,
state
from
modules.shared
import
opts
,
cmd_opts
,
state
import
modules.shared
as
shared
import
modules.shared
as
shared
import
modules.sd_samplers
import
modules.sd_samplers
...
@@ -60,9 +60,9 @@ def apply_order(p, x, xs):
...
@@ -60,9 +60,9 @@ def apply_order(p, x, xs):
p
.
prompt
=
prompt_tmp
+
p
.
prompt
p
.
prompt
=
prompt_tmp
+
p
.
prompt
def
build_samplers_dict
(
p
):
def
build_samplers_dict
():
samplers_dict
=
{}
samplers_dict
=
{}
for
i
,
sampler
in
enumerate
(
get_correct_sampler
(
p
)
):
for
i
,
sampler
in
enumerate
(
sd_samplers
.
all_samplers
):
samplers_dict
[
sampler
.
name
.
lower
()]
=
i
samplers_dict
[
sampler
.
name
.
lower
()]
=
i
for
alias
in
sampler
.
aliases
:
for
alias
in
sampler
.
aliases
:
samplers_dict
[
alias
.
lower
()]
=
i
samplers_dict
[
alias
.
lower
()]
=
i
...
@@ -70,7 +70,7 @@ def build_samplers_dict(p):
...
@@ -70,7 +70,7 @@ def build_samplers_dict(p):
def
apply_sampler
(
p
,
x
,
xs
):
def
apply_sampler
(
p
,
x
,
xs
):
sampler_index
=
build_samplers_dict
(
p
)
.
get
(
x
.
lower
(),
None
)
sampler_index
=
build_samplers_dict
()
.
get
(
x
.
lower
(),
None
)
if
sampler_index
is
None
:
if
sampler_index
is
None
:
raise
RuntimeError
(
f
"Unknown sampler: {x}"
)
raise
RuntimeError
(
f
"Unknown sampler: {x}"
)
...
@@ -78,7 +78,7 @@ def apply_sampler(p, x, xs):
...
@@ -78,7 +78,7 @@ def apply_sampler(p, x, xs):
def
confirm_samplers
(
p
,
xs
):
def
confirm_samplers
(
p
,
xs
):
samplers_dict
=
build_samplers_dict
(
p
)
samplers_dict
=
build_samplers_dict
()
for
x
in
xs
:
for
x
in
xs
:
if
x
.
lower
()
not
in
samplers_dict
.
keys
():
if
x
.
lower
()
not
in
samplers_dict
.
keys
():
raise
RuntimeError
(
f
"Unknown sampler: {x}"
)
raise
RuntimeError
(
f
"Unknown sampler: {x}"
)
...
...
webui-user.bat
View file @
336c341a
...
@@ -4,5 +4,6 @@ set PYTHON=
...
@@ -4,5 +4,6 @@ set PYTHON=
set
GIT
=
set
GIT
=
set
VENV_DIR
=
set
VENV_DIR
=
set
COMMANDLINE_ARGS
=
set
COMMANDLINE_ARGS
=
set
ACCELERATE
=
call
webui
.bat
call
webui
.bat
webui-user.sh
View file @
336c341a
...
@@ -40,4 +40,7 @@ export COMMANDLINE_ARGS=""
...
@@ -40,4 +40,7 @@ export COMMANDLINE_ARGS=""
#export CODEFORMER_COMMIT_HASH=""
#export CODEFORMER_COMMIT_HASH=""
#export BLIP_COMMIT_HASH=""
#export BLIP_COMMIT_HASH=""
# Uncomment to enable accelerated launch
#export ACCELERATE="True"
###########################################
###########################################
webui.bat
View file @
336c341a
...
@@ -28,15 +28,27 @@ goto :show_stdout_stderr
...
@@ -28,15 +28,27 @@ goto :show_stdout_stderr
:activate_venv
:activate_venv
set PYTHON="
%~dp0
%VENV_DIR%
\Scripts\Python.exe"
set PYTHON="
%~dp0
%VENV_DIR%
\Scripts\Python.exe"
echo venv
%PYTHON%
echo venv
%PYTHON%
if [
%ACCELERATE%
] == ["True"] goto :accelerate
goto :launch
goto :launch
:skip_venv
:skip_venv
:accelerate
echo "Checking for accelerate"
set ACCELERATE="
%~dp0
%VENV_DIR%
\Scripts\accelerate.exe"
if EXIST
%ACCELERATE%
goto :accelerate_launch
:launch
:launch
%PYTHON%
launch.py
%
*
%PYTHON%
launch.py
%
*
pause
pause
exit /b
exit /b
:accelerate_launch
echo "Accelerating"
%ACCELERATE%
launch --num_cpu_threads_per_process=6 launch.py
pause
exit /b
:show_stdout_stderr
:show_stdout_stderr
echo.
echo.
...
...
webui.py
View file @
336c341a
...
@@ -82,6 +82,7 @@ def initialize():
...
@@ -82,6 +82,7 @@ def initialize():
modules
.
sd_models
.
load_model
()
modules
.
sd_models
.
load_model
()
shared
.
opts
.
onchange
(
"sd_model_checkpoint"
,
wrap_queued_call
(
lambda
:
modules
.
sd_models
.
reload_model_weights
()))
shared
.
opts
.
onchange
(
"sd_model_checkpoint"
,
wrap_queued_call
(
lambda
:
modules
.
sd_models
.
reload_model_weights
()))
shared
.
opts
.
onchange
(
"sd_vae"
,
wrap_queued_call
(
lambda
:
modules
.
sd_vae
.
reload_vae_weights
()),
call
=
False
)
shared
.
opts
.
onchange
(
"sd_vae"
,
wrap_queued_call
(
lambda
:
modules
.
sd_vae
.
reload_vae_weights
()),
call
=
False
)
shared
.
opts
.
onchange
(
"sd_vae_as_default"
,
wrap_queued_call
(
lambda
:
modules
.
sd_vae
.
reload_vae_weights
()),
call
=
False
)
shared
.
opts
.
onchange
(
"sd_hypernetwork"
,
wrap_queued_call
(
lambda
:
modules
.
hypernetworks
.
hypernetwork
.
load_hypernetwork
(
shared
.
opts
.
sd_hypernetwork
)))
shared
.
opts
.
onchange
(
"sd_hypernetwork"
,
wrap_queued_call
(
lambda
:
modules
.
hypernetworks
.
hypernetwork
.
load_hypernetwork
(
shared
.
opts
.
sd_hypernetwork
)))
shared
.
opts
.
onchange
(
"sd_hypernetwork_strength"
,
modules
.
hypernetworks
.
hypernetwork
.
apply_strength
)
shared
.
opts
.
onchange
(
"sd_hypernetwork_strength"
,
modules
.
hypernetworks
.
hypernetwork
.
apply_strength
)
...
...
webui.sh
View file @
336c341a
...
@@ -134,7 +134,15 @@ else
...
@@ -134,7 +134,15 @@ else
exit
1
exit
1
fi
fi
printf
"
\n
%s
\n
"
"
${
delimiter
}
"
if
[[
!
-z
"
${
ACCELERATE
}
"
]]
&&
[
${
ACCELERATE
}
=
"True"
]
&&
[
-x
"
$(
command
-v
accelerate
)
"
]
printf
"Launching launch.py..."
then
printf
"
\n
%s
\n
"
"
${
delimiter
}
"
printf
"
\n
%s
\n
"
"
${
delimiter
}
"
"
${
python_cmd
}
"
"
${
LAUNCH_SCRIPT
}
"
"
$@
"
printf
"Accelerating launch.py..."
printf
"
\n
%s
\n
"
"
${
delimiter
}
"
accelerate launch
--num_cpu_threads_per_process
=
6
"
${
LAUNCH_SCRIPT
}
"
"
$@
"
else
printf
"
\n
%s
\n
"
"
${
delimiter
}
"
printf
"Launching launch.py..."
printf
"
\n
%s
\n
"
"
${
delimiter
}
"
"
${
python_cmd
}
"
"
${
LAUNCH_SCRIPT
}
"
"
$@
"
fi
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