Compare commits

...
5 changed files with 34 additions and 21 deletions
+3
View File
@@ -44,6 +44,7 @@ additional metadata to ensure compatibility with metadata detection on websites
See [SD Prompt Reader](https://github.com/receyuki/stable-diffusion-prompt-reader#supported-formats) for details
## Installation
>While ZIP package is available, it is strongly recommended not to use it for installation.
### Install and update via [ComfyUI Manager](https://github.com/ltdrdata/ComfyUI-Manager) (Recommended)
Search for `SD Prompt Reader` in the ComfyUI Manager and install it.
### Install manually
@@ -123,3 +124,5 @@ have higher priority, so do not connect `STRING` inputs unless necessary, as the
## Credits
- The SD Prompt Reader node is based on [ComfyUI Load Image With Metadata](https://github.com/tkoenig89/ComfyUI_Load_Image_With_Metadata)
- The SD Prompt Saver node is based on [Comfy Image Saver](https://github.com/giriss/comfy-image-saver) & [Stable Diffusion Webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui)
- The seed generator in the SD Parameter Generator is modified from [rgthree's Comfy Nodes](https://github.com/rgthree/rgthree-comfy#rgthrees-comfy-nodes)
- A special thanks to [@alessandroperilli](https://github.com/alessandroperilli) and his [AP Workflow](https://perilli.com/ai/comfyui/) for providing numerous suggestions
+6 -4
View File
@@ -10,8 +10,10 @@ comfy_path = os.path.dirname(folder_paths.__file__)
tk_nodes_path = os.path.join(os.path.dirname(__file__))
js_dest_path = os.path.join(comfy_path, "web", "extensions", "SDPromptReader")
if not os.path.exists(js_dest_path):
os.makedirs(js_dest_path)
os.makedirs(js_dest_path, exist_ok=True)
js_src_path = os.path.join(tk_nodes_path, "js", "promptDisplay.js")
shutil.copy(js_src_path, js_dest_path)
files_to_copy = ["promptDisplay.js", "parameterDisplay.js", "seedGen.js"]
for file in files_to_copy:
js_src_path = os.path.join(tk_nodes_path, "js", file)
shutil.copy(js_src_path, js_dest_path)
+11 -3
View File
@@ -41,13 +41,21 @@ app.registerExtension({
} else {
ar_message = `Optimal resolution for ${message.text[1]} model
with aspect ratio ${message.text[0]}: ${message.text[2]} x ${message.text[3]}`;
this.widgets.find(obj => obj.name === "width").value = message.text[2];
this.widgets.find(obj => obj.name === "height").value = message.text[3];
}
const start_at_float = parseFloat(message.text[5])
const base_percentage = Math.round(start_at_float * 100) + "%";
const refiner_percentage = Math.round((1 - start_at_float) * 100) + "%";
const step_message = `Total steps: ${message.text[4]}, refiner start at ${base_percentage},
Base steps: ${message.text[6]} (${base_percentage}), Refiner steps: ${message.text[7]} (${refiner_percentage})`;
// const refiner_percentage = Math.round((1 - start_at_float) * 100) + "%";
let step_message;
if (start_at_float === 1) {
step_message = `Total steps: ${message.text[4]},
Refiner off`;
} else {
step_message = `Total steps: ${message.text[4]},
Refiner start at step: ${message.text[6]} (${base_percentage})`;
}
this.widgets.find(obj => obj.name === "steps_display").value = step_message;
this.widgets.find(obj => obj.name === "aspect_ratio_display").value = ar_message;
+3 -2
View File
@@ -65,7 +65,7 @@ class SeedControl {
if (typeof this.lastSeed === "number" && !SPECIAL_SEEDS.includes(this.lastSeed)) {
if (inputSeed === SPECIAL_SEED_INCREMENT) {
this.serializedCtx.seedUsed = this.lastSeed + 1;
} else if (inputSeed === SPECIAL_SEED_INCREMENT) {
} else if (inputSeed === SPECIAL_SEED_DECREMENT) {
this.serializedCtx.seedUsed = this.lastSeed - 1;
}
}
@@ -142,11 +142,12 @@ app.registerExtension({
if (nodeData.name === "SDParameterGenerator") {
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
onNodeCreated ? onNodeCreated.apply(this, []) : undefined;
const result = onNodeCreated?.apply(this, []);
this.seedControl = new SeedControl(this);
const nodeWidth = this.size[0];
const nodeHeight = this.size[1];
this.setSize([nodeWidth * 1.5, nodeHeight * 1.1]);
return result;
};
}
},
+11 -12
View File
@@ -64,7 +64,7 @@ class SDPromptReader:
return {
"required": {
"image": (sorted(files), {"image_upload": True}),
"data_index": (
"parameter_index": (
"INT",
{"default": 0, "min": 0, "max": 255, "step": 1},
),
@@ -94,7 +94,7 @@ class SDPromptReader:
"CFG",
"WIDTH",
"HEIGHT",
"SETTING",
"SETTINGS",
"FILE_NAME",
)
@@ -102,7 +102,7 @@ class SDPromptReader:
CATEGORY = "SD Prompt Reader"
OUTPUT_NODE = True
def load_image(self, image, data_index):
def load_image(self, image, parameter_index):
image_path = folder_paths.get_annotated_filepath(image)
i = Image.open(image_path)
i = ImageOps.exif_transpose(i)
@@ -128,13 +128,15 @@ class SDPromptReader:
raise ValueError(MESSAGE["format_error"][1])
seed = int(
self.param_parser(image_data.parameter.get("seed"), data_index) or 0
self.param_parser(image_data.parameter.get("seed"), parameter_index)
or 0
)
steps = int(
self.param_parser(image_data.parameter.get("steps"), data_index) or 0
self.param_parser(image_data.parameter.get("steps"), parameter_index)
or 0
)
cfg = float(
self.param_parser(image_data.parameter.get("cfg"), data_index) or 0
self.param_parser(image_data.parameter.get("cfg"), parameter_index) or 0
)
width = int(image_data.width or 0)
height = int(image_data.height or 0)
@@ -454,7 +456,7 @@ class SDParameterGenerator:
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"refiner_start": (
"FLOAT",
{"default": 0.8, "min": 0.0, "max": 1.0, "step": 0.1},
{"default": 0.8, "min": 0.0, "max": 1.0, "step": 0.01},
),
"cfg": (
"FLOAT",
@@ -507,7 +509,6 @@ class SDParameterGenerator:
"INT",
"INT",
"INT",
"INT",
"FLOAT",
comfy.samplers.KSampler.SAMPLERS,
comfy.samplers.KSampler.SCHEDULERS,
@@ -526,8 +527,7 @@ class SDParameterGenerator:
"VAE",
"SEED",
"STEPS",
"BASE_STEPS",
"REFINER_STEPS",
"REFINER_START_STEP",
"CFG",
"SAMPLER_NAME",
"SCHEDULER",
@@ -601,7 +601,7 @@ class SDParameterGenerator:
f"Sampler: {sampler_name},\n"
f"Scheduler: {scheduler},\n"
f"Size: {str(width)}x{str(height)},\n"
f"Batch size: {str(batch_size)},\n"
f"Batch size: {str(batch_size)}\n"
)
return {
@@ -624,7 +624,6 @@ class SDParameterGenerator:
seed,
steps,
base_steps,
refiner_steps,
cfg,
sampler_name,
scheduler,