Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
432ba1c1
Commit
432ba1c1
authored
Jan 13, 2024
by
comfyanonymous
Browse files
Merge branch 'control_before_generate' of
https://github.com/pythongosssss/ComfyUI
parents
b5ece635
8e916735
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
2 deletions
+73
-2
web/scripts/app.js
web/scripts/app.js
+10
-1
web/scripts/widgets.js
web/scripts/widgets.js
+63
-1
No files found.
web/scripts/app.js
View file @
432ba1c1
import
{
ComfyLogging
}
from
"
./logging.js
"
;
import
{
ComfyLogging
}
from
"
./logging.js
"
;
import
{
ComfyWidgets
}
from
"
./widgets.js
"
;
import
{
ComfyWidgets
,
initWidgets
}
from
"
./widgets.js
"
;
import
{
ComfyUI
,
$el
}
from
"
./ui.js
"
;
import
{
ComfyUI
,
$el
}
from
"
./ui.js
"
;
import
{
api
}
from
"
./api.js
"
;
import
{
api
}
from
"
./api.js
"
;
import
{
defaultGraph
}
from
"
./defaultGraph.js
"
;
import
{
defaultGraph
}
from
"
./defaultGraph.js
"
;
...
@@ -1420,6 +1420,7 @@ export class ComfyApp {
...
@@ -1420,6 +1420,7 @@ export class ComfyApp {
await
this
.
#
invokeExtensionsAsync
(
"
init
"
);
await
this
.
#
invokeExtensionsAsync
(
"
init
"
);
await
this
.
registerNodes
();
await
this
.
registerNodes
();
initWidgets
(
this
);
// Load previous workflow
// Load previous workflow
let
restored
=
false
;
let
restored
=
false
;
...
@@ -1774,6 +1775,14 @@ export class ComfyApp {
...
@@ -1774,6 +1775,14 @@ export class ComfyApp {
*/
*/
async
graphToPrompt
()
{
async
graphToPrompt
()
{
for
(
const
outerNode
of
this
.
graph
.
computeExecutionOrder
(
false
))
{
for
(
const
outerNode
of
this
.
graph
.
computeExecutionOrder
(
false
))
{
if
(
outerNode
.
widgets
)
{
for
(
const
widget
of
outerNode
.
widgets
)
{
// Allow widgets to run callbacks before a prompt has been queued
// e.g. random seed before every gen
widget
.
beforeQueued
?.();
}
}
const
innerNodes
=
outerNode
.
getInnerNodes
?
outerNode
.
getInnerNodes
()
:
[
outerNode
];
const
innerNodes
=
outerNode
.
getInnerNodes
?
outerNode
.
getInnerNodes
()
:
[
outerNode
];
for
(
const
node
of
innerNodes
)
{
for
(
const
node
of
innerNodes
)
{
if
(
node
.
isVirtualNode
)
{
if
(
node
.
isVirtualNode
)
{
...
...
web/scripts/widgets.js
View file @
432ba1c1
import
{
api
}
from
"
./api.js
"
import
{
api
}
from
"
./api.js
"
import
"
./domWidget.js
"
;
import
"
./domWidget.js
"
;
let
controlValueRunBefore
=
false
;
export
function
updateControlWidgetLabel
(
widget
)
{
let
replacement
=
"
after
"
;
let
find
=
"
before
"
;
if
(
controlValueRunBefore
)
{
[
find
,
replacement
]
=
[
replacement
,
find
]
}
widget
.
label
=
(
widget
.
label
??
widget
.
name
).
replace
(
find
,
replacement
);
}
const
IS_CONTROL_WIDGET
=
Symbol
();
const
HAS_EXECUTED
=
Symbol
();
function
getNumberDefaults
(
inputData
,
defaultStep
,
precision
,
enable_rounding
)
{
function
getNumberDefaults
(
inputData
,
defaultStep
,
precision
,
enable_rounding
)
{
let
defaultVal
=
inputData
[
1
][
"
default
"
];
let
defaultVal
=
inputData
[
1
][
"
default
"
];
let
{
min
,
max
,
step
,
round
}
=
inputData
[
1
];
let
{
min
,
max
,
step
,
round
}
=
inputData
[
1
];
...
@@ -62,6 +75,8 @@ export function addValueControlWidgets(node, targetWidget, defaultValue = "rando
...
@@ -62,6 +75,8 @@ export function addValueControlWidgets(node, targetWidget, defaultValue = "rando
serialize
:
false
,
// Don't include this in prompt.
serialize
:
false
,
// Don't include this in prompt.
}
}
);
);
valueControl
[
IS_CONTROL_WIDGET
]
=
true
;
updateControlWidgetLabel
(
valueControl
);
widgets
.
push
(
valueControl
);
widgets
.
push
(
valueControl
);
const
isCombo
=
targetWidget
.
type
===
"
combo
"
;
const
isCombo
=
targetWidget
.
type
===
"
combo
"
;
...
@@ -76,10 +91,12 @@ export function addValueControlWidgets(node, targetWidget, defaultValue = "rando
...
@@ -76,10 +91,12 @@ export function addValueControlWidgets(node, targetWidget, defaultValue = "rando
serialize
:
false
,
// Don't include this in prompt.
serialize
:
false
,
// Don't include this in prompt.
}
}
);
);
updateControlWidgetLabel
(
comboFilter
);
widgets
.
push
(
comboFilter
);
widgets
.
push
(
comboFilter
);
}
}
valueControl
.
afterQueued
=
()
=>
{
const
applyWidgetControl
=
()
=>
{
var
v
=
valueControl
.
value
;
var
v
=
valueControl
.
value
;
if
(
isCombo
&&
v
!==
"
fixed
"
)
{
if
(
isCombo
&&
v
!==
"
fixed
"
)
{
...
@@ -159,6 +176,23 @@ export function addValueControlWidgets(node, targetWidget, defaultValue = "rando
...
@@ -159,6 +176,23 @@ export function addValueControlWidgets(node, targetWidget, defaultValue = "rando
targetWidget
.
callback
(
targetWidget
.
value
);
targetWidget
.
callback
(
targetWidget
.
value
);
}
}
};
};
valueControl
.
beforeQueued
=
()
=>
{
if
(
controlValueRunBefore
)
{
// Don't run on first execution
if
(
valueControl
[
HAS_EXECUTED
])
{
applyWidgetControl
();
}
}
valueControl
[
HAS_EXECUTED
]
=
true
;
};
valueControl
.
afterQueued
=
()
=>
{
if
(
!
controlValueRunBefore
)
{
applyWidgetControl
();
}
};
return
widgets
;
return
widgets
;
};
};
...
@@ -224,6 +258,34 @@ function isSlider(display, app) {
...
@@ -224,6 +258,34 @@ function isSlider(display, app) {
return
(
display
===
"
slider
"
)
?
"
slider
"
:
"
number
"
return
(
display
===
"
slider
"
)
?
"
slider
"
:
"
number
"
}
}
export
function
initWidgets
(
app
)
{
app
.
ui
.
settings
.
addSetting
({
id
:
"
Comfy.WidgetControlMode
"
,
name
:
"
Widget Value Control Mode
"
,
type
:
"
combo
"
,
defaultValue
:
"
after
"
,
options
:
[
"
before
"
,
"
after
"
],
tooltip
:
"
Controls when widget values are updated (randomize/increment/decrement), either before the prompt is queued or after.
"
,
onChange
(
value
)
{
controlValueRunBefore
=
value
===
"
before
"
;
for
(
const
n
of
app
.
graph
.
_nodes
)
{
if
(
!
n
.
widgets
)
continue
;
for
(
const
w
of
n
.
widgets
)
{
if
(
w
[
IS_CONTROL_WIDGET
])
{
updateControlWidgetLabel
(
w
);
if
(
w
.
linkedWidgets
)
{
for
(
const
l
of
w
.
linkedWidgets
)
{
updateControlWidgetLabel
(
l
);
}
}
}
}
}
app
.
graph
.
setDirtyCanvas
(
true
);
},
});
}
export
const
ComfyWidgets
=
{
export
const
ComfyWidgets
=
{
"
INT:seed
"
:
seedWidget
,
"
INT:seed
"
:
seedWidget
,
"
INT:noise_seed
"
:
seedWidget
,
"
INT:noise_seed
"
:
seedWidget
,
...
...
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