mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
update upscalers
This commit is contained in:
@@ -527,6 +527,7 @@ def load_upscalers():
|
||||
classname = str(cls)
|
||||
if classname not in used_classes:
|
||||
used_classes[classname] = cls
|
||||
names = []
|
||||
for cls in reversed(used_classes.values()):
|
||||
name = cls.__name__
|
||||
cmd_name = f"{name.lower().replace('upscaler', '')}_models_path"
|
||||
@@ -535,8 +536,6 @@ def load_upscalers():
|
||||
scaler.user_path = commandline_model_path
|
||||
scaler.model_download_path = commandline_model_path or scaler.model_path
|
||||
datas += scaler.scalers
|
||||
shared.sd_upscalers = sorted(
|
||||
datas,
|
||||
key=lambda x: x.name.lower() if not isinstance(x.scaler, (UpscalerNone, UpscalerLanczos, UpscalerNearest)) else "" # Special case for UpscalerNone keeps it at the beginning of the list.
|
||||
)
|
||||
shared.log.debug(f"Loaded upscalers: total={len(shared.sd_upscalers)} downloaded={len([x for x in shared.sd_upscalers if x.data_path is not None and os.path.isfile(x.data_path)])} user={len([x for x in shared.sd_upscalers if x.custom])}")
|
||||
names.append(name[8:])
|
||||
shared.sd_upscalers = sorted(datas, key=lambda x: x.name.lower() if not isinstance(x.scaler, (UpscalerNone, UpscalerLanczos, UpscalerNearest)) else "") # Special case for UpscalerNone keeps it at the beginning of the list.
|
||||
shared.log.debug(f"Loaded upscalers: total={len(shared.sd_upscalers)} downloaded={len([x for x in shared.sd_upscalers if x.data_path is not None and os.path.isfile(x.data_path)])} user={len([x for x in shared.sd_upscalers if x.custom])} {names}")
|
||||
|
||||
@@ -2,7 +2,7 @@ import PIL.Image
|
||||
import numpy as np
|
||||
import torch
|
||||
from rich.progress import Progress, TextColumn, BarColumn, TaskProgressColumn, TimeRemainingColumn, TimeElapsedColumn
|
||||
from modules import devices, script_callbacks
|
||||
from modules import devices
|
||||
from modules.postprocess.scunet_model_arch import SCUNet as net
|
||||
from modules.shared import opts, log, console, device
|
||||
from modules.upscaler import Upscaler
|
||||
@@ -67,7 +67,7 @@ class UpscalerSCUNet(Upscaler):
|
||||
output = E.div_(W)
|
||||
return output
|
||||
|
||||
def do_upscale(self, img: PIL.Image.Image, selected_file): # pylint: disable=arguments-renamed
|
||||
def do_upscale(self, img: PIL.Image.Image, selected_file):
|
||||
devices.torch_gc()
|
||||
model = self.load_model(selected_file)
|
||||
if model is None:
|
||||
|
||||
@@ -6,7 +6,7 @@ from modules.upscaler import Upscaler, UpscalerData
|
||||
|
||||
class UpscalerSD(Upscaler):
|
||||
def __init__(self, dirname): # pylint: disable=super-init-not-called
|
||||
self.name = "StableDiffusion"
|
||||
self.name = "SDUpscale"
|
||||
self.user_path = dirname
|
||||
if shared.backend != shared.Backend.DIFFUSERS:
|
||||
super().__init__()
|
||||
@@ -13,13 +13,16 @@ def load_module(path):
|
||||
module_spec = importlib.util.spec_from_file_location(os.path.basename(path), path)
|
||||
module = importlib.util.module_from_spec(module_spec)
|
||||
try:
|
||||
# stdout = io.StringIO()
|
||||
with contextlib.redirect_stdout(io.StringIO()) as stdout:
|
||||
if '/sd-extension-' in path: # safe extensions without stdout intercept
|
||||
module_spec.loader.exec_module(module)
|
||||
setup_logging() # reset since scripts can hijaack logging
|
||||
for line in stdout.getvalue().splitlines():
|
||||
if len(line) > 0:
|
||||
errors.log.info(f"Extension: script='{os.path.relpath(path)}' {line.strip()}")
|
||||
else:
|
||||
# stdout = io.StringIO()
|
||||
with contextlib.redirect_stdout(io.StringIO()) as stdout:
|
||||
module_spec.loader.exec_module(module)
|
||||
setup_logging() # reset since scripts can hijaack logging
|
||||
for line in stdout.getvalue().splitlines():
|
||||
if len(line) > 0:
|
||||
errors.log.info(f"Extension: script='{os.path.relpath(path)}' {line.strip()}")
|
||||
except Exception as e:
|
||||
errors.display(e, f'Module load: {path}')
|
||||
return module
|
||||
|
||||
@@ -97,23 +97,26 @@ class ExtraNetworksPageStyles(ui_extra_networks.ExtraNetworksPage):
|
||||
|
||||
def list_items(self):
|
||||
for k, style in shared.prompt_styles.styles.items():
|
||||
fn = os.path.splitext(style.filename)[0]
|
||||
txt = f'Prompt: {style.prompt}'
|
||||
if len(style.negative_prompt) > 0:
|
||||
fn = os.path.splitext(getattr(style, 'filename', ''))[0]
|
||||
name = getattr(style, 'name', '')
|
||||
if name == '':
|
||||
continue
|
||||
txt = f'Prompt: {getattr(style, "prompt", "")}'
|
||||
if len(getattr(style, 'negative_prompt', '')) > 0:
|
||||
txt += f'\nNegative: {style.negative_prompt}'
|
||||
yield {
|
||||
"type": 'Style',
|
||||
"name": style.name,
|
||||
"name": name,
|
||||
"title": k,
|
||||
"filename": style.filename,
|
||||
"search_term": f'{txt} {self.search_terms_from_path(style.name)}',
|
||||
"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 '',
|
||||
"search_term": f'{txt} {self.search_terms_from_path(name)}',
|
||||
"preview": style.preview if getattr(style, 'preview', None) is not None and style.preview.startswith('data:') else self.find_preview(fn),
|
||||
"description": style.description if getattr(style, 'description', None) is not None and len(style.description) > 0 else txt,
|
||||
"prompt": getattr(style, 'prompt', ''),
|
||||
"negative": getattr(style, 'negative_prompt', ''),
|
||||
"extra": getattr(style, 'extra', ''),
|
||||
"local_preview": f"{fn}.{shared.opts.samples_format}",
|
||||
"onclick": '"' + html.escape(f"""return selectStyle({json.dumps(style.name)})""") + '"',
|
||||
"onclick": '"' + html.escape(f"""return selectStyle({json.dumps(name)})""") + '"',
|
||||
}
|
||||
|
||||
def allowed_directories_for_previews(self):
|
||||
|
||||
Reference in New Issue
Block a user