Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
b7f45e67
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
11 个月 前同步成功
通知
1759
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
b7f45e67
编写于
2月 11, 2024
作者:
A
AUTOMATIC1111
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add before_token_counter callback and use it for prompt comments
上级
02ab75b8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
1 deletion
+43
-1
modules/processing_scripts/comments.py
modules/processing_scripts/comments.py
+11
-1
modules/script_callbacks.py
modules/script_callbacks.py
+26
-0
modules/ui.py
modules/ui.py
+6
-0
未找到文件。
modules/processing_scripts/comments.py
浏览文件 @
b7f45e67
from
modules
import
scripts
,
shared
from
modules
import
scripts
,
shared
,
script_callbacks
import
re
...
...
@@ -27,6 +27,16 @@ class ScriptStripComments(scripts.Script):
p
.
main_negative_prompt
=
strip_comments
(
p
.
main_negative_prompt
)
def
before_token_counter
(
params
:
script_callbacks
.
BeforeTokenCounterParams
):
if
not
shared
.
opts
.
enable_prompt_comments
:
return
params
.
prompt
=
strip_comments
(
params
.
prompt
)
script_callbacks
.
on_before_token_counter
(
before_token_counter
)
shared
.
options_templates
.
update
(
shared
.
options_section
((
'sd'
,
"Stable Diffusion"
,
"sd"
),
{
"enable_prompt_comments"
:
shared
.
OptionInfo
(
True
,
"Enable comments"
).
info
(
"Use # anywhere in the prompt to hide the text between # and the end of the line from the generation."
),
}))
modules/script_callbacks.py
浏览文件 @
b7f45e67
import
dataclasses
import
inspect
import
os
from
collections
import
namedtuple
...
...
@@ -106,6 +107,15 @@ class ImageGridLoopParams:
self
.
rows
=
rows
@
dataclasses
.
dataclass
class
BeforeTokenCounterParams
:
prompt
:
str
steps
:
int
styles
:
list
is_positive
:
bool
=
True
ScriptCallback
=
namedtuple
(
"ScriptCallback"
,
[
"script"
,
"callback"
])
callback_map
=
dict
(
callbacks_app_started
=
[],
...
...
@@ -128,6 +138,7 @@ callback_map = dict(
callbacks_on_reload
=
[],
callbacks_list_optimizers
=
[],
callbacks_list_unets
=
[],
callbacks_before_token_counter
=
[],
)
...
...
@@ -309,6 +320,14 @@ def list_unets_callback():
return
res
def
before_token_counter_callback
(
params
:
BeforeTokenCounterParams
):
for
c
in
callback_map
[
'callbacks_before_token_counter'
]:
try
:
c
.
callback
(
params
)
except
Exception
:
report_exception
(
c
,
'before_token_counter'
)
def
add_callback
(
callbacks
,
fun
):
stack
=
[
x
for
x
in
inspect
.
stack
()
if
x
.
filename
!=
__file__
]
filename
=
stack
[
0
].
filename
if
stack
else
'unknown file'
...
...
@@ -483,3 +502,10 @@ def on_list_unets(callback):
The function will be called with one argument, a list, and shall add objects of type modules.sd_unet.SdUnetOption to it."""
add_callback
(
callback_map
[
'callbacks_list_unets'
],
callback
)
def
on_before_token_counter
(
callback
):
"""register a function to be called when UI is counting tokens for a prompt.
The function will be called with one argument of type BeforeTokenCounterParams, and should modify its fields if necessary."""
add_callback
(
callback_map
[
'callbacks_before_token_counter'
],
callback
)
modules/ui.py
浏览文件 @
b7f45e67
...
...
@@ -152,6 +152,12 @@ def connect_clear_prompt(button):
def
update_token_counter
(
text
,
steps
,
styles
,
*
,
is_positive
=
True
):
params
=
script_callbacks
.
BeforeTokenCounterParams
(
text
,
steps
,
styles
,
is_positive
=
is_positive
)
script_callbacks
.
before_token_counter_callback
(
params
)
text
=
params
.
prompt
steps
=
params
.
steps
styles
=
params
.
styles
is_positive
=
params
.
is_positive
if
shared
.
opts
.
include_styles_into_token_counters
:
apply_styles
=
shared
.
prompt_styles
.
apply_styles_to_prompt
if
is_positive
else
shared
.
prompt_styles
.
apply_negative_styles_to_prompt
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录