Skip to content

Commit

Permalink
go back to single path for filenames in extra networks metadata dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTOMATIC1111 committed Aug 30, 2023
1 parent 3989d7e commit 338d0b6
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions modules/ui_extra_networks_user_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@
import html
import json
import os.path
from pathlib import Path

import gradio as gr

from modules import generation_parameters_copypaste, images, sysinfo, errors
from modules import generation_parameters_copypaste, images, sysinfo, errors, ui_extra_networks
from modules.paths_internal import models_path


def exclude_root_path(root_path, path):
path_object = Path(path)
if path_object.is_relative_to(root_path):
path_object = path_object.relative_to(root_path)

return path_object.as_posix()


class UserMetadataEditor:

def __init__(self, ui, tabname, page):
Expand Down Expand Up @@ -99,6 +90,13 @@ def get_card_html(self, name):

return preview

def relative_path(self, path):
for parent_path in self.page.allowed_directories_for_previews():
if ui_extra_networks.path_is_parent(parent_path, path):
return os.path.relpath(path, parent_path)

return os.path.basename(path)

def get_metadata_table(self, name):
item = self.page.items.get(name, {})
try:
Expand All @@ -107,8 +105,7 @@ def get_metadata_table(self, name):

stats = os.stat(filename)
params = [
('Filename: ', os.path.basename(filename)),
('Path: ', exclude_root_path(models_path, filename)),
('Filename: ', self.relative_path(filename)),
('File size: ', sysinfo.pretty_bytes(stats.st_size)),
('Hash: ', shorthash),
('Modified: ', datetime.datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M')),
Expand Down

0 comments on commit 338d0b6

Please sign in to comment.