observantdistressed commited on
Commit
bb9df7f
·
1 Parent(s): 1b93f28

Rebuild auto LoRA activation: ICF-scored prompt matching + live preview

Browse files

New architecture (not a restore of the prior implementation):
- Normalized matching (hyphen/space-insensitive, punctuation-stripped) so
'face-fucking' == 'face fucking'
- Inverse-concept-frequency scoring: distinctive phrases (unique to few
LoRAs) score high, generic phrases shared across many score low; replaces
the old longest-keyword-wins heuristic with a principled signal
- Category dedupe by highest score (one LoRA per concept), Smashcut gated
on pussy-thrusting scene via LORA_AUTO_REQUIRES
- auto_activation_details() returns matched phrases + score for a live,
explainable preview panel under the prompt box (checkbox default ON)
- Data-completeness: generic sex prompts fire the NSFW Booster; thrusting
into pussy fires Penetration Insert
- Prompt adaptation ported: trigger-words-only merge (user scene wins),
full body kept for camera/booster LoRAs

Files changed (2) hide show
  1. app.py +66 -0
  2. lora_loader.py +766 -0
app.py CHANGED
@@ -469,6 +469,15 @@ def run_inference(
469
  except Exception as e:
470
  print(f"LoRA warning: {e}")
471
 
 
 
 
 
 
 
 
 
 
472
  result = pipe(
473
  image=resized_image,
474
  last_image=processed_last_image,
@@ -535,6 +544,7 @@ def generate_video(
535
  frame_multiplier=16,
536
  safe_mode=False,
537
  lora_groups=None,
 
538
  video_component=True,
539
  progress=gr.Progress(track_tqdm=True),
540
  ):
@@ -594,6 +604,22 @@ def generate_video(
594
  if last_image:
595
  processed_last_image = resize_and_crop_to_match(last_image, resized_image)
596
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597
  video_path, task_n = run_inference(
598
  resized_image,
599
  processed_last_image,
@@ -618,6 +644,22 @@ def generate_video(
618
  return (video_path if video_component else None), video_path, current_seed
619
 
620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
621
  CSS = """
622
  #hidden-timestamp {
623
  opacity: 0;
@@ -640,6 +682,17 @@ with gr.Blocks(delete_cache=(3600, 10800)) as demo:
640
  with gr.Column():
641
  input_image_component = gr.Image(type="pil", label="Input Image", sources=["upload", "clipboard"])
642
  prompt_input = gr.Textbox(label="Prompt", value=default_prompt_i2v)
 
 
 
 
 
 
 
 
 
 
 
643
  duration_seconds_input = gr.Slider(minimum=MIN_DURATION, maximum=MAX_DURATION, step=0.1, value=3.5, label="Duration (seconds)", info=f"Clamped to model's {MIN_FRAMES_MODEL}-{MAX_FRAMES_MODEL} frames at {FIXED_FPS}fps.")
644
  frame_multi = gr.Dropdown(
645
  choices=[FIXED_FPS, FIXED_FPS*2, FIXED_FPS*4, FIXED_FPS*8],
@@ -692,6 +745,7 @@ with gr.Blocks(delete_cache=(3600, 10800)) as demo:
692
  quality_slider, scheduler_dropdown, flow_shift_slider, frame_multi,
693
  safe_mode_checkbox,
694
  lora_dropdown,
 
695
  play_result_video
696
  ]
697
 
@@ -701,6 +755,18 @@ with gr.Blocks(delete_cache=(3600, 10800)) as demo:
701
  outputs=[video_output, file_output, seed_input]
702
  )
703
 
 
 
 
 
 
 
 
 
 
 
 
 
704
  # --- Frame Grabbing Events ---
705
  # 1. Click button -> JS runs -> puts time in hidden number box
706
  grab_frame_btn.click(
 
469
  except Exception as e:
470
  print(f"LoRA warning: {e}")
471
 
472
+ # LoRA prompt + user prompt combined — lora triggers first for activation
473
+ try:
474
+ additions = lora_loader.get_lora_prompt_additions(lora_groups)
475
+ except Exception:
476
+ additions = ""
477
+ if additions:
478
+ prompt = f"{additions} {prompt}"
479
+ print(f"Combined prompt: {prompt}")
480
+
481
  result = pipe(
482
  image=resized_image,
483
  last_image=processed_last_image,
 
544
  frame_multiplier=16,
545
  safe_mode=False,
546
  lora_groups=None,
547
+ auto_lora_enabled=True,
548
  video_component=True,
549
  progress=gr.Progress(track_tqdm=True),
550
  ):
 
604
  if last_image:
605
  processed_last_image = resize_and_crop_to_match(last_image, resized_image)
606
 
607
+ # Auto-activate LoRAs from the prompt when enabled, merging with manual picks
608
+ if auto_lora_enabled and prompt:
609
+ try:
610
+ auto_loras = lora_loader.auto_activate_loras(prompt)
611
+ except Exception as e:
612
+ auto_loras = []
613
+ print(f"Auto-LoRA detection error: {e}")
614
+ if auto_loras:
615
+ print(f"Auto-activated LoRAs: {auto_loras}")
616
+ manual = list(lora_groups or [])
617
+ merged = list(auto_loras)
618
+ for m in manual:
619
+ if m not in merged:
620
+ merged.append(m)
621
+ lora_groups = merged
622
+
623
  video_path, task_n = run_inference(
624
  resized_image,
625
  processed_last_image,
 
644
  return (video_path if video_component else None), video_path, current_seed
645
 
646
 
647
+ def _update_auto_lora_preview(prompt, auto_lora_enabled):
648
+ if not auto_lora_enabled or not prompt:
649
+ return ""
650
+ try:
651
+ details = lora_loader.auto_activation_details(prompt)
652
+ except Exception as e:
653
+ return f"<span style='color:#888'>auto-detection error: {e}</span>"
654
+ if not details:
655
+ return "<span style='color:#888'>No LoRAs matched.</span>"
656
+ items = []
657
+ for d in details:
658
+ phrases = ", ".join(d.get("matched", [])) or "—"
659
+ items.append(f"<li><b>{d['group']}</b> <span style='color:#888'>(score {d['score']})</span><br><small>{phrases}</small></li>")
660
+ return "<b>Auto-activated:</b><ul style='margin:2px 0;padding-left:18px'>" + "".join(items) + "</ul>"
661
+
662
+
663
  CSS = """
664
  #hidden-timestamp {
665
  opacity: 0;
 
682
  with gr.Column():
683
  input_image_component = gr.Image(type="pil", label="Input Image", sources=["upload", "clipboard"])
684
  prompt_input = gr.Textbox(label="Prompt", value=default_prompt_i2v)
685
+ auto_lora_checkbox = gr.Checkbox(
686
+ label="Auto-activate LoRAs from prompt",
687
+ value=True,
688
+ interactive=True,
689
+ info="Automatically detect matching LoRAs from your prompt text (deduplicated by concept).",
690
+ )
691
+ auto_lora_preview = gr.HTML(
692
+ label="Auto-detected LoRAs",
693
+ value="",
694
+ elem_id="auto-lora-preview",
695
+ )
696
  duration_seconds_input = gr.Slider(minimum=MIN_DURATION, maximum=MAX_DURATION, step=0.1, value=3.5, label="Duration (seconds)", info=f"Clamped to model's {MIN_FRAMES_MODEL}-{MAX_FRAMES_MODEL} frames at {FIXED_FPS}fps.")
697
  frame_multi = gr.Dropdown(
698
  choices=[FIXED_FPS, FIXED_FPS*2, FIXED_FPS*4, FIXED_FPS*8],
 
745
  quality_slider, scheduler_dropdown, flow_shift_slider, frame_multi,
746
  safe_mode_checkbox,
747
  lora_dropdown,
748
+ auto_lora_checkbox,
749
  play_result_video
750
  ]
751
 
 
755
  outputs=[video_output, file_output, seed_input]
756
  )
757
 
758
+ # --- Auto-LoRA Preview Events ---
759
+ prompt_input.change(
760
+ fn=_update_auto_lora_preview,
761
+ inputs=[prompt_input, auto_lora_checkbox],
762
+ outputs=[auto_lora_preview],
763
+ )
764
+ auto_lora_checkbox.change(
765
+ fn=_update_auto_lora_preview,
766
+ inputs=[prompt_input, auto_lora_checkbox],
767
+ outputs=[auto_lora_preview],
768
+ )
769
+
770
  # --- Frame Grabbing Events ---
771
  # 1. Click button -> JS runs -> puts time in hidden number box
772
  grab_frame_btn.click(
lora_loader.py CHANGED
@@ -3,10 +3,17 @@ LoRA Loader for WAN 2.2 I2V - multi-repo.
3
  Baseline: lkzd7/WAN2.2_LoraSet_NSFW. Plus curated I2V act/helper LoRAs from
4
  Lythiga/WAN2.2_I2V_Lora, rolechar/rc_wan2.2_i2v_loraset_nsfw_private,
5
  lopi999/Wan2.2-I2V_General-NSFW-LoRA. T2V / lightning / furry / dance / male-char filtered out.
 
 
 
 
 
 
6
  """
7
  import os
8
  import urllib.parse
9
  import re
 
10
  from huggingface_hub import hf_hub_download
11
 
12
  LORA_REPO = "lkzd7/WAN2.2_LoraSet_NSFW"
@@ -159,6 +166,765 @@ def get_lora_choices():
159
  return choices
160
 
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  def download_lora(group_name):
163
  if not group_name:
164
  return None, None
 
3
  Baseline: lkzd7/WAN2.2_LoraSet_NSFW. Plus curated I2V act/helper LoRAs from
4
  Lythiga/WAN2.2_I2V_Lora, rolechar/rc_wan2.2_i2v_loraset_nsfw_private,
5
  lopi999/Wan2.2-I2V_General-NSFW-LoRA. T2V / lightning / furry / dance / male-char filtered out.
6
+
7
+ Auto-activation: scored inverse-concept-frequency (ICF) matching against the
8
+ normalized prompt. Each LoRA's score sums the distinctiveness weights of every
9
+ trigger phrase present in the prompt; concept categories dedupe output to at
10
+ most one LoRA per category. See LORA_AUTO_PHRASES / LORA_AUTO_CATEGORIES /
11
+ auto_activation_details below.
12
  """
13
  import os
14
  import urllib.parse
15
  import re
16
+ import math
17
  from huggingface_hub import hf_hub_download
18
 
19
  LORA_REPO = "lkzd7/WAN2.2_LoraSet_NSFW"
 
166
  return choices
167
 
168
 
169
+ # ── Auto-activation: scored inverse-concept-frequency (ICF) ───────────────
170
+ # New architecture. Instead of the old "longest matched keyword wins" tie-break
171
+ # per category, every trigger phrase carries an ICF weight: log(N / (1 + k))
172
+ # where N is the number of LoRAs that have trigger phrases and k is how many of
173
+ # those LoRAs contain this phrase. Phrases unique to one LoRA (e.g.
174
+ # "deepthroat") get a high weight; phrases shared by many LoRAs (generic) get a
175
+ # low weight. A LoRA's score is the sum of the ICF weights of every phrase
176
+ # present in the NORMALIZED prompt. Concept categories still dedupe the output
177
+ # to at most one LoRA per category, but the winner is the highest score, not
178
+ # the longest keyword.
179
+ #
180
+ # All matching happens against _normalize()d text, so "face-fucking" matches
181
+ # "face fucking", "deepthroat" matches "deepthroats", etc. Only DISTINCTIVE
182
+ # phrases are listed so a plain prompt ("a woman walking in a garden") does not
183
+ # activate anything. Near-duplicate variants of the same concept are left
184
+ # manual-only to keep auto firing on one representative LoRA per concept.
185
+
186
+ def _normalize(text):
187
+ """Normalize text for phrase matching.
188
+
189
+ Lowercases, strips everything except letters/digits (so hyphens, slashes,
190
+ newlines, tabs and punctuation all become spaces), collapses whitespace
191
+ runs to single spaces, and pads the result with surrounding spaces so
192
+ substring matches respect token boundaries. "face-fucking" and
193
+ "face fucking" both normalize to "face fucking".
194
+ """
195
+ if not text or not isinstance(text, str):
196
+ return ""
197
+ t = text.lower()
198
+ t = re.sub(r"[^a-z0-9]+", " ", t)
199
+ t = re.sub(r"\s+", " ", t)
200
+ return " " + t.strip() + " "
201
+
202
+
203
+ LORA_AUTO_PHRASES = {
204
+ # ── blowjob / deepthroat family ──
205
+ "Ultimate Deepthroat": [
206
+ "deepthroat", "deep throat", "facefuck", "face-fuck", "facefucking",
207
+ "face-fucking", "face fucking", "piston", "piston-like", "in and out of her throat",
208
+ "into her throat", "down her throat", "deep in her throat", "nose against his pelvis",
209
+ "nose pressed against his pelvis", "nose is pressed", "cock down her throat",
210
+ "gagging on his cock", "gags on his cock", "throatpie", "throat pie",
211
+ "all the way down his cock",
212
+ ],
213
+ "BBC Deepthroat": [
214
+ "bbc deep throat", "bbc deepthroat", "black deep throat", "bbc facefuck",
215
+ "bbc face-fuck", "bbc face fucking", "interracial deepthroat", "bbc down her throat",
216
+ "black cock down her throat", "bbc throatpie",
217
+ ],
218
+ "Throat V2": [
219
+ "throat fuck", "throatfuck", "throat deep penetration", "throatpie", "throat pie",
220
+ "throat depth", "pushed into her throat", "deep in her throat", "throat gagging",
221
+ "choking on his cock",
222
+ ],
223
+ "wan22-mouthfull-140epoc-high-k3nk": [
224
+ "mouthfull", "mouth full", "m0u7hfu11", "mouth full of his cock", "mouth full of cock",
225
+ "cock fills her mouth", "stuffed mouth", "mouth stretched around",
226
+ ],
227
+ "BBC Blowjob Extreme": [
228
+ "bbc blowjob", "black blowjob", "bbc extreme blowjob", "bbc sucking",
229
+ "interracial blowjob", "black cock in her mouth", "bbc facefuck", "bbc bj",
230
+ ],
231
+ "POV Blowjob": [
232
+ "pov blowjob", "point of view blowjob", "pov bj", "pov blow job", "point of view bj",
233
+ "pov sucking",
234
+ ],
235
+ "iGOON_Blink_Blowjob_I2V": [
236
+ "blowjob", "blow job", "sucking his cock", "sucking cock", "sucking him off",
237
+ "sucking his dick", "cock in her mouth", "cock into her mouth", "into her open mouth",
238
+ "cock between her lips", "her lips around his cock", "mouth around his cock",
239
+ "bobbing her head", "taking him in her mouth", "sucks his cock", "open mouth",
240
+ "cock in her open mouth", "mouth on his cock",
241
+ ],
242
+ "lips-bj": [
243
+ "lips bj", "lipjob", "lips-bj", "cock between her lips", "lips around his cock",
244
+ "lip blowjob", "cock against her lips",
245
+ ],
246
+ "WAN-2.2-I2V-SensualTeasingBlowjob": [
247
+ "sensual blowjob", "sensual bj", "teasing blowjob", "sensualbj", "teasing his cock",
248
+ "licking the tip", "licking his shaft", "slow teasing", "kissing the tip",
249
+ "licking his cock",
250
+ ],
251
+ "WAN-2.2-I2V-HandjobBlowjobCombo": [
252
+ "handjob blowjob", "handjob and blowjob", "hand and mouth", "stroking and sucking",
253
+ "handjob and bj", "hand on his cock while sucking", "combination handjob",
254
+ ],
255
+ "WAN-2.2-I2V-Double-Blowjob": [
256
+ "double blowjob", "double bj", "two men blowjob", "two cocks in her mouth",
257
+ "both cocks", "double facefuck", "two men facefuck", "double blow job",
258
+ ],
259
+ # ── cowgirl / riding ──
260
+ "Blink_Squatting_Cowgirl_Position_I2V": [
261
+ "squatting cowgirl", "squat cowgirl", "squatting on his cock", "squat position",
262
+ "squatting ride", "squat riding",
263
+ ],
264
+ "Reverse Cowgirl v2": [
265
+ "reverse cowgirl", "reverse cowgirl position", "cowgirl facing away",
266
+ "riding backwards", "facing away riding", "cowgirl facing the feet",
267
+ ],
268
+ # ── doggystyle family ──
269
+ "iGoon - Blink_Back_Doggystyle": [
270
+ "back doggystyle", "doggystyle from behind", "rear doggy", "doggy from the back",
271
+ "doggystyle from the back", "rear entry doggy", "doggy from behind",
272
+ ],
273
+ "iGoon - Blink_Front_Doggystyle_I2V": [
274
+ "front doggystyle", "front doggy", "doggystyle facing the camera",
275
+ "front facing doggy", "doggy facing camera", "doggy facing her",
276
+ ],
277
+ "Fucked From Behind": [
278
+ "sex from behind", "fucked from behind", "bent over gripping", "taking it from behind",
279
+ "pounding from behind", "grabbing her hips from behind", "from behind while standing",
280
+ ],
281
+ "Prone Bone": [
282
+ "prone bone", "pronebone", "prone position", "lying flat on her stomach",
283
+ "flat on the bed face down", "lying under him face down",
284
+ ],
285
+ "sfbehind_v2.1": [
286
+ "sfbehind", "sfb3hind", "bent over at the waist", "bent over", "bent forward",
287
+ "leaning over the bed", "bent over the edge",
288
+ ],
289
+ "mql_casting_sex_doggy_kneel_diagonally_behind_vagina_wan22_i2v_v1": [
290
+ "mqldgy", "diagonal doggy", "doggy diagonally", "kneeling doggy", "doggy kneel",
291
+ "diagonal behind", "diagonal doggystyle",
292
+ ],
293
+ "mql_casting_sex_spoon_wan22_i2v_v1": [
294
+ "spooning", "spoon position", "mqlspn", "spooning position", "spooning sex",
295
+ "side by side sex", "laying on their sides",
296
+ ],
297
+ "sid3l3g_transition_v2.0_H": [
298
+ "side leg", "sid3l3g", "leg transition", "side leg position", "one leg over",
299
+ "leg over his shoulder",
300
+ ],
301
+ "Doggy Slider": [
302
+ "doggy slider", "sliding in and out", "slow in and out", "in and out sliding",
303
+ "doggystyle slider", "sliding his cock in and out",
304
+ ],
305
+ # ── missionary family ──
306
+ "POV Missionary": [
307
+ "pov missionary", "pov missionary position", "missionary pov", "point of view missionary",
308
+ ],
309
+ "iGoon - Blink_Missionary_I2V": [
310
+ "missionary", "missionary position", "face to face sex", "man on top",
311
+ "lying on top of her",
312
+ ],
313
+ "iGoon_Blink_Missionary_I2V": [
314
+ "deep missionary", "missionary deep", "ankles over shoulders", "legs over his shoulders",
315
+ "legs on his shoulders", "deep penetration missionary", "pinned her legs back",
316
+ ],
317
+ "Mating Press": [
318
+ "mating press", "matingpress", "folded in half", "legs pushed to her chest",
319
+ "pressed against his chest", "legs folded up",
320
+ ],
321
+ "Reverse Suspended Congress": [
322
+ "reverse suspended congress", "suspended congress", "reverse suspended",
323
+ "suspended congress position", "suspended in the air",
324
+ ],
325
+ "Standing Upright Sex": [
326
+ "standing sex", "upright sex", "standing against the wall", "standing position",
327
+ "standing pressed against the wall", "upright against wall", "standing doggy",
328
+ "sex while standing",
329
+ ],
330
+ # ── oral on her / fingering ──
331
+ "Cunnilingus": [
332
+ "cunnilingus", "eating her out", "eating pussy", "licking her pussy",
333
+ "licking her clit", "tongue on her pussy", "eating her cunt", "licking her slit",
334
+ "muff diving", "going down on her",
335
+ ],
336
+ "Fingering": [
337
+ "fingering", "fingers her", "finger her pussy", "fingers inside her",
338
+ "playing with her pussy", "finger her", "rub her clit", "fingering her pussy",
339
+ ],
340
+ "Oral Insertion": [
341
+ "oral insertion", "oral insert", "tip of his cock", "just the tip",
342
+ "cock at her entrance", "penis head at", "inserting the tip",
343
+ ],
344
+ "Handjob": [
345
+ "handjob", "hand job", "jerking him off", "jerking", "stroking his cock",
346
+ "stroking his dick", "pumping his cock", "hand around his cock",
347
+ "jerking him", "stroke him off", "handjob with her hand",
348
+ ],
349
+ "Balls Sucking": [
350
+ "balls sucking", "sucking his balls", "ball sucking", "licking his balls",
351
+ "balls in her mouth", "sucking his testicles", "sucking his sack",
352
+ ],
353
+ "iGoon_Blink_Titjob_I2V": [
354
+ "titjob", "tit job", "titty fuck", "tittyfuck", "between her breasts",
355
+ "cock between her tits", "tits around his cock", "boobjob", "breast job",
356
+ "squeezing his cock between her breasts", "cock between her boobs",
357
+ ],
358
+ # ── cum family ──
359
+ "Cum (generic)": [
360
+ "cumshot", "cum shot", "shooting his load", "ejaculates", "ejaculation",
361
+ "cumming on", "load on her", "shoots his cum", "cum bursting",
362
+ ],
363
+ "Facesplash Cumshot": [
364
+ "facesplash", "cum on her face", "cum on face", "facial cumshot",
365
+ "load on her face", "cum across her face", "cum on her face and mouth",
366
+ ],
367
+ "iGoon - Blink_Facial_I2V": [
368
+ "facial", "cum across her face", "cum on her face", "facial cumshot",
369
+ "cums on her face", "facial finish",
370
+ ],
371
+ "Pornmaster_wan 2.2_14b_I2V_bukkake_v1.4": [
372
+ "bukkake", "multiple men cum", "group cumshot", "cum bath", "gangbang cumshot",
373
+ "many men cumming",
374
+ ],
375
+ "Creampie CRM": [
376
+ "creampie", "cum inside her", "cum inside", "internal cumshot", "load inside her",
377
+ "cum inside her pussy", "creampie shot",
378
+ ],
379
+ "Pornmaster Creampie": [
380
+ "pornmaster creampie", "detailed creampie", "extreme creampie",
381
+ ],
382
+ # ── size / penis focus ──
383
+ "Biggest Cock (size)": [
384
+ "biggest cock", "huge cock", "massive cock", "big cock", "enormous cock",
385
+ "giant cock", "monster cock", "thick cock", "long cock", "massive penis",
386
+ ],
387
+ "PENISLORA_22_i2v_HIGH_e320": [
388
+ "erect penis", "cock close up", "penis close up", "penis focus", "cock detail",
389
+ "penis detail", "cock closeup", "penis closeup", "focus on his cock",
390
+ ],
391
+ # ── pussy / penetration ──
392
+ "Pussy Helper": [
393
+ "pussy spread", "spread her pussy", "pussy helper", "rub her vagina",
394
+ "opens her pussy", "spreading her", "pussy spread open",
395
+ ],
396
+ "wan2.2_i2v_high_ulitmate_pussy_asshole": [
397
+ "pussy and asshole", "asshole focus", "pussy and anus", "asshole spread",
398
+ "anus focus", "pussy and ass", "both holes",
399
+ ],
400
+ "Penetration Insert": [
401
+ "penetration insert", "moment of entry", "penetrating her", "entering her",
402
+ "sliding inside her", "first penetration", "cock entering", "sliding in",
403
+ "penetration close up", "thrusting into her pussy", "thrusting into and out of her",
404
+ "thrusting in and out of her pussy", "thrusts into her pussy",
405
+ "penetrating her pussy", "entering her pussy",
406
+ ],
407
+ # ── expressions / foreplay ──
408
+ "Ahegao Drooling": [
409
+ "ahegao", "tongue out eyes rolled", "ahegao face", "tongue out", "eyes rolled back",
410
+ "drooling", "tongue hanging out", "brain melt", "pleasure overload face",
411
+ ],
412
+ "French Kiss": [
413
+ "french kiss", "tongues intertwined", "making out", "tongues together",
414
+ "kissing tongues", "deep kiss", "open mouth kiss",
415
+ ],
416
+ "Twerking": [
417
+ "twerking", "twerk", "shaking her ass", "bounce her ass", "booty shake",
418
+ "ass shaking", "twerk on him",
419
+ ],
420
+ "mql_massage_tits_wan22_i2v_v1": [
421
+ "breast massage", "massage her tits", "boob massage", "massaging her breasts",
422
+ "cupping her breasts", "fondling her breasts", "kneading her tits", "groping her tits",
423
+ ],
424
+ "mql_panties_aside_wan22_i2v_v1": [
425
+ "panties aside", "panties to the side", "pulled to one side", "panties pulled aside",
426
+ "pulling her panties aside", "knickers aside", "panties to the side",
427
+ ],
428
+ # ── camera / scene effects ──
429
+ "FOV Slider (camera)": [
430
+ "camera zooms", "push in", "fov slider", "zoom", "zoom in", "push in close",
431
+ "camera pushes in", "fov change", "close up on",
432
+ ],
433
+ "Smashcut (camera)": [
434
+ "smashcut", "sm4shcut", "jump cut", "quick cut", "hard cut", "instant cut",
435
+ "abrupt cut", "no transition", "no morphing", "no blending", "no fade",
436
+ "hard cut to", "instant cut to",
437
+ ],
438
+ "W22_Multiscene_Photoshoot_Softcore_i2v": [
439
+ "softcore", "photoshoot", "posing provocatively", "glamour photoshoot",
440
+ "posing for the camera", "studio photoshoot",
441
+ ],
442
+ # ── generic sex / scene quality ──
443
+ "General NSFW Booster": [
444
+ "having sex", "have sex", "sexual intercourse", "intercourse", "making love",
445
+ "fucking her", "fucking him", "fucking each other", "hardcore sex", "rough sex",
446
+ "sex scene", "porn scene",
447
+ ],
448
+ }
449
+
450
+
451
+ # ── Concept categories for auto-activation dedupe ─────────────────────────
452
+ # LoRAs of the same type are grouped so at most ONE fires per category:
453
+ # no double blowjob, no double doggystyle, no double sex LoRA, etc.
454
+ # When several LoRAs in a category match, the one with the HIGHEST ICF score
455
+ # wins (not the longest keyword).
456
+ LORA_AUTO_CATEGORIES = {
457
+ "oral": [
458
+ "Ultimate Deepthroat",
459
+ "BBC Deepthroat",
460
+ "Throat V2",
461
+ "wan22-mouthfull-140epoc-high-k3nk",
462
+ "BBC Blowjob Extreme",
463
+ "POV Blowjob",
464
+ "iGOON_Blink_Blowjob_I2V",
465
+ "lips-bj",
466
+ "WAN-2.2-I2V-SensualTeasingBlowjob",
467
+ "WAN-2.2-I2V-HandjobBlowjobCombo",
468
+ "WAN-2.2-I2V-Double-Blowjob",
469
+ "Oral Insertion",
470
+ ],
471
+ "handjob": ["Handjob"],
472
+ "balls": ["Balls Sucking"],
473
+ "titjob": ["iGoon_Blink_Titjob_I2V"],
474
+ "cunnilingus": ["Cunnilingus"],
475
+ "fingering": ["Fingering"],
476
+ "cowgirl": ["Blink_Squatting_Cowgirl_Position_I2V", "Reverse Cowgirl v2"],
477
+ "doggystyle": [
478
+ "iGoon - Blink_Back_Doggystyle",
479
+ "iGoon - Blink_Front_Doggystyle_I2V",
480
+ "Fucked From Behind",
481
+ "Prone Bone",
482
+ "sfbehind_v2.1",
483
+ "mql_casting_sex_doggy_kneel_diagonally_behind_vagina_wan22_i2v_v1",
484
+ "mql_casting_sex_spoon_wan22_i2v_v1",
485
+ "sid3l3g_transition_v2.0_H",
486
+ "Doggy Slider",
487
+ ],
488
+ "missionary": [
489
+ "iGoon - Blink_Missionary_I2V",
490
+ "iGoon_Blink_Missionary_I2V",
491
+ "POV Missionary",
492
+ "Mating Press",
493
+ "Reverse Suspended Congress",
494
+ "Standing Upright Sex",
495
+ ],
496
+ "cumshot": [
497
+ "Cum (generic)",
498
+ "Facesplash Cumshot",
499
+ "iGoon - Blink_Facial_I2V",
500
+ "Pornmaster_wan 2.2_14b_I2V_bukkake_v1.4",
501
+ ],
502
+ "creampie": ["Creampie CRM", "Pornmaster Creampie"],
503
+ "penis": ["Biggest Cock (size)", "PENISLORA_22_i2v_HIGH_e320"],
504
+ "pussy": [
505
+ "Pussy Helper",
506
+ "wan2.2_i2v_high_ulitmate_pussy_asshole",
507
+ "Penetration Insert",
508
+ ],
509
+ "foreplay": [
510
+ "Ahegao Drooling",
511
+ "French Kiss",
512
+ "Twerking",
513
+ "mql_massage_tits_wan22_i2v_v1",
514
+ "mql_panties_aside_wan22_i2v_v1",
515
+ ],
516
+ "camera": [
517
+ "FOV Slider (camera)",
518
+ "Smashcut (camera)",
519
+ "W22_Multiscene_Photoshoot_Softcore_i2v",
520
+ ],
521
+ "generic": ["General NSFW Booster"],
522
+ }
523
+
524
+ # Extra phrases a LoRA must additionally see in the prompt (ANY match).
525
+ # Smashcut only fires when the cut leads to a scene of a man thrusting
526
+ # into her pussy — matching its replacement prompt "SM4SHCUT, the scene
527
+ # changes and a man is thrusting his penis into and out of her pussy".
528
+ LORA_AUTO_REQUIRES = {
529
+ "Smashcut (camera)": [
530
+ "thrusting his penis into and out of her pussy",
531
+ "thrusting his cock into and out of her pussy",
532
+ "thrusting into and out of her pussy",
533
+ "penis into and out of her pussy",
534
+ "cock into and out of her pussy",
535
+ "in and out of her pussy",
536
+ "thrusting into her pussy",
537
+ "pounding her pussy",
538
+ "fucking her pussy",
539
+ ],
540
+ }
541
+
542
+
543
+ # ── ICF weights (computed once at import) ─────────────────────────────────
544
+ # A phrase's inverse-concept-frequency (ICF) is log(N / (1 + k)) where N is the
545
+ # number of LoRAs that carry trigger phrases and k is the number of those LoRAs
546
+ # containing the phrase. A phrase unique to one LoRA (e.g. "deepthroat") gets a
547
+ # high weight (~3.28); a phrase shared by many LoRAs gets a low weight. This is
548
+ # the principled replacement for the old "longest keyword wins" heuristic.
549
+ _phrase_to_groups = {}
550
+ for _g, _phrases in LORA_AUTO_PHRASES.items():
551
+ for _p in _phrases:
552
+ _np = _normalize(_p)
553
+ _phrase_to_groups.setdefault(_np, set()).add(_g)
554
+ _phrase_icf = {}
555
+ _total_phrase_groups = len(LORA_AUTO_PHRASES)
556
+ for _np, _groups in _phrase_to_groups.items():
557
+ _phrase_icf[_np] = math.log(_total_phrase_groups / (1.0 + len(_groups)))
558
+
559
+ # Per-group list of unique NORMALIZED phrases (deduped so "facefuck" and
560
+ # "face-fuck" — which normalize identically — are not double-counted). The
561
+ # stored entries keep the padded _normalize() form for ICF lookup; matching
562
+ # strips the padding so inflected variants still hit (see auto_activation_details).
563
+ _NORM_PHRASES_BY_GROUP = {}
564
+ for _g in LORA_AUTO_PHRASES:
565
+ _seen = []
566
+ for _p in LORA_AUTO_PHRASES[_g]:
567
+ _np = _normalize(_p)
568
+ if _np not in _seen:
569
+ _seen.append(_np)
570
+ _NORM_PHRASES_BY_GROUP[_g] = _seen
571
+
572
+ # Minimum score a group needs to auto-activate. A single distinctive phrase
573
+ # ("deepthroat") scores ~3.28; even the most shared phrase in the current table
574
+ # still scores > 2.5, so 0.35 only guards against stray low-weight/shared
575
+ # phrases leaking through.
576
+ AUTO_SCORE_THRESHOLD = 0.35
577
+
578
+
579
+ def auto_activation_details(prompt):
580
+ """Score every LoRA group against the prompt and return activation details.
581
+
582
+ Returns a list of dicts (one per activated LoRA), sorted by descending
583
+ score:
584
+ {"group": <name>, "score": <rounded float>, "matched": [phrases...]}
585
+
586
+ Matching runs on the _normalize()d prompt. Each LoRA's score is the sum of
587
+ the ICF weights of every phrase present in the prompt. Groups with
588
+ LORA_AUTO_REQUIRES entries additionally need at least one require phrase
589
+ (ANY-match) or they are excluded. Results are deduped per concept category
590
+ so at most one LoRA per category fires — the highest-scoring group wins.
591
+ LoRAs that have phrases but appear in no category are treated as their own
592
+ category. Empty/None prompts return [].
593
+ """
594
+ if not prompt:
595
+ return []
596
+ text = _normalize(prompt)
597
+
598
+ scored = [] # (score, group, matched_phrases)
599
+ for group, phrases in _NORM_PHRASES_BY_GROUP.items():
600
+ matched = []
601
+ score = 0.0
602
+ for np in phrases:
603
+ # Match the normalized phrase (padding stripped) as a substring of
604
+ # the padded normalized prompt. The prompt's surrounding spaces keep
605
+ # matches token-safe, while the unpadded phrase still catches
606
+ # morphological variants: "deepthroat" matches "deepthroats",
607
+ # "piston" matches "pistoning", "face fuck" matches "face fucks".
608
+ inner = np.strip()
609
+ if inner in text:
610
+ matched.append(inner)
611
+ score += _phrase_icf[np]
612
+ if not matched:
613
+ continue
614
+ reqs = LORA_AUTO_REQUIRES.get(group)
615
+ if reqs and not any(_normalize(r).strip() in text for r in reqs):
616
+ continue
617
+ scored.append((score, group, matched))
618
+
619
+ # Dedupe by concept category: at most one (highest-scoring) group per
620
+ # category. Groups without a category become their own category.
621
+ cat_groups = {}
622
+ for cat, groups in LORA_AUTO_CATEGORIES.items():
623
+ members = [g for g in groups if g in LORA_AUTO_PHRASES]
624
+ if members:
625
+ cat_groups[cat] = members
626
+ covered = set(g for members in cat_groups.values() for g in members)
627
+ for g in LORA_AUTO_PHRASES:
628
+ if g not in covered:
629
+ cat_groups[g] = [g]
630
+
631
+ results = []
632
+ for members in cat_groups.values():
633
+ best = None
634
+ for score, group, matched in scored:
635
+ if group in members and (best is None or score > best[0]):
636
+ best = (score, group, matched)
637
+ if best and best[0] >= AUTO_SCORE_THRESHOLD:
638
+ results.append({"group": best[1], "score": round(best[0], 3), "matched": best[2]})
639
+
640
+ results.sort(key=lambda d: (-d["score"], d["group"]))
641
+ return results
642
+
643
+
644
+ def auto_activate_loras(prompt):
645
+ """Return the LoRA group names to auto-activate for the prompt."""
646
+ return [d["group"] for d in auto_activation_details(prompt)]
647
+
648
+
649
+ # ── Full replacement prompts for each LoRA ────────────────────────────────
650
+ # When a LoRA is selected, its trigger words are prepended to the user's
651
+ # prompt. Format: [TRIGGER]; [SUBJECT], [MOTION], [CAMERA], [SCENE]
652
+ # (80–120 words, Wan 2.2 4-layer formula — early tokens weighted most)
653
+
654
+ LORA_PROMPT_TRIGGERS = {
655
+
656
+ "Ahegao Drooling":
657
+ "ahegao face drooling, a woman shows her middle finger flipping off the viewer, sticks out her "
658
+ "tongue and rolls her eyes, she is drooling",
659
+
660
+ "BBC Blowjob Extreme":
661
+ "bbc extreme blowjob, a woman with glossy lips stretching her mouth around a large thick black "
662
+ "erect penis",
663
+
664
+ "BBC Deepthroat":
665
+ "deep throat blowjob, a woman in front of a large thick black penis, she "
666
+ "swallows the thick penis all the way",
667
+
668
+ "Balls Sucking":
669
+ "balls sucking, a woman with her lips wrapped around a man's testicles sucking",
670
+
671
+ "Biggest Cock (size)":
672
+ "biggest cock huge penis, an extraordinarily large erect penis with extreme length and girth",
673
+
674
+ "Blink_Squatting_Cowgirl_Position_I2V":
675
+ "squatting cowgirl position, a thick woman with thick thighs squatting over a man's erect penis",
676
+
677
+ "Creampie CRM":
678
+ "creampie, a woman with legs spread wide after intercourse",
679
+
680
+ "Cum (generic)":
681
+ "cumshot, a man ejaculating thick ropes of semen from his erect penis",
682
+
683
+ "Cunnilingus":
684
+ "cunnilingus, a woman lying back with her legs spread wide, a man's head between her thighs",
685
+
686
+ "Doggy Front View v2":
687
+ "front doggystyle, front doggystyle position, a woman on hands and knees facing the camera with a "
688
+ "man kneeling behind her",
689
+
690
+ "Doggy Slider":
691
+ "doggy slider, a man sliding his cock in and out of a woman from behind in "
692
+ "doggy style",
693
+
694
+ "FOV Slider (camera)":
695
+ "the camera zooms out while she is having sex, the camera pushes in very tight on "
696
+ "the action then pulls back",
697
+
698
+ "Facesplash Cumshot":
699
+ "f4c3spl4sh, a woman kneeling eyes closed mouth open",
700
+
701
+ "Fingering":
702
+ "sensual_fingering, fingering, a woman lying back with her legs spread",
703
+
704
+ "French Kiss":
705
+ "french kiss, a man and woman already kissing deeply mouths locked together",
706
+
707
+ "Fucked From Behind":
708
+ "sex from behind, a woman bent over gripping her ankles as a man stands behind her",
709
+
710
+ "General NSFW Booster":
711
+ "nsfwsks, highly detailed realistic scene with sharp focus and vivid textures",
712
+
713
+ "Handjob":
714
+ "handjob, a woman's hand with manicured nails wrapped around an erect penis",
715
+
716
+ "JFJ Deepthroat":
717
+ "blowjob, deepthroat",
718
+
719
+ "Mating Press":
720
+ "mating press, a small woman folded in half with her knees pressed to her chest",
721
+
722
+ "Oral Insertion":
723
+ "oral insertion, a woman with parted lips taking the tip of an erect penis into her "
724
+ "mouth",
725
+
726
+ "PENISLORA_22_i2v_HIGH_e320":
727
+ "erect penis focus, a fully erect penis standing upright with prominent veins and flared glans",
728
+
729
+ "PENISLORA_22_i2v_LOW_e496":
730
+ "erect penis focus, a fully erect penis standing upright with prominent veins and flared glans",
731
+
732
+ "POV Blowjob":
733
+ "pov blowjob, the view from a man lying back watching a woman descend onto his erect "
734
+ "penis",
735
+
736
+ "POV Missionary":
737
+ "pov missionary, missionary position, the view from a man's perspective looking down at a woman beneath "
738
+ "him",
739
+
740
+ "Penetration Insert":
741
+ "penetration insertion, the moment of entry as an erect penis drives into a wet vagina",
742
+
743
+ "Pornmaster Creampie":
744
+ "pornmaster creampie, a woman's vulva filled with semen already leaking onto her thighs",
745
+
746
+ "Pornmaster_wan 2.2_14b_I2V_bukkake_v1.4":
747
+ "pornmaster bukkake, a woman, after a completely black screen, the camera quickly switches and excessive sperm "
748
+ "on her face, excessive sperm on her hair",
749
+
750
+ "Prone Bone":
751
+ "prone bone position, a woman lying flat on her stomach with a man lying on top "
752
+ "of her",
753
+
754
+ "Pussy Helper":
755
+ "pussy spread open, she rubs her vagina with her hand, she inserts her finger into her "
756
+ "vagina",
757
+
758
+ "Reverse Cowgirl v2":
759
+ "reverse cowgirl, a woman with heavy curves straddling a man facing away from him",
760
+
761
+ "Reverse Suspended Congress":
762
+ "reverse suspended congress, a woman lying on her back with her hips raised and legs over "
763
+ "a man's shoulders",
764
+
765
+ "Smashcut (camera)":
766
+ "SM4SHCUT, the scene changes and a man is thrusting his penis into and out of her "
767
+ "pussy",
768
+
769
+ "Standing Upright Sex":
770
+ "standing sex, a woman pressed against a wall with one leg wrapped around a man's hip",
771
+
772
+ "Throat V2":
773
+ "throat fuck deep penetration, a woman gripping a man's thighs as he thrusts into her throat",
774
+
775
+ "Twerking":
776
+ "twerking, a thick woman with large buttocks bent over shaking her ass rhythmically",
777
+
778
+ "Ultimate Deepthroat":
779
+ "deep throat blowjob, a woman in front of a penis, she swallows the penis "
780
+ "all the way",
781
+
782
+ "W22_Multiscene_Photoshoot_Softcore_i2v":
783
+ "softcore photoshoot, a beautiful woman posing provocatively on a bed wearing delicate lingerie",
784
+
785
+ "WAN-2.2-I2V-Double-Blowjob":
786
+ "double blowjob, a woman kneeling between two men, their erect penises positioned on either side of "
787
+ "her face",
788
+
789
+ "WAN-2.2-I2V-HandjobBlowjobCombo":
790
+ "handjob blowjob combination, a woman with manicured nails kneeling in front of a man",
791
+
792
+ "WAN-2.2-I2V-SensualTeasingBlowjob":
793
+ "sensualBJ, a woman with glossy lips kneeling before a man, his erect penis inches from her "
794
+ "mouth",
795
+
796
+ "iGOON_Blink_Blowjob_I2V":
797
+ "blowjob, a woman kneeling in front of a man, his erect penis in front of her "
798
+ "face",
799
+
800
+ "iGoon - Blink_Back_Doggystyle":
801
+ "back doggystyle, back doggystyle position, a thick woman on all fours with her back arched deeply",
802
+
803
+ "iGoon - Blink_Facial_I2V":
804
+ "facial, a woman on her knees looking up at the camera with mouth open and tongue "
805
+ "extended",
806
+
807
+ "iGoon - Blink_Front_Doggystyle_I2V":
808
+ "front doggystyle, front doggystyle position, a woman on hands and knees facing toward the camera",
809
+
810
+ "iGoon - Blink_Missionary_I2V":
811
+ "missionary, missionary position, a woman with a lean body lying on her back with legs spread "
812
+ "wide",
813
+
814
+ "iGoon_Blink_Missionary_I2V":
815
+ "missionary position deep, a small woman lying back with her ankles hooked over a man's shoulders",
816
+
817
+ "iGoon_Blink_Titjob_I2V":
818
+ "titjob, titjob motion, a woman with heavy tits kneeling in front of a man",
819
+
820
+ "lips-bj":
821
+ "lips-bj, a woman with full prominent lips stretched taut around an erect penis",
822
+
823
+ "mql_casting_sex_doggy_kneel_diagonally_behind_vagina_wan22_i2v_v1":
824
+ "mqldgy_a, the woman is on all fours, the man is behind her",
825
+
826
+ "mql_casting_sex_reverse_cowgirl_lie_front_vagina_wan22_i2v_v1":
827
+ "reverse cowgirl, a full-figured woman straddling a man while facing his feet, leaning forward onto her "
828
+ "hands",
829
+
830
+ "mql_casting_sex_spoon_wan22_i2v_v1":
831
+ "mqlspn_a, the woman lies on her side, the man spoons behind her",
832
+
833
+ "mql_massage_tits_wan22_i2v_v1":
834
+ "breast massage, a woman with full natural breasts lying back",
835
+
836
+ "mql_panties_aside_wan22_i2v_v1":
837
+ "panties aside, a woman with her panties pulled to one side revealing her exposed vulva",
838
+
839
+ "sfbehind_v2.1":
840
+ "sfb3hind, sfbehind, a woman bent over at the waist gripping the edge of a surface",
841
+
842
+ "sid3l3g_transition_v2.0_H":
843
+ "side leg transition, a toned woman lying on her side with her top leg raised and "
844
+ "hooked",
845
+
846
+ "sid3l3g_transition_v2.0_L":
847
+ "side leg transition, a toned woman lying on her side with her top leg raised and "
848
+ "hooked",
849
+
850
+ "wan2.2_i2v_high_ulitmate_pussy_asshole":
851
+ "pussy and asshole focus, a woman's vulva and anus fully exposed, labia spread open",
852
+
853
+ "wan2.2_i2v_low_ulitmate_pussy_asshole":
854
+ "pussy and asshole focus, a woman's vulva and anus fully exposed, labia spread open",
855
+
856
+ "wan22-mouthfull-140epoc-high-k3nk":
857
+ "m0u7hfu11, a woman with her mouth completely full of a penis",
858
+
859
+ "wan22-mouthfull-152epoc-low-k3nk":
860
+ "m0u7hfu11, a woman with her mouth completely full of a penis",
861
+ }
862
+
863
+
864
+ def _get_trigger_words(prompt_text):
865
+ """Extract the activation trigger phrase from a LoRA prompt.
866
+
867
+ The trigger is the leading concept clause (everything before the first
868
+ comma or semicolon). Scene/position details later in the body are dropped
869
+ so they never override the user's own prompt.
870
+ """
871
+ text = prompt_text.strip()
872
+ for sep in (",", ";"):
873
+ idx = text.find(sep)
874
+ if idx != -1:
875
+ return text[:idx].strip()
876
+ return text
877
+
878
+
879
+ # LoRAs whose prompt body IS the effect (camera moves, generic quality
880
+ # boost) rather than a scene that conflicts with the user's prompt. These
881
+ # keep their full prompt; all other LoRAs contribute trigger words only.
882
+ LORA_KEEP_FULL_BODY = {
883
+ "FOV Slider (camera)",
884
+ "Smashcut (camera)",
885
+ "General NSFW Booster",
886
+ }
887
+
888
+
889
+ def get_lora_prompt_additions(lora_groups):
890
+ """Return the trigger phrase(s) for the selected LoRA group names.
891
+
892
+ Scene LoRAs contribute ONLY their activation trigger words (the leading
893
+ concept clause) so the user's own prompt controls the scene — a LoRA that
894
+ describes "lying back" will never override a user prompt that says
895
+ "standing up". Camera/booster LoRAs keep their full prompt because their
896
+ body is the effect itself. A single selection returns its phrase; multiple
897
+ selections join their phrases with '; ' so every selected LoRA activates.
898
+ Far under the 512-token cap.
899
+
900
+ Strips '(HIGH only)' / '(LOW only)' suffixes before lookup.
901
+ Returns empty string when no triggers are found.
902
+ """
903
+ if not lora_groups:
904
+ return ""
905
+ cleaned = []
906
+ for name in lora_groups:
907
+ if not name or not isinstance(name, str):
908
+ continue # skip None / non-string entries from the API/MCP client
909
+ n = re.sub(r'\s*\(HIGH only\)|\s*\(LOW only\)', '', name)
910
+ prompt = LORA_PROMPT_TRIGGERS.get(n)
911
+ if prompt:
912
+ cleaned.append((n, prompt))
913
+
914
+ if not cleaned:
915
+ return ""
916
+ if len(cleaned) == 1:
917
+ n, p = cleaned[0]
918
+ return p if n in LORA_KEEP_FULL_BODY else _get_trigger_words(p)
919
+
920
+ # Multiple LoRAs: join each LoRA's phrase so every LoRA activates
921
+ triggers = "; ".join(
922
+ p if n in LORA_KEEP_FULL_BODY else _get_trigger_words(p)
923
+ for n, p in cleaned
924
+ )
925
+ return triggers
926
+
927
+
928
  def download_lora(group_name):
929
  if not group_name:
930
  return None, None