mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
Adding support to inline prompt references
This commit is contained in:
@@ -4,6 +4,8 @@ import random
|
||||
import math
|
||||
import os
|
||||
import cv2
|
||||
import re
|
||||
from typing import List, Tuple, AnyStr
|
||||
|
||||
from PIL import Image
|
||||
|
||||
@@ -179,3 +181,23 @@ def get_files_from_folder(folder_path, exensions=None, name_filter=None):
|
||||
|
||||
def ordinal_suffix(number: int) -> str:
|
||||
return 'th' if 10 <= number % 100 <= 20 else {1: 'st', 2: 'nd', 3: 'rd'}.get(number % 10, 'th')
|
||||
|
||||
|
||||
def parse_lora_references_from_prompt(items: str, loras: List[Tuple[AnyStr, float]]):
|
||||
pattern = re.compile(".*<lora:(.+):(([0-9]*[.])?[0-9]+)>.*")
|
||||
new_loras = []
|
||||
|
||||
for token in items.split(","):
|
||||
print(token)
|
||||
m = pattern.match(token)
|
||||
|
||||
if m:
|
||||
new_loras.append((f"{m.group(1)}.safetensors", float(m.group(2))))
|
||||
|
||||
updated_loras = []
|
||||
for lora in loras + new_loras:
|
||||
|
||||
if lora[0] != "None":
|
||||
updated_loras.append(lora)
|
||||
|
||||
return updated_loras
|
||||
|
||||
Reference in New Issue
Block a user