aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2024-02-01 22:02:28 +0300
committerGitHub <noreply@github.com>2024-02-01 22:02:28 +0300
commitb594f518b7c3b1704b5bb0da34014372ed688f18 (patch)
tree226a3ed5871eccd0458bc87b639062a4899009c6
parent652a7bbf809d8885b3ba6d42321d5828f66ac4c6 (diff)
parentbbe8e02d74ab8f2efca44407488e38a1bb733983 (diff)
Merge pull request #14814 from AUTOMATIC1111/catch-load-style.csv-error
catch load style.csv error
-rw-r--r--modules/styles.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/modules/styles.py b/modules/styles.py
index 9edcc7e4..60bd8a7f 100644
--- a/modules/styles.py
+++ b/modules/styles.py
@@ -1,4 +1,5 @@
from pathlib import Path
+from modules import errors
import csv
import os
import typing
@@ -128,19 +129,22 @@ class StyleDatabase:
self.load_from_csv(styles_file)
def load_from_csv(self, path: str | Path):
- with open(path, "r", encoding="utf-8-sig", newline="") as file:
- reader = csv.DictReader(file, skipinitialspace=True)
- for row in reader:
- # Ignore empty rows or rows starting with a comment
- if not row or row["name"].startswith("#"):
- continue
- # Support loading old CSV format with "name, text"-columns
- prompt = row["prompt"] if "prompt" in row else row["text"]
- negative_prompt = row.get("negative_prompt", "")
- # Add style to database
- self.styles[row["name"]] = PromptStyle(
- row["name"], prompt, negative_prompt, str(path)
- )
+ try:
+ with open(path, "r", encoding="utf-8-sig", newline="") as file:
+ reader = csv.DictReader(file, skipinitialspace=True)
+ for row in reader:
+ # Ignore empty rows or rows starting with a comment
+ if not row or row["name"].startswith("#"):
+ continue
+ # Support loading old CSV format with "name, text"-columns
+ prompt = row["prompt"] if "prompt" in row else row["text"]
+ negative_prompt = row.get("negative_prompt", "")
+ # Add style to database
+ self.styles[row["name"]] = PromptStyle(
+ row["name"], prompt, negative_prompt, str(path)
+ )
+ except Exception:
+ errors.report(f'Error loading styles from {path}: ', exc_info=True)
def get_style_paths(self) -> set:
"""Returns a set of all distinct paths of files that styles are loaded from."""