switch abs to relative paths

This commit is contained in:
Vladimir Mandic
2023-08-21 08:11:30 +00:00
parent 464810be9f
commit 53dcf157fb
7 changed files with 18 additions and 27 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ group.add_argument("--medvram", action='store_true', help="Split model stages an
group.add_argument("--lowvram", action='store_true', help="Split model components and keep only active part in VRAM, default: %(default)s")
group.add_argument("--ckpt", type=str, default=None, help="Path to model checkpoint to load immediately, default: %(default)s")
group.add_argument('--vae', type=str, default=None, help='Path to VAE checkpoint to load immediately, default: %(default)s')
group.add_argument("--data-dir", type=str, default=os.path.dirname(os.path.dirname(os.path.realpath(__file__))), help="Base path where all user data is stored, default: %(default)s")
group.add_argument("--data-dir", type=str, default="", help="Base path where all user data is stored, default: %(default)s")
group.add_argument("--models-dir", type=str, default="models", help="Base path where all models are stored, default: %(default)s",)
group.add_argument("--allow-code", action='store_true', help="Allow custom script execution, default: %(default)s")
group.add_argument("--share", action='store_true', help="Enable UI accessible through Gradio site, default: %(default)s")
-1
View File
@@ -277,7 +277,6 @@ def load_models(model_path: str, model_url: str = None, command_path: str = None
@return: A list of paths containing the desired model(s)
"""
places = unique_directories([model_path, command_path])
#shared.log.debug(f"{inspect.currentframe().f_code.co_name}: {', '.join(places)}")
output = []
try:
output:list = [*filter(extension_filter(ext_filter, ext_blacklist), directory_files(*places))]
+1 -1
View File
@@ -63,7 +63,7 @@ def create_paths(opts):
def fix_path(folder):
if opts.data.get(folder, None) is None or opts.data[folder] is None or opts.data[folder] == '':
return
if os.path.isabs(opts.data[folder]) or opts.data[folder].startswith(data_path):
if os.path.isabs(opts.data[folder]) or (len(data_path) > 0 and opts.data[folder].startswith(data_path)) and not opts.data[folder].startswith(script_path):
return
fullpath = os.path.join(data_path, opts.data[folder])
relpath = os.path.relpath(fullpath, script_path)
+1 -1
View File
@@ -12,7 +12,7 @@ default_sd_model_file = sd_model_file
# Parse the --data-dir flag first so we can use it as a base for our other argument default values
parser_pre = argparse.ArgumentParser(add_help=False)
parser_pre.add_argument("--data-dir", type=str, default=os.path.dirname(modules_path), help="base path where all user data is stored", )
parser_pre.add_argument("--data-dir", type=str, default="", help="base path where all user data is stored", )
parser_pre.add_argument("--models-dir", type=str, default="models", help="base path where all models are stored",)
cmd_opts_pre = parser_pre.parse_known_args()[0]
data_path = cmd_opts_pre.data_dir
-1
View File
@@ -266,7 +266,6 @@ def process_diffusers(p: StableDiffusionProcessing, seeds, prompts, negative_pro
if shared.opts.save and not p.do_not_save_samples and shared.opts.save_images_before_highres_fix and hasattr(shared.sd_model, 'vae'):
save_intermediate(latents=output.images, suffix="-before-hires")
hires_resize(latents=output.images)
print('HERE', p.init_images)
sd_models.set_diffuser_pipe(shared.sd_model, sd_models.DiffusersTaskType.IMAGE_2_IMAGE)
p.ops.append('hires')
hires_args = set_pipeline_args(
+15 -20
View File
@@ -113,7 +113,8 @@ class ExtraNetworksPage:
def link_preview(self, filename):
quoted_filename = urllib.parse.quote(filename.replace('\\', '/'))
mtime = os.path.getmtime(filename)
return f"./sd_extra_networks/thumb?filename={quoted_filename}&mtime={mtime}"
preview = f"./sd_extra_networks/thumb?filename={quoted_filename}&mtime={mtime}"
return preview
def search_terms_from_path(self, filename, possible_directories=None):
abspath = os.path.abspath(filename)
@@ -158,16 +159,16 @@ class ExtraNetworksPage:
return f"<div id='{tabname}_{self_name_id}_subdirs' class='extra-network-subdirs'></div><div id='{tabname}_{self_name_id}_cards' class='extra-network-cards'>Extra network page not ready<br>Click refresh to try again</div>"
subdirs = {}
allowed_folders = [os.path.abspath(x) for x in self.allowed_directories_for_previews()]
for parentdir, dirs in {dir: modelloader.directory_directories(dir) for dir in allowed_folders}.items(): # pylint: disable=redefined-builtin
for dir in dirs.keys(): # pylint: disable=redefined-builtin
if shared.opts.diffusers_dir in dir:
for parentdir, dirs in {d: modelloader.directory_directories(d) for d in allowed_folders}.items():
for tgt in dirs.keys():
if shared.opts.diffusers_dir in tgt:
subdirs[os.path.basename(shared.opts.diffusers_dir)] = 1
if 'models--' in dir:
if 'models--' in tgt:
continue
subdir = dir[len(parentdir):].replace("\\", "/")
subdir = tgt[len(parentdir):].replace("\\", "/")
while subdir.startswith("/"):
subdir = subdir[1:]
if not self.is_empty(dir):
if not self.is_empty(tgt):
subdirs[subdir] = 1
if subdirs:
subdirs = OrderedDict(sorted(subdirs.items()))
@@ -183,9 +184,9 @@ class ExtraNetworksPage:
self.html = ''
try:
self.items = list(self.list_items())
except Exception:
except Exception as e:
self.items = []
shared.log.error(f'Extra networks error listing items: {self.__class__}')
shared.log.error(f'Extra networks error listing items: class={self.__class__} tab={tabname} {e}')
self.create_xyz_grid()
htmls = []
items = self.items
@@ -202,7 +203,7 @@ class ExtraNetworksPage:
threading.Thread(target=self.create_thumb).start()
return res
except Exception as e:
shared.log.error(f'Extra networks {self.title} {tabname} page error: {e.__class__.__name__} -> {e}')
shared.log.error(f'Extra networks page error: title={self.title} tab={tabname} class={e.__class__.__name__} {e}')
return f"<div id='{tabname}_{self_name_id}_subdirs' class='extra-network-subdirs'></div><div id='{tabname}_{self_name_id}_cards' class='extra-network-cards'>Extra network error<br>{e}</div>"
def list_items(self):
@@ -247,22 +248,18 @@ class ExtraNetworksPage:
def find_preview(self, path):
preview_extensions = ["jpg", "jpeg", "png", "webp", "tiff", "jp2"]
dir = os.path.dirname(path) # pylint: disable=redefined-builtin
paths = modelloader.directory_directories(dir, recursive=False)
for file in [f'{path}.thumb.{ext}' for ext in preview_extensions]: # use thumbnail if exists
if file in paths[dir][1] and os.path.exists(file):
if os.path.exists(file):
return self.link_preview(file)
for file in [f'{path}{mid}{ext}' for ext in preview_extensions for mid in ['.preview.', '.']]:
if file in paths[dir][1] and os.path.exists(file):
if os.path.exists(file):
self.missing_thumbs.append(file)
return self.link_preview(file)
return self.link_preview('html/card-no-preview.png')
def find_description(self, path):
dir = os.path.dirname(path) # pylint: disable=redefined-builtin
paths = modelloader.directory_directories(dir, recursive=False)
for file in [f"{path}.txt", f"{path}.description.txt"]:
if file in paths[dir][1]:
if os.path.exists(file):
try:
with open(file, "r", encoding="utf-8", errors="replace") as f:
txt = f.read()
@@ -273,11 +270,9 @@ class ExtraNetworksPage:
return None
def find_info(self, path):
dir = os.path.dirname(path) # pylint: disable=redefined-builtin
paths = modelloader.directory_directories(dir, recursive=False)
basename, _ext = os.path.splitext(path)
for file in [f"{path}.info", f"{path}.civitai.info", f"{basename}.info", f"{basename}.civitai.info"]:
if file in paths[dir][1]:
if os.path.exists(file):
try:
with open(file, "r", encoding="utf-8", errors="replace") as f:
txt = f.read()
-2
View File
@@ -16,8 +16,6 @@ class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
checkpoint: sd_models.CheckpointInfo
for name, checkpoint in sd_models.checkpoints_list.items():
path, _ext = os.path.splitext(checkpoint.filename)
if not os.path.exists(path) and sd_models.model_path not in path:
path = os.path.abspath(os.path.join(checkpoint.path, os.pardir, os.pardir))
yield {
"name": checkpoint.name_for_extra,
"filename": path,