Skip to content

Commit

Permalink
feat: ✨ a111 like style loader
Browse files Browse the repository at this point in the history
  • Loading branch information
melMass committed Jun 23, 2023
1 parent 9a2e986 commit f59b68e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
8 changes: 5 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
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,
Expand All @@ -51,6 +52,7 @@
"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,
Expand Down
55 changes: 54 additions & 1 deletion nodes/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,57 @@ def do_step(self, step,start_percent,end_percent):
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 changes: 3 additions & 0 deletions styles.csv
Original file line number Diff line number Diff line change
@@ -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",

0 comments on commit f59b68e

Please sign in to comment.