Florence2 nodes support Florence-2-Flux and Florence-2-Flus-Large

This commit is contained in:
chflame163
2024-12-10 22:21:12 +08:00
parent 61660a4b55
commit a4f3112cbe
5 changed files with 60 additions and 56 deletions
+3 -2
View File
@@ -25,14 +25,14 @@ Some JSON workflow files in the ```workflow``` directory, That's examples of
git clone https://github.com/chflame163/ComfyUI_LayerStyle_Advance.git
```
* Or download the zip file and extracted, copy the resulting folder to ```ComfyUI\custom_ Nodes```
* Or download the zip file and extracted, copy the resulting folder to ```ComfyUI\custom_nodes```
### Install dependency packages
* for ComfyUI official portable package, double-click the ```install_requirements.bat``` in the plugin directory, for Aki ComfyUI package double-click on the ```install_requirements_aki.bat``` in the plugin directory, and wait for the installation to complete.
* Or install dependency packages, open the cmd window in the ComfyUI_LayerStyle plugin directory like
```ComfyUI\custom_ Nodes\ComfyUI_LayerStyle_Advance``` and enter the following command,
```ComfyUI\custom_nodes\ComfyUI_LayerStyle_Advance``` and enter the following command,
  for ComfyUI official portable package, type:
@@ -144,6 +144,7 @@ Please try downgrading the ```protobuf``` dependency package to 3.20.3, or set e
**If the dependency package error after updating, please double clicking ```repair_dependency.bat``` (for Official ComfyUI Protable) or ```repair_dependency_aki.bat``` (for ComfyUI-aki-v1.x) in the plugin folder to reinstall the dependency packages.
* Florence2 add support [gokaygokay/Florence-2-Flux-Large](https://huggingface.co/gokaygokay/Florence-2-Flux-Large) and [gokaygokay/Florence-2-Flux](https://huggingface.co/gokaygokay/Florence-2-Flux) models, download Florence-2-Flux-Large and Florence-2-Flux folder from [BaiduNetdisk](https://pan.baidu.com/s/1wBwJZjgMUKt0zluLAetMOQ?pwd=d6fb) or [huggingface](https://huggingface.co/chflame163/ComfyUI_LayerStyle/tree/main/ComfyUI/models/florence2) and copy to ```ComfyUI\models\florence2`` folder.
* Discard the dependencies required for the [ObjectDetector YOLOWorld](#ObjectDetectorYOLOWorld) node from the requirements. txt file. To use this node, please manually install the dependency package.
* Strip some nodes from [ComfyUI Layer Style](https://github.com/chflame163/ComfyUI_LayerStyle) to this repository.
+1
View File
@@ -120,6 +120,7 @@ If this call came from a _pb2.py file, your generated code is out of date and mu
## 更新说明
**如果本插件更新后出现依赖包错误,请双击运行插件目录下的```install_requirements.bat```(官方便携包),或 ```install_requirements_aki.bat```(秋叶整合包) 重新安装依赖包。
* Florence2 节点支持[gokaygokay/Florence-2-Flux-Large](https://huggingface.co/gokaygokay/Florence-2-Flux-Large) 和 [gokaygokay/Florence-2-Flux](https://huggingface.co/gokaygokay/Florence-2-Flux)模型。从[百度网盘](https://pan.baidu.com/s/1wBwJZjgMUKt0zluLAetMOQ?pwd=d6fb) 或者 [huggingface](https://huggingface.co/chflame163/ComfyUI_LayerStyle/tree/main/ComfyUI/models/florence2) 下载Florence-2-Flux-Large 和 Florence-2-Flux 两个目录,并放到```ComfyUI\models\florence2``文件夹。
* 从requirements.txt 中废弃 [ObjectDetector YOLOWorld](#ObjectDetectorYOLOWorld) 节点所需的依赖。如需使用此节点,请手动安装依赖包。
* 从ComfyUI Layer Style 剥离部分节点至本仓库。
+3 -1
View File
@@ -27,7 +27,9 @@ fl2_model_repos = {
"base-PromptGen-v1.5":"MiaoshouAI/Florence-2-base-PromptGen-v1.5",
"large-PromptGen-v1.5":"MiaoshouAI/Florence-2-large-PromptGen-v1.5",
"base-PromptGen-v2.0":"MiaoshouAI/Florence-2-base-PromptGen-v2.0",
"large-PromptGen-v2.0":"MiaoshouAI/Florence-2-large-PromptGen-v2.0"
"large-PromptGen-v2.0":"MiaoshouAI/Florence-2-large-PromptGen-v2.0",
"Florence-2-Flux":"gokaygokay/Florence-2-Flux",
"Florence-2-Flux-Large":"gokaygokay/Florence-2-Flux-Large"
}
def fixed_get_imports(filename) -> list[str]:
+52 -52
View File
@@ -1253,58 +1253,6 @@ def pixel_spread(image:Image, mask:Image) -> Image:
return tensor2pil(torch.from_numpy(fg.astype(np.float32)))
def generate_text_image(text:str, font_path:str, font_size:int, text_color:str="#FFFFFF",
vertical:bool=True, stroke_width:int=1, stroke_color:str="#000000",
spacing:int=0, leading:int=0) -> tuple:
lines = text.split("\n")
if vertical:
layout = "vertical"
else:
layout = "horizontal"
char_coordinates = []
if layout == "vertical":
x = 0
y = 0
for i in range(len(lines)):
line = lines[i]
for char in line:
char_coordinates.append((x, y))
y += font_size + spacing
x += font_size + leading
y = 0
else:
x = 0
y = 0
for line in lines:
for char in line:
char_coordinates.append((x, y))
x += font_size + spacing
y += font_size + leading
x = 0
if layout == "vertical":
width = (len(lines) * (font_size + spacing)) - spacing
height = ((len(max(lines, key=len)) + 1) * (font_size + spacing)) + spacing
else:
width = (len(max(lines, key=len)) * (font_size + spacing)) - spacing
height = ((len(lines) - 1) * (font_size + spacing)) + font_size
image = Image.new('RGBA', size=(width, height), color=stroke_color)
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(font_path, font_size)
index = 0
for i, line in enumerate(lines):
for j, char in enumerate(line):
x, y = char_coordinates[index]
if stroke_width > 0:
draw.text((x - stroke_width, y), char, font=font, fill=stroke_color)
draw.text((x + stroke_width, y), char, font=font, fill=stroke_color)
draw.text((x, y - stroke_width), char, font=font, fill=stroke_color)
draw.text((x, y + stroke_width), char, font=font, fill=stroke_color)
draw.text((x, y), char, font=font, fill=text_color)
index += 1
return (image.convert('RGB'), image.split()[3])
def watermark_image_size(image:Image) -> int:
size = int(math.sqrt(image.width * image.height * 0.015625) * 0.9)
return size
@@ -1393,6 +1341,58 @@ def decode_watermark(image:Image, watermark_image_size:int=94) -> Image:
ret_image = normalize_gray(ret_image)
return ret_image
# def generate_text_image(text:str, font_path:str, font_size:int, text_color:str="#FFFFFF",
# vertical:bool=True, stroke_width:int=1, stroke_color:str="#000000",
# spacing:int=0, leading:int=0) -> tuple:
#
# lines = text.split("\n")
# if vertical:
# layout = "vertical"
# else:
# layout = "horizontal"
# char_coordinates = []
# if layout == "vertical":
# x = 0
# y = 0
# for i in range(len(lines)):
# line = lines[i]
# for char in line:
# char_coordinates.append((x, y))
# y += font_size + spacing
# x += font_size + leading
# y = 0
# else:
# x = 0
# y = 0
# for line in lines:
# for char in line:
# char_coordinates.append((x, y))
# x += font_size + spacing
# y += font_size + leading
# x = 0
# if layout == "vertical":
# width = (len(lines) * (font_size + spacing)) - spacing
# height = ((len(max(lines, key=len)) + 1) * (font_size + spacing)) + spacing
# else:
# width = (len(max(lines, key=len)) * (font_size + spacing)) - spacing
# height = ((len(lines) - 1) * (font_size + spacing)) + font_size
#
# image = Image.new('RGBA', size=(width, height), color=stroke_color)
# draw = ImageDraw.Draw(image)
# font = ImageFont.truetype(font_path, font_size)
# index = 0
# for i, line in enumerate(lines):
# for j, char in enumerate(line):
# x, y = char_coordinates[index]
# if stroke_width > 0:
# draw.text((x - stroke_width, y), char, font=font, fill=stroke_color)
# draw.text((x + stroke_width, y), char, font=font, fill=stroke_color)
# draw.text((x, y - stroke_width), char, font=font, fill=stroke_color)
# draw.text((x, y + stroke_width), char, font=font, fill=stroke_color)
# draw.text((x, y), char, font=font, fill=text_color)
# index += 1
# return (image.convert('RGB'), image.split()[3])
def generate_text_image(width:int, height:int, text:str, font_file:str, text_scale:float=1, font_color:str="#FFFFFF",) -> Image:
image = Image.new("RGBA", (width, height), (0, 0, 0, 0))
draw = ImageDraw.Draw(image)
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui_layerstyle_advance"
description = "The nodes detached from ComfyUI Layer Style are mainly those with complex requirements for dependency packages."
version = "2.0.1"
version = "2.0.2"
license = "MIT"
dependencies = ["numpy", "matplotlib", "scikit_image", "scikit_learn", "opencv-contrib-python", "pymatting", "timm", "blend_modes", "transformers", "diffusers", "loguru", "colour-science", "huggingface_hub", "segment_anything", "addict", "omegaconf", "yapf", "wget", "iopath", "mediapipe", "typer_config", "fastapi", "rich", "google-generativeai", "ultralytics", "transparent-background", "accelerate", "onnxruntime", "bitsandbytes", "peft", "protobuf", "hydra-core", "blind-watermark", "qrcode", "pyzbar", "psd-tools", "wandb"]