Follow-up to e2548f69: add missing paths module, fix gallery extension

This commit is contained in:
oobabooga 2026-03-06 00:57:32 -03:00
parent 8d43123f73
commit ddcad3cc51
2 changed files with 31 additions and 2 deletions

View file

@ -2,6 +2,7 @@ from pathlib import Path
import gradio as gr
import modules.shared as shared
from modules.html_generator import get_image_cache
from modules.shared import gradio
@ -72,13 +73,13 @@ def generate_html():
global cards
cards = []
# Iterate through files in image folder
for file in sorted(Path("user_data/characters").glob("*")):
for file in sorted((shared.user_data_dir / "characters").glob("*")):
if file.suffix in [".json", ".yml", ".yaml"]:
character = file.stem
container_html = '<div class="character-container">'
image_html = "<div class='placeholder'></div>"
for path in [Path(f"user_data/characters/{character}.{extension}") for extension in ['png', 'jpg', 'jpeg']]:
for path in [shared.user_data_dir / "characters" / f"{character}.{extension}" for extension in ['png', 'jpg', 'jpeg']]:
if path.exists():
image_html = f'<img src="file/{get_image_cache(path)}">'
break

28
modules/paths.py Normal file
View file

@ -0,0 +1,28 @@
import sys
from pathlib import Path
def resolve_user_data_dir():
"""
Resolve the user_data directory path. Order of precedence:
1. --user-data-dir CLI flag (pre-parsed from sys.argv before argparse)
2. Auto-detect: if ./user_data doesn't exist but ../user_data does, use ../user_data
3. Default: 'user_data'
"""
script_dir = Path(__file__).resolve().parent.parent
# Check sys.argv for --user-data-dir before argparse runs
for i, arg in enumerate(sys.argv):
if arg == '--user-data-dir' and i + 1 < len(sys.argv):
return Path(sys.argv[i + 1])
elif arg.startswith('--user-data-dir='):
return Path(arg.split('=', 1)[1])
# Auto-detect: check if user_data exists locally vs one folder up
local_path = script_dir / 'user_data'
parent_path = script_dir.parent / 'user_data'
if not local_path.exists() and parent_path.exists():
return parent_path
return Path('user_data')