Instructions to use bbbboiwow/cocccck with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use bbbboiwow/cocccck with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("bbbboiwow/cocccck", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
File size: 13,321 Bytes
edb09f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | # roop_custom_nodes.py
import os
import subprocess
import glob
from PIL import Image
import numpy as np
import torch
import hmac
import hashlib
import requests
# Helper: save tensor image
def save_tensor_as_image(tensor, path):
np_img = (tensor[0].cpu().numpy() * 255).astype(np.uint8)
if np_img.shape[0] == 3: # If format is CHW
np_img = np.transpose(np_img, (1, 2, 0)) # Convert to HWC for PIL
img = Image.fromarray(np_img)
img.save(path)
# Helper: load image as tensor
def load_image_as_tensor(path):
img = Image.open(path).convert("RGB")
np_img = np.array(img).astype(np.float32) / 255.0
return torch.from_numpy(np_img).unsqueeze(0)
def get_unique_filename(path):
base, ext = os.path.splitext(path)
counter = 1
new_path = path
while os.path.exists(new_path):
new_path = f"{base}_{counter}{ext}"
counter += 1
return new_path
def send_webhook_image(webhook_url, webhook_secret, output_path, extra_data=None):
if not webhook_url:
return
with open(output_path, 'rb') as f:
image_data = f.read()
# GitHub-style HMAC signature
signature = 'sha256=' + hmac.new(
webhook_secret.encode('utf-8'),
image_data,
hashlib.sha256
).hexdigest()
headers = {
'X-Hub-Signature-256': signature
}
files = {
'file': ('swapped.png', image_data, 'image/png')
}
data = extra_data or {}
try:
resp = requests.post(webhook_url, headers=headers, files=files, data=data)
resp.raise_for_status()
print(f"[Webhook] Sent successfully to {webhook_url}")
except Exception as e:
print(f"[Webhook Error] {e}")
class RoopFaceSwap:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"source_image": ("IMAGE",),
"target_image": ("IMAGE",),
"roop_dir": ("STRING", {"default": "/content/roop"}),
"output_name": ("STRING", {"default": "roop_output.png"}),
"many_faces": ("BOOLEAN", {"default": False})
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("swapped_image",)
FUNCTION = "run"
CATEGORY = "Roop/Basic"
def run(self, source_image, target_image, roop_dir, output_name, many_faces):
temp_dir = os.path.join(roop_dir, "temp_io")
os.makedirs(temp_dir, exist_ok=True)
source_path = os.path.join(temp_dir, "source.png")
target_path = os.path.join(temp_dir, "target.png")
output_path = get_unique_filename(os.path.join(temp_dir, output_name))
save_tensor_as_image(source_image, source_path)
save_tensor_as_image(target_image, target_path)
cmd = [
"python", "run.py",
"-s", source_path,
"-t", target_path,
"-o", output_path,
"--execution-provider", "cuda",
"--frame-processor", "face_swapper"
]
if many_faces:
cmd.append("--many-faces")
subprocess.run(cmd, check=True, cwd=roop_dir)
if not os.path.exists(output_path):
print(f"[Warning] Roop did not produce output: {output_path}")
blank = torch.zeros_like(target_image)
return (blank,)
return (load_image_as_tensor(output_path),)
class RoopFaceSwapWithEnhancer:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"source_image": ("IMAGE",),
"target_image": ("IMAGE",),
"roop_dir": ("STRING", {"default": "/content/roop"}),
"output_name": ("STRING", {"default": "roop_output.png"}),
"many_faces": ("BOOLEAN", {"default": False})
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("swapped_image",)
FUNCTION = "run"
CATEGORY = "Roop/Enhanced"
def run(self, source_image, target_image, roop_dir, output_name, many_faces):
temp_dir = os.path.join(roop_dir, "temp_io")
os.makedirs(temp_dir, exist_ok=True)
source_path = os.path.join(temp_dir, "source.png")
target_path = os.path.join(temp_dir, "target.png")
output_path = get_unique_filename(os.path.join(temp_dir, output_name))
save_tensor_as_image(source_image, source_path)
save_tensor_as_image(target_image, target_path)
cmd = [
"python", "run.py",
"-s", source_path,
"-t", target_path,
"-o", output_path,
"--execution-provider", "cuda",
"--frame-processor", "face_swapper", "face_enhancer"
]
if many_faces:
cmd.append("--many-faces")
subprocess.run(cmd, check=True, cwd=roop_dir)
if not os.path.exists(output_path):
print(f"[Warning] Roop did not produce output: {output_path}")
blank = torch.zeros_like(target_image)
return (blank,)
return (load_image_as_tensor(output_path),)
class RoopBatchFaceSwap:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"source_image": ("IMAGE",),
"input_dir": ("STRING", {"default": "/input/images"}),
"output_dir": ("STRING", {"default": "/output/images"}),
"roop_dir": ("STRING", {"default": "/content/roop"}),
"use_enhancer": ("BOOLEAN", {"default": False}),
"many_faces": ("BOOLEAN", {"default": False})
}
}
RETURN_TYPES = ()
RETURN_NAMES = ()
FUNCTION = "run"
CATEGORY = "Roop/Batch"
def run(self, source_image, input_dir, output_dir, roop_dir, use_enhancer, many_faces):
os.makedirs(output_dir, exist_ok=True)
temp_dir = os.path.join(roop_dir, "temp_io")
os.makedirs(temp_dir, exist_ok=True)
source_path = os.path.join(temp_dir, "source.png")
save_tensor_as_image(source_image, source_path)
image_paths = glob.glob(os.path.join(input_dir, "*.jpg")) + \
glob.glob(os.path.join(input_dir, "*.png"))
for img_path in image_paths:
target_name = os.path.basename(img_path)
target_path = os.path.join(temp_dir, "target.png")
output_path = os.path.join(output_dir, f"out_{target_name}")
Image.open(img_path).save(target_path)
cmd = [
"python", "run.py",
"-s", source_path,
"-t", target_path,
"-o", output_path,
"--execution-provider", "cuda",
"--frame-processor", "face_swapper"
]
if use_enhancer:
cmd[-1] += " face_enhancer"
if many_faces:
cmd.append("--many-faces")
subprocess.run(cmd, check=True, cwd=roop_dir)
if not os.path.exists(output_path):
print(f"[Skipped] NSFW or error: {img_path} -> No output generated.")
continue
return ()
class RoopFaceSwapVideo:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"source_image": ("IMAGE",),
"target_video_path": ("STRING", {"default": "/path/to/video.mp4"}),
"roop_dir": ("STRING", {"default": "/content/roop"}),
"output_name": ("STRING", {"default": "swapped_video.mp4"}),
"many_faces": ("BOOLEAN", {"default": False})
}
}
RETURN_TYPES = ()
RETURN_NAMES = ()
FUNCTION = "run"
CATEGORY = "Roop/Video"
def run(self, source_image, target_video_path, roop_dir, output_name, many_faces):
temp_dir = os.path.join(roop_dir, "temp_io")
os.makedirs(temp_dir, exist_ok=True)
source_path = os.path.join(temp_dir, "source.png")
output_path = get_unique_filename(os.path.join(temp_dir, output_name))
save_tensor_as_image(source_image, source_path)
cmd = [
"python", "run.py",
"-s", source_path,
"-t", target_video_path,
"-o", output_path,
"--keep-fps",
"--keep-frames",
"--execution-provider", "cuda",
"--frame-processor", "face_swapper"
]
if many_faces:
cmd.append("--many-faces")
subprocess.run(cmd, check=True, cwd=roop_dir)
if not os.path.exists(output_path):
print(f"[Warning] Roop did not produce video output: {output_path}")
return ()
class RoopSendWebhookImage:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image_tensor": ("IMAGE",),
"filename": ("STRING", {"default": "output.png"}),
"webhook_url": ("STRING", {"default": ""}),
"webhook_secret": ("STRING", {"default": ""}),
"enable_webhook": ("BOOLEAN", {"default": True}),
"roop_dir": ("STRING", {"default": "/content/roop"})
}
}
RETURN_TYPES = ()
RETURN_NAMES = ()
FUNCTION = "run"
CATEGORY = "Roop/Webhook"
def run(self, image_tensor, filename, webhook_url, webhook_secret, enable_webhook, roop_dir):
if not enable_webhook or not webhook_url:
print("[WebhookImage] Disabled or URL not set — skipping.")
return ()
temp_dir = os.path.join(roop_dir, "temp_io")
os.makedirs(temp_dir, exist_ok=True)
output_path = os.path.join(temp_dir, filename)
save_tensor_as_image(image_tensor, output_path)
try:
with open(output_path, 'rb') as f:
file_data = f.read()
headers = {}
if webhook_secret:
signature = 'sha256=' + hmac.new(
webhook_secret.encode('utf-8'),
file_data,
hashlib.sha256
).hexdigest()
headers['X-Hub-Signature-256'] = signature
files = {
'file': (filename, file_data, 'image/png')
}
resp = requests.post(webhook_url, headers=headers, files=files)
resp.raise_for_status()
print(f"[WebhookImage] Sent image: {filename} → {webhook_url}")
except Exception as e:
print(f"[WebhookImage Error] {e}")
return ()
class RoopSendWebhookFile:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"file_path": ("STRING",),
"filename": ("STRING", {"default": "output.mp4"}),
"webhook_url": ("STRING", {"default": ""}),
"webhook_secret": ("STRING", {"default": ""}),
"enable_webhook": ("BOOLEAN", {"default": True})
}
}
RETURN_TYPES = ()
RETURN_NAMES = ()
FUNCTION = "run"
CATEGORY = "Roop/Webhook"
def run(self, file_path, filename, webhook_url, webhook_secret, enable_webhook):
if not enable_webhook or not webhook_url:
print("[WebhookFile] Disabled or URL not set — skipping.")
return ()
if not os.path.exists(file_path):
print(f"[WebhookFile] File does not exist: {file_path}")
return ()
try:
with open(file_path, 'rb') as f:
file_data = f.read()
headers = {}
if webhook_secret:
signature = 'sha256=' + hmac.new(
webhook_secret.encode('utf-8'),
file_data,
hashlib.sha256
).hexdigest()
headers['X-Hub-Signature-256'] = signature
content_type = "video/mp4" if filename.endswith(".mp4") else "application/octet-stream"
files = {
'file': (filename, file_data, content_type)
}
resp = requests.post(webhook_url, headers=headers, files=files)
resp.raise_for_status()
print(f"[WebhookFile] Sent file: {filename} → {webhook_url}")
except Exception as e:
print(f"[WebhookFile Error] {e}")
return ()
# Register with ComfyUI
NODE_CLASS_MAPPINGS = {
"RoopFaceSwap": RoopFaceSwap,
"RoopFaceSwapWithEnhancer": RoopFaceSwapWithEnhancer,
"RoopBatchFaceSwap": RoopBatchFaceSwap,
"RoopFaceSwapVideo": RoopFaceSwapVideo,
"RoopSendWebhookImage": RoopSendWebhookImage,
"RoopSendWebhookFile": RoopSendWebhookFile,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"RoopFaceSwap": "Roop Face Swap (Image)",
"RoopFaceSwapWithEnhancer": "Roop Face Swap + Enhancer",
"RoopBatchFaceSwap": "Roop Batch Image Folder",
"RoopFaceSwapVideo": "Roop Face Swap (Video)",
"RoopSendWebhookImage": "Roop Webhook: Image Tensor",
"RoopSendWebhookFile": "Roop Webhook: File Path",
}
|