Spaces:
Sleeping
Sleeping
Commit
·
202caac
1
Parent(s):
71c385f
commit
Browse files
python.py
CHANGED
|
@@ -12,6 +12,7 @@ from custom_nodes.ComfyUI_Comfyroll_CustomNodes.node_mappings import NODE_CLASS_
|
|
| 12 |
from comfy_extras.nodes_model_advanced import NODE_CLASS_MAPPINGS as NODE_CLASS_MAPPINGS_5
|
| 13 |
from comfy_extras.nodes_flux import NODE_CLASS_MAPPINGS as NODE_CLASS_MAPPINGS_6
|
| 14 |
from torchvision.transforms.functional import to_pil_image
|
|
|
|
| 15 |
import time
|
| 16 |
|
| 17 |
from huggingface_hub import hf_hub_download
|
|
@@ -126,6 +127,21 @@ def import_custom_nodes() -> None:
|
|
| 126 |
# Initializing custom nodes
|
| 127 |
init_extra_nodes()
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
add_comfyui_directory_to_sys_path()
|
|
@@ -266,5 +282,7 @@ def generate_image(prompt,
|
|
| 266 |
# saveimage_9 = saveimage.save_images(
|
| 267 |
# filename_prefix="image", images=get_value_at_index(vaedecode_8, 0)
|
| 268 |
# )
|
| 269 |
-
|
| 270 |
-
|
|
|
|
|
|
|
|
|
| 12 |
from comfy_extras.nodes_model_advanced import NODE_CLASS_MAPPINGS as NODE_CLASS_MAPPINGS_5
|
| 13 |
from comfy_extras.nodes_flux import NODE_CLASS_MAPPINGS as NODE_CLASS_MAPPINGS_6
|
| 14 |
from torchvision.transforms.functional import to_pil_image
|
| 15 |
+
from PIL import Image
|
| 16 |
import time
|
| 17 |
|
| 18 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 127 |
# Initializing custom nodes
|
| 128 |
init_extra_nodes()
|
| 129 |
|
| 130 |
+
def preprocess_image_tensor(image):
|
| 131 |
+
# If image has a batch dimension (shape: [1, C, H, W]), remove it.
|
| 132 |
+
if image.ndim == 4 and image.shape[0] == 1:
|
| 133 |
+
image = image.squeeze(0)
|
| 134 |
+
# If image is in channels-first format (i.e. [C, H, W]) and has 3 or 4 channels,
|
| 135 |
+
# convert it to channels-last format ([H, W, C]).
|
| 136 |
+
if image.ndim == 3 and image.shape[0] in [1, 3, 4]:
|
| 137 |
+
image = image.permute(1, 2, 0)
|
| 138 |
+
# Ensure the image values are between 0 and 1. Then scale them to [0, 255].
|
| 139 |
+
image = image.detach().cpu().numpy()
|
| 140 |
+
image = np.clip(image, 0, 1) * 255
|
| 141 |
+
# Convert to unsigned 8-bit integer type.
|
| 142 |
+
image = image.astype(np.uint8)
|
| 143 |
+
return image
|
| 144 |
+
|
| 145 |
|
| 146 |
|
| 147 |
add_comfyui_directory_to_sys_path()
|
|
|
|
| 282 |
# saveimage_9 = saveimage.save_images(
|
| 283 |
# filename_prefix="image", images=get_value_at_index(vaedecode_8, 0)
|
| 284 |
# )
|
| 285 |
+
image_tensor = get_value_at_index(vaedecode_8, 0)
|
| 286 |
+
preprocessed_image = preprocess_image_tensor(image_tensor)
|
| 287 |
+
pil_image = Image.fromarray(preprocessed_image)
|
| 288 |
+
return pil_image, seed
|