Prompt Editor prototype finished

This commit is contained in:
Joel Trauger
2023-12-26 03:02:07 -06:00
parent 9a1da5f744
commit 1892d771e2
2 changed files with 48 additions and 18 deletions
+18 -10
View File
@@ -1,5 +1,6 @@
import json
from pathlib import Path
from server import PromptServer
import server
class Harronode:
@@ -55,26 +56,34 @@ class PromptEditor:
def INPUT_TYPES(cls):
inputs = {
"optional": {
"prompt": ("STRING", {"forceInput": True}) # forceInput makes it an input node
},
"required": {
"prompt": ("STRING", {"forceInput": True}), # forceInput makes it an input node
"mode": (["Edit", "Bypass"],{}),
"promptEditor": ("STRING", {"default": "", "multiline": True})
},
"hidden": {
"unique_id": "UNIQUE_ID",
"extra_pnginfo": "EXTRA_PNGINFO",
"extra_pnginfo": "EXTRA_PNGINFO"
},
}
return inputs
RETURN_TYPES = ("STRING",)
FUNCTION = "EditPrompt"
OUTPUT_NODE = True
OUTPUT_IS_LIST = (True,)
CATEGORY = "Harronode/PromptBuilder"
def EditPrompt(self, prompt, mode, promptEditor, unique_id = None, extra_pnginfo=None):
print("Enter EditPrompt")
def EditPrompt(self, *args, **kwargs):
print("EditPrompt")
output = ''
prompt = ''
unique_id = kwargs["unique_id"]
extra_pnginfo = kwargs["extra_pnginfo"]
mode = kwargs["mode"]
promptEditor = kwargs["promptEditor"]
if "prompt" in kwargs:
prompt = kwargs["prompt"]
if unique_id and extra_pnginfo and "workflow" in extra_pnginfo:
workflow = extra_pnginfo["workflow"]
target_id = unique_id
@@ -85,10 +94,9 @@ class PromptEditor:
break
# if the node is found, set the value of the textbox (3rd input, 0-indexed) to the prompt
if node:
node["widgets_values"][2] = [prompt]
print(node)
if mode == "Edit":
# edit the prompt and wait for user to click GO
# set output
server.PromptServer.instance.send_sync("harronode-populate-promptEditor", {"node_id": unique_id, "value": prompt,})
output = promptEditor,
else:
# just set the output to the string we input
@@ -104,7 +112,7 @@ def onprompt_populate_prompt(json_data):
inputs = v['inputs']
if isinstance(inputs['prompt'], str):
inputs['prompt'] = prompt_builder.build_prompt(inputs)
server.PromptServer.instance.send_sync("harronode-node-feedback", {"node_id": k, "widget_name": "prompt", "type": "STRING", "value": inputs['prompt']})
# server.PromptServer.instance.send_sync("harronode-node-feedback", {"node_id": k, "widget_name": "prompt", "type": "STRING", "value": inputs['prompt']})
updated_widget_values[k] = inputs['prompt']
except Exception as e:
print(f"[WARN] ComfyUI-Harronode: Error on prompt\n{e}")
+30 -8
View File
@@ -3,6 +3,7 @@ import { api } from "../../scripts/api.js";
let origProps = {};
let initialized = false;
let previousPrompt = "";
const harroWidgetHandlers = {
"Harronode": {
@@ -35,14 +36,14 @@ function handleContentCount(node, widget) {
}
function handleMode (node, widget) {
const goButton = findWidgetByName(node, "Prompt looks good (GO)");
//const goButton = findWidgetByName(node, "Prompt looks good (GO)");
const promptEditor = findWidgetByName(node, "promptEditor");
if (widget.value == "Bypass"){
goButton.disabled = 1==1;
//goButton.disabled = 1==1;
promptEditor.inputEl.disabled = 1==1;
}
else {
goButton.disabled = 1==0;
//goButton.disabled = 1==0;
promptEditor.inputEl.disabled = 1==0;
}
}
@@ -163,6 +164,24 @@ function progressButtonPressed (){
app.registerExtension({
name: "harronode.harronode",
setup(){
function harronode_populate_promptEditor(event)
{
const node = app.graph._nodes_by_id[event.detail.node_id];
if (node) {
if(node.comfyClass == "PromptEditor") {
let prompt = event.detail.value;
if (prompt != previousPrompt){
previousPrompt = prompt;
node.widgets[1].inputEl.value = event.detail.value;
}
}
} else {
console.log(`Image Chooser Preview - failed to find ${event.detail.id}`)
}
}
api.addEventListener("harronode-populate-promptEditor", harronode_populate_promptEditor);
},
nodeCreated(node) {
for (const w of node.widgets || []) {
let widgetValue = w.value;
@@ -201,13 +220,16 @@ app.registerExtension({
}
//do this if we're messing with the prompt editor
if(node.comfyClass == "PromptEditor") {
console.log (node.widgets);
const mode = node.widgets.find((w) => w.name === "mode");
node.send_button_widget = node.addWidget("button", "progress_button", "", progressButtonPressed);
node.send_button_widget.name = "Prompt looks good (GO)";
enable_disabling(node.send_button_widget);
//node.send_button_widget = node.addWidget("button", "progress_button", "", progressButtonPressed);
//node.send_button_widget.name = "Prompt looks good (GO)";
node.widgets[1].inputEl.placeholder = "Populated Prompt (Will be generated automatically)";
//need to call one last time after adding the button
startupLogic(node, node.send_button_widget);
//startupLogic(node, node.send_button_widget);
// set height after we're done. :)
console.log("setting size");
const newHeight = node.computeSize()[1];
node.setSize([node.size[0], newHeight]);
}
}
});