Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
README.md
CHANGED
|
@@ -54,7 +54,8 @@ another video encode. Video, audio, local enhancement and joining share one heav
|
|
| 54 |
|
| 55 |
**Prepare prompt & LoRA/effects** and **Split into clips** share one selection.
|
| 56 |
Refresh browses up to **five relevant rotating suggestions**, wraps back to the beginning and
|
| 57 |
-
keeps up to **two selected adapters** ticked.
|
|
|
|
| 58 |
**Refresh does not call an AI model or request a GPU**. Suggestions are not random.
|
| 59 |
|
| 60 |
General NSFW **all-in-one / AIO** entries, including **General NSFW Booster**, stay visible on every
|
|
@@ -66,8 +67,16 @@ suggestions. Confirmed invalid entries remain excluded, including all-in-one ent
|
|
| 66 |
- Authentication errors, rate limits and timeouts do not permanently blacklist an adapter.
|
| 67 |
All-in-one choices remain visible through temporary availability failures.
|
| 68 |
- Link checks cannot prove that weights load correctly or that an effect will look good.
|
| 69 |
-
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
- Initial preparation can ask the writing model to choose suitable adapters; it can choose none.
|
| 72 |
Refresh preserves your choices and does not rewrite prompts with AI or regenerate the scene.
|
| 73 |
|
|
@@ -242,7 +251,9 @@ reduce concrete memory risks; the real restart cause still requires a live runti
|
|
| 242 |
The app still relies on the Space's existing model files, helper modules and dependencies.
|
| 243 |
Replace `app.py` and this `README.md` in the corresponding Space; this update is not a complete
|
| 244 |
standalone repository. Local checks cover reservation and resize calculations, looping LoRA selection,
|
| 245 |
-
Gradio choices,
|
|
|
|
|
|
|
| 246 |
workflow must be verified in the Space.
|
| 247 |
|
| 248 |
## Quota and credit accounting
|
|
|
|
| 54 |
|
| 55 |
**Prepare prompt & LoRA/effects** and **Split into clips** share one selection.
|
| 56 |
Refresh browses up to **five relevant rotating suggestions**, wraps back to the beginning and
|
| 57 |
+
keeps up to **two selected adapters** ticked. If both places are occupied, ticking another suggestion
|
| 58 |
+
replaces the oldest selection; the new choice is no longer silently ignored. It uses local name/trigger matching and link checks;
|
| 59 |
**Refresh does not call an AI model or request a GPU**. Suggestions are not random.
|
| 60 |
|
| 61 |
General NSFW **all-in-one / AIO** entries, including **General NSFW Booster**, stay visible on every
|
|
|
|
| 67 |
- Authentication errors, rate limits and timeouts do not permanently blacklist an adapter.
|
| 68 |
All-in-one choices remain visible through temporary availability failures.
|
| 69 |
- Link checks cannot prove that weights load correctly or that an effect will look good.
|
| 70 |
+
- **Automatic trigger sync:** selecting, replacing or clearing an adapter updates the main prompt
|
| 71 |
+
and every non-empty clip prompt. All selected adapters are loaded for each clip, so their known
|
| 72 |
+
activation words are applied consistently; prompt-word matching no longer suppresses them.
|
| 73 |
+
- The app removes only insertions it has tracked in the current session. It preserves your original
|
| 74 |
+
words, handles reordered clip lines and keeps text appended after an inserted trigger. Words
|
| 75 |
+
imported from an older profile without insertion history are treated as user-authored text.
|
| 76 |
+
- Explicit trigger metadata can come from saved catalogue entries, built-in adapter metadata or
|
| 77 |
+
CivitAI's trained words. Missing metadata is reported; the app does not invent activation words.
|
| 78 |
+
- Manual changes through LoRA Studio, the built-in/custom controls and the quick-link control
|
| 79 |
+
also sync known activation words. This uses no writing model or GPU request.
|
| 80 |
- Initial preparation can ask the writing model to choose suitable adapters; it can choose none.
|
| 81 |
Refresh preserves your choices and does not rewrite prompts with AI or regenerate the scene.
|
| 82 |
|
|
|
|
| 251 |
The app still relies on the Space's existing model files, helper modules and dependencies.
|
| 252 |
Replace `app.py` and this `README.md` in the corresponding Space; this update is not a complete
|
| 253 |
standalone repository. Local checks cover reservation and resize calculations, looping LoRA selection,
|
| 254 |
+
Gradio choices, trigger replacement in both prompt fields, manual slot changes, remote
|
| 255 |
+
authentication/retry limits, failure cleanup and real ffmpeg audio/video joins. Fifteen regression
|
| 256 |
+
tests passed, and the added event bindings were checked with Gradio 6.24.0. GPU model inference and the live browser
|
| 257 |
workflow must be verified in the Space.
|
| 258 |
|
| 259 |
## Quota and credit accounting
|
app.py
CHANGED
|
@@ -5837,7 +5837,15 @@ def _library_pool():
|
|
| 5837 |
for section in ("nsfw", "normal"):
|
| 5838 |
for item in (data.get(section) or []):
|
| 5839 |
if isinstance(item, dict) and item.get("url") and item.get("name"):
|
| 5840 |
-
pool.append({**item, "_picker_section": section
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5841 |
return pool
|
| 5842 |
|
| 5843 |
|
|
@@ -5908,20 +5916,69 @@ def _ask_which_loras(space_id, prompt_text, shortlist):
|
|
| 5908 |
return picked[:2]
|
| 5909 |
|
| 5910 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5911 |
def _add_triggers(prompt_text, items):
|
| 5912 |
-
"""Append
|
| 5913 |
text = str(prompt_text or "")
|
| 5914 |
missing = []
|
|
|
|
| 5915 |
for item in items:
|
| 5916 |
-
|
| 5917 |
-
|
| 5918 |
-
|
| 5919 |
-
|
| 5920 |
-
|
|
|
|
| 5921 |
missing.append(trigger)
|
| 5922 |
if not missing:
|
| 5923 |
return text
|
| 5924 |
-
|
|
|
|
| 5925 |
|
| 5926 |
|
| 5927 |
def _split_picks(picks):
|
|
@@ -6209,29 +6266,47 @@ def _pick_text(text, picks, sheet=False):
|
|
| 6209 |
for index, line in enumerate(lines):
|
| 6210 |
if not line.strip():
|
| 6211 |
continue
|
| 6212 |
-
|
| 6213 |
-
|
| 6214 |
-
|
| 6215 |
-
relevant = [item for item in picks if _shortlist_loras(line, [item], limit=1)]
|
| 6216 |
-
updated = _add_triggers(line, relevant)
|
| 6217 |
if updated != line:
|
| 6218 |
-
# _add_triggers normalises commas. Store the complete original suffix too.
|
| 6219 |
prefix = line.rstrip().rstrip(',')
|
| 6220 |
suffix = updated[len(prefix):] if updated.startswith(prefix) else ""
|
| 6221 |
if suffix:
|
| 6222 |
-
records.append({"line": index, "suffix": suffix, "original": line
|
|
|
|
| 6223 |
lines[index] = updated
|
| 6224 |
return "\n".join(lines), records
|
| 6225 |
|
| 6226 |
|
| 6227 |
def _pick_clean(text, records):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6228 |
lines = str(text or "").splitlines()
|
|
|
|
| 6229 |
for record in records or []:
|
| 6230 |
-
|
| 6231 |
-
|
| 6232 |
-
|
| 6233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6234 |
lines[index] = original if original.rstrip().rstrip(',') == prefix else prefix
|
|
|
|
| 6235 |
return "\n".join(lines)
|
| 6236 |
|
| 6237 |
|
|
@@ -6262,21 +6337,102 @@ def _pick_result(mode, advance, prompt_text, sheet_text, idea_text, space_id, st
|
|
| 6262 |
else:
|
| 6263 |
page = list(state.get("page") or [])
|
| 6264 |
labels = [_pick_label(i, item) for i, item in enumerate(page)]
|
| 6265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6266 |
detail = "Up to 2 selected adapters; choices are shared by prompt and scene."
|
| 6267 |
chosen = [i for i in chosen if isinstance(i, int) and 0 <= i < len(page)][:2]
|
| 6268 |
-
picks = [page[i] for i in chosen
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6269 |
labels = [_pick_label(i, item) for i, item in enumerate(page)]
|
| 6270 |
selected = [labels[i] for i, item in enumerate(page) if item in picks]
|
| 6271 |
-
|
| 6272 |
-
|
|
|
|
| 6273 |
state.update(applied=picks, prompt_added=prompt_added, sheet_added=sheet_added)
|
| 6274 |
names = ", ".join(str(item.get("name", ""))[:80] for item in picks)
|
| 6275 |
note = ("Selected: " + names + ". " if names else "No LoRA selected. ") + detail
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6276 |
note += " Link availability does not guarantee model compatibility."
|
| 6277 |
return state, page, selected, note, prompt_text, sheet_text, picks, old_picks
|
| 6278 |
|
| 6279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6280 |
def _pick_links(shortlist, picks):
|
| 6281 |
"""A link to each candidate's own page, so a name can be read up on before it is
|
| 6282 |
ticked. The page is usually saved with the entry; when it is not, the download link
|
|
@@ -6394,8 +6550,8 @@ with gr.Blocks(title="Wan 2.2 Studio | NEW AI Scene Planner · 64 Clips · 3 Aud
|
|
| 6394 |
basic_pick = gr.CheckboxGroup(
|
| 6395 |
choices=[], value=[], visible=False,
|
| 6396 |
label="Effects it chose — tick another one to swap",
|
| 6397 |
-
info="
|
| 6398 |
-
"
|
| 6399 |
)
|
| 6400 |
basic_links = gr.Markdown("")
|
| 6401 |
basic_shortlist = gr.State({})
|
|
@@ -7305,13 +7461,13 @@ with gr.Blocks(title="Wan 2.2 Studio | NEW AI Scene Planner · 64 Clips · 3 Aud
|
|
| 7305 |
if _event is not None:
|
| 7306 |
_event(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7307 |
|
| 7308 |
-
simple_lora.change(
|
| 7309 |
_apply_simple_loras, [simple_lora, simple_lora_strength], _SIMPLE_LORA_OUT
|
| 7310 |
).then(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7311 |
# One button back to nothing selected. Without it the only way out is to pick the
|
| 7312 |
# entries off one at a time, which is exactly the sort of thing that makes a person
|
| 7313 |
# decide the feature is not for them.
|
| 7314 |
-
simple_lora_clear.click(
|
| 7315 |
fn=lambda strength: [gr.update(value=[])] + _apply_simple_loras([], strength),
|
| 7316 |
inputs=[simple_lora_strength],
|
| 7317 |
outputs=[simple_lora] + _SIMPLE_LORA_OUT,
|
|
@@ -7320,11 +7476,13 @@ with gr.Blocks(title="Wan 2.2 Studio | NEW AI Scene Planner · 64 Clips · 3 Aud
|
|
| 7320 |
_apply_simple_loras, [simple_lora, simple_lora_strength], _SIMPLE_LORA_OUT
|
| 7321 |
).then(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7322 |
|
|
|
|
|
|
|
| 7323 |
# Setting a slot by hand in the advanced tab is read the same way. `.input` fires only
|
| 7324 |
# for a real click, so the panel filling these three in does not start a second pass.
|
| 7325 |
for _dropdown in (lora1_preset, lora2_preset, lora3_preset):
|
| 7326 |
_event = getattr(_dropdown, "input", None) or _dropdown.change
|
| 7327 |
-
_event(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7328 |
|
| 7329 |
# The five custom slots: on leaving a repo box, and on picking a High or Low file by
|
| 7330 |
# hand. `.input` again, so the file lists being filled in for you is not a second pass.
|
|
@@ -7336,10 +7494,10 @@ with gr.Blocks(title="Wan 2.2 Studio | NEW AI Scene Planner · 64 Clips · 3 Aud
|
|
| 7336 |
for _event_name in ("blur", "submit"):
|
| 7337 |
_event = getattr(_repo_box, _event_name, None)
|
| 7338 |
if _event is not None:
|
| 7339 |
-
_event(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7340 |
for _file_box in (_high_box, _low_box):
|
| 7341 |
_event = getattr(_file_box, "input", None) or _file_box.change
|
| 7342 |
-
_event(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7343 |
|
| 7344 |
def _quick_link(link):
|
| 7345 |
text = str(link or "").strip()
|
|
@@ -7350,10 +7508,10 @@ with gr.Blocks(title="Wan 2.2 Studio | NEW AI Scene Planner · 64 Clips · 3 Aud
|
|
| 7350 |
"<span>open ⚙️ Advanced → Custom lora to change it</span></div>")
|
| 7351 |
return gr.update(value=text), high, low, note
|
| 7352 |
|
| 7353 |
-
quick_lora_btn.click(_quick_link, [quick_lora_link],
|
| 7354 |
[my1_repo, my1_high, my1_low, simple_lora_status]
|
| 7355 |
).then(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7356 |
-
quick_lora_link.submit(_quick_link, [quick_lora_link],
|
| 7357 |
[my1_repo, my1_high, my1_low, simple_lora_status]
|
| 7358 |
).then(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7359 |
|
|
@@ -7748,8 +7906,8 @@ with gr.Blocks(title="Wan 2.2 Studio | NEW AI Scene Planner · 64 Clips · 3 Aud
|
|
| 7748 |
_basic_prepared.success(_pick_prompt, _PICK_INPUTS, _PICK_OUTPUTS, show_progress="hidden", concurrency_id="lora-picker"),
|
| 7749 |
basic_refresh_btn.click(_refresh_prompt, _PICK_INPUTS, _PICK_OUTPUTS, show_progress="minimal", concurrency_id="lora-picker"),
|
| 7750 |
scene_refresh_btn.click(_refresh_scene, _PICK_INPUTS, _PICK_OUTPUTS, show_progress="minimal", concurrency_id="lora-picker"),
|
| 7751 |
-
basic_pick.input(_swap_pick, [basic_pick, *_PICK_INPUTS], _PICK_OUTPUTS, show_progress="hidden", concurrency_id="lora-picker"),
|
| 7752 |
-
scene_pick.input(_swap_pick, [scene_pick, *_PICK_INPUTS], _PICK_OUTPUTS, show_progress="hidden", concurrency_id="lora-picker"),
|
| 7753 |
]
|
| 7754 |
for event in _pick_events:
|
| 7755 |
event.success(_read_effects, _LORA_READ_IN, _LORA_READ_OUT, show_progress="hidden")
|
|
@@ -7758,6 +7916,16 @@ with gr.Blocks(title="Wan 2.2 Studio | NEW AI Scene Planner · 64 Clips · 3 Aud
|
|
| 7758 |
_pick_scene, _PICK_INPUTS, _PICK_OUTPUTS, show_progress="hidden", concurrency_id="lora-picker")
|
| 7759 |
_scene_pick_event.success(_read_effects, _LORA_READ_IN, _LORA_READ_OUT, show_progress="hidden")
|
| 7760 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7761 |
_PRO_ONLY = [pro_promptbuilder, pro_chips, pro_speed, pro_advanced,
|
| 7762 |
pro_soundset, pro_loop]
|
| 7763 |
|
|
|
|
| 5837 |
for section in ("nsfw", "normal"):
|
| 5838 |
for item in (data.get(section) or []):
|
| 5839 |
if isinstance(item, dict) and item.get("url") and item.get("name"):
|
| 5840 |
+
pool.append({**item, "_picker_section": section,
|
| 5841 |
+
"trigger": ", ".join(_trigger_words(item))})
|
| 5842 |
+
for item in pool:
|
| 5843 |
+
if item.get("builtin"):
|
| 5844 |
+
saved = next((entry for entry in pool if not entry.get("builtin") and
|
| 5845 |
+
str(entry.get("name", "")).casefold() == item["name"].casefold()
|
| 5846 |
+
and _trigger_words(entry)), None)
|
| 5847 |
+
if saved:
|
| 5848 |
+
item["trigger"] = ", ".join(_trigger_words(saved))
|
| 5849 |
return pool
|
| 5850 |
|
| 5851 |
|
|
|
|
| 5916 |
return picked[:2]
|
| 5917 |
|
| 5918 |
|
| 5919 |
+
def _trigger_words(value):
|
| 5920 |
+
"""Read explicit activation metadata; descriptions and model names are not triggers."""
|
| 5921 |
+
if isinstance(value, dict):
|
| 5922 |
+
words = []
|
| 5923 |
+
for key in ("trigger", "triggers", "trigger_words", "trainedWords", "trained_words", "activation_words"):
|
| 5924 |
+
words.extend(_trigger_words(value.get(key)))
|
| 5925 |
+
return list(dict.fromkeys(words))
|
| 5926 |
+
if isinstance(value, (list, tuple)):
|
| 5927 |
+
return list(dict.fromkeys(word for part in value for word in _trigger_words(part)))
|
| 5928 |
+
if not isinstance(value, str):
|
| 5929 |
+
return []
|
| 5930 |
+
return list(dict.fromkeys(part.strip() for part in re.split(r"[,\n]+", value) if part.strip()))
|
| 5931 |
+
|
| 5932 |
+
|
| 5933 |
+
def _resolve_pick_triggers(item):
|
| 5934 |
+
item = dict(item)
|
| 5935 |
+
words = _trigger_words(item)
|
| 5936 |
+
if not words and item.get("builtin"):
|
| 5937 |
+
name = str(item.get("name") or "")
|
| 5938 |
+
for module in (lora_loader, lora_library):
|
| 5939 |
+
for attribute in ("LORA_INFO", "LORA_PRESETS", "PRESETS", "CATALOGUE", "CATALOG", "LIBRARY"):
|
| 5940 |
+
table = getattr(module, attribute, None)
|
| 5941 |
+
if isinstance(table, dict) and isinstance(table.get(name), dict):
|
| 5942 |
+
words.extend(_trigger_words(table[name]))
|
| 5943 |
+
for attribute in ("get_lora_info", "lora_info"):
|
| 5944 |
+
function = getattr(module, attribute, None)
|
| 5945 |
+
if callable(function):
|
| 5946 |
+
try:
|
| 5947 |
+
info = function(name)
|
| 5948 |
+
if isinstance(info, dict):
|
| 5949 |
+
words.extend(_trigger_words(info))
|
| 5950 |
+
except Exception:
|
| 5951 |
+
pass
|
| 5952 |
+
if not words:
|
| 5953 |
+
for field in ("high", "low", "url"):
|
| 5954 |
+
reference = str(item.get(field) or "")
|
| 5955 |
+
if CIVITAI_DOWNLOAD_RE.search(reference):
|
| 5956 |
+
try:
|
| 5957 |
+
_, found = describe_lora(reference)
|
| 5958 |
+
words.extend(_trigger_words(found))
|
| 5959 |
+
except Exception:
|
| 5960 |
+
pass
|
| 5961 |
+
item["trigger"] = ", ".join(dict.fromkeys(words))
|
| 5962 |
+
return item
|
| 5963 |
+
|
| 5964 |
+
|
| 5965 |
def _add_triggers(prompt_text, items):
|
| 5966 |
+
"""Append actual activation words once, without substring false positives."""
|
| 5967 |
text = str(prompt_text or "")
|
| 5968 |
missing = []
|
| 5969 |
+
seen = set()
|
| 5970 |
for item in items:
|
| 5971 |
+
for trigger in _trigger_words(item):
|
| 5972 |
+
key = trigger.casefold()
|
| 5973 |
+
if key in seen:
|
| 5974 |
+
continue
|
| 5975 |
+
seen.add(key)
|
| 5976 |
+
if not re.search(r"(?<!\w)" + re.escape(trigger) + r"(?!\w)", text, re.I):
|
| 5977 |
missing.append(trigger)
|
| 5978 |
if not missing:
|
| 5979 |
return text
|
| 5980 |
+
base = text.rstrip().rstrip(',')
|
| 5981 |
+
return f"{base}, {', '.join(missing)}" if base.strip() else ", ".join(missing)
|
| 5982 |
|
| 5983 |
|
| 5984 |
def _split_picks(picks):
|
|
|
|
| 6266 |
for index, line in enumerate(lines):
|
| 6267 |
if not line.strip():
|
| 6268 |
continue
|
| 6269 |
+
# The selected adapters are loaded for every clip. Their explicit activation
|
| 6270 |
+
# words must therefore reach every non-empty clip prompt, including general AIOs.
|
| 6271 |
+
updated = _add_triggers(line, picks)
|
|
|
|
|
|
|
| 6272 |
if updated != line:
|
|
|
|
| 6273 |
prefix = line.rstrip().rstrip(',')
|
| 6274 |
suffix = updated[len(prefix):] if updated.startswith(prefix) else ""
|
| 6275 |
if suffix:
|
| 6276 |
+
records.append({"line": index, "suffix": suffix, "original": line,
|
| 6277 |
+
"rendered": updated})
|
| 6278 |
lines[index] = updated
|
| 6279 |
return "\n".join(lines), records
|
| 6280 |
|
| 6281 |
|
| 6282 |
def _pick_clean(text, records):
|
| 6283 |
+
"""Remove owned insertions, including moved lines and text appended after a trigger.
|
| 6284 |
+
|
| 6285 |
+
Never globally replace a trigger word: it may also occur in the user's own prose.
|
| 6286 |
+
Older picker records without `rendered` remain readable.
|
| 6287 |
+
"""
|
| 6288 |
lines = str(text or "").splitlines()
|
| 6289 |
+
used = set()
|
| 6290 |
for record in records or []:
|
| 6291 |
+
suffix = record.get("suffix", "")
|
| 6292 |
+
original = record.get("original", "")
|
| 6293 |
+
rendered = record.get("rendered") or (original.rstrip().rstrip(',') + suffix)
|
| 6294 |
+
if not suffix:
|
| 6295 |
+
continue
|
| 6296 |
+
exact = [i for i, line in enumerate(lines) if i not in used and line == rendered]
|
| 6297 |
+
extended = [i for i, line in enumerate(lines) if i not in used and line.startswith(rendered)]
|
| 6298 |
+
index = (exact or extended or [record.get("line", -1)])[0]
|
| 6299 |
+
if not isinstance(index, int) or not 0 <= index < len(lines) or index in used:
|
| 6300 |
+
continue
|
| 6301 |
+
line = lines[index]
|
| 6302 |
+
if line.startswith(rendered):
|
| 6303 |
+
lines[index] = original + line[len(rendered):]
|
| 6304 |
+
used.add(index)
|
| 6305 |
+
elif line.endswith(suffix):
|
| 6306 |
+
# Keep edits made to the original sentence before our still-intact suffix.
|
| 6307 |
+
prefix = line[:-len(suffix)]
|
| 6308 |
lines[index] = original if original.rstrip().rstrip(',') == prefix else prefix
|
| 6309 |
+
used.add(index)
|
| 6310 |
return "\n".join(lines)
|
| 6311 |
|
| 6312 |
|
|
|
|
| 6337 |
else:
|
| 6338 |
page = list(state.get("page") or [])
|
| 6339 |
labels = [_pick_label(i, item) for i, item in enumerate(page)]
|
| 6340 |
+
checked = [i for i, label in enumerate(labels) if label in (ticked or [])]
|
| 6341 |
+
previous_keys = [_pick_key(item) for item in old_picks]
|
| 6342 |
+
kept = [i for key in previous_keys for i in checked if _pick_key(page[i]) == key]
|
| 6343 |
+
added = [i for i in checked if _pick_key(page[i]) not in previous_keys]
|
| 6344 |
+
# A new tick replaces the oldest held pick instead of being silently discarded.
|
| 6345 |
+
chosen = (kept + added)[-2:]
|
| 6346 |
detail = "Up to 2 selected adapters; choices are shared by prompt and scene."
|
| 6347 |
chosen = [i for i in chosen if isinstance(i, int) and 0 <= i < len(page)][:2]
|
| 6348 |
+
picks = [_resolve_pick_triggers(page[i]) for i in chosen
|
| 6349 |
+
if _health_read(_pick_key(page[i])).get("status") != "bad"]
|
| 6350 |
+
resolved = {_pick_key(item): item for item in picks}
|
| 6351 |
+
page = [resolved.get(_pick_key(item), item) for item in page]
|
| 6352 |
+
state["page"] = page
|
| 6353 |
labels = [_pick_label(i, item) for i, item in enumerate(page)]
|
| 6354 |
selected = [labels[i] for i, item in enumerate(page) if item in picks]
|
| 6355 |
+
active = picks + list(state.get("extra_picks") or [])
|
| 6356 |
+
prompt_text, prompt_added = _pick_text(prompt_text, active)
|
| 6357 |
+
sheet_text, sheet_added = _pick_text(sheet_text, active, sheet=True)
|
| 6358 |
state.update(applied=picks, prompt_added=prompt_added, sheet_added=sheet_added)
|
| 6359 |
names = ", ".join(str(item.get("name", ""))[:80] for item in picks)
|
| 6360 |
note = ("Selected: " + names + ". " if names else "No LoRA selected. ") + detail
|
| 6361 |
+
missing = [str(item.get("name", "")) for item in picks if not _trigger_words(item)]
|
| 6362 |
+
if missing:
|
| 6363 |
+
note += " No activation words available for: " + ", ".join(missing) + "."
|
| 6364 |
+
note += " Available trigger words are synced to the main prompt and every clip."
|
| 6365 |
note += " Link availability does not guarantee model compatibility."
|
| 6366 |
return state, page, selected, note, prompt_text, sheet_text, picks, old_picks
|
| 6367 |
|
| 6368 |
|
| 6369 |
+
def _slot_trigger_items(fields, state):
|
| 6370 |
+
"""Read actual adapter slots, resolving only explicit saved/API activation words."""
|
| 6371 |
+
pool = list((state or {}).get("page") or []) + list((state or {}).get("applied") or []) + _library_pool()
|
| 6372 |
+
pool.sort(key=lambda item: not bool(_trigger_words(item)))
|
| 6373 |
+
active, extras, seen = [], [], set()
|
| 6374 |
+
def remember(item, extra=False):
|
| 6375 |
+
key = _pick_key(item)
|
| 6376 |
+
if key in seen:
|
| 6377 |
+
return
|
| 6378 |
+
seen.add(key)
|
| 6379 |
+
item = _resolve_pick_triggers(item)
|
| 6380 |
+
active.append(item)
|
| 6381 |
+
if extra:
|
| 6382 |
+
extras.append(item)
|
| 6383 |
+
for name in list(fields)[:3]:
|
| 6384 |
+
if not name or name == "(None)":
|
| 6385 |
+
continue
|
| 6386 |
+
match = next((item for item in pool if str(item.get("name", "")).casefold() == str(name).casefold()), {})
|
| 6387 |
+
remember({**match, "name": str(name), "builtin": True, "url": ""})
|
| 6388 |
+
values = list(fields)[3:]
|
| 6389 |
+
for index in range(0, len(values) - 2, 3):
|
| 6390 |
+
repo, high, low = (str(value or "").strip() for value in values[index:index+3])
|
| 6391 |
+
files = [value for value in (high, low) if value and value != "(None)"]
|
| 6392 |
+
if not files:
|
| 6393 |
+
continue
|
| 6394 |
+
references = list(files)
|
| 6395 |
+
if repo and not repo.startswith(("http://", "https://")):
|
| 6396 |
+
references += [f"https://huggingface.co/{repo}/resolve/main/{file}" for file in files
|
| 6397 |
+
if not file.startswith(("http://", "https://"))]
|
| 6398 |
+
references.append(repo)
|
| 6399 |
+
match = next((item for ref in references for item in pool if not item.get("builtin") and ref and
|
| 6400 |
+
ref in [str(item.get(field) or "") for field in ("url", "high", "low")]), None)
|
| 6401 |
+
if match is None:
|
| 6402 |
+
# No inferred words from a filename: unknown metadata stays visibly unknown.
|
| 6403 |
+
source = next((ref for ref in references if ref.startswith(("http://", "https://"))), repo + "/" + files[0])
|
| 6404 |
+
match = {"name": files[0].rsplit("/", 1)[-1], "url": source, "high": high, "low": low}
|
| 6405 |
+
remember(match, extra=index >= 6) # Guided picks replace custom slots 1 and 2 only.
|
| 6406 |
+
return active, extras
|
| 6407 |
+
|
| 6408 |
+
|
| 6409 |
+
def _sync_slot_triggers(prompt_text, sheet_text, state, *slot_fields):
|
| 6410 |
+
"""One local update for manual changes; never ask a writing model."""
|
| 6411 |
+
import copy
|
| 6412 |
+
state = copy.deepcopy(state) if isinstance(state, dict) else {}
|
| 6413 |
+
active, extras = _slot_trigger_items(slot_fields, state)
|
| 6414 |
+
prompt_text = _pick_clean(prompt_text, state.get("prompt_added"))
|
| 6415 |
+
sheet_text = _pick_clean(sheet_text, state.get("sheet_added"))
|
| 6416 |
+
prompt_text, prompt_added = _pick_text(prompt_text, active)
|
| 6417 |
+
sheet_text, sheet_added = _pick_text(sheet_text, active, sheet=True)
|
| 6418 |
+
active_keys = {_pick_key(item) for item in active}
|
| 6419 |
+
page = list(state.get("page") or [])
|
| 6420 |
+
resolved = {_pick_key(item): item for item in active}
|
| 6421 |
+
page = [resolved.get(_pick_key(item), item) for item in page]
|
| 6422 |
+
held_keys = [_pick_key(item) for item in state.get("applied", []) if _pick_key(item) in active_keys]
|
| 6423 |
+
held_keys += [_pick_key(item) for item in page if _pick_key(item) in active_keys and
|
| 6424 |
+
_pick_key(item) not in held_keys]
|
| 6425 |
+
held = [resolved[key] for key in held_keys[:2]]
|
| 6426 |
+
labels = [_pick_label(i, item) for i, item in enumerate(page)]
|
| 6427 |
+
selected = [labels[i] for i, item in enumerate(page) if item in held]
|
| 6428 |
+
state.update(page=page, applied=held, extra_picks=extras, prompt_added=prompt_added, sheet_added=sheet_added)
|
| 6429 |
+
# Choice labels can change when metadata is resolved. Always send matching choices/value,
|
| 6430 |
+
# and give each panel its own update object.
|
| 6431 |
+
def update():
|
| 6432 |
+
return gr.update(choices=list(labels), value=list(selected), visible=bool(page))
|
| 6433 |
+
return prompt_text, sheet_text, state, update(), update()
|
| 6434 |
+
|
| 6435 |
+
|
| 6436 |
def _pick_links(shortlist, picks):
|
| 6437 |
"""A link to each candidate's own page, so a name can be read up on before it is
|
| 6438 |
ticked. The page is usually saved with the entry; when it is not, the download link
|
|
|
|
| 6550 |
basic_pick = gr.CheckboxGroup(
|
| 6551 |
choices=[], value=[], visible=False,
|
| 6552 |
label="Effects it chose — tick another one to swap",
|
| 6553 |
+
info="Up to two selected. A new tick replaces the oldest selection when full. "
|
| 6554 |
+
"Known trigger words update the main prompt and every clip automatically.",
|
| 6555 |
)
|
| 6556 |
basic_links = gr.Markdown("")
|
| 6557 |
basic_shortlist = gr.State({})
|
|
|
|
| 7461 |
if _event is not None:
|
| 7462 |
_event(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7463 |
|
| 7464 |
+
_simple_lora_event = simple_lora.change(
|
| 7465 |
_apply_simple_loras, [simple_lora, simple_lora_strength], _SIMPLE_LORA_OUT
|
| 7466 |
).then(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7467 |
# One button back to nothing selected. Without it the only way out is to pick the
|
| 7468 |
# entries off one at a time, which is exactly the sort of thing that makes a person
|
| 7469 |
# decide the feature is not for them.
|
| 7470 |
+
_simple_lora_clear_event = simple_lora_clear.click(
|
| 7471 |
fn=lambda strength: [gr.update(value=[])] + _apply_simple_loras([], strength),
|
| 7472 |
inputs=[simple_lora_strength],
|
| 7473 |
outputs=[simple_lora] + _SIMPLE_LORA_OUT,
|
|
|
|
| 7476 |
_apply_simple_loras, [simple_lora, simple_lora_strength], _SIMPLE_LORA_OUT
|
| 7477 |
).then(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7478 |
|
| 7479 |
+
_manual_lora_events = [_simple_lora_event, _simple_lora_clear_event]
|
| 7480 |
+
|
| 7481 |
# Setting a slot by hand in the advanced tab is read the same way. `.input` fires only
|
| 7482 |
# for a real click, so the panel filling these three in does not start a second pass.
|
| 7483 |
for _dropdown in (lora1_preset, lora2_preset, lora3_preset):
|
| 7484 |
_event = getattr(_dropdown, "input", None) or _dropdown.change
|
| 7485 |
+
_manual_lora_events.append(_event(_read_effects, _LORA_READ_IN, _LORA_READ_OUT))
|
| 7486 |
|
| 7487 |
# The five custom slots: on leaving a repo box, and on picking a High or Low file by
|
| 7488 |
# hand. `.input` again, so the file lists being filled in for you is not a second pass.
|
|
|
|
| 7494 |
for _event_name in ("blur", "submit"):
|
| 7495 |
_event = getattr(_repo_box, _event_name, None)
|
| 7496 |
if _event is not None:
|
| 7497 |
+
_manual_lora_events.append(_event(_read_effects, _LORA_READ_IN, _LORA_READ_OUT))
|
| 7498 |
for _file_box in (_high_box, _low_box):
|
| 7499 |
_event = getattr(_file_box, "input", None) or _file_box.change
|
| 7500 |
+
_manual_lora_events.append(_event(_read_effects, _LORA_READ_IN, _LORA_READ_OUT))
|
| 7501 |
|
| 7502 |
def _quick_link(link):
|
| 7503 |
text = str(link or "").strip()
|
|
|
|
| 7508 |
"<span>open ⚙️ Advanced → Custom lora to change it</span></div>")
|
| 7509 |
return gr.update(value=text), high, low, note
|
| 7510 |
|
| 7511 |
+
_quick_lora_event = quick_lora_btn.click(_quick_link, [quick_lora_link],
|
| 7512 |
[my1_repo, my1_high, my1_low, simple_lora_status]
|
| 7513 |
).then(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7514 |
+
_quick_lora_submit_event = quick_lora_link.submit(_quick_link, [quick_lora_link],
|
| 7515 |
[my1_repo, my1_high, my1_low, simple_lora_status]
|
| 7516 |
).then(_read_effects, _LORA_READ_IN, _LORA_READ_OUT)
|
| 7517 |
|
|
|
|
| 7906 |
_basic_prepared.success(_pick_prompt, _PICK_INPUTS, _PICK_OUTPUTS, show_progress="hidden", concurrency_id="lora-picker"),
|
| 7907 |
basic_refresh_btn.click(_refresh_prompt, _PICK_INPUTS, _PICK_OUTPUTS, show_progress="minimal", concurrency_id="lora-picker"),
|
| 7908 |
scene_refresh_btn.click(_refresh_scene, _PICK_INPUTS, _PICK_OUTPUTS, show_progress="minimal", concurrency_id="lora-picker"),
|
| 7909 |
+
basic_pick.input(_swap_pick, [basic_pick, *_PICK_INPUTS], _PICK_OUTPUTS, show_progress="hidden", concurrency_id="lora-picker", trigger_mode="always_last"),
|
| 7910 |
+
scene_pick.input(_swap_pick, [scene_pick, *_PICK_INPUTS], _PICK_OUTPUTS, show_progress="hidden", concurrency_id="lora-picker", trigger_mode="always_last"),
|
| 7911 |
]
|
| 7912 |
for event in _pick_events:
|
| 7913 |
event.success(_read_effects, _LORA_READ_IN, _LORA_READ_OUT, show_progress="hidden")
|
|
|
|
| 7916 |
_pick_scene, _PICK_INPUTS, _PICK_OUTPUTS, show_progress="hidden", concurrency_id="lora-picker")
|
| 7917 |
_scene_pick_event.success(_read_effects, _LORA_READ_IN, _LORA_READ_OUT, show_progress="hidden")
|
| 7918 |
|
| 7919 |
+
_TRIGGER_INPUTS = [prompt_input, scene_prompts, basic_shortlist,
|
| 7920 |
+
lora1_preset, lora2_preset, lora3_preset,
|
| 7921 |
+
my1_repo, my1_high, my1_low, my2_repo, my2_high, my2_low,
|
| 7922 |
+
my3_repo, my3_high, my3_low, my4_repo, my4_high, my4_low,
|
| 7923 |
+
my5_repo, my5_high, my5_low]
|
| 7924 |
+
_TRIGGER_OUTPUTS = [prompt_input, scene_prompts, basic_shortlist, basic_pick, scene_pick]
|
| 7925 |
+
for event in [*_manual_lora_events, _quick_lora_event, _quick_lora_submit_event]:
|
| 7926 |
+
event.success(_sync_slot_triggers, _TRIGGER_INPUTS, _TRIGGER_OUTPUTS,
|
| 7927 |
+
show_progress="hidden", concurrency_id="lora-picker", trigger_mode="always_last")
|
| 7928 |
+
|
| 7929 |
_PRO_ONLY = [pro_promptbuilder, pro_chips, pro_speed, pro_advanced,
|
| 7930 |
pro_soundset, pro_loop]
|
| 7931 |
|