Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -4709,6 +4709,10 @@ def scene_step(state, scene_prompts, sound_on, sound_engine, sound_prompt, sound
|
|
| 4709 |
total = int(state.get("total", left))
|
| 4710 |
index = total - left
|
| 4711 |
values = list(state.get("values") or ui_values)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4712 |
if ui_values:
|
| 4713 |
values[0] = ui_values[0] # Last frame from the preceding completed clip.
|
| 4714 |
|
|
@@ -4810,9 +4814,11 @@ def scene_step(state, scene_prompts, sound_on, sound_engine, sound_prompt, sound
|
|
| 4810 |
# Commit the file and next frame before CPU stitching or a second audio booking.
|
| 4811 |
# If either operation fails, the finished clips remain accessible and resumable.
|
| 4812 |
stage = "Joining the completed scene…" if state["left"] == 0 else "Clip saved; next clip starting…"
|
|
|
|
|
|
|
| 4813 |
yield (state, video, file_path, seed,
|
| 4814 |
_scene_progress(done, total, label=stage, running=True, note=trimmed_note),
|
| 4815 |
-
gr.update(), gr.update(), queue, _queue_status(len(queue)),
|
| 4816 |
1 if state["left"] == 0 else done + 1)
|
| 4817 |
if state["left"] > 0:
|
| 4818 |
return
|
|
@@ -4822,7 +4828,7 @@ def scene_step(state, scene_prompts, sound_on, sound_engine, sound_prompt, sound
|
|
| 4822 |
yield (state, video, file_path, seed,
|
| 4823 |
"<div class='status-idle'><b>Clips completed; joining failed.</b>"
|
| 4824 |
"<span>All clips are in the queue. Use Join to retry without generating again.</span></div>",
|
| 4825 |
-
gr.update(), gr.update(), queue, _queue_status(len(queue)),
|
| 4826 |
return
|
| 4827 |
if sound_on and merged:
|
| 4828 |
yield (state, gr.update(), gr.update(), gr.update(),
|
|
@@ -4843,7 +4849,7 @@ def scene_step(state, scene_prompts, sound_on, sound_engine, sound_prompt, sound
|
|
| 4843 |
note = _scene_progress(done, total, label="Scene finished", running=False,
|
| 4844 |
note=f"{len(queue)} clip(s) joined{trimmed_note}")
|
| 4845 |
yield (state, video, file_path, seed, note, merged, _copy_update(merged), queue,
|
| 4846 |
-
_queue_status(len(queue), merged),
|
| 4847 |
|
| 4848 |
|
| 4849 |
def scene_kick(state):
|
|
@@ -5916,7 +5922,7 @@ def _pick_probe(item):
|
|
| 5916 |
return result
|
| 5917 |
|
| 5918 |
|
| 5919 |
-
def _pick_page(basis, state, advance=False):
|
| 5920 |
from concurrent.futures import ThreadPoolExecutor
|
| 5921 |
pool = _library_pool() # Read the current catalogue on every press.
|
| 5922 |
ranked = _shortlist_loras(basis, pool, limit=len(pool))
|
|
@@ -5930,7 +5936,21 @@ def _pick_page(basis, state, advance=False):
|
|
| 5930 |
same = state.get("basis") == basis
|
| 5931 |
start = int(state.get("cursor", 0)) % count if count and advance and same else 0
|
| 5932 |
ordered = unique[start:] + unique[:start]
|
| 5933 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5934 |
# Bound each refresh even if an entire remote catalogue is unavailable.
|
| 5935 |
with ThreadPoolExecutor(max_workers=LORA_PICK_PAGE) as workers:
|
| 5936 |
for offset in range(0, min(len(ordered), 20), LORA_PICK_PAGE):
|
|
@@ -5989,10 +6009,15 @@ def _pick_result(mode, advance, prompt_text, sheet_text, idea_text, space_id, st
|
|
| 5989 |
old_picks = list(state.get("applied") or [])
|
| 5990 |
if ticked is None:
|
| 5991 |
basis = prompt_text if mode == "prompt" else (str(idea_text or "").strip() + "\n" + sheet_text).strip()
|
| 5992 |
-
|
| 5993 |
-
|
|
|
|
|
|
|
|
|
|
| 5994 |
state.update(basis=basis, cursor=cursor, page=page)
|
| 5995 |
detail = f"{len(page)} suggestions shown; {skipped} unavailable entries skipped."
|
|
|
|
|
|
|
| 5996 |
if available > len(page):
|
| 5997 |
detail += " Refresh shows the next group of up to 5."
|
| 5998 |
else:
|
|
|
|
| 4709 |
total = int(state.get("total", left))
|
| 4710 |
index = total - left
|
| 4711 |
values = list(state.get("values") or ui_values)
|
| 4712 |
+
# The image the scene was started from. Kept aside so the box can be put back to it
|
| 4713 |
+
# once the scene is joined - otherwise it is left holding the last frame of the last
|
| 4714 |
+
# clip, and the next scene silently starts from the wrong picture.
|
| 4715 |
+
opening_frame = (state.get("values") or list(ui_values) or [None])[0]
|
| 4716 |
if ui_values:
|
| 4717 |
values[0] = ui_values[0] # Last frame from the preceding completed clip.
|
| 4718 |
|
|
|
|
| 4814 |
# Commit the file and next frame before CPU stitching or a second audio booking.
|
| 4815 |
# If either operation fails, the finished clips remain accessible and resumable.
|
| 4816 |
stage = "Joining the completed scene…" if state["left"] == 0 else "Clip saved; next clip starting…"
|
| 4817 |
+
closing_frame = next_frame if state["left"] > 0 else (
|
| 4818 |
+
opening_frame if opening_frame is not None else next_frame)
|
| 4819 |
yield (state, video, file_path, seed,
|
| 4820 |
_scene_progress(done, total, label=stage, running=True, note=trimmed_note),
|
| 4821 |
+
gr.update(), gr.update(), queue, _queue_status(len(queue)), closing_frame,
|
| 4822 |
1 if state["left"] == 0 else done + 1)
|
| 4823 |
if state["left"] > 0:
|
| 4824 |
return
|
|
|
|
| 4828 |
yield (state, video, file_path, seed,
|
| 4829 |
"<div class='status-idle'><b>Clips completed; joining failed.</b>"
|
| 4830 |
"<span>All clips are in the queue. Use Join to retry without generating again.</span></div>",
|
| 4831 |
+
gr.update(), gr.update(), queue, _queue_status(len(queue)), closing_frame, 1)
|
| 4832 |
return
|
| 4833 |
if sound_on and merged:
|
| 4834 |
yield (state, gr.update(), gr.update(), gr.update(),
|
|
|
|
| 4849 |
note = _scene_progress(done, total, label="Scene finished", running=False,
|
| 4850 |
note=f"{len(queue)} clip(s) joined{trimmed_note}")
|
| 4851 |
yield (state, video, file_path, seed, note, merged, _copy_update(merged), queue,
|
| 4852 |
+
_queue_status(len(queue), merged), closing_frame, 1)
|
| 4853 |
|
| 4854 |
|
| 4855 |
def scene_kick(state):
|
|
|
|
| 5922 |
return result
|
| 5923 |
|
| 5924 |
|
| 5925 |
+
def _pick_page(basis, state, advance=False, keep=None):
|
| 5926 |
from concurrent.futures import ThreadPoolExecutor
|
| 5927 |
pool = _library_pool() # Read the current catalogue on every press.
|
| 5928 |
ranked = _shortlist_loras(basis, pool, limit=len(pool))
|
|
|
|
| 5936 |
same = state.get("basis") == basis
|
| 5937 |
start = int(state.get("cursor", 0)) % count if count and advance and same else 0
|
| 5938 |
ordered = unique[start:] + unique[:start]
|
| 5939 |
+
|
| 5940 |
+
# A ticked entry stays where it is. Refresh replaces only the ones that were not
|
| 5941 |
+
# chosen, so browsing for a second effect never drops the first one.
|
| 5942 |
+
page, held = [], set()
|
| 5943 |
+
for item in (keep or []):
|
| 5944 |
+
key = _pick_key(item)
|
| 5945 |
+
if key in held or _health_read(key).get("status") == "bad":
|
| 5946 |
+
continue
|
| 5947 |
+
held.add(key)
|
| 5948 |
+
page.append(item)
|
| 5949 |
+
if len(page) >= LORA_PICK_PAGE:
|
| 5950 |
+
break
|
| 5951 |
+
ordered = [item for item in ordered if _pick_key(item) not in held]
|
| 5952 |
+
|
| 5953 |
+
checked, skipped = 0, 0
|
| 5954 |
# Bound each refresh even if an entire remote catalogue is unavailable.
|
| 5955 |
with ThreadPoolExecutor(max_workers=LORA_PICK_PAGE) as workers:
|
| 5956 |
for offset in range(0, min(len(ordered), 20), LORA_PICK_PAGE):
|
|
|
|
| 6009 |
old_picks = list(state.get("applied") or [])
|
| 6010 |
if ticked is None:
|
| 6011 |
basis = prompt_text if mode == "prompt" else (str(idea_text or "").strip() + "\n" + sheet_text).strip()
|
| 6012 |
+
held = old_picks if advance else []
|
| 6013 |
+
page, cursor, skipped, available = _pick_page(basis, state, advance, keep=held)
|
| 6014 |
+
held_keys = {_pick_key(item) for item in held}
|
| 6015 |
+
kept = [i for i, item in enumerate(page) if _pick_key(item) in held_keys]
|
| 6016 |
+
chosen = kept if kept else _ask_which_loras(space_id, basis, page)
|
| 6017 |
state.update(basis=basis, cursor=cursor, page=page)
|
| 6018 |
detail = f"{len(page)} suggestions shown; {skipped} unavailable entries skipped."
|
| 6019 |
+
if kept:
|
| 6020 |
+
detail += f" {len(kept)} kept ticked; only the unticked ones were replaced."
|
| 6021 |
if available > len(page):
|
| 6022 |
detail += " Refresh shows the next group of up to 5."
|
| 6023 |
else:
|