Support artist and ar placeholders
Browse files
app.py
CHANGED
|
@@ -96,7 +96,7 @@ OUTPUT_DIR = DATA_DIR / "output"
|
|
| 96 |
IMAGE_DIR = DATA_DIR / "img"
|
| 97 |
STAR_DB = DATA_DIR / "explorer.db"
|
| 98 |
ARTIST_DB = Path(tempfile.gettempdir()) / "artists.sqlite"
|
| 99 |
-
ARTIST_PLACEHOLDER = re.compile(r"\{ar(\d
|
| 100 |
TIMEZONE = ZoneInfo("Asia/Singapore")
|
| 101 |
CPU_DEVICE = torch.device("cpu")
|
| 102 |
MIB = 1024 * 1024
|
|
@@ -361,6 +361,8 @@ def copy_artist_database():
|
|
| 361 |
for path in (
|
| 362 |
DATA_MOUNT / "_cache" / "artists.sqlite",
|
| 363 |
DATA_DIR / "_cache" / "artists.sqlite",
|
|
|
|
|
|
|
| 364 |
Path.cwd() / "artists.sqlite",
|
| 365 |
)
|
| 366 |
if path.is_file()
|
|
@@ -766,11 +768,11 @@ class DirectRequest(BaseModel):
|
|
| 766 |
|
| 767 |
|
| 768 |
def resolve_artist_prompts(request):
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
)
|
| 772 |
-
|
| 773 |
-
|
| 774 |
if not identifiers:
|
| 775 |
return
|
| 776 |
if not ARTIST_DB.is_file():
|
|
@@ -800,10 +802,17 @@ def resolve_artist_prompts(request):
|
|
| 800 |
replacements = dict(zip(identifiers, selected))
|
| 801 |
|
| 802 |
def replace(match):
|
| 803 |
-
|
|
|
|
| 804 |
|
| 805 |
request.prompt = ARTIST_PLACEHOLDER.sub(replace, request.prompt)
|
| 806 |
request.second_prompt = ARTIST_PLACEHOLDER.sub(replace, request.second_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 807 |
request.selected_artists = list(dict.fromkeys(selected))
|
| 808 |
|
| 809 |
|
|
|
|
| 96 |
IMAGE_DIR = DATA_DIR / "img"
|
| 97 |
STAR_DB = DATA_DIR / "explorer.db"
|
| 98 |
ARTIST_DB = Path(tempfile.gettempdir()) / "artists.sqlite"
|
| 99 |
+
ARTIST_PLACEHOLDER = re.compile(r"\{(?:artist|ar)(\d*)\}", re.I)
|
| 100 |
TIMEZONE = ZoneInfo("Asia/Singapore")
|
| 101 |
CPU_DEVICE = torch.device("cpu")
|
| 102 |
MIB = 1024 * 1024
|
|
|
|
| 361 |
for path in (
|
| 362 |
DATA_MOUNT / "_cache" / "artists.sqlite",
|
| 363 |
DATA_DIR / "_cache" / "artists.sqlite",
|
| 364 |
+
DATA_MOUNT / "artists.sqlite",
|
| 365 |
+
DATA_DIR / "artists.sqlite",
|
| 366 |
Path.cwd() / "artists.sqlite",
|
| 367 |
)
|
| 368 |
if path.is_file()
|
|
|
|
| 768 |
|
| 769 |
|
| 770 |
def resolve_artist_prompts(request):
|
| 771 |
+
prompts = [request.prompt, request.second_prompt]
|
| 772 |
+
prompts.extend(d.prompt for d in getattr(request, "detailers", []) if getattr(d, "prompt", None))
|
| 773 |
+
prompts.extend(r.prompt for r in getattr(request, "regions", []) if getattr(r, "prompt", None))
|
| 774 |
+
matches = ARTIST_PLACEHOLDER.findall("\n".join(prompts))
|
| 775 |
+
identifiers = list(dict.fromkeys(value.lstrip("0") or "1" for value in matches))
|
| 776 |
if not identifiers:
|
| 777 |
return
|
| 778 |
if not ARTIST_DB.is_file():
|
|
|
|
| 802 |
replacements = dict(zip(identifiers, selected))
|
| 803 |
|
| 804 |
def replace(match):
|
| 805 |
+
artist = replacements[match.group(1).lstrip("0") or "1"]
|
| 806 |
+
return re.sub(r"[()]", r"\\\g<0>", artist)
|
| 807 |
|
| 808 |
request.prompt = ARTIST_PLACEHOLDER.sub(replace, request.prompt)
|
| 809 |
request.second_prompt = ARTIST_PLACEHOLDER.sub(replace, request.second_prompt)
|
| 810 |
+
for d in getattr(request, "detailers", []):
|
| 811 |
+
if getattr(d, "prompt", None):
|
| 812 |
+
d.prompt = ARTIST_PLACEHOLDER.sub(replace, d.prompt)
|
| 813 |
+
for r in getattr(request, "regions", []):
|
| 814 |
+
if getattr(r, "prompt", None):
|
| 815 |
+
r.prompt = ARTIST_PLACEHOLDER.sub(replace, r.prompt)
|
| 816 |
request.selected_artists = list(dict.fromkeys(selected))
|
| 817 |
|
| 818 |
|