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
62a371e1
Commit
62a371e1
authored
May 18, 2023
by
comfyanonymous
Browse files
Load workflow from latent file.
parent
faf899ad
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
3 deletions
+24
-3
nodes.py
nodes.py
+1
-1
web/scripts/app.js
web/scripts/app.js
+6
-1
web/scripts/pnginfo.js
web/scripts/pnginfo.js
+16
-0
web/scripts/ui.js
web/scripts/ui.js
+1
-1
No files found.
nodes.py
View file @
62a371e1
...
@@ -274,7 +274,7 @@ class SaveLatent:
...
@@ -274,7 +274,7 @@ class SaveLatent:
if
prompt
is
not
None
:
if
prompt
is
not
None
:
prompt_info
=
json
.
dumps
(
prompt
)
prompt_info
=
json
.
dumps
(
prompt
)
metadata
=
{
"
workflow
"
:
prompt_info
}
metadata
=
{
"
prompt
"
:
prompt_info
}
if
extra_pnginfo
is
not
None
:
if
extra_pnginfo
is
not
None
:
for
x
in
extra_pnginfo
:
for
x
in
extra_pnginfo
:
metadata
[
x
]
=
json
.
dumps
(
extra_pnginfo
[
x
])
metadata
[
x
]
=
json
.
dumps
(
extra_pnginfo
[
x
])
...
...
web/scripts/app.js
View file @
62a371e1
...
@@ -2,7 +2,7 @@ import { ComfyWidgets } from "./widgets.js";
...
@@ -2,7 +2,7 @@ import { ComfyWidgets } 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
"
;
import
{
getPngMetadata
,
importA1111
}
from
"
./pnginfo.js
"
;
import
{
getPngMetadata
,
importA1111
,
getLatentMetadata
}
from
"
./pnginfo.js
"
;
/**
/**
* @typedef {import("types/comfy").ComfyExtension} ComfyExtension
* @typedef {import("types/comfy").ComfyExtension} ComfyExtension
...
@@ -1308,6 +1308,11 @@ export class ComfyApp {
...
@@ -1308,6 +1308,11 @@ export class ComfyApp {
this
.
loadGraphData
(
JSON
.
parse
(
reader
.
result
));
this
.
loadGraphData
(
JSON
.
parse
(
reader
.
result
));
};
};
reader
.
readAsText
(
file
);
reader
.
readAsText
(
file
);
}
else
if
(
file
.
name
?.
endsWith
(
"
.latent
"
))
{
const
info
=
await
getLatentMetadata
(
file
);
if
(
info
.
workflow
)
{
this
.
loadGraphData
(
JSON
.
parse
(
info
.
workflow
));
}
}
}
}
}
...
...
web/scripts/pnginfo.js
View file @
62a371e1
...
@@ -47,6 +47,22 @@ export function getPngMetadata(file) {
...
@@ -47,6 +47,22 @@ export function getPngMetadata(file) {
});
});
}
}
export
function
getLatentMetadata
(
file
)
{
return
new
Promise
((
r
)
=>
{
const
reader
=
new
FileReader
();
reader
.
onload
=
(
event
)
=>
{
const
safetensorsData
=
new
Uint8Array
(
event
.
target
.
result
);
const
dataView
=
new
DataView
(
safetensorsData
.
buffer
);
let
header_size
=
dataView
.
getUint32
(
0
,
true
);
let
offset
=
8
;
let
header
=
JSON
.
parse
(
String
.
fromCharCode
(...
safetensorsData
.
slice
(
offset
,
offset
+
header_size
)));
r
(
header
.
__metadata__
);
};
reader
.
readAsArrayBuffer
(
file
);
});
}
export
async
function
importA1111
(
graph
,
parameters
)
{
export
async
function
importA1111
(
graph
,
parameters
)
{
const
p
=
parameters
.
lastIndexOf
(
"
\n
Steps:
"
);
const
p
=
parameters
.
lastIndexOf
(
"
\n
Steps:
"
);
if
(
p
>
-
1
)
{
if
(
p
>
-
1
)
{
...
...
web/scripts/ui.js
View file @
62a371e1
...
@@ -465,7 +465,7 @@ export class ComfyUI {
...
@@ -465,7 +465,7 @@ export class ComfyUI {
const
fileInput
=
$el
(
"
input
"
,
{
const
fileInput
=
$el
(
"
input
"
,
{
id
:
"
comfy-file-input
"
,
id
:
"
comfy-file-input
"
,
type
:
"
file
"
,
type
:
"
file
"
,
accept
:
"
.json,image/png
"
,
accept
:
"
.json,image/png
,.latent
"
,
style
:
{
display
:
"
none
"
},
style
:
{
display
:
"
none
"
},
parent
:
document
.
body
,
parent
:
document
.
body
,
onchange
:
()
=>
{
onchange
:
()
=>
{
...
...
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