Skip to content

Commit

Permalink
Add user-friendly warnings and remove the exception raised during the…
Browse files Browse the repository at this point in the history
… reading of metadata #58 #63
receyuki committed Feb 27, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
receyuki Rhys Yang
1 parent cbf771f commit 91336e9
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions nodes.py
Original file line number Diff line number Diff line change
@@ -30,7 +30,6 @@

from .stable_diffusion_prompt_reader.sd_prompt_reader.constants import (
SUPPORTED_FORMATS,
MESSAGE,
)
from .stable_diffusion_prompt_reader.sd_prompt_reader.image_data_reader import (
ImageDataReader,
@@ -45,6 +44,15 @@
CYAN = "\033[36m"
RESET = "\033[0m"

ERROR_MESSAGE = {
"format_error": "No data detected or unsupported format. "
"Please see the README for more details.\n"
"https://github.com/receyuki/comfyui-prompt-reader-node#supported-formats",
"complex_workflow": "The workflow is overly complex, or unsupported custom nodes have been used. "
"Please see the README for more details.\n"
"https://github.com/receyuki/comfyui-prompt-reader-node#prompt-reader-node",
}


def output_to_terminal(text: str):
print(f"{RESET+BLUE}" f"[SD Prompt Reader] " f"{CYAN+text+RESET}")
@@ -148,15 +156,30 @@ def load_image(self, image, parameter_index):

file_path = Path(image_path)

if file_path.suffix not in SUPPORTED_FORMATS:
output_to_terminal(MESSAGE["suffix_error"][1])
raise ValueError(MESSAGE["suffix_error"][1])

with open(file_path, "rb") as f:
image_data = ImageDataReader(f)
try:
image_data = ImageDataReader(f)
except:
output_to_terminal(ERROR_MESSAGE["complex_workflow"])
return self.error_output(
error_message=ERROR_MESSAGE["complex_workflow"],
image=image,
mask=mask,
width=i.width,
height=i.height,
filename=file_path.stem,
)

if not image_data.tool:
output_to_terminal(MESSAGE["format_error"][1])
raise ValueError(MESSAGE["format_error"][1])
output_to_terminal(ERROR_MESSAGE["format_error"])
return self.error_output(
error_message=ERROR_MESSAGE["format_error"],
image=image,
mask=mask,
width=i.width,
height=i.height,
filename=file_path.stem,
)

seed = int(
self.param_parser(image_data.parameter.get("seed", 0), parameter_index)
@@ -235,6 +258,28 @@ def search_model(model: str):

return model

@staticmethod
def error_output(
error_message, image=None, mask=None, width=0, height=0, filename=""
):
return {
"ui": {"text": ("", "", error_message)},
"result": (
image,
mask,
"",
"",
0,
0,
0.0,
width,
height,
"",
filename,
"",
),
}

@classmethod
def IS_CHANGED(s, image, parameter_index):
if image in SDPromptReader.files:

0 comments on commit 91336e9

Please sign in to comment.