Download src/styles.py from Nate-M/StyleX: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/Nate-M/StyleX/resolve/main/src/styles.py
- Command line
-
hf download hf://spaces/Nate-M/StyleX/src/styles.py
-
curl -L -o styles.py https://huggingface.co/spaces/Nate-M/StyleX/resolve/main/src/styles.py
1.3 kB
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from pathlib import Path | |
| class Style: | |
| name: str | |
| folder: Path | |
| # Style descriptor vocabulary for embedding-based style extraction. Curated list of common style keywords. | |
| def list_styles(styles_root: Path) -> list[str]: | |
| if not styles_root.exists(): | |
| return [] | |
| return sorted([p.name for p in styles_root.iterdir() if p.is_dir()]) | |
| # Load a style by name from the styles directory. Validates that the specified style exists and returns a Style object with the relevant information about the style folder and embedding settings | |
| # The function checks if the style folder exists and is a directory, and raises an error if not. This ensures that the rest of the generation process has a valid style to work with | |
| # The Style object returned by this function can then be used in the generation process to access the reference images and embedding settings for that style | |
| def load_style(styles_root: Path, style_name: str) -> Style: | |
| folder = styles_root / style_name | |
| if not folder.exists() or not folder.is_dir(): | |
| raise FileNotFoundError(f"Style '{style_name}' not found in {styles_root}") | |
| return Style( | |
| name=style_name, | |
| folder=folder, | |
| ) | |