ImageStudio Maintainer Claude Opus 4.8 (1M context) commited on
Commit
657da31
·
1 Parent(s): 7b2085d

fix(prompt): strip web prompt-helper @ markers before diffusion

Browse files

The web prompt-helper glues an @ marker onto character/series tokens
(e.g. @hatsune_miku). Diffusion models don't recognise it, so strip a
leading @-before-word at the top of generate_image — covering both the
direct image path and the video first-frame render. Emails / mid-word @
are preserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -148,6 +148,21 @@ MINOR_NEG = (
148
  # from biting into ``girlish`` etc.
149
  _GIRL_RE = re.compile(r"(?<![a-z0-9])(\d*)\s*girls?(?![a-z])", re.IGNORECASE)
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
  def _adultify_prompt(prompt):
153
  """Replace youthful female subject tokens with adult equivalents.
@@ -952,6 +967,11 @@ def generate_image(
952
  _gpu_start = time.time()
953
  total_steps = int(num_inference_steps)
954
 
 
 
 
 
 
955
  # Optional prompt-improvement pass: rewrite the user's prompt with the VLM
956
  # before sampling. Runs inside this same @spaces.GPU window (single ZeroGPU
957
  # allocation), mirroring how the moderation check rides along below.
 
148
  # from biting into ``girlish`` etc.
149
  _GIRL_RE = re.compile(r"(?<![a-z0-9])(\d*)\s*girls?(?![a-z])", re.IGNORECASE)
150
 
151
+ # The web prompt-helper glues an ``@`` marker onto character/series tokens it
152
+ # inserts (e.g. ``@hatsune_miku``). That ``@`` is purely a UI affordance — the
153
+ # diffusion models don't recognise it and it pollutes the conditioning. Strip a
154
+ # leading ``@`` wherever it sits directly in front of a word so the bare booru
155
+ # token (``hatsune_miku``) reaches the sampler. Mid-word ``@`` (none expected in
156
+ # tag-space) is left alone.
157
+ _AT_MARK_RE = re.compile(r"(?<![\w@])@(?=\w)")
158
+
159
+
160
+ def _strip_trigger_marks(prompt):
161
+ """Remove the prompt-helper ``@`` markers from a user prompt (no-op if none)."""
162
+ if not prompt:
163
+ return prompt
164
+ return _AT_MARK_RE.sub("", prompt)
165
+
166
 
167
  def _adultify_prompt(prompt):
168
  """Replace youthful female subject tokens with adult equivalents.
 
967
  _gpu_start = time.time()
968
  total_steps = int(num_inference_steps)
969
 
970
+ # Strip the web prompt-helper's ``@`` markers (e.g. ``@hatsune_miku``) up
971
+ # front — the models don't recognise them — so the improve/adultify passes
972
+ # and the sampler all see the clean tokens.
973
+ prompt = _strip_trigger_marks(prompt)
974
+
975
  # Optional prompt-improvement pass: rewrite the user's prompt with the VLM
976
  # before sampling. Runs inside this same @spaces.GPU window (single ZeroGPU
977
  # allocation), mirroring how the moderation check rides along below.