Files
melMass-comfy_mtb/utils.py
T
melMass 811443b921 feat: ✨ add a few nodes
- QRCode: self explanatory
- SmartStep: a very basic node to get percent of steps, to use
  in KSample Advanced.
- ImageDeglaze: taken from this archived repo
  https://github.com/Fannovel16/FN16-ComfyUI-nodes/commit/f5ecf948e11a4912e9ee3925c5ea73c4434b6c89
2023-06-18 16:41:49 +02:00

34 lines
992 B
Python

from PIL import Image
import numpy as np
import torch
from pathlib import Path
import sys
# Get the absolute path of the parent directory of the current script
here = Path(__file__).parent.resolve()
# Construct the absolute path to the ComfyUI directory
comfy_dir = here.parent.parent
# Construct the path to the font file
font_path = here / "font.ttf"
# Add extern folder to path
extern = (here / "extern", here / "extern" / "SadTalker")
sys.path.extend([ x.as_posix() for x in extern])
# Add the ComfyUI directory path to the sys.path list
sys.path.append(comfy_dir.resolve().as_posix())
# Tensor to PIL (grabbed from WAS Suite)
def tensor2pil(image: torch.Tensor) -> Image.Image:
return Image.fromarray(
np.clip(255.0 * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)
)
# Convert PIL to Tensor (grabbed from WAS Suite)
def pil2tensor(image: Image.Image) -> torch.Tensor:
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)