mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
feat: only use valid inline loras, add subfolder support
This commit is contained in:
+29
-12
@@ -1,3 +1,5 @@
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import datetime
|
||||
import random
|
||||
@@ -360,6 +362,14 @@ def is_json(data: str) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def get_filname_by_stem(lora_name, filenames: List[str]) -> str | None:
|
||||
for filename in filenames:
|
||||
path = Path(filename)
|
||||
if lora_name == path.stem:
|
||||
return filename
|
||||
return None
|
||||
|
||||
|
||||
def get_file_from_folder_list(name, folders):
|
||||
if not isinstance(folders, list):
|
||||
folders = [folders]
|
||||
@@ -377,28 +387,35 @@ def get_enabled_loras(loras: list, remove_none=True) -> list:
|
||||
|
||||
|
||||
def parse_lora_references_from_prompt(prompt: str, loras: List[Tuple[AnyStr, float]], loras_limit: int = 5,
|
||||
prompt_cleanup=True, deduplicate_loras=True) -> tuple[List[Tuple[AnyStr, float]], str]:
|
||||
skip_file_check=False, prompt_cleanup=True, deduplicate_loras=True) -> tuple[List[Tuple[AnyStr, float]], str]:
|
||||
found_loras = []
|
||||
prompt_without_loras = ""
|
||||
for token in prompt.split(" "):
|
||||
prompt_without_loras = ''
|
||||
cleaned_prompt = ''
|
||||
for token in prompt.split(','):
|
||||
matches = LORAS_PROMPT_PATTERN.findall(token)
|
||||
|
||||
if matches:
|
||||
for match in matches:
|
||||
found_loras.append((f"{match[1]}.safetensors", float(match[2])))
|
||||
prompt_without_loras += token.replace(match[0], '')
|
||||
else:
|
||||
prompt_without_loras += token
|
||||
prompt_without_loras += ' '
|
||||
if len(matches) == 0:
|
||||
prompt_without_loras += token + ', '
|
||||
continue
|
||||
for match in matches:
|
||||
lora_name = match[1] + '.safetensors'
|
||||
if not skip_file_check:
|
||||
lora_name = get_filname_by_stem(match[1], modules.config.lora_filenames_no_special)
|
||||
if lora_name is not None:
|
||||
found_loras.append((lora_name, float(match[2])))
|
||||
token = token.replace(match[0], '')
|
||||
prompt_without_loras += token + ', '
|
||||
|
||||
if prompt_without_loras != '':
|
||||
cleaned_prompt = prompt_without_loras[:-2]
|
||||
|
||||
cleaned_prompt = prompt_without_loras[:-1]
|
||||
if prompt_cleanup:
|
||||
cleaned_prompt = cleanup_prompt(prompt_without_loras)
|
||||
|
||||
new_loras = []
|
||||
lora_names = [lora[0] for lora in loras]
|
||||
for found_lora in found_loras:
|
||||
if deduplicate_loras and found_lora[0] in lora_names:
|
||||
if deduplicate_loras and (found_lora[0] in lora_names or found_lora in new_loras):
|
||||
continue
|
||||
new_loras.append(found_lora)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user