JS6969 commited on
Commit
6120301
·
verified ·
1 Parent(s): f4c864c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -285,14 +285,22 @@ def _compile_shape_aliases_from_file():
285
  return []
286
  compiled = []
287
  for item in s.get("shape_aliases", []):
288
- shape = (item.get("shape") or "").strip()
289
- name = (item.get("name") or "").strip()
290
- if not shape or not name:
291
  continue
292
- pat = rf"\b{re.escape(shape)}(?:-?shaped)?\b"
 
 
 
 
 
 
 
293
  compiled.append((re.compile(pat, flags=re.I), name))
294
  return compiled
295
 
 
296
  _SHAPE_ALIASES = _compile_shape_aliases_from_file()
297
  def _refresh_shape_aliases_cache():
298
  global _SHAPE_ALIASES
@@ -621,7 +629,11 @@ with gr.Blocks(css=BASE_CSS, title="ForgeCaptions") as demo:
621
  gr.Markdown(
622
  "### 🔷 Shape Aliases\n"
623
  "Replace literal **shape tokens** in captions with a preferred **name**.\n\n"
624
- "**How to use:** left column = shape token (e.g., `diamond`), right column = replacement name (e.g., `starkey-emblem`)."
 
 
 
 
625
  )
626
  init_rows, init_enabled = get_shape_alias_rows_ui_defaults()
627
  enable_aliases = gr.Checkbox(label="Enable shape alias replacements", value=init_enabled)
 
285
  return []
286
  compiled = []
287
  for item in s.get("shape_aliases", []):
288
+ raw = (item.get("shape") or "").strip()
289
+ name = (item.get("name") or "").strip()
290
+ if not raw or not name:
291
  continue
292
+ # allow comma or pipe separated synonyms in one cell
293
+ tokens = [t.strip() for t in re.split(r"[|,]", raw) if t.strip()]
294
+ if not tokens:
295
+ continue
296
+ # de-dup and prefer longer phrases first (prevents "diamond" eating "diamond emblem")
297
+ tokens = sorted(set(tokens), key=lambda t: -len(t))
298
+ # word boundaries at ends; allow optional "-shaped" suffix
299
+ pat = r"\b(?:" + "|".join(re.escape(t) for t in tokens) + r")(?:-?shaped)?\b"
300
  compiled.append((re.compile(pat, flags=re.I), name))
301
  return compiled
302
 
303
+
304
  _SHAPE_ALIASES = _compile_shape_aliases_from_file()
305
  def _refresh_shape_aliases_cache():
306
  global _SHAPE_ALIASES
 
629
  gr.Markdown(
630
  "### 🔷 Shape Aliases\n"
631
  "Replace literal **shape tokens** in captions with a preferred **name**.\n\n"
632
+ "**How to use:**\n"
633
+ "- Left column = a single token **or** comma/pipe-separated synonyms, e.g. `penis, cock | phallic`\n"
634
+ "- Right column = replacement name, e.g. `family-emblem`\n\n"
635
+ "Matches are case-insensitive, use whole words, and also catch `*-shaped` (e.g., `diamond-shaped`).\n"
636
+ "Multi-word phrases are supported."
637
  )
638
  init_rows, init_enabled = get_shape_alias_rows_ui_defaults()
639
  enable_aliases = gr.Checkbox(label="Enable shape alias replacements", value=init_enabled)