mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-06-07 21:20:49 +00:00
Merge pull request #14814 from AUTOMATIC1111/catch-load-style.csv-error
catch load style.csv error
This commit is contained in:
commit
b594f518b7
@ -1,4 +1,5 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from modules import errors
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
import typing
|
import typing
|
||||||
@ -128,19 +129,22 @@ class StyleDatabase:
|
|||||||
self.load_from_csv(styles_file)
|
self.load_from_csv(styles_file)
|
||||||
|
|
||||||
def load_from_csv(self, path: str | Path):
|
def load_from_csv(self, path: str | Path):
|
||||||
with open(path, "r", encoding="utf-8-sig", newline="") as file:
|
try:
|
||||||
reader = csv.DictReader(file, skipinitialspace=True)
|
with open(path, "r", encoding="utf-8-sig", newline="") as file:
|
||||||
for row in reader:
|
reader = csv.DictReader(file, skipinitialspace=True)
|
||||||
# Ignore empty rows or rows starting with a comment
|
for row in reader:
|
||||||
if not row or row["name"].startswith("#"):
|
# Ignore empty rows or rows starting with a comment
|
||||||
continue
|
if not row or row["name"].startswith("#"):
|
||||||
# Support loading old CSV format with "name, text"-columns
|
continue
|
||||||
prompt = row["prompt"] if "prompt" in row else row["text"]
|
# Support loading old CSV format with "name, text"-columns
|
||||||
negative_prompt = row.get("negative_prompt", "")
|
prompt = row["prompt"] if "prompt" in row else row["text"]
|
||||||
# Add style to database
|
negative_prompt = row.get("negative_prompt", "")
|
||||||
self.styles[row["name"]] = PromptStyle(
|
# Add style to database
|
||||||
row["name"], prompt, negative_prompt, str(path)
|
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:
|
def get_style_paths(self) -> set:
|
||||||
"""Returns a set of all distinct paths of files that styles are loaded from."""
|
"""Returns a set of all distinct paths of files that styles are loaded from."""
|
||||||
|
Loading…
Reference in New Issue
Block a user