Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
7a7a201d
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
8 个月 前同步成功
通知
1717
Star
78
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
7a7a201d
编写于
6月 05, 2023
作者:
A
AUTOMATIC1111
提交者:
GitHub
6月 05, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10956 from akx/len
Simplify a bunch of `len(x) > 0`/`len(x) == 0` style expressions
上级
9781f31f
51864790
变更
25
隐藏空白更改
内联
并排
Showing
25 changed file
with
47 addition
and
48 deletion
+47
-48
extensions-builtin/LDSR/sd_hijack_autoencoder.py
extensions-builtin/LDSR/sd_hijack_autoencoder.py
+2
-1
extensions-builtin/LDSR/sd_hijack_ddpm_v1.py
extensions-builtin/LDSR/sd_hijack_ddpm_v1.py
+2
-2
extensions-builtin/Lora/extra_networks_lora.py
extensions-builtin/Lora/extra_networks_lora.py
+2
-2
extensions-builtin/Lora/lora.py
extensions-builtin/Lora/lora.py
+2
-2
extensions-builtin/extra-options-section/scripts/extra_options_section.py
...in/extra-options-section/scripts/extra_options_section.py
+1
-1
modules/api/api.py
modules/api/api.py
+1
-1
modules/call_queue.py
modules/call_queue.py
+1
-1
modules/extra_networks_hypernet.py
modules/extra_networks_hypernet.py
+2
-2
modules/generation_parameters_copypaste.py
modules/generation_parameters_copypaste.py
+2
-4
modules/images.py
modules/images.py
+3
-3
modules/img2img.py
modules/img2img.py
+1
-2
modules/models/diffusion/ddpm_edit.py
modules/models/diffusion/ddpm_edit.py
+2
-2
modules/processing.py
modules/processing.py
+2
-1
modules/prompt_parser.py
modules/prompt_parser.py
+3
-3
modules/script_callbacks.py
modules/script_callbacks.py
+2
-2
modules/sd_hijack_clip.py
modules/sd_hijack_clip.py
+1
-1
modules/sd_hijack_clip_old.py
modules/sd_hijack_clip_old.py
+1
-1
modules/textual_inversion/autocrop.py
modules/textual_inversion/autocrop.py
+7
-7
modules/textual_inversion/dataset.py
modules/textual_inversion/dataset.py
+1
-1
modules/textual_inversion/preprocess.py
modules/textual_inversion/preprocess.py
+2
-2
modules/textual_inversion/textual_inversion.py
modules/textual_inversion/textual_inversion.py
+1
-1
modules/ui.py
modules/ui.py
+1
-1
modules/ui_extensions.py
modules/ui_extensions.py
+3
-2
modules/ui_settings.py
modules/ui_settings.py
+1
-1
scripts/prompts_from_file.py
scripts/prompts_from_file.py
+1
-2
未找到文件。
extensions-builtin/LDSR/sd_hijack_autoencoder.py
浏览文件 @
7a7a201d
...
@@ -91,8 +91,9 @@ class VQModel(pl.LightningModule):
...
@@ -91,8 +91,9 @@ class VQModel(pl.LightningModule):
del
sd
[
k
]
del
sd
[
k
]
missing
,
unexpected
=
self
.
load_state_dict
(
sd
,
strict
=
False
)
missing
,
unexpected
=
self
.
load_state_dict
(
sd
,
strict
=
False
)
print
(
f
"Restored from
{
path
}
with
{
len
(
missing
)
}
missing and
{
len
(
unexpected
)
}
unexpected keys"
)
print
(
f
"Restored from
{
path
}
with
{
len
(
missing
)
}
missing and
{
len
(
unexpected
)
}
unexpected keys"
)
if
len
(
missing
)
>
0
:
if
missing
:
print
(
f
"Missing Keys:
{
missing
}
"
)
print
(
f
"Missing Keys:
{
missing
}
"
)
if
unexpected
:
print
(
f
"Unexpected Keys:
{
unexpected
}
"
)
print
(
f
"Unexpected Keys:
{
unexpected
}
"
)
def
on_train_batch_end
(
self
,
*
args
,
**
kwargs
):
def
on_train_batch_end
(
self
,
*
args
,
**
kwargs
):
...
...
extensions-builtin/LDSR/sd_hijack_ddpm_v1.py
浏览文件 @
7a7a201d
...
@@ -195,9 +195,9 @@ class DDPMV1(pl.LightningModule):
...
@@ -195,9 +195,9 @@ class DDPMV1(pl.LightningModule):
missing
,
unexpected
=
self
.
load_state_dict
(
sd
,
strict
=
False
)
if
not
only_model
else
self
.
model
.
load_state_dict
(
missing
,
unexpected
=
self
.
load_state_dict
(
sd
,
strict
=
False
)
if
not
only_model
else
self
.
model
.
load_state_dict
(
sd
,
strict
=
False
)
sd
,
strict
=
False
)
print
(
f
"Restored from
{
path
}
with
{
len
(
missing
)
}
missing and
{
len
(
unexpected
)
}
unexpected keys"
)
print
(
f
"Restored from
{
path
}
with
{
len
(
missing
)
}
missing and
{
len
(
unexpected
)
}
unexpected keys"
)
if
len
(
missing
)
>
0
:
if
missing
:
print
(
f
"Missing Keys:
{
missing
}
"
)
print
(
f
"Missing Keys:
{
missing
}
"
)
if
len
(
unexpected
)
>
0
:
if
unexpected
:
print
(
f
"Unexpected Keys:
{
unexpected
}
"
)
print
(
f
"Unexpected Keys:
{
unexpected
}
"
)
def
q_mean_variance
(
self
,
x_start
,
t
):
def
q_mean_variance
(
self
,
x_start
,
t
):
...
...
extensions-builtin/Lora/extra_networks_lora.py
浏览文件 @
7a7a201d
...
@@ -9,14 +9,14 @@ class ExtraNetworkLora(extra_networks.ExtraNetwork):
...
@@ -9,14 +9,14 @@ class ExtraNetworkLora(extra_networks.ExtraNetwork):
def
activate
(
self
,
p
,
params_list
):
def
activate
(
self
,
p
,
params_list
):
additional
=
shared
.
opts
.
sd_lora
additional
=
shared
.
opts
.
sd_lora
if
additional
!=
"None"
and
additional
in
lora
.
available_loras
and
len
([
x
for
x
in
params_list
if
x
.
items
[
0
]
==
additional
])
==
0
:
if
additional
!=
"None"
and
additional
in
lora
.
available_loras
and
not
any
(
x
for
x
in
params_list
if
x
.
items
[
0
]
==
additional
)
:
p
.
all_prompts
=
[
x
+
f
"<lora:
{
additional
}
:
{
shared
.
opts
.
extra_networks_default_multiplier
}
>"
for
x
in
p
.
all_prompts
]
p
.
all_prompts
=
[
x
+
f
"<lora:
{
additional
}
:
{
shared
.
opts
.
extra_networks_default_multiplier
}
>"
for
x
in
p
.
all_prompts
]
params_list
.
append
(
extra_networks
.
ExtraNetworkParams
(
items
=
[
additional
,
shared
.
opts
.
extra_networks_default_multiplier
]))
params_list
.
append
(
extra_networks
.
ExtraNetworkParams
(
items
=
[
additional
,
shared
.
opts
.
extra_networks_default_multiplier
]))
names
=
[]
names
=
[]
multipliers
=
[]
multipliers
=
[]
for
params
in
params_list
:
for
params
in
params_list
:
assert
len
(
params
.
items
)
>
0
assert
params
.
items
names
.
append
(
params
.
items
[
0
])
names
.
append
(
params
.
items
[
0
])
multipliers
.
append
(
float
(
params
.
items
[
1
])
if
len
(
params
.
items
)
>
1
else
1.0
)
multipliers
.
append
(
float
(
params
.
items
[
1
])
if
len
(
params
.
items
)
>
1
else
1.0
)
...
...
extensions-builtin/Lora/lora.py
浏览文件 @
7a7a201d
...
@@ -219,7 +219,7 @@ def load_lora(name, lora_on_disk):
...
@@ -219,7 +219,7 @@ def load_lora(name, lora_on_disk):
else
:
else
:
raise
AssertionError
(
f
"Bad Lora layer name:
{
key_diffusers
}
- must end in lora_up.weight, lora_down.weight or alpha"
)
raise
AssertionError
(
f
"Bad Lora layer name:
{
key_diffusers
}
- must end in lora_up.weight, lora_down.weight or alpha"
)
if
len
(
keys_failed_to_match
)
>
0
:
if
keys_failed_to_match
:
print
(
f
"Failed to match keys when loading Lora
{
lora_on_disk
.
filename
}
:
{
keys_failed_to_match
}
"
)
print
(
f
"Failed to match keys when loading Lora
{
lora_on_disk
.
filename
}
:
{
keys_failed_to_match
}
"
)
return
lora
return
lora
...
@@ -267,7 +267,7 @@ def load_loras(names, multipliers=None):
...
@@ -267,7 +267,7 @@ def load_loras(names, multipliers=None):
lora
.
multiplier
=
multipliers
[
i
]
if
multipliers
else
1.0
lora
.
multiplier
=
multipliers
[
i
]
if
multipliers
else
1.0
loaded_loras
.
append
(
lora
)
loaded_loras
.
append
(
lora
)
if
len
(
failed_to_load_loras
)
>
0
:
if
failed_to_load_loras
:
sd_hijack
.
model_hijack
.
comments
.
append
(
"Failed to find Loras: "
+
", "
.
join
(
failed_to_load_loras
))
sd_hijack
.
model_hijack
.
comments
.
append
(
"Failed to find Loras: "
+
", "
.
join
(
failed_to_load_loras
))
...
...
extensions-builtin/extra-options-section/scripts/extra_options_section.py
浏览文件 @
7a7a201d
...
@@ -21,7 +21,7 @@ class ExtraOptionsSection(scripts.Script):
...
@@ -21,7 +21,7 @@ class ExtraOptionsSection(scripts.Script):
self
.
setting_names
=
[]
self
.
setting_names
=
[]
with
gr
.
Blocks
()
as
interface
:
with
gr
.
Blocks
()
as
interface
:
with
gr
.
Accordion
(
"Options"
,
open
=
False
)
if
shared
.
opts
.
extra_options_accordion
and
len
(
shared
.
opts
.
extra_options
)
>
0
else
gr
.
Group
(),
gr
.
Row
():
with
gr
.
Accordion
(
"Options"
,
open
=
False
)
if
shared
.
opts
.
extra_options_accordion
and
shared
.
opts
.
extra_options
else
gr
.
Group
(),
gr
.
Row
():
for
setting_name
in
shared
.
opts
.
extra_options
:
for
setting_name
in
shared
.
opts
.
extra_options
:
with
FormColumn
():
with
FormColumn
():
comp
=
ui_settings
.
create_setting_component
(
setting_name
)
comp
=
ui_settings
.
create_setting_component
(
setting_name
)
...
...
modules/api/api.py
浏览文件 @
7a7a201d
...
@@ -281,7 +281,7 @@ class Api:
...
@@ -281,7 +281,7 @@ class Api:
script_args
[
0
]
=
selectable_idx
+
1
script_args
[
0
]
=
selectable_idx
+
1
# Now check for always on scripts
# Now check for always on scripts
if
request
.
alwayson_scripts
and
(
len
(
request
.
alwayson_scripts
)
>
0
)
:
if
request
.
alwayson_scripts
:
for
alwayson_script_name
in
request
.
alwayson_scripts
.
keys
():
for
alwayson_script_name
in
request
.
alwayson_scripts
.
keys
():
alwayson_script
=
self
.
get_script
(
alwayson_script_name
,
script_runner
)
alwayson_script
=
self
.
get_script
(
alwayson_script_name
,
script_runner
)
if
alwayson_script
is
None
:
if
alwayson_script
is
None
:
...
...
modules/call_queue.py
浏览文件 @
7a7a201d
...
@@ -21,7 +21,7 @@ def wrap_gradio_gpu_call(func, extra_outputs=None):
...
@@ -21,7 +21,7 @@ def wrap_gradio_gpu_call(func, extra_outputs=None):
def
f
(
*
args
,
**
kwargs
):
def
f
(
*
args
,
**
kwargs
):
# if the first argument is a string that says "task(...)", it is treated as a job id
# if the first argument is a string that says "task(...)", it is treated as a job id
if
len
(
args
)
>
0
and
type
(
args
[
0
])
==
str
and
args
[
0
][
0
:
5
]
==
"task("
and
args
[
0
][
-
1
]
==
")"
:
if
args
and
type
(
args
[
0
])
==
str
and
args
[
0
].
startswith
(
"task("
)
and
args
[
0
].
endswith
(
")"
)
:
id_task
=
args
[
0
]
id_task
=
args
[
0
]
progress
.
add_task_to_queue
(
id_task
)
progress
.
add_task_to_queue
(
id_task
)
else
:
else
:
...
...
modules/extra_networks_hypernet.py
浏览文件 @
7a7a201d
...
@@ -9,7 +9,7 @@ class ExtraNetworkHypernet(extra_networks.ExtraNetwork):
...
@@ -9,7 +9,7 @@ class ExtraNetworkHypernet(extra_networks.ExtraNetwork):
def
activate
(
self
,
p
,
params_list
):
def
activate
(
self
,
p
,
params_list
):
additional
=
shared
.
opts
.
sd_hypernetwork
additional
=
shared
.
opts
.
sd_hypernetwork
if
additional
!=
"None"
and
additional
in
shared
.
hypernetworks
and
len
([
x
for
x
in
params_list
if
x
.
items
[
0
]
==
additional
])
==
0
:
if
additional
!=
"None"
and
additional
in
shared
.
hypernetworks
and
not
any
(
x
for
x
in
params_list
if
x
.
items
[
0
]
==
additional
)
:
hypernet_prompt_text
=
f
"<hypernet:
{
additional
}
:
{
shared
.
opts
.
extra_networks_default_multiplier
}
>"
hypernet_prompt_text
=
f
"<hypernet:
{
additional
}
:
{
shared
.
opts
.
extra_networks_default_multiplier
}
>"
p
.
all_prompts
=
[
f
"
{
prompt
}{
hypernet_prompt_text
}
"
for
prompt
in
p
.
all_prompts
]
p
.
all_prompts
=
[
f
"
{
prompt
}{
hypernet_prompt_text
}
"
for
prompt
in
p
.
all_prompts
]
params_list
.
append
(
extra_networks
.
ExtraNetworkParams
(
items
=
[
additional
,
shared
.
opts
.
extra_networks_default_multiplier
]))
params_list
.
append
(
extra_networks
.
ExtraNetworkParams
(
items
=
[
additional
,
shared
.
opts
.
extra_networks_default_multiplier
]))
...
@@ -17,7 +17,7 @@ class ExtraNetworkHypernet(extra_networks.ExtraNetwork):
...
@@ -17,7 +17,7 @@ class ExtraNetworkHypernet(extra_networks.ExtraNetwork):
names
=
[]
names
=
[]
multipliers
=
[]
multipliers
=
[]
for
params
in
params_list
:
for
params
in
params_list
:
assert
len
(
params
.
items
)
>
0
assert
params
.
items
names
.
append
(
params
.
items
[
0
])
names
.
append
(
params
.
items
[
0
])
multipliers
.
append
(
float
(
params
.
items
[
1
])
if
len
(
params
.
items
)
>
1
else
1.0
)
multipliers
.
append
(
float
(
params
.
items
[
1
])
if
len
(
params
.
items
)
>
1
else
1.0
)
...
...
modules/generation_parameters_copypaste.py
浏览文件 @
7a7a201d
...
@@ -55,7 +55,7 @@ def image_from_url_text(filedata):
...
@@ -55,7 +55,7 @@ def image_from_url_text(filedata):
if
filedata
is
None
:
if
filedata
is
None
:
return
None
return
None
if
type
(
filedata
)
==
list
and
len
(
filedata
)
>
0
and
type
(
filedata
[
0
])
==
dict
and
filedata
[
0
].
get
(
"is_file"
,
False
):
if
type
(
filedata
)
==
list
and
filedata
and
type
(
filedata
[
0
])
==
dict
and
filedata
[
0
].
get
(
"is_file"
,
False
):
filedata
=
filedata
[
0
]
filedata
=
filedata
[
0
]
if
type
(
filedata
)
==
dict
and
filedata
.
get
(
"is_file"
,
False
):
if
type
(
filedata
)
==
dict
and
filedata
.
get
(
"is_file"
,
False
):
...
@@ -445,7 +445,7 @@ def connect_paste(button, paste_fields, input_comp, override_settings_component,
...
@@ -445,7 +445,7 @@ def connect_paste(button, paste_fields, input_comp, override_settings_component,
vals_pairs
=
[
f
"
{
k
}
:
{
v
}
"
for
k
,
v
in
vals
.
items
()]
vals_pairs
=
[
f
"
{
k
}
:
{
v
}
"
for
k
,
v
in
vals
.
items
()]
return
gr
.
Dropdown
.
update
(
value
=
vals_pairs
,
choices
=
vals_pairs
,
visible
=
len
(
vals_pairs
)
>
0
)
return
gr
.
Dropdown
.
update
(
value
=
vals_pairs
,
choices
=
vals_pairs
,
visible
=
bool
(
vals_pairs
)
)
paste_fields
=
paste_fields
+
[(
override_settings_component
,
paste_settings
)]
paste_fields
=
paste_fields
+
[(
override_settings_component
,
paste_settings
)]
...
@@ -462,5 +462,3 @@ def connect_paste(button, paste_fields, input_comp, override_settings_component,
...
@@ -462,5 +462,3 @@ def connect_paste(button, paste_fields, input_comp, override_settings_component,
outputs
=
[],
outputs
=
[],
show_progress
=
False
,
show_progress
=
False
,
)
)
modules/images.py
浏览文件 @
7a7a201d
...
@@ -406,7 +406,7 @@ class FilenameGenerator:
...
@@ -406,7 +406,7 @@ class FilenameGenerator:
prompt_no_style
=
self
.
prompt
prompt_no_style
=
self
.
prompt
for
style
in
shared
.
prompt_styles
.
get_style_prompts
(
self
.
p
.
styles
):
for
style
in
shared
.
prompt_styles
.
get_style_prompts
(
self
.
p
.
styles
):
if
len
(
style
)
>
0
:
if
style
:
for
part
in
style
.
split
(
"{prompt}"
):
for
part
in
style
.
split
(
"{prompt}"
):
prompt_no_style
=
prompt_no_style
.
replace
(
part
,
""
).
replace
(
", ,"
,
","
).
strip
().
strip
(
','
)
prompt_no_style
=
prompt_no_style
.
replace
(
part
,
""
).
replace
(
", ,"
,
","
).
strip
().
strip
(
','
)
...
@@ -415,7 +415,7 @@ class FilenameGenerator:
...
@@ -415,7 +415,7 @@ class FilenameGenerator:
return
sanitize_filename_part
(
prompt_no_style
,
replace_spaces
=
False
)
return
sanitize_filename_part
(
prompt_no_style
,
replace_spaces
=
False
)
def
prompt_words
(
self
):
def
prompt_words
(
self
):
words
=
[
x
for
x
in
re_nonletters
.
split
(
self
.
prompt
or
""
)
if
len
(
x
)
>
0
]
words
=
[
x
for
x
in
re_nonletters
.
split
(
self
.
prompt
or
""
)
if
x
]
if
len
(
words
)
==
0
:
if
len
(
words
)
==
0
:
words
=
[
"empty"
]
words
=
[
"empty"
]
return
sanitize_filename_part
(
" "
.
join
(
words
[
0
:
opts
.
directories_max_prompt_words
]),
replace_spaces
=
False
)
return
sanitize_filename_part
(
" "
.
join
(
words
[
0
:
opts
.
directories_max_prompt_words
]),
replace_spaces
=
False
)
...
@@ -423,7 +423,7 @@ class FilenameGenerator:
...
@@ -423,7 +423,7 @@ class FilenameGenerator:
def
datetime
(
self
,
*
args
):
def
datetime
(
self
,
*
args
):
time_datetime
=
datetime
.
datetime
.
now
()
time_datetime
=
datetime
.
datetime
.
now
()
time_format
=
args
[
0
]
if
len
(
args
)
>
0
and
args
[
0
]
!=
""
else
self
.
default_time_format
time_format
=
args
[
0
]
if
(
args
and
args
[
0
]
!=
""
)
else
self
.
default_time_format
try
:
try
:
time_zone
=
pytz
.
timezone
(
args
[
1
])
if
len
(
args
)
>
1
else
None
time_zone
=
pytz
.
timezone
(
args
[
1
])
if
len
(
args
)
>
1
else
None
except
pytz
.
exceptions
.
UnknownTimeZoneError
:
except
pytz
.
exceptions
.
UnknownTimeZoneError
:
...
...
modules/img2img.py
浏览文件 @
7a7a201d
...
@@ -22,8 +22,7 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args, to_scale=Fal
...
@@ -22,8 +22,7 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args, to_scale=Fal
is_inpaint_batch
=
False
is_inpaint_batch
=
False
if
inpaint_mask_dir
:
if
inpaint_mask_dir
:
inpaint_masks
=
shared
.
listfiles
(
inpaint_mask_dir
)
inpaint_masks
=
shared
.
listfiles
(
inpaint_mask_dir
)
is_inpaint_batch
=
len
(
inpaint_masks
)
>
0
is_inpaint_batch
=
bool
(
inpaint_masks
)
if
is_inpaint_batch
:
print
(
f
"
\n
Inpaint batch is enabled.
{
len
(
inpaint_masks
)
}
masks found."
)
print
(
f
"
\n
Inpaint batch is enabled.
{
len
(
inpaint_masks
)
}
masks found."
)
print
(
f
"Will process
{
len
(
images
)
}
images, creating
{
p
.
n_iter
*
p
.
batch_size
}
new images for each."
)
print
(
f
"Will process
{
len
(
images
)
}
images, creating
{
p
.
n_iter
*
p
.
batch_size
}
new images for each."
)
...
...
modules/models/diffusion/ddpm_edit.py
浏览文件 @
7a7a201d
...
@@ -230,9 +230,9 @@ class DDPM(pl.LightningModule):
...
@@ -230,9 +230,9 @@ class DDPM(pl.LightningModule):
missing
,
unexpected
=
self
.
load_state_dict
(
sd
,
strict
=
False
)
if
not
only_model
else
self
.
model
.
load_state_dict
(
missing
,
unexpected
=
self
.
load_state_dict
(
sd
,
strict
=
False
)
if
not
only_model
else
self
.
model
.
load_state_dict
(
sd
,
strict
=
False
)
sd
,
strict
=
False
)
print
(
f
"Restored from
{
path
}
with
{
len
(
missing
)
}
missing and
{
len
(
unexpected
)
}
unexpected keys"
)
print
(
f
"Restored from
{
path
}
with
{
len
(
missing
)
}
missing and
{
len
(
unexpected
)
}
unexpected keys"
)
if
len
(
missing
)
>
0
:
if
missing
:
print
(
f
"Missing Keys:
{
missing
}
"
)
print
(
f
"Missing Keys:
{
missing
}
"
)
if
len
(
unexpected
)
>
0
:
if
unexpected
:
print
(
f
"Unexpected Keys:
{
unexpected
}
"
)
print
(
f
"Unexpected Keys:
{
unexpected
}
"
)
def
q_mean_variance
(
self
,
x_start
,
t
):
def
q_mean_variance
(
self
,
x_start
,
t
):
...
...
modules/processing.py
浏览文件 @
7a7a201d
...
@@ -981,7 +981,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
...
@@ -981,7 +981,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
latent_scale_mode
=
shared
.
latent_upscale_modes
.
get
(
self
.
hr_upscaler
,
None
)
if
self
.
hr_upscaler
is
not
None
else
shared
.
latent_upscale_modes
.
get
(
shared
.
latent_upscale_default_mode
,
"nearest"
)
latent_scale_mode
=
shared
.
latent_upscale_modes
.
get
(
self
.
hr_upscaler
,
None
)
if
self
.
hr_upscaler
is
not
None
else
shared
.
latent_upscale_modes
.
get
(
shared
.
latent_upscale_default_mode
,
"nearest"
)
if
self
.
enable_hr
and
latent_scale_mode
is
None
:
if
self
.
enable_hr
and
latent_scale_mode
is
None
:
assert
len
([
x
for
x
in
shared
.
sd_upscalers
if
x
.
name
==
self
.
hr_upscaler
])
>
0
,
f
"could not find upscaler named
{
self
.
hr_upscaler
}
"
if
not
any
(
x
.
name
==
self
.
hr_upscaler
for
x
in
shared
.
sd_upscalers
):
raise
Exception
(
f
"could not find upscaler named
{
self
.
hr_upscaler
}
"
)
x
=
create_random_tensors
([
opt_C
,
self
.
height
//
opt_f
,
self
.
width
//
opt_f
],
seeds
=
seeds
,
subseeds
=
subseeds
,
subseed_strength
=
self
.
subseed_strength
,
seed_resize_from_h
=
self
.
seed_resize_from_h
,
seed_resize_from_w
=
self
.
seed_resize_from_w
,
p
=
self
)
x
=
create_random_tensors
([
opt_C
,
self
.
height
//
opt_f
,
self
.
width
//
opt_f
],
seeds
=
seeds
,
subseeds
=
subseeds
,
subseed_strength
=
self
.
subseed_strength
,
seed_resize_from_h
=
self
.
seed_resize_from_h
,
seed_resize_from_w
=
self
.
seed_resize_from_w
,
p
=
self
)
samples
=
self
.
sampler
.
sample
(
self
,
x
,
conditioning
,
unconditional_conditioning
,
image_conditioning
=
self
.
txt2img_image_conditioning
(
x
))
samples
=
self
.
sampler
.
sample
(
self
,
x
,
conditioning
,
unconditional_conditioning
,
image_conditioning
=
self
.
txt2img_image_conditioning
(
x
))
...
...
modules/prompt_parser.py
浏览文件 @
7a7a201d
...
@@ -336,11 +336,11 @@ def parse_prompt_attention(text):
...
@@ -336,11 +336,11 @@ def parse_prompt_attention(text):
round_brackets
.
append
(
len
(
res
))
round_brackets
.
append
(
len
(
res
))
elif
text
==
'['
:
elif
text
==
'['
:
square_brackets
.
append
(
len
(
res
))
square_brackets
.
append
(
len
(
res
))
elif
weight
is
not
None
and
len
(
round_brackets
)
>
0
:
elif
weight
is
not
None
and
round_brackets
:
multiply_range
(
round_brackets
.
pop
(),
float
(
weight
))
multiply_range
(
round_brackets
.
pop
(),
float
(
weight
))
elif
text
==
')'
and
len
(
round_brackets
)
>
0
:
elif
text
==
')'
and
round_brackets
:
multiply_range
(
round_brackets
.
pop
(),
round_bracket_multiplier
)
multiply_range
(
round_brackets
.
pop
(),
round_bracket_multiplier
)
elif
text
==
']'
and
len
(
square_brackets
)
>
0
:
elif
text
==
']'
and
square_brackets
:
multiply_range
(
square_brackets
.
pop
(),
square_bracket_multiplier
)
multiply_range
(
square_brackets
.
pop
(),
square_bracket_multiplier
)
else
:
else
:
parts
=
re
.
split
(
re_break
,
text
)
parts
=
re
.
split
(
re_break
,
text
)
...
...
modules/script_callbacks.py
浏览文件 @
7a7a201d
...
@@ -287,14 +287,14 @@ def list_unets_callback():
...
@@ -287,14 +287,14 @@ def list_unets_callback():
def
add_callback
(
callbacks
,
fun
):
def
add_callback
(
callbacks
,
fun
):
stack
=
[
x
for
x
in
inspect
.
stack
()
if
x
.
filename
!=
__file__
]
stack
=
[
x
for
x
in
inspect
.
stack
()
if
x
.
filename
!=
__file__
]
filename
=
stack
[
0
].
filename
if
len
(
stack
)
>
0
else
'unknown file'
filename
=
stack
[
0
].
filename
if
stack
else
'unknown file'
callbacks
.
append
(
ScriptCallback
(
filename
,
fun
))
callbacks
.
append
(
ScriptCallback
(
filename
,
fun
))
def
remove_current_script_callbacks
():
def
remove_current_script_callbacks
():
stack
=
[
x
for
x
in
inspect
.
stack
()
if
x
.
filename
!=
__file__
]
stack
=
[
x
for
x
in
inspect
.
stack
()
if
x
.
filename
!=
__file__
]
filename
=
stack
[
0
].
filename
if
len
(
stack
)
>
0
else
'unknown file'
filename
=
stack
[
0
].
filename
if
stack
else
'unknown file'
if
filename
==
'unknown file'
:
if
filename
==
'unknown file'
:
return
return
for
callback_list
in
callback_map
.
values
():
for
callback_list
in
callback_map
.
values
():
...
...
modules/sd_hijack_clip.py
浏览文件 @
7a7a201d
...
@@ -167,7 +167,7 @@ class FrozenCLIPEmbedderWithCustomWordsBase(torch.nn.Module):
...
@@ -167,7 +167,7 @@ class FrozenCLIPEmbedderWithCustomWordsBase(torch.nn.Module):
chunk
.
multipliers
+=
[
weight
]
*
emb_len
chunk
.
multipliers
+=
[
weight
]
*
emb_len
position
+=
embedding_length_in_tokens
position
+=
embedding_length_in_tokens
if
len
(
chunk
.
tokens
)
>
0
or
len
(
chunks
)
==
0
:
if
chunk
.
tokens
or
not
chunks
:
next_chunk
(
is_last
=
True
)
next_chunk
(
is_last
=
True
)
return
chunks
,
token_count
return
chunks
,
token_count
...
...
modules/sd_hijack_clip_old.py
浏览文件 @
7a7a201d
...
@@ -74,7 +74,7 @@ def forward_old(self: sd_hijack_clip.FrozenCLIPEmbedderWithCustomWordsBase, text
...
@@ -74,7 +74,7 @@ def forward_old(self: sd_hijack_clip.FrozenCLIPEmbedderWithCustomWordsBase, text
self
.
hijack
.
comments
+=
hijack_comments
self
.
hijack
.
comments
+=
hijack_comments
if
len
(
used_custom_terms
)
>
0
:
if
used_custom_terms
:
embedding_names
=
", "
.
join
(
f
"
{
word
}
[
{
checksum
}
]"
for
word
,
checksum
in
used_custom_terms
)
embedding_names
=
", "
.
join
(
f
"
{
word
}
[
{
checksum
}
]"
for
word
,
checksum
in
used_custom_terms
)
self
.
hijack
.
comments
.
append
(
f
"Used embeddings:
{
embedding_names
}
"
)
self
.
hijack
.
comments
.
append
(
f
"Used embeddings:
{
embedding_names
}
"
)
...
...
modules/textual_inversion/autocrop.py
浏览文件 @
7a7a201d
...
@@ -77,27 +77,27 @@ def focal_point(im, settings):
...
@@ -77,27 +77,27 @@ def focal_point(im, settings):
pois
=
[]
pois
=
[]
weight_pref_total
=
0
weight_pref_total
=
0
if
len
(
corner_points
)
>
0
:
if
corner_points
:
weight_pref_total
+=
settings
.
corner_points_weight
weight_pref_total
+=
settings
.
corner_points_weight
if
len
(
entropy_points
)
>
0
:
if
entropy_points
:
weight_pref_total
+=
settings
.
entropy_points_weight
weight_pref_total
+=
settings
.
entropy_points_weight
if
len
(
face_points
)
>
0
:
if
face_points
:
weight_pref_total
+=
settings
.
face_points_weight
weight_pref_total
+=
settings
.
face_points_weight
corner_centroid
=
None
corner_centroid
=
None
if
len
(
corner_points
)
>
0
:
if
corner_points
:
corner_centroid
=
centroid
(
corner_points
)
corner_centroid
=
centroid
(
corner_points
)
corner_centroid
.
weight
=
settings
.
corner_points_weight
/
weight_pref_total
corner_centroid
.
weight
=
settings
.
corner_points_weight
/
weight_pref_total
pois
.
append
(
corner_centroid
)
pois
.
append
(
corner_centroid
)
entropy_centroid
=
None
entropy_centroid
=
None
if
len
(
entropy_points
)
>
0
:
if
entropy_points
:
entropy_centroid
=
centroid
(
entropy_points
)
entropy_centroid
=
centroid
(
entropy_points
)
entropy_centroid
.
weight
=
settings
.
entropy_points_weight
/
weight_pref_total
entropy_centroid
.
weight
=
settings
.
entropy_points_weight
/
weight_pref_total
pois
.
append
(
entropy_centroid
)
pois
.
append
(
entropy_centroid
)
face_centroid
=
None
face_centroid
=
None
if
len
(
face_points
)
>
0
:
if
face_points
:
face_centroid
=
centroid
(
face_points
)
face_centroid
=
centroid
(
face_points
)
face_centroid
.
weight
=
settings
.
face_points_weight
/
weight_pref_total
face_centroid
.
weight
=
settings
.
face_points_weight
/
weight_pref_total
pois
.
append
(
face_centroid
)
pois
.
append
(
face_centroid
)
...
@@ -187,7 +187,7 @@ def image_face_points(im, settings):
...
@@ -187,7 +187,7 @@ def image_face_points(im, settings):
except
Exception
:
except
Exception
:
continue
continue
if
len
(
faces
)
>
0
:
if
faces
:
rects
=
[[
f
[
0
],
f
[
1
],
f
[
0
]
+
f
[
2
],
f
[
1
]
+
f
[
3
]]
for
f
in
faces
]
rects
=
[[
f
[
0
],
f
[
1
],
f
[
0
]
+
f
[
2
],
f
[
1
]
+
f
[
3
]]
for
f
in
faces
]
return
[
PointOfInterest
((
r
[
0
]
+
r
[
2
])
//
2
,
(
r
[
1
]
+
r
[
3
])
//
2
,
size
=
abs
(
r
[
0
]
-
r
[
2
]),
weight
=
1
/
len
(
rects
))
for
r
in
rects
]
return
[
PointOfInterest
((
r
[
0
]
+
r
[
2
])
//
2
,
(
r
[
1
]
+
r
[
3
])
//
2
,
size
=
abs
(
r
[
0
]
-
r
[
2
]),
weight
=
1
/
len
(
rects
))
for
r
in
rects
]
return
[]
return
[]
...
...
modules/textual_inversion/dataset.py
浏览文件 @
7a7a201d
...
@@ -32,7 +32,7 @@ class DatasetEntry:
...
@@ -32,7 +32,7 @@ class DatasetEntry:
class
PersonalizedBase
(
Dataset
):
class
PersonalizedBase
(
Dataset
):
def
__init__
(
self
,
data_root
,
width
,
height
,
repeats
,
flip_p
=
0.5
,
placeholder_token
=
"*"
,
model
=
None
,
cond_model
=
None
,
device
=
None
,
template_file
=
None
,
include_cond
=
False
,
batch_size
=
1
,
gradient_step
=
1
,
shuffle_tags
=
False
,
tag_drop_out
=
0
,
latent_sampling_method
=
'once'
,
varsize
=
False
,
use_weight
=
False
):
def
__init__
(
self
,
data_root
,
width
,
height
,
repeats
,
flip_p
=
0.5
,
placeholder_token
=
"*"
,
model
=
None
,
cond_model
=
None
,
device
=
None
,
template_file
=
None
,
include_cond
=
False
,
batch_size
=
1
,
gradient_step
=
1
,
shuffle_tags
=
False
,
tag_drop_out
=
0
,
latent_sampling_method
=
'once'
,
varsize
=
False
,
use_weight
=
False
):
re_word
=
re
.
compile
(
shared
.
opts
.
dataset_filename_word_regex
)
if
len
(
shared
.
opts
.
dataset_filename_word_regex
)
>
0
else
None
re_word
=
re
.
compile
(
shared
.
opts
.
dataset_filename_word_regex
)
if
shared
.
opts
.
dataset_filename_word_regex
else
None
self
.
placeholder_token
=
placeholder_token
self
.
placeholder_token
=
placeholder_token
...
...
modules/textual_inversion/preprocess.py
浏览文件 @
7a7a201d
...
@@ -47,7 +47,7 @@ def save_pic_with_caption(image, index, params: PreprocessParams, existing_capti
...
@@ -47,7 +47,7 @@ def save_pic_with_caption(image, index, params: PreprocessParams, existing_capti
caption
+=
shared
.
interrogator
.
generate_caption
(
image
)
caption
+=
shared
.
interrogator
.
generate_caption
(
image
)
if
params
.
process_caption_deepbooru
:
if
params
.
process_caption_deepbooru
:
if
len
(
caption
)
>
0
:
if
caption
:
caption
+=
", "
caption
+=
", "
caption
+=
deepbooru
.
model
.
tag_multi
(
image
)
caption
+=
deepbooru
.
model
.
tag_multi
(
image
)
...
@@ -67,7 +67,7 @@ def save_pic_with_caption(image, index, params: PreprocessParams, existing_capti
...
@@ -67,7 +67,7 @@ def save_pic_with_caption(image, index, params: PreprocessParams, existing_capti
caption
=
caption
.
strip
()
caption
=
caption
.
strip
()
if
len
(
caption
)
>
0
:
if
caption
:
with
open
(
os
.
path
.
join
(
params
.
dstdir
,
f
"
{
basename
}
.txt"
),
"w"
,
encoding
=
"utf8"
)
as
file
:
with
open
(
os
.
path
.
join
(
params
.
dstdir
,
f
"
{
basename
}
.txt"
),
"w"
,
encoding
=
"utf8"
)
as
file
:
file
.
write
(
caption
)
file
.
write
(
caption
)
...
...
modules/textual_inversion/textual_inversion.py
浏览文件 @
7a7a201d
...
@@ -251,7 +251,7 @@ class EmbeddingDatabase:
...
@@ -251,7 +251,7 @@ class EmbeddingDatabase:
if
self
.
previously_displayed_embeddings
!=
displayed_embeddings
:
if
self
.
previously_displayed_embeddings
!=
displayed_embeddings
:
self
.
previously_displayed_embeddings
=
displayed_embeddings
self
.
previously_displayed_embeddings
=
displayed_embeddings
print
(
f
"Textual inversion embeddings loaded(
{
len
(
self
.
word_embeddings
)
}
):
{
', '
.
join
(
self
.
word_embeddings
.
keys
())
}
"
)
print
(
f
"Textual inversion embeddings loaded(
{
len
(
self
.
word_embeddings
)
}
):
{
', '
.
join
(
self
.
word_embeddings
.
keys
())
}
"
)
if
len
(
self
.
skipped_embeddings
)
>
0
:
if
self
.
skipped_embeddings
:
print
(
f
"Textual inversion embeddings skipped(
{
len
(
self
.
skipped_embeddings
)
}
):
{
', '
.
join
(
self
.
skipped_embeddings
.
keys
())
}
"
)
print
(
f
"Textual inversion embeddings skipped(
{
len
(
self
.
skipped_embeddings
)
}
):
{
', '
.
join
(
self
.
skipped_embeddings
.
keys
())
}
"
)
def
find_embedding_at_position
(
self
,
tokens
,
offset
):
def
find_embedding_at_position
(
self
,
tokens
,
offset
):
...
...
modules/ui.py
浏览文件 @
7a7a201d
...
@@ -400,7 +400,7 @@ def create_override_settings_dropdown(tabname, row):
...
@@ -400,7 +400,7 @@ def create_override_settings_dropdown(tabname, row):
dropdown
=
gr
.
Dropdown
([],
label
=
"Override settings"
,
visible
=
False
,
elem_id
=
f
"
{
tabname
}
_override_settings"
,
multiselect
=
True
)
dropdown
=
gr
.
Dropdown
([],
label
=
"Override settings"
,
visible
=
False
,
elem_id
=
f
"
{
tabname
}
_override_settings"
,
multiselect
=
True
)
dropdown
.
change
(
dropdown
.
change
(
fn
=
lambda
x
:
gr
.
Dropdown
.
update
(
visible
=
len
(
x
)
>
0
),
fn
=
lambda
x
:
gr
.
Dropdown
.
update
(
visible
=
bool
(
x
)
),
inputs
=
[
dropdown
],
inputs
=
[
dropdown
],
outputs
=
[
dropdown
],
outputs
=
[
dropdown
],
)
)
...
...
modules/ui_extensions.py
浏览文件 @
7a7a201d
...
@@ -333,7 +333,8 @@ def install_extension_from_url(dirname, url, branch_name=None):
...
@@ -333,7 +333,8 @@ def install_extension_from_url(dirname, url, branch_name=None):
assert
not
os
.
path
.
exists
(
target_dir
),
f
'Extension directory already exists:
{
target_dir
}
'
assert
not
os
.
path
.
exists
(
target_dir
),
f
'Extension directory already exists:
{
target_dir
}
'
normalized_url
=
normalize_git_url
(
url
)
normalized_url
=
normalize_git_url
(
url
)
assert
len
([
x
for
x
in
extensions
.
extensions
if
normalize_git_url
(
x
.
remote
)
==
normalized_url
])
==
0
,
'Extension with this URL is already installed'
if
any
(
x
for
x
in
extensions
.
extensions
if
normalize_git_url
(
x
.
remote
)
==
normalized_url
):
raise
Exception
(
f
'Extension with this URL is already installed:
{
url
}
'
)
tmpdir
=
os
.
path
.
join
(
paths
.
data_path
,
"tmp"
,
dirname
)
tmpdir
=
os
.
path
.
join
(
paths
.
data_path
,
"tmp"
,
dirname
)
...
@@ -449,7 +450,7 @@ def refresh_available_extensions_from_data(hide_tags, sort_column, filter_text="
...
@@ -449,7 +450,7 @@ def refresh_available_extensions_from_data(hide_tags, sort_column, filter_text="
existing
=
installed_extension_urls
.
get
(
normalize_git_url
(
url
),
None
)
existing
=
installed_extension_urls
.
get
(
normalize_git_url
(
url
),
None
)
extension_tags
=
extension_tags
+
[
"installed"
]
if
existing
else
extension_tags
extension_tags
=
extension_tags
+
[
"installed"
]
if
existing
else
extension_tags
if
len
([
x
for
x
in
extension_tags
if
x
in
tags_to_hide
])
>
0
:
if
any
(
x
for
x
in
extension_tags
if
x
in
tags_to_hide
)
:
hidden
+=
1
hidden
+=
1
continue
continue
...
...
modules/ui_settings.py
浏览文件 @
7a7a201d
...
@@ -81,7 +81,7 @@ class UiSettings:
...
@@ -81,7 +81,7 @@ class UiSettings:
opts
.
save
(
shared
.
config_filename
)
opts
.
save
(
shared
.
config_filename
)
except
RuntimeError
:
except
RuntimeError
:
return
opts
.
dumpjson
(),
f
'
{
len
(
changed
)
}
settings changed without save:
{
", "
.
join
(
changed
)
}
.'
return
opts
.
dumpjson
(),
f
'
{
len
(
changed
)
}
settings changed without save:
{
", "
.
join
(
changed
)
}
.'
return
opts
.
dumpjson
(),
f
'
{
len
(
changed
)
}
settings changed
{
": "
if
len
(
changed
)
>
0
else
""
}{
", "
.
join
(
changed
)
}
.'
return
opts
.
dumpjson
(),
f
'
{
len
(
changed
)
}
settings changed
{
": "
if
changed
else
""
}{
", "
.
join
(
changed
)
}
.'
def
run_settings_single
(
self
,
value
,
key
):
def
run_settings_single
(
self
,
value
,
key
):
if
not
opts
.
same_type
(
value
,
opts
.
data_labels
[
key
].
default
):
if
not
opts
.
same_type
(
value
,
opts
.
data_labels
[
key
].
default
):
...
...
scripts/prompts_from_file.py
浏览文件 @
7a7a201d
...
@@ -121,8 +121,7 @@ class Script(scripts.Script):
...
@@ -121,8 +121,7 @@ class Script(scripts.Script):
return
[
checkbox_iterate
,
checkbox_iterate_batch
,
prompt_txt
]
return
[
checkbox_iterate
,
checkbox_iterate_batch
,
prompt_txt
]
def
run
(
self
,
p
,
checkbox_iterate
,
checkbox_iterate_batch
,
prompt_txt
:
str
):
def
run
(
self
,
p
,
checkbox_iterate
,
checkbox_iterate_batch
,
prompt_txt
:
str
):
lines
=
[
x
.
strip
()
for
x
in
prompt_txt
.
splitlines
()]
lines
=
[
x
for
x
in
(
x
.
strip
()
for
x
in
prompt_txt
.
splitlines
())
if
x
]
lines
=
[
x
for
x
in
lines
if
len
(
x
)
>
0
]
p
.
do_not_save_grid
=
True
p
.
do_not_save_grid
=
True
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录