Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +53 -0
- README.md +37 -10
- app.py +281 -0
- custom_nodes/__init__.py +184 -0
- workflows/nwn_enhance.json +100 -0
Dockerfile
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
# Install system dependencies
|
| 4 |
+
RUN apt-get update && apt-get install -y \
|
| 5 |
+
git \
|
| 6 |
+
wget \
|
| 7 |
+
libgl1-mesa-glx \
|
| 8 |
+
libglib2.0-0 \
|
| 9 |
+
libsm6 \
|
| 10 |
+
libxext6 \
|
| 11 |
+
libxrender-dev \
|
| 12 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
+
|
| 14 |
+
# Set working directory
|
| 15 |
+
WORKDIR /app
|
| 16 |
+
|
| 17 |
+
# Clone ComfyUI
|
| 18 |
+
RUN git clone https://github.com/comfyanonymous/ComfyUI.git /app/ComfyUI
|
| 19 |
+
|
| 20 |
+
# Install ComfyUI dependencies
|
| 21 |
+
WORKDIR /app/ComfyUI
|
| 22 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 23 |
+
|
| 24 |
+
# Install additional packages for API
|
| 25 |
+
RUN pip install --no-cache-dir gradio fastapi uvicorn pillow
|
| 26 |
+
|
| 27 |
+
# Create custom nodes directory
|
| 28 |
+
RUN mkdir -p /app/ComfyUI/custom_nodes/dgg_nwn_nodes
|
| 29 |
+
|
| 30 |
+
# Copy custom nodes
|
| 31 |
+
COPY custom_nodes/ /app/ComfyUI/custom_nodes/dgg_nwn_nodes/
|
| 32 |
+
|
| 33 |
+
# Copy workflows
|
| 34 |
+
RUN mkdir -p /app/ComfyUI/workflows
|
| 35 |
+
COPY workflows/ /app/ComfyUI/workflows/
|
| 36 |
+
|
| 37 |
+
# Copy API wrapper
|
| 38 |
+
COPY app.py /app/
|
| 39 |
+
|
| 40 |
+
# Download base model (SD 1.5 for speed on free tier)
|
| 41 |
+
RUN mkdir -p /app/ComfyUI/models/checkpoints && \
|
| 42 |
+
wget -O /app/ComfyUI/models/checkpoints/v1-5-pruned-emaonly.safetensors \
|
| 43 |
+
https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors || true
|
| 44 |
+
|
| 45 |
+
# Expose ports
|
| 46 |
+
EXPOSE 7860 8188
|
| 47 |
+
|
| 48 |
+
# Set environment
|
| 49 |
+
ENV PYTHONUNBUFFERED=1
|
| 50 |
+
|
| 51 |
+
# Run the Gradio wrapper
|
| 52 |
+
WORKDIR /app
|
| 53 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,37 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: DGG ComfyUI
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: DGG ComfyUI - NWN Character Enhancement
|
| 3 |
+
emoji: 🎮
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# DGG ComfyUI - NWN Character Enhancement
|
| 12 |
+
|
| 13 |
+
A ComfyUI deployment optimized for enhancing Neverwinter Nights characters into photorealistic images for MetaHuman conversion.
|
| 14 |
+
|
| 15 |
+
## Features
|
| 16 |
+
- **NWN Enhancement Workflow**: Pre-configured for game character upscaling
|
| 17 |
+
- **API Access**: Trigger workflows programmatically
|
| 18 |
+
- **Custom Nodes**: Specialized for fantasy character art
|
| 19 |
+
|
| 20 |
+
## Usage
|
| 21 |
+
|
| 22 |
+
### Web Interface
|
| 23 |
+
Open the Space and use the ComfyUI interface directly.
|
| 24 |
+
|
| 25 |
+
### API Access
|
| 26 |
+
```python
|
| 27 |
+
from gradio_client import Client
|
| 28 |
+
client = Client("BenjaminPittsley/DGG-ComfyUI")
|
| 29 |
+
result = client.predict(
|
| 30 |
+
image="path/to/nwn_screenshot.png",
|
| 31 |
+
api_name="/enhance"
|
| 32 |
+
)
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## Workflows
|
| 36 |
+
- `nwn_enhance.json`: Enhance NWN character screenshots
|
| 37 |
+
- `fantasy_portrait.json`: Generate fantasy character portraits
|
app.py
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
DGG ComfyUI API Wrapper for HuggingFace Spaces
|
| 3 |
+
Provides Gradio interface and API endpoints for NWN character enhancement.
|
| 4 |
+
"""
|
| 5 |
+
import os
|
| 6 |
+
import subprocess
|
| 7 |
+
import threading
|
| 8 |
+
import time
|
| 9 |
+
import json
|
| 10 |
+
import base64
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
import gradio as gr
|
| 14 |
+
from PIL import Image
|
| 15 |
+
import requests
|
| 16 |
+
|
| 17 |
+
# Start ComfyUI in background
|
| 18 |
+
COMFYUI_PORT = 8188
|
| 19 |
+
COMFYUI_URL = f"http://127.0.0.1:{COMFYUI_PORT}"
|
| 20 |
+
|
| 21 |
+
def start_comfyui():
|
| 22 |
+
"""Start ComfyUI server in background."""
|
| 23 |
+
subprocess.Popen([
|
| 24 |
+
"python", "ComfyUI/main.py",
|
| 25 |
+
"--listen", "127.0.0.1",
|
| 26 |
+
"--port", str(COMFYUI_PORT),
|
| 27 |
+
"--disable-auto-launch"
|
| 28 |
+
])
|
| 29 |
+
|
| 30 |
+
# Start ComfyUI on import
|
| 31 |
+
comfyui_thread = threading.Thread(target=start_comfyui, daemon=True)
|
| 32 |
+
comfyui_thread.start()
|
| 33 |
+
|
| 34 |
+
# Wait for ComfyUI to be ready
|
| 35 |
+
def wait_for_comfyui(timeout=60):
|
| 36 |
+
"""Wait for ComfyUI to be ready."""
|
| 37 |
+
start = time.time()
|
| 38 |
+
while time.time() - start < timeout:
|
| 39 |
+
try:
|
| 40 |
+
r = requests.get(f"{COMFYUI_URL}/system_stats", timeout=2)
|
| 41 |
+
if r.status_code == 200:
|
| 42 |
+
print("ComfyUI is ready!")
|
| 43 |
+
return True
|
| 44 |
+
except:
|
| 45 |
+
pass
|
| 46 |
+
time.sleep(2)
|
| 47 |
+
return False
|
| 48 |
+
|
| 49 |
+
# NWN Enhancement Workflow
|
| 50 |
+
NWN_ENHANCE_WORKFLOW = {
|
| 51 |
+
"3": {
|
| 52 |
+
"class_type": "KSampler",
|
| 53 |
+
"inputs": {
|
| 54 |
+
"seed": 42,
|
| 55 |
+
"steps": 20,
|
| 56 |
+
"cfg": 7.5,
|
| 57 |
+
"sampler_name": "euler_ancestral",
|
| 58 |
+
"scheduler": "normal",
|
| 59 |
+
"denoise": 0.65,
|
| 60 |
+
"model": ["4", 0],
|
| 61 |
+
"positive": ["6", 0],
|
| 62 |
+
"negative": ["7", 0],
|
| 63 |
+
"latent_image": ["5", 0]
|
| 64 |
+
}
|
| 65 |
+
},
|
| 66 |
+
"4": {
|
| 67 |
+
"class_type": "CheckpointLoaderSimple",
|
| 68 |
+
"inputs": {
|
| 69 |
+
"ckpt_name": "v1-5-pruned-emaonly.safetensors"
|
| 70 |
+
}
|
| 71 |
+
},
|
| 72 |
+
"5": {
|
| 73 |
+
"class_type": "VAEEncode",
|
| 74 |
+
"inputs": {
|
| 75 |
+
"pixels": ["10", 0],
|
| 76 |
+
"vae": ["4", 2]
|
| 77 |
+
}
|
| 78 |
+
},
|
| 79 |
+
"6": {
|
| 80 |
+
"class_type": "CLIPTextEncode",
|
| 81 |
+
"inputs": {
|
| 82 |
+
"text": "photorealistic fantasy character portrait, highly detailed facial features, 8k, cinematic lighting, professional character art, sharp focus, intricate armor details",
|
| 83 |
+
"clip": ["4", 1]
|
| 84 |
+
}
|
| 85 |
+
},
|
| 86 |
+
"7": {
|
| 87 |
+
"class_type": "CLIPTextEncode",
|
| 88 |
+
"inputs": {
|
| 89 |
+
"text": "blurry, low quality, low poly, pixelated, cartoonish, anime, simple",
|
| 90 |
+
"clip": ["4", 1]
|
| 91 |
+
}
|
| 92 |
+
},
|
| 93 |
+
"8": {
|
| 94 |
+
"class_type": "VAEDecode",
|
| 95 |
+
"inputs": {
|
| 96 |
+
"samples": ["3", 0],
|
| 97 |
+
"vae": ["4", 2]
|
| 98 |
+
}
|
| 99 |
+
},
|
| 100 |
+
"9": {
|
| 101 |
+
"class_type": "SaveImage",
|
| 102 |
+
"inputs": {
|
| 103 |
+
"filename_prefix": "nwn_enhanced",
|
| 104 |
+
"images": ["8", 0]
|
| 105 |
+
}
|
| 106 |
+
},
|
| 107 |
+
"10": {
|
| 108 |
+
"class_type": "LoadImage",
|
| 109 |
+
"inputs": {
|
| 110 |
+
"image": "input.png"
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
def enhance_nwn_character(
|
| 116 |
+
input_image: Image.Image,
|
| 117 |
+
prompt: str = "photorealistic fantasy character, detailed skin, cinematic lighting",
|
| 118 |
+
negative_prompt: str = "blurry, low quality, pixelated",
|
| 119 |
+
denoise: float = 0.65,
|
| 120 |
+
steps: int = 20,
|
| 121 |
+
seed: int = -1
|
| 122 |
+
) -> Image.Image:
|
| 123 |
+
"""
|
| 124 |
+
Enhance an NWN character screenshot using Stable Diffusion.
|
| 125 |
+
|
| 126 |
+
Args:
|
| 127 |
+
input_image: PIL Image of NWN character
|
| 128 |
+
prompt: Enhancement prompt
|
| 129 |
+
negative_prompt: What to avoid
|
| 130 |
+
denoise: How much to change (0=none, 1=complete)
|
| 131 |
+
steps: Sampling steps
|
| 132 |
+
seed: Random seed (-1 for random)
|
| 133 |
+
|
| 134 |
+
Returns:
|
| 135 |
+
Enhanced PIL Image
|
| 136 |
+
"""
|
| 137 |
+
if not wait_for_comfyui(timeout=30):
|
| 138 |
+
raise Exception("ComfyUI not available")
|
| 139 |
+
|
| 140 |
+
# Save input image
|
| 141 |
+
input_path = Path("/tmp/input.png")
|
| 142 |
+
input_image.save(input_path)
|
| 143 |
+
|
| 144 |
+
# Upload image to ComfyUI
|
| 145 |
+
with open(input_path, "rb") as f:
|
| 146 |
+
files = {"image": f}
|
| 147 |
+
r = requests.post(f"{COMFYUI_URL}/upload/image", files=files)
|
| 148 |
+
if r.status_code != 200:
|
| 149 |
+
raise Exception(f"Failed to upload image: {r.text}")
|
| 150 |
+
upload_result = r.json()
|
| 151 |
+
|
| 152 |
+
# Modify workflow
|
| 153 |
+
workflow = NWN_ENHANCE_WORKFLOW.copy()
|
| 154 |
+
workflow["6"]["inputs"]["text"] = prompt
|
| 155 |
+
workflow["7"]["inputs"]["text"] = negative_prompt
|
| 156 |
+
workflow["3"]["inputs"]["denoise"] = denoise
|
| 157 |
+
workflow["3"]["inputs"]["steps"] = steps
|
| 158 |
+
workflow["3"]["inputs"]["seed"] = seed if seed >= 0 else int(time.time() * 1000) % 2**32
|
| 159 |
+
workflow["10"]["inputs"]["image"] = upload_result.get("name", "input.png")
|
| 160 |
+
|
| 161 |
+
# Queue prompt
|
| 162 |
+
prompt_data = {"prompt": workflow}
|
| 163 |
+
r = requests.post(f"{COMFYUI_URL}/prompt", json=prompt_data)
|
| 164 |
+
if r.status_code != 200:
|
| 165 |
+
raise Exception(f"Failed to queue prompt: {r.text}")
|
| 166 |
+
|
| 167 |
+
prompt_id = r.json().get("prompt_id")
|
| 168 |
+
|
| 169 |
+
# Wait for completion
|
| 170 |
+
for _ in range(120): # 2 minute timeout
|
| 171 |
+
time.sleep(1)
|
| 172 |
+
r = requests.get(f"{COMFYUI_URL}/history/{prompt_id}")
|
| 173 |
+
if r.status_code == 200:
|
| 174 |
+
history = r.json()
|
| 175 |
+
if prompt_id in history:
|
| 176 |
+
outputs = history[prompt_id].get("outputs", {})
|
| 177 |
+
if "9" in outputs: # SaveImage node
|
| 178 |
+
images = outputs["9"].get("images", [])
|
| 179 |
+
if images:
|
| 180 |
+
# Get the output image
|
| 181 |
+
img_info = images[0]
|
| 182 |
+
img_r = requests.get(
|
| 183 |
+
f"{COMFYUI_URL}/view",
|
| 184 |
+
params={
|
| 185 |
+
"filename": img_info["filename"],
|
| 186 |
+
"subfolder": img_info.get("subfolder", ""),
|
| 187 |
+
"type": img_info.get("type", "output")
|
| 188 |
+
}
|
| 189 |
+
)
|
| 190 |
+
if img_r.status_code == 200:
|
| 191 |
+
from io import BytesIO
|
| 192 |
+
return Image.open(BytesIO(img_r.content))
|
| 193 |
+
|
| 194 |
+
raise Exception("Timeout waiting for result")
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
# Gradio Interface
|
| 198 |
+
def gradio_enhance(
|
| 199 |
+
image,
|
| 200 |
+
character_type: str,
|
| 201 |
+
denoise: float,
|
| 202 |
+
steps: int,
|
| 203 |
+
seed: int
|
| 204 |
+
):
|
| 205 |
+
"""Gradio wrapper for enhancement."""
|
| 206 |
+
prompt = f"photorealistic {character_type}, highly detailed facial features, 8k, cinematic lighting, professional character art"
|
| 207 |
+
negative = "blurry, low quality, low poly, pixelated, cartoonish, anime"
|
| 208 |
+
|
| 209 |
+
result = enhance_nwn_character(
|
| 210 |
+
input_image=image,
|
| 211 |
+
prompt=prompt,
|
| 212 |
+
negative_prompt=negative,
|
| 213 |
+
denoise=denoise,
|
| 214 |
+
steps=steps,
|
| 215 |
+
seed=seed
|
| 216 |
+
)
|
| 217 |
+
return result
|
| 218 |
+
|
| 219 |
+
# Create Gradio app
|
| 220 |
+
with gr.Blocks(title="DGG NWN Character Enhancer") as demo:
|
| 221 |
+
gr.Markdown("# 🎮 DGG NWN Character Enhancer")
|
| 222 |
+
gr.Markdown("Transform low-poly NWN characters into photorealistic images for MetaHuman conversion.")
|
| 223 |
+
|
| 224 |
+
with gr.Row():
|
| 225 |
+
with gr.Column():
|
| 226 |
+
input_image = gr.Image(type="pil", label="NWN Screenshot")
|
| 227 |
+
character_type = gr.Dropdown(
|
| 228 |
+
choices=[
|
| 229 |
+
"female elf paladin in silver armor",
|
| 230 |
+
"male human warrior in plate armor",
|
| 231 |
+
"female human mage in robes",
|
| 232 |
+
"male dwarf fighter in heavy armor",
|
| 233 |
+
"female half-elf ranger in leather armor",
|
| 234 |
+
"male elf wizard in arcane robes"
|
| 235 |
+
],
|
| 236 |
+
value="female elf paladin in silver armor",
|
| 237 |
+
label="Character Type"
|
| 238 |
+
)
|
| 239 |
+
denoise = gr.Slider(
|
| 240 |
+
minimum=0.3, maximum=0.9, value=0.65, step=0.05,
|
| 241 |
+
label="Enhancement Strength (lower = more faithful to original)"
|
| 242 |
+
)
|
| 243 |
+
steps = gr.Slider(
|
| 244 |
+
minimum=10, maximum=50, value=20, step=5,
|
| 245 |
+
label="Quality Steps"
|
| 246 |
+
)
|
| 247 |
+
seed = gr.Number(value=-1, label="Seed (-1 for random)")
|
| 248 |
+
enhance_btn = gr.Button("✨ Enhance Character", variant="primary")
|
| 249 |
+
|
| 250 |
+
with gr.Column():
|
| 251 |
+
output_image = gr.Image(type="pil", label="Enhanced Result")
|
| 252 |
+
|
| 253 |
+
enhance_btn.click(
|
| 254 |
+
fn=gradio_enhance,
|
| 255 |
+
inputs=[input_image, character_type, denoise, steps, seed],
|
| 256 |
+
outputs=output_image
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
gr.Markdown("""
|
| 260 |
+
## API Usage
|
| 261 |
+
```python
|
| 262 |
+
from gradio_client import Client
|
| 263 |
+
client = Client("BenjaminPittsley/DGG-ComfyUI")
|
| 264 |
+
result = client.predict(
|
| 265 |
+
image="screenshot.png",
|
| 266 |
+
character_type="female elf paladin in silver armor",
|
| 267 |
+
denoise=0.65,
|
| 268 |
+
steps=20,
|
| 269 |
+
seed=-1,
|
| 270 |
+
api_name="/enhance"
|
| 271 |
+
)
|
| 272 |
+
```
|
| 273 |
+
""")
|
| 274 |
+
|
| 275 |
+
if __name__ == "__main__":
|
| 276 |
+
# Wait for ComfyUI to start
|
| 277 |
+
print("Waiting for ComfyUI to start...")
|
| 278 |
+
wait_for_comfyui(timeout=120)
|
| 279 |
+
|
| 280 |
+
# Launch Gradio
|
| 281 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
custom_nodes/__init__.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
DGG NWN Custom Nodes for ComfyUI
|
| 3 |
+
Specialized nodes for Neverwinter Nights character enhancement workflow.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
class NWNCharacterEnhancePrompt:
|
| 7 |
+
"""
|
| 8 |
+
Generate optimized prompts for NWN character enhancement.
|
| 9 |
+
Automatically creates prompt/negative prompt pairs based on character archetype.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
CHARACTER_PRESETS = {
|
| 13 |
+
"paladin_female": {
|
| 14 |
+
"base": "female paladin warrior, ornate silver plate armor with golden trim",
|
| 15 |
+
"features": "noble elven features, determined expression, flowing hair",
|
| 16 |
+
},
|
| 17 |
+
"paladin_male": {
|
| 18 |
+
"base": "male paladin warrior, heavy plate armor with holy symbols",
|
| 19 |
+
"features": "strong jawline, short hair, battle-worn face",
|
| 20 |
+
},
|
| 21 |
+
"mage_female": {
|
| 22 |
+
"base": "female arcane mage, flowing magical robes with arcane patterns",
|
| 23 |
+
"features": "intelligent eyes, mysterious aura, elegant features",
|
| 24 |
+
},
|
| 25 |
+
"mage_male": {
|
| 26 |
+
"base": "male wizard, elaborate robes with mystical symbols",
|
| 27 |
+
"features": "wise expression, aged features, long beard",
|
| 28 |
+
},
|
| 29 |
+
"rogue_female": {
|
| 30 |
+
"base": "female rogue assassin, dark leather armor with hidden blades",
|
| 31 |
+
"features": "cunning eyes, agile build, sharp features",
|
| 32 |
+
},
|
| 33 |
+
"rogue_male": {
|
| 34 |
+
"base": "male thief, practical leather gear with pouches",
|
| 35 |
+
"features": "shadowy expression, quick reflexes, scarred face",
|
| 36 |
+
},
|
| 37 |
+
"warrior_female": {
|
| 38 |
+
"base": "female barbarian warrior, fur-lined armor with battle damage",
|
| 39 |
+
"features": "fierce expression, muscular build, war paint",
|
| 40 |
+
},
|
| 41 |
+
"warrior_male": {
|
| 42 |
+
"base": "male fighter, practical plate mail with sword and shield",
|
| 43 |
+
"features": "battle-hardened face, strong build, short cropped hair",
|
| 44 |
+
},
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
QUALITY_SUFFIXES = {
|
| 48 |
+
"ultra": "masterpiece, best quality, ultra detailed, 8k uhd, ray tracing, photorealistic",
|
| 49 |
+
"high": "high quality, detailed, 4k, professional lighting, realistic",
|
| 50 |
+
"medium": "good quality, detailed, sharp focus",
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
NEGATIVE_BASE = "low quality, blurry, pixelated, low poly, cartoonish, anime style, deformed, bad anatomy, extra limbs, watermark, signature, text"
|
| 54 |
+
|
| 55 |
+
@classmethod
|
| 56 |
+
def INPUT_TYPES(cls):
|
| 57 |
+
return {
|
| 58 |
+
"required": {
|
| 59 |
+
"character_class": (["paladin", "mage", "rogue", "warrior"],),
|
| 60 |
+
"gender": (["female", "male"],),
|
| 61 |
+
"race": (["human", "elf", "dwarf", "halfling", "half-elf", "half-orc"],),
|
| 62 |
+
"quality": (["ultra", "high", "medium"],),
|
| 63 |
+
"custom_details": ("STRING", {"default": "", "multiline": True}),
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
RETURN_TYPES = ("STRING", "STRING")
|
| 68 |
+
RETURN_NAMES = ("positive_prompt", "negative_prompt")
|
| 69 |
+
FUNCTION = "generate_prompt"
|
| 70 |
+
CATEGORY = "DGG/NWN"
|
| 71 |
+
|
| 72 |
+
def generate_prompt(self, character_class, gender, race, quality, custom_details):
|
| 73 |
+
# Get preset
|
| 74 |
+
preset_key = f"{character_class}_{gender}"
|
| 75 |
+
preset = self.CHARACTER_PRESETS.get(preset_key, self.CHARACTER_PRESETS["warrior_male"])
|
| 76 |
+
|
| 77 |
+
# Build prompt
|
| 78 |
+
race_desc = f"{race} " if race != "human" else ""
|
| 79 |
+
|
| 80 |
+
positive = f"photorealistic {race_desc}{preset['base']}, {preset['features']}"
|
| 81 |
+
|
| 82 |
+
if custom_details.strip():
|
| 83 |
+
positive += f", {custom_details.strip()}"
|
| 84 |
+
|
| 85 |
+
positive += f", {self.QUALITY_SUFFIXES[quality]}"
|
| 86 |
+
|
| 87 |
+
negative = self.NEGATIVE_BASE
|
| 88 |
+
|
| 89 |
+
return (positive, negative)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class NWNImagePreprocess:
|
| 93 |
+
"""
|
| 94 |
+
Preprocess NWN screenshots for better enhancement results.
|
| 95 |
+
- Removes UI elements
|
| 96 |
+
- Normalizes lighting
|
| 97 |
+
- Isolates character
|
| 98 |
+
"""
|
| 99 |
+
|
| 100 |
+
@classmethod
|
| 101 |
+
def INPUT_TYPES(cls):
|
| 102 |
+
return {
|
| 103 |
+
"required": {
|
| 104 |
+
"image": ("IMAGE",),
|
| 105 |
+
"remove_background": ("BOOLEAN", {"default": True}),
|
| 106 |
+
"normalize_lighting": ("BOOLEAN", {"default": True}),
|
| 107 |
+
"upscale_first": ("BOOLEAN", {"default": False}),
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
RETURN_TYPES = ("IMAGE",)
|
| 112 |
+
FUNCTION = "preprocess"
|
| 113 |
+
CATEGORY = "DGG/NWN"
|
| 114 |
+
|
| 115 |
+
def preprocess(self, image, remove_background, normalize_lighting, upscale_first):
|
| 116 |
+
import torch
|
| 117 |
+
import numpy as np
|
| 118 |
+
|
| 119 |
+
# Convert to numpy
|
| 120 |
+
if isinstance(image, torch.Tensor):
|
| 121 |
+
img_np = image.cpu().numpy()
|
| 122 |
+
if img_np.ndim == 4:
|
| 123 |
+
img_np = img_np[0] # Remove batch dimension
|
| 124 |
+
else:
|
| 125 |
+
img_np = np.array(image)
|
| 126 |
+
|
| 127 |
+
# Normalize to 0-1 if needed
|
| 128 |
+
if img_np.max() > 1.0:
|
| 129 |
+
img_np = img_np / 255.0
|
| 130 |
+
|
| 131 |
+
if normalize_lighting:
|
| 132 |
+
# Simple contrast normalization
|
| 133 |
+
for c in range(3):
|
| 134 |
+
channel = img_np[:, :, c]
|
| 135 |
+
min_val = channel.min()
|
| 136 |
+
max_val = channel.max()
|
| 137 |
+
if max_val > min_val:
|
| 138 |
+
img_np[:, :, c] = (channel - min_val) / (max_val - min_val)
|
| 139 |
+
|
| 140 |
+
# Convert back to tensor
|
| 141 |
+
result = torch.from_numpy(img_np).unsqueeze(0)
|
| 142 |
+
|
| 143 |
+
return (result,)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
class NWNBatchProcessor:
|
| 147 |
+
"""
|
| 148 |
+
Process multiple NWN character images in batch.
|
| 149 |
+
Useful for generating front/side/back views consistently.
|
| 150 |
+
"""
|
| 151 |
+
|
| 152 |
+
@classmethod
|
| 153 |
+
def INPUT_TYPES(cls):
|
| 154 |
+
return {
|
| 155 |
+
"required": {
|
| 156 |
+
"images": ("IMAGE",),
|
| 157 |
+
"prompt_template": ("STRING", {"default": "photorealistic fantasy character, {view} view"}),
|
| 158 |
+
"views": ("STRING", {"default": "front,side,back"}),
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
RETURN_TYPES = ("IMAGE", "STRING")
|
| 163 |
+
RETURN_NAMES = ("images", "view_prompts")
|
| 164 |
+
FUNCTION = "process_batch"
|
| 165 |
+
CATEGORY = "DGG/NWN"
|
| 166 |
+
|
| 167 |
+
def process_batch(self, images, prompt_template, views):
|
| 168 |
+
view_list = [v.strip() for v in views.split(",")]
|
| 169 |
+
prompts = [prompt_template.format(view=v) for v in view_list]
|
| 170 |
+
return (images, "\n".join(prompts))
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
# Node mappings for ComfyUI
|
| 174 |
+
NODE_CLASS_MAPPINGS = {
|
| 175 |
+
"NWNCharacterEnhancePrompt": NWNCharacterEnhancePrompt,
|
| 176 |
+
"NWNImagePreprocess": NWNImagePreprocess,
|
| 177 |
+
"NWNBatchProcessor": NWNBatchProcessor,
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
NODE_DISPLAY_NAME_MAPPINGS = {
|
| 181 |
+
"NWNCharacterEnhancePrompt": "🎮 NWN Character Prompt",
|
| 182 |
+
"NWNImagePreprocess": "🎮 NWN Image Preprocess",
|
| 183 |
+
"NWNBatchProcessor": "🎮 NWN Batch Processor",
|
| 184 |
+
}
|
workflows/nwn_enhance.json
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"last_node_id": 12,
|
| 3 |
+
"last_link_id": 12,
|
| 4 |
+
"nodes": [
|
| 5 |
+
{
|
| 6 |
+
"id": 1,
|
| 7 |
+
"type": "LoadImage",
|
| 8 |
+
"pos": [50, 100],
|
| 9 |
+
"size": [300, 300],
|
| 10 |
+
"title": "NWN Screenshot"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"id": 2,
|
| 14 |
+
"type": "NWNCharacterEnhancePrompt",
|
| 15 |
+
"pos": [50, 450],
|
| 16 |
+
"size": [300, 200],
|
| 17 |
+
"title": "Character Prompt Generator",
|
| 18 |
+
"widgets_values": ["paladin", "female", "elf", "ultra", "ornate silver armor, flowing blonde hair"]
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"id": 3,
|
| 22 |
+
"type": "CheckpointLoaderSimple",
|
| 23 |
+
"pos": [400, 50],
|
| 24 |
+
"size": [300, 100],
|
| 25 |
+
"title": "Load Model"
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"id": 4,
|
| 29 |
+
"type": "CLIPTextEncode",
|
| 30 |
+
"pos": [400, 200],
|
| 31 |
+
"size": [300, 100],
|
| 32 |
+
"title": "Positive Prompt"
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"id": 5,
|
| 36 |
+
"type": "CLIPTextEncode",
|
| 37 |
+
"pos": [400, 350],
|
| 38 |
+
"size": [300, 100],
|
| 39 |
+
"title": "Negative Prompt"
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"id": 6,
|
| 43 |
+
"type": "VAEEncode",
|
| 44 |
+
"pos": [400, 500],
|
| 45 |
+
"size": [200, 100],
|
| 46 |
+
"title": "Encode Image"
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"id": 7,
|
| 50 |
+
"type": "KSampler",
|
| 51 |
+
"pos": [750, 200],
|
| 52 |
+
"size": [300, 250],
|
| 53 |
+
"title": "Sampler",
|
| 54 |
+
"widgets_values": [42, "randomize", 25, 7.5, "euler_ancestral", "normal", 0.65]
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"id": 8,
|
| 58 |
+
"type": "VAEDecode",
|
| 59 |
+
"pos": [1100, 200],
|
| 60 |
+
"size": [200, 100],
|
| 61 |
+
"title": "Decode Image"
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"id": 9,
|
| 65 |
+
"type": "SaveImage",
|
| 66 |
+
"pos": [1100, 350],
|
| 67 |
+
"size": [300, 300],
|
| 68 |
+
"title": "Save Enhanced"
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"id": 10,
|
| 72 |
+
"type": "PreviewImage",
|
| 73 |
+
"pos": [1350, 200],
|
| 74 |
+
"size": [300, 300],
|
| 75 |
+
"title": "Preview"
|
| 76 |
+
}
|
| 77 |
+
],
|
| 78 |
+
"links": [
|
| 79 |
+
[1, 1, 0, 6, 0, "IMAGE"],
|
| 80 |
+
[2, 2, 0, 4, 0, "STRING"],
|
| 81 |
+
[3, 2, 1, 5, 0, "STRING"],
|
| 82 |
+
[4, 3, 0, 7, 0, "MODEL"],
|
| 83 |
+
[5, 3, 1, 4, 1, "CLIP"],
|
| 84 |
+
[6, 3, 1, 5, 1, "CLIP"],
|
| 85 |
+
[7, 3, 2, 6, 1, "VAE"],
|
| 86 |
+
[8, 4, 0, 7, 1, "CONDITIONING"],
|
| 87 |
+
[9, 5, 0, 7, 2, "CONDITIONING"],
|
| 88 |
+
[10, 6, 0, 7, 3, "LATENT"],
|
| 89 |
+
[11, 7, 0, 8, 0, "LATENT"],
|
| 90 |
+
[12, 3, 2, 8, 1, "VAE"],
|
| 91 |
+
[13, 8, 0, 9, 0, "IMAGE"],
|
| 92 |
+
[14, 8, 0, 10, 0, "IMAGE"]
|
| 93 |
+
],
|
| 94 |
+
"config": {},
|
| 95 |
+
"extra": {
|
| 96 |
+
"workflow_name": "NWN Character Enhancement",
|
| 97 |
+
"author": "DGG Pipeline",
|
| 98 |
+
"description": "Enhance NWN character screenshots to photorealistic quality for MetaHuman conversion"
|
| 99 |
+
}
|
| 100 |
+
}
|