feat: ✨ a111 like style loader

This commit is contained in:
melMass
2023-06-23 04:00:22 +02:00
parent 9a2e986327
commit f59b68e3ad
3 changed files with 62 additions and 4 deletions
+5 -3
View File
@@ -30,9 +30,10 @@ try:
except Exception:
log.error("DeglazeImage failed to load. This is probably an opencv mismatch. This node requires opencv-python-contrib.")
from .nodes.crop import Crop, Uncrop, BoundingBox
from .nodes.graph_utils import IntToNumber, Modulo
from .nodes.conditions import SmartStep
from .nodes.conditions import (
SmartStep,
StylesLoader,
)
# NODE MAPPING
NODE_CLASS_MAPPINGS = {
"Latent Lerp (mtb) [DEPRECATED]": LatentLerp,
@@ -51,6 +52,7 @@ NODE_CLASS_MAPPINGS = {
"Modulo (mtb)": Modulo,
"Deglaze Image (mtb)": DeglazeImage,
"Smart Step (mtb)": SmartStep,
"Styles Loader (mtb)": StylesLoader,
"Mask to Image (mtb)": MaskToImage,
"Colored Image (mtb)": ColoredImage,
# "Load Geometry (mtb)": LoadGeometry,
+54 -1
View File
@@ -29,4 +29,57 @@ class SmartStep:
start = int(step * start_percent / 100)
end = int(step * end_percent / 100)
return (step,start, end)
return (step,start, end)
import folder_paths
from pathlib import Path
import shutil
from ..utils import here
def install_default_styles():
styles_dir = Path(folder_paths.base_path) / "styles"
styles_dir.mkdir(parents=True, exist_ok=True)
default_style = here / "styles.csv"
dest_style = styles_dir / "default.csv"
print("\n\n\n\tINSTALLING DEFAULT STYLE\n\n\n")
shutil.copy2(default_style.as_posix(), dest_style.as_posix())
print("\n\n\n\tDEFAULT STYLE INSTALLED\n\n\n")
return dest_style
import csv
# class that load csv files and populate a dropdown from the rows
class StylesLoader:
options = {}
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
input_dir = Path(folder_paths.base_path) / "styles"
if not input_dir.exists():
install_default_styles()
if not (files := [f for f in input_dir.iterdir() if f.suffix == ".csv"]):
log.error("No styles found in the styles folder, place at least one csv file in the styles folder")
return {"required":
{"style_name": (["error"],), }
}
for file in files:
with open(file, "r", encoding="utf8") as f:
parsed = csv.reader(f)
for row in parsed:
log.debug(f"Adding style {row[0]}")
cls.options[row[0]] = (row[1], row[2])
return {"required":
{"style_name": (list(cls.options.keys()),), }
}
CATEGORY = "conditioning"
RETURN_TYPES = ("STRING","STRING")
RETURN_NAMES = ("positive","negative")
FUNCTION = "load_style"
def load_style(self, style_name):
return (self.options[style_name][0],self.options[style_name][1])
+3
View File
@@ -0,0 +1,3 @@
name,prompt,negative_prompt
❌Low Token,,"embedding:EasyNegative, NSFW, Cleavage, Pubic Hair, Nudity, Naked, censored"
✅Line Art / Manga,"(Anime Scene, Toonshading, Satoshi Kon, Ken Sugimori, Hiromu Arakawa:1.2), (Anime Style, Manga Style:1.3), Low detail, sketch, concept art, line art, webtoon, manhua, hand drawn, defined lines, simple shades, minimalistic, High contrast, Linear compositions, Scalable artwork, Digital art, High Contrast Shadows, glow effects, humorous illustration, big depth of field, Masterpiece, colors, concept art, trending on artstation, Vivid colors, dramatic",
1 name prompt negative_prompt
2 ❌Low Token embedding:EasyNegative, NSFW, Cleavage, Pubic Hair, Nudity, Naked, censored
3 ✅Line Art / Manga (Anime Scene, Toonshading, Satoshi Kon, Ken Sugimori, Hiromu Arakawa:1.2), (Anime Style, Manga Style:1.3), Low detail, sketch, concept art, line art, webtoon, manhua, hand drawn, defined lines, simple shades, minimalistic, High contrast, Linear compositions, Scalable artwork, Digital art, High Contrast Shadows, glow effects, humorous illustration, big depth of field, Masterpiece, colors, concept art, trending on artstation, Vivid colors, dramatic