From 6ca61e1a23542c834196f22ae9404e88bc27a5ce Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Sun, 7 Apr 2024 16:54:51 +0200 Subject: Make it compatible with Python < 3.10 --- modules/styles.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'modules/styles.py') diff --git a/modules/styles.py b/modules/styles.py index 60bd8a7f..4ce32b8e 100644 --- a/modules/styles.py +++ b/modules/styles.py @@ -3,14 +3,15 @@ from modules import errors import csv import os import typing +from typing import Optional, Union import shutil class PromptStyle(typing.NamedTuple): name: str - prompt: str | None - negative_prompt: str | None - path: str | None = None + prompt: Optional[str] + negative_prompt: Optional[str] + path: Optional[str] = None def merge_prompts(style_prompt: str, prompt: str) -> str: @@ -79,7 +80,7 @@ def extract_original_prompts(style: PromptStyle, prompt, negative_prompt): class StyleDatabase: - def __init__(self, paths: list[str | Path]): + def __init__(self, paths: list[Union[str, Path]]): self.no_style = PromptStyle("None", "", "", None) self.styles = {} self.paths = paths @@ -128,7 +129,7 @@ class StyleDatabase: if styles_file.is_file(): self.load_from_csv(styles_file) - def load_from_csv(self, path: str | Path): + def load_from_csv(self, path: Union[str, Path]): try: with open(path, "r", encoding="utf-8-sig", newline="") as file: reader = csv.DictReader(file, skipinitialspace=True) -- cgit v1.2.3