support load A1111 prompt from txt file, fix a bug if "Step:" is not first tag.

This commit is contained in:
Snower 2023-05-10 17:11:07 +08:00
parent 8e3d1cbf3b
commit b83fe1ca8e
3 changed files with 11 additions and 2 deletions

View File

@ -1267,6 +1267,12 @@ export class ComfyApp {
this.loadGraphData(JSON.parse(reader.result));
};
reader.readAsText(file);
} else if (file.type === "text/plain" || file.name?.endsWith(".txt")) {
const reader = new FileReader();
reader.onload = () => {
importA1111(this.graph, reader.result);
};
reader.readAsText(file);
}
}

View File

@ -48,7 +48,10 @@ export function getPngMetadata(file) {
}
export async function importA1111(graph, parameters) {
const p = parameters.lastIndexOf("\nSteps:");
var p = parameters.lastIndexOf("Steps:");
if (p > -1) {
p = parameters.substr(0, p).lastIndexOf("\n");
}
if (p > -1) {
const embeddings = await api.getEmbeddings();
const opts = parameters

View File

@ -465,7 +465,7 @@ export class ComfyUI {
const fileInput = $el("input", {
id: "comfy-file-input",
type: "file",
accept: ".json,image/png",
accept: ".json,.txt,image/png",
style: { display: "none" },
parent: document.body,
onchange: () => {