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
0cbcc4d8
Commit
0cbcc4d8
authored
May 22, 2023
by
AUTOMATIC1111
Committed by
GitHub
May 22, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10611 from akx/disable-token-counters
Add option to disable token counters
parents
ee2f4fb9
618c59b0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
70 deletions
+87
-70
.eslintrc.js
.eslintrc.js
+2
-0
javascript/token-counters.js
javascript/token-counters.js
+83
-0
javascript/ui.js
javascript/ui.js
+1
-70
modules/shared.py
modules/shared.py
+1
-0
No files found.
.eslintrc.js
View file @
0cbcc4d8
...
@@ -84,5 +84,7 @@ module.exports = {
...
@@ -84,5 +84,7 @@ module.exports = {
// imageviewer.js
// imageviewer.js
modalPrevImage
:
"
readonly
"
,
modalPrevImage
:
"
readonly
"
,
modalNextImage
:
"
readonly
"
,
modalNextImage
:
"
readonly
"
,
// token-counters.js
setupTokenCounters
:
"
readonly
"
,
}
}
};
};
javascript/token-counters.js
0 → 100644
View file @
0cbcc4d8
let
promptTokenCountDebounceTime
=
800
;
let
promptTokenCountTimeouts
=
{};
var
promptTokenCountUpdateFunctions
=
{};
function
update_txt2img_tokens
(...
args
)
{
// Called from Gradio
update_token_counter
(
"
txt2img_token_button
"
);
if
(
args
.
length
==
2
)
{
return
args
[
0
];
}
return
args
;
}
function
update_img2img_tokens
(...
args
)
{
// Called from Gradio
update_token_counter
(
"
img2img_token_button
"
);
if
(
args
.
length
==
2
)
{
return
args
[
0
];
}
return
args
;
}
function
update_token_counter
(
button_id
)
{
if
(
opts
.
disable_token_counters
)
{
return
;
}
if
(
promptTokenCountTimeouts
[
button_id
])
{
clearTimeout
(
promptTokenCountTimeouts
[
button_id
]);
}
promptTokenCountTimeouts
[
button_id
]
=
setTimeout
(
()
=>
gradioApp
().
getElementById
(
button_id
)?.
click
(),
promptTokenCountDebounceTime
,
);
}
function
recalculatePromptTokens
(
name
)
{
promptTokenCountUpdateFunctions
[
name
]?.();
}
function
recalculate_prompts_txt2img
()
{
// Called from Gradio
recalculatePromptTokens
(
'
txt2img_prompt
'
);
recalculatePromptTokens
(
'
txt2img_neg_prompt
'
);
return
Array
.
from
(
arguments
);
}
function
recalculate_prompts_img2img
()
{
// Called from Gradio
recalculatePromptTokens
(
'
img2img_prompt
'
);
recalculatePromptTokens
(
'
img2img_neg_prompt
'
);
return
Array
.
from
(
arguments
);
}
function
setupTokenCounting
(
id
,
id_counter
,
id_button
)
{
var
prompt
=
gradioApp
().
getElementById
(
id
);
var
counter
=
gradioApp
().
getElementById
(
id_counter
);
var
textarea
=
gradioApp
().
querySelector
(
`#
${
id
}
> label > textarea`
);
if
(
opts
.
disable_token_counters
)
{
counter
.
style
.
display
=
"
none
"
;
return
;
}
if
(
counter
.
parentElement
==
prompt
.
parentElement
)
{
return
;
}
prompt
.
parentElement
.
insertBefore
(
counter
,
prompt
);
prompt
.
parentElement
.
style
.
position
=
"
relative
"
;
promptTokenCountUpdateFunctions
[
id
]
=
function
()
{
update_token_counter
(
id_button
);
};
textarea
.
addEventListener
(
"
input
"
,
promptTokenCountUpdateFunctions
[
id
]);
}
function
setupTokenCounters
()
{
setupTokenCounting
(
'
txt2img_prompt
'
,
'
txt2img_token_counter
'
,
'
txt2img_token_button
'
);
setupTokenCounting
(
'
txt2img_neg_prompt
'
,
'
txt2img_negative_token_counter
'
,
'
txt2img_negative_token_button
'
);
setupTokenCounting
(
'
img2img_prompt
'
,
'
img2img_token_counter
'
,
'
img2img_token_button
'
);
setupTokenCounting
(
'
img2img_neg_prompt
'
,
'
img2img_negative_token_counter
'
,
'
img2img_negative_token_button
'
);
}
javascript/ui.js
View file @
0cbcc4d8
...
@@ -248,27 +248,6 @@ function confirm_clear_prompt(prompt, negative_prompt) {
...
@@ -248,27 +248,6 @@ function confirm_clear_prompt(prompt, negative_prompt) {
}
}
var
promptTokecountUpdateFuncs
=
{};
function
recalculatePromptTokens
(
name
)
{
if
(
promptTokecountUpdateFuncs
[
name
])
{
promptTokecountUpdateFuncs
[
name
]();
}
}
function
recalculate_prompts_txt2img
()
{
recalculatePromptTokens
(
'
txt2img_prompt
'
);
recalculatePromptTokens
(
'
txt2img_neg_prompt
'
);
return
Array
.
from
(
arguments
);
}
function
recalculate_prompts_img2img
()
{
recalculatePromptTokens
(
'
img2img_prompt
'
);
recalculatePromptTokens
(
'
img2img_neg_prompt
'
);
return
Array
.
from
(
arguments
);
}
var
opts
=
{};
var
opts
=
{};
onUiUpdate
(
function
()
{
onUiUpdate
(
function
()
{
if
(
Object
.
keys
(
opts
).
length
!=
0
)
return
;
if
(
Object
.
keys
(
opts
).
length
!=
0
)
return
;
...
@@ -302,28 +281,7 @@ onUiUpdate(function() {
...
@@ -302,28 +281,7 @@ onUiUpdate(function() {
json_elem
.
parentElement
.
style
.
display
=
"
none
"
;
json_elem
.
parentElement
.
style
.
display
=
"
none
"
;
function
registerTextarea
(
id
,
id_counter
,
id_button
)
{
setupTokenCounters
();
var
prompt
=
gradioApp
().
getElementById
(
id
);
var
counter
=
gradioApp
().
getElementById
(
id_counter
);
var
textarea
=
gradioApp
().
querySelector
(
"
#
"
+
id
+
"
> label > textarea
"
);
if
(
counter
.
parentElement
==
prompt
.
parentElement
)
{
return
;
}
prompt
.
parentElement
.
insertBefore
(
counter
,
prompt
);
prompt
.
parentElement
.
style
.
position
=
"
relative
"
;
promptTokecountUpdateFuncs
[
id
]
=
function
()
{
update_token_counter
(
id_button
);
};
textarea
.
addEventListener
(
"
input
"
,
promptTokecountUpdateFuncs
[
id
]);
}
registerTextarea
(
'
txt2img_prompt
'
,
'
txt2img_token_counter
'
,
'
txt2img_token_button
'
);
registerTextarea
(
'
txt2img_neg_prompt
'
,
'
txt2img_negative_token_counter
'
,
'
txt2img_negative_token_button
'
);
registerTextarea
(
'
img2img_prompt
'
,
'
img2img_token_counter
'
,
'
img2img_token_button
'
);
registerTextarea
(
'
img2img_neg_prompt
'
,
'
img2img_negative_token_counter
'
,
'
img2img_negative_token_button
'
);
var
show_all_pages
=
gradioApp
().
getElementById
(
'
settings_show_all_pages
'
);
var
show_all_pages
=
gradioApp
().
getElementById
(
'
settings_show_all_pages
'
);
var
settings_tabs
=
gradioApp
().
querySelector
(
'
#settings div
'
);
var
settings_tabs
=
gradioApp
().
querySelector
(
'
#settings div
'
);
...
@@ -354,33 +312,6 @@ onOptionsChanged(function() {
...
@@ -354,33 +312,6 @@ onOptionsChanged(function() {
});
});
let
txt2img_textarea
,
img2img_textarea
=
undefined
;
let
txt2img_textarea
,
img2img_textarea
=
undefined
;
let
wait_time
=
800
;
let
token_timeouts
=
{};
function
update_txt2img_tokens
(...
args
)
{
update_token_counter
(
"
txt2img_token_button
"
);
if
(
args
.
length
==
2
)
{
return
args
[
0
];
}
return
args
;
}
function
update_img2img_tokens
(...
args
)
{
update_token_counter
(
"
img2img_token_button
"
);
if
(
args
.
length
==
2
)
{
return
args
[
0
];
}
return
args
;
}
function
update_token_counter
(
button_id
)
{
if
(
token_timeouts
[
button_id
])
{
clearTimeout
(
token_timeouts
[
button_id
]);
}
token_timeouts
[
button_id
]
=
setTimeout
(()
=>
gradioApp
().
getElementById
(
button_id
)?.
click
(),
wait_time
);
}
function
restart_reload
()
{
function
restart_reload
()
{
document
.
body
.
innerHTML
=
'
<h1 style="font-family:monospace;margin-top:20%;color:lightgray;text-align:center;">Reloading...</h1>
'
;
document
.
body
.
innerHTML
=
'
<h1 style="font-family:monospace;margin-top:20%;color:lightgray;text-align:center;">Reloading...</h1>
'
;
...
...
modules/shared.py
View file @
0cbcc4d8
...
@@ -488,6 +488,7 @@ options_templates.update(options_section(('ui', "User interface"), {
...
@@ -488,6 +488,7 @@ options_templates.update(options_section(('ui', "User interface"), {
"ui_reorder"
:
OptionInfo
(
", "
.
join
(
ui_reorder_categories
),
"txt2img/img2img UI item order"
)
.
needs_restart
(),
"ui_reorder"
:
OptionInfo
(
", "
.
join
(
ui_reorder_categories
),
"txt2img/img2img UI item order"
)
.
needs_restart
(),
"hires_fix_show_sampler"
:
OptionInfo
(
False
,
"Hires fix: show hires sampler selection"
)
.
needs_restart
(),
"hires_fix_show_sampler"
:
OptionInfo
(
False
,
"Hires fix: show hires sampler selection"
)
.
needs_restart
(),
"hires_fix_show_prompts"
:
OptionInfo
(
False
,
"Hires fix: show hires prompt and negative prompt"
)
.
needs_restart
(),
"hires_fix_show_prompts"
:
OptionInfo
(
False
,
"Hires fix: show hires prompt and negative prompt"
)
.
needs_restart
(),
"disable_token_counters"
:
OptionInfo
(
False
,
"Disable prompt token counters"
)
.
needs_restart
(),
}))
}))
options_templates
.
update
(
options_section
((
'infotext'
,
"Infotext"
),
{
options_templates
.
update
(
options_section
((
'infotext'
,
"Infotext"
),
{
...
...
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