Merge branch 'master'
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# Draw Things ComfyUI Wrapper
|
||||
|
||||
These nodes provide a wrapper for calling [Draw Things](https://drawthings.ai/) image generations from [ComfyUI](https://github.com/comfyanonymous/ComfyUI).
|
||||
|
||||
**Wait, why?** The Draw Things app has been optimized for Apple hardware and runs roughly x3 faster than ComfyUI generations. But ComfyUI is a flexible and powerful tools, and has some features - like queuing and face swapping - that haven't been implemented in Draw Things.
|
||||
|
||||
This simple node calls a local instance of Draw Things through its API and returns the resulting image to ComfyUI.
|
||||
|
||||
# Set up
|
||||
|
||||
Start Draw Things, and in the "Advanced" tab on the left-hand side, enable "API Server" with settings Protocol HTTP, Port 7860 and IP localhost only. ComfyUI jobs can now generate via Draw Things. The generations will also display in the Draw Things as if they had been triggered natively.
|
||||
|
||||
# Limitations
|
||||
|
||||
This node treats Draw Things as a black box, and can only change the settings available through the [Draw Things API](https://docs.drawthings.ai/documentation/documentation/8.scripts). Settings changed through the API automatically change the values in the Draw Things UI. Other settings can be set manually inside the UI. These manual settings _do_ take effect for jobs initiated by ComfyUI, but are _not_ recorded by ComfyUI, so such ComfyUI workflows are not reproducible (without also ensuring the Draw Things settings are the same).
|
||||
|
||||
# Disclaimer
|
||||
|
||||
This repo is 100% unofficial and unaffiliated with either Draw Things or ComfyUI.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
|
||||
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
|
||||
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Wrapper nodes for calling Draw Things from ComfyUI
|
||||
"""
|
||||
|
||||
import base64
|
||||
import numpy as np
|
||||
import requests
|
||||
from PIL import Image
|
||||
import io
|
||||
import torch
|
||||
|
||||
|
||||
class DrawThingsWrapper:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
CATEGORY = "DrawThingsWrapper"
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"prompt": ("STRING", {"default": ""}),
|
||||
"seed": ("INT", {"default": 42}),
|
||||
"width": ("INT", {"default": 512}),
|
||||
"height": ("INT", {"default": 512}),
|
||||
"guidance_scale": ("FLOAT", {"default": 3.5}),
|
||||
"steps": ("INT", {"default": 20}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
RETURN_NAMES = ("generated_image",)
|
||||
FUNCTION = "generate_image"
|
||||
|
||||
def generate_image(self, prompt, seed, width, height, guidance_scale, steps):
|
||||
# Call the Draw Things API
|
||||
api_url = "http://127.0.0.1:7860/sdapi/v1/txt2img"
|
||||
|
||||
payload = {
|
||||
"prompt": prompt,
|
||||
"seed": seed,
|
||||
"width": width,
|
||||
"height": height,
|
||||
"guidance_scale": guidance_scale,
|
||||
"steps": steps,
|
||||
}
|
||||
|
||||
response = requests.post(api_url, json=payload)
|
||||
|
||||
# Raise an error if the request failed
|
||||
response.raise_for_status()
|
||||
|
||||
# Parse the JSON response
|
||||
data = response.json()
|
||||
|
||||
# Process the images (assuming they are base64 encoded or raw binary data)
|
||||
images = []
|
||||
for img_data in data["images"]:
|
||||
image_bytes = base64.b64decode(img_data)
|
||||
# Convert the image data to a Pillow Image object
|
||||
image = Image.open(io.BytesIO(image_bytes))
|
||||
image_np = np.array(image)
|
||||
# Convert to float32 tensor and normalize
|
||||
tensor_image = torch.from_numpy(image_np.astype(np.float32) / 255.0)
|
||||
images.append(tensor_image)
|
||||
return (torch.stack(images),)
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {"DrawThingsWrapper": DrawThingsWrapper}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {"DrawThingsWrapper": "Draw Things Wrapper"}
|
||||
@@ -0,0 +1,4 @@
|
||||
numpy
|
||||
PIL
|
||||
requests
|
||||
torch
|
||||
Reference in New Issue
Block a user