fix: use example prompts instead of trigger words, serve LoRA preview images (#52)

- Prompt text now uses civitai example prompts (images[].meta.prompt)
  when available, falling back to model name instead of trigger words
- Image serving now allows paths within LoRA directories when the
  integration is enabled, fixing 403 errors on preview images
This commit is contained in:
Vito Sansevero
2026-04-03 08:20:20 -07:00
parent b71e4780e9
commit fea745deb9
3 changed files with 41 additions and 6 deletions
+19 -4
View File
@@ -303,11 +303,26 @@ class ImageRoutesMixin:
image_path = Path(image["image_path"]).resolve()
# Validate path is within any configured output directory
output_dirs = self._get_all_output_dirs()
if output_dirs:
# Validate path is within any allowed directory
allowed_dirs = list(self._get_all_output_dirs())
# Also allow LoRA directories when integration is enabled
try:
from ..config import IntegrationConfig
if IntegrationConfig.LORA_MANAGER_ENABLED:
from ..lora_utils import find_lora_directories
lora_dirs = find_lora_directories(
IntegrationConfig.LORA_MANAGER_PATH
)
allowed_dirs.extend(Path(d) for d in lora_dirs)
except Exception:
pass
if allowed_dirs:
allowed = any(
image_path.is_relative_to(d.resolve()) for d in output_dirs
image_path.is_relative_to(d.resolve()) for d in allowed_dirs
)
if not allowed:
return web.json_response(
+4 -2
View File
@@ -154,6 +154,7 @@ class LoraIntegrationMixin:
from ..config import IntegrationConfig
from ..lora_utils import (
find_lora_directories,
get_example_prompt_from_metadata,
get_preview_image_from_metadata,
get_trigger_words_from_metadata,
get_model_name_from_metadata,
@@ -228,8 +229,9 @@ class LoraIntegrationMixin:
get_preview_image_from_metadata, metadata, meta_file
)
# Build prompt text from trigger words or model name
prompt_text = ", ".join(trigger_words) if trigger_words else model_name
# Build prompt text: prefer example prompt, then model name
example_prompt = get_example_prompt_from_metadata(metadata)
prompt_text = example_prompt or model_name
# Build tags
tags = ["lora-manager", f"lora:{model_name}"]
+18
View File
@@ -208,6 +208,24 @@ def get_trigger_words_from_metadata(metadata: Dict) -> List[str]:
return []
def get_example_prompt_from_metadata(metadata: Dict) -> Optional[str]:
"""Extract an example prompt from civitai image metadata.
Looks at civitai.images[].meta.prompt for the first available example.
"""
civitai = metadata.get("civitai", {})
images = civitai.get("images", [])
for img in images:
if not isinstance(img, dict):
continue
meta = img.get("meta")
if isinstance(meta, dict):
prompt = meta.get("prompt", "")
if isinstance(prompt, str) and prompt.strip():
return prompt.strip()
return None
def get_model_name_from_metadata(metadata: Dict) -> str:
"""Extract the model display name from metadata."""
# Try civitai model name first, then file_name, then fallback