├── README.md ├── __init__.py ├── __pycache__ ├── __init__.cpython-311.pyc └── nodes.cpython-311.pyc └── nodes.py /README.md: -------------------------------------------------------------------------------- 1 | 建议强度开到:0.3 测试版本(希望官方能实现滑块控制 哈哈) 2 | 3 | ![3197f4d44645d146838cb42b4eccdc0](https://github.com/user-attachments/assets/cfd22b08-67f1-4405-a584-c742a762de4d) 4 | 5 | ![1732262508738](https://github.com/user-attachments/assets/a1d8e23d-b3ad-45d0-a372-ba0828f6ccd9) 6 | 7 | ![f58efd1824768aa94fa93e6ba1e10d1](https://github.com/user-attachments/assets/69c878b7-461d-42ea-895b-1a6f4984a7ed) 8 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from .nodes import CXH_StyleModelApply 3 | 4 | NODE_CLASS_MAPPINGS = { 5 | "CXH_StyleModelApply":CXH_StyleModelApply, 6 | } 7 | 8 | NODE_DISPLAY_NAME_MAPPINGS = { 9 | 10 | "CXH_StyleModelApply":"CXH_StyleModelApply", 11 | } 12 | -------------------------------------------------------------------------------- /__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StartHua/Comfyui_Flux_Style_Ctr/ed8cfc5ed03b6fb8b1ef0a3491d8ab9ea8f86f43/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /__pycache__/nodes.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StartHua/Comfyui_Flux_Style_Ctr/ed8cfc5ed03b6fb8b1ef0a3491d8ab9ea8f86f43/__pycache__/nodes.cpython-311.pyc -------------------------------------------------------------------------------- /nodes.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | import torch 4 | from PIL import Image 5 | import folder_paths 6 | from comfy.utils import ProgressBar, common_upscale 7 | 8 | class CXH_StyleModelApply: 9 | @classmethod 10 | def INPUT_TYPES(s): 11 | return {"required": { 12 | "conditioning": ("CONDITIONING",), 13 | "style_model": ("STYLE_MODEL",), 14 | "clip_vision_output": ("CLIP_VISION_OUTPUT",), 15 | "strength": ("FLOAT", { 16 | "default": 1.0, 17 | "min": 0.0, 18 | "max": 2.0, 19 | "step": 0.01, 20 | "display": "slider" 21 | }), 22 | }} 23 | 24 | RETURN_TYPES = ("CONDITIONING",) 25 | FUNCTION = "apply_stylemodel" 26 | CATEGORY = "conditioning/style_model" 27 | 28 | def apply_stylemodel(self, clip_vision_output, style_model, conditioning, strength): 29 | # 获取 style model 的条件向量,仅计算一次 30 | style_cond = style_model.get_cond(clip_vision_output).flatten(start_dim=0, end_dim=1).unsqueeze(dim=0) 31 | style_dim = style_cond.shape[1] 32 | 33 | # 平滑缩放函数 34 | def smooth_scale(x, strength): 35 | return x * (strength ** 2) if strength <= 1.0 else x * (1.0 + (strength - 1.0) ** 0.5) 36 | 37 | 38 | # 对 style_cond 应用平滑缩放 39 | scaled_style = smooth_scale(style_cond, strength) 40 | 41 | # 初始化返回值 42 | updated_conditioning = [] 43 | 44 | for orig_cond, extra_data in conditioning: 45 | orig_dim = orig_cond.shape[1] 46 | 47 | # 分离基础条件和样式条件 48 | if orig_dim > style_dim: 49 | # 如果原始条件已经包含样式向量,则截取基础部分 50 | base_conditioning = orig_cond[:, :-style_dim] 51 | else: 52 | # 否则,整个向量都是基础条件 53 | base_conditioning = orig_cond 54 | 55 | # 对样式条件进行平滑缩放 56 | scaled_style = smooth_scale(style_cond, strength) 57 | 58 | # 合并条件 59 | combined_conditioning = torch.cat((base_conditioning, scaled_style), dim=1) 60 | updated_conditioning.append([combined_conditioning, extra_data]) 61 | 62 | 63 | return (updated_conditioning,) 64 | 65 | --------------------------------------------------------------------------------