styles editing phase one

This commit is contained in:
Vladimir Mandic
2023-09-26 19:11:51 -04:00
parent 7ceb1df1f5
commit 75c41498dd
6 changed files with 52 additions and 22 deletions
+2
View File
@@ -18,6 +18,7 @@ Upgrades are still possible and supported, but above is recommended for best exp
main ui now has a single button on each en to trigger details view
- details view includes model/lora metadata parser!
- details view includes civitai model metadata!
- styles can be edited in details view
- faster search, ability to show/hide/sort networks
- refactored subfolder handling
*note*: this will trigger model hash recaclulation on first model use
@@ -42,6 +43,7 @@ Upgrades are still possible and supported, but above is recommended for best exp
- `stabilityai/stable-diffusion-x4-upscaler` *(1.7GB)*
- better **TI embeddings** support for SD and SDXL
faster loading, wider compatibility and support for embeddings with multiple vectors
information about used embedding is now also added to image metadata
- **Upscalers**:
- more high quality upscalers available by default
*SwinIR:2, ESRGAN:12, RealESRGAN:6, SCUNet:2*
+1 -1
View File
@@ -527,7 +527,7 @@ def install_packages():
install('pi-heif', 'pi_heif', ignore=True)
tensorflow_package = os.environ.get('TENSORFLOW_PACKAGE', 'tensorflow==2.13.0')
install(tensorflow_package, 'tensorflow', ignore=True)
install('git+https://github.com/google-research/torchsde', 'torchsde', ignore=True)
# install('git+https://github.com/google-research/torchsde', 'torchsde', ignore=True)
bitsandbytes_package = os.environ.get('BITSANDBYTES_PACKAGE', None)
if bitsandbytes_package is not None:
install(bitsandbytes_package, 'bitsandbytes', ignore=True)
+18 -6
View File
@@ -9,8 +9,9 @@ from modules import paths
class Style():
def __init__(self, name: str, prompt: str = "", negative_prompt: str = "", extra: str = "", filename: str = "", preview: str = ""):
def __init__(self, name: str, desc: str = "", prompt: str = "", negative_prompt: str = "", extra: str = "", filename: str = "", preview: str = ""):
self.name = name
self.description = desc
self.prompt = prompt
self.negative_prompt = negative_prompt
self.extra = extra
@@ -64,11 +65,22 @@ class StyleDatabase:
if os.path.isfile(fn) and fn.lower().endswith(".json"):
with open(fn, 'r', encoding='utf-8') as f:
try:
style = json.load(f)
basename = os.path.splitext(os.path.basename(fn))[0]
name = re.sub(r'[\t\r\n]', '', style.get("name", basename)).strip()
name = os.path.join(os.path.dirname(os.path.relpath(fn, self.path)), name)
self.styles[style["name"]] = Style(name=name, prompt=style.get("prompt", ""), negative_prompt=style.get("negative", ""), extra=style.get("extra", ""), filename=fn, preview=style.get("preview", ""))
all_styles = json.load(f)
if type(all_styles) is dict:
all_styles = [all_styles]
for style in all_styles:
basename = os.path.splitext(os.path.basename(fn))[0]
name = re.sub(r'[\t\r\n]', '', style.get("name", basename)).strip()
name = os.path.join(os.path.dirname(os.path.relpath(fn, self.path)), name)
self.styles[style["name"]] = Style(
name=name,
desc=style.get('description', name),
prompt=style.get("prompt", ""),
negative_prompt=style.get("negative", ""),
extra=style.get("extra", ""),
preview=style.get("preview", None),
filename=fn
)
except Exception as e:
log.error(f'Failed to load style: file={fn} error={e}')
elif os.path.isdir(fn) and not fn.startswith('.'):
+24 -12
View File
@@ -270,7 +270,7 @@ class ExtraNetworksPage:
def find_preview(self, path):
fn = os.path.splitext(path)[0]
preview_extensions = ["jpg", "jpeg", "png", "webp", "tiff", "jp2"]
for file in [f'{fn}{mid}{ext}' for ext in preview_extensions for mid in ['.thumb.', '.preview.', '.']]:
for file in [f'{fn}{mid}{ext}' for ext in preview_extensions for mid in ['.thumb.', '.', '.preview.']]:
if os.path.exists(file):
if '.thumb.' not in file:
self.missing_thumbs.append(file)
@@ -286,16 +286,15 @@ class ExtraNetworksPage:
if tag == 'p':
self.text += '\n'
fn = os.path.splitext(path)[0]
for file in [f"{fn}.txt", f"{fn}.description.txt"]:
if os.path.exists(file):
try:
with open(file, "r", encoding="utf-8", errors="replace") as f:
txt = f.read()
txt = re.sub('[<>]', '', txt)
return txt
except OSError:
pass
fn = os.path.splitext(path)[0] + '.txt'
if os.path.exists(fn):
try:
with open(fn, "r", encoding="utf-8", errors="replace") as f:
txt = f.read()
txt = re.sub('[<>]', '', txt)
return txt
except OSError:
pass
info = self.find_info(path)
desc = info.get('description', '') or ''
f = HTMLFilter()
@@ -305,7 +304,10 @@ class ExtraNetworksPage:
def find_info(self, path):
fn = os.path.splitext(path)[0] + '.json'
if os.path.exists(fn):
return shared.readfile(fn, silent=True)
data = shared.readfile(fn, silent=True)
if type(data) is list:
data = data[0]
return data
return {}
@@ -527,6 +529,7 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
img = page.find_preview_file(item.filename)
lora = ''
model = ''
style = ''
if page.title == 'Model':
merge = len(list(meta.get('sd_merge_models', {})))
if merge > 0:
@@ -548,6 +551,13 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
<tr><td>Training images</td><td>{meta.get('ss_num_train_images', 'N/A')}</td></tr>
<tr><td>Comment</td><td>{meta.get('ss_training_comment', 'N/A')}</td></tr>
'''
if page.title == 'Style':
style = f'''
<tr><td>Name</td><td>{item.name}</td></tr>
<tr><td>Description</td><td>{item.description}</td></tr>
<tr><td>Preview Embedded</td><td>{item.preview.startswith('data:')}</td></tr>
'''
desc = f'Name: {item.name}\nDescription: {item.description}\nPrompt: {item.prompt}\nNegative: {item.negative}\nExtra: {item.extra}\n'
text = f'''
<h2 style="border-bottom: 1px solid var(--button-primary-border-color); margin-bottom: 1em; margin-top: -1.3em !important;">{item.name}</h2>
<table style="width: 100%; line-height: 1.3em;"><tbody>
@@ -557,8 +567,10 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
<tr><td>Hash</td><td>{getattr(item, 'hash', 'N/A')}</td></tr>
<tr><td>Size</td><td>{round(stat.st_size/1024/1024, 2)} MB</td></tr>
<tr><td>Last modified</td><td>{datetime.fromtimestamp(stat.st_mtime)}</td></tr>
<tr><td style="border-top: 1px solid var(--button-primary-border-color);"></td><td></td></tr>
{lora}
{model}
{style}
</tbody></table>
'''
return [text, img, desc, info, meta, gr.update(visible=item is not None)]
+5 -2
View File
@@ -55,9 +55,12 @@ class ExtraNetworksPageStyles(ui_extra_networks.ExtraNetworksPage):
"title": k,
"filename": style.filename,
"search_term": f'{txt} {self.search_terms_from_path(style.name)}',
"preview": self.find_preview(fn),
"preview": style.preview if style.preview is not None and style.preview.startswith('data:') else self.find_preview(fn),
"description": style.description if style.description is not None and len(style.description) > 0 else txt,
"prompt": style.prompt or '',
"negative": style.negative_prompt or '',
"extra": style.extra or '',
"local_preview": f"{fn}.{shared.opts.samples_format}",
"description": txt,
"onclick": '"' + html.escape(f"""return selectStyle({json.dumps(style.name)})""") + '"',
}
+2 -1
View File
@@ -38,9 +38,10 @@ voluptuous
yapf
scikit-image
basicsr
compel==2.0.2
fasteners
dctorch
compel==2.0.2
torchsde==0.2.6
typing-extensions==4.7.1
antlr4-python3-runtime==4.9.3
requests==2.31.0