Spaces:
Running on Zero
Running on Zero
Upload app.py
Browse files4708 unmodified lines47094710471147124713471495 unmodified lines4810481148124813481448154816481748183 unmodified lines482248234824482548264827482814 unmodified lines48434844484548464847484848491066 unmodified lines59165917591859195920592159227 unmodified lines593059315932593359345935593652 unmodified lines59895990599159925993599459955996599759984708 unmodified linestotal = int(state.get("total", left))index = total - leftvalues = list(state.get("values") or ui_values)if ui_values:values[0] = ui_values[0] # Last frame from the preceding completed clip.95 unmodified lines# Commit the file and next frame before CPU stitching or a second audio booking.# If either operation fails, the finished clips remain accessible and resumable.stage = "Joining the completed scene…" if state["left"] == 0 else "Clip saved; next clip starting…"yield (state, video, file_path, seed,_scene_progress(done, total, label=stage, running=True, note=trimmed_note),gr.update(), gr.update(), queue, _queue_status(len(queue)), next_frame,1 if state["left"] == 0 else done + 1)if state["left"] > 0:return3 unmodified linesyield (state, video, file_path, seed,"<div class='status-idle'><b>Clips completed; joining failed.</b>""<span>All clips are in the queue. Use Join to retry without generating again.</span></div>",gr.update(), gr.update(), queue, _queue_status(len(queue)), next_frame, 1)returnif sound_on and merged:yield (state, gr.update(), gr.update(), gr.update(),14 unmodified linesnote = _scene_progress(done, total, label="Scene finished", running=False,note=f"{len(queue)} clip(s) joined{trimmed_note}")yield (state, video, file_path, seed, note, merged, _copy_update(merged), queue,_queue_status(len(queue), merged), next_frame, 1)def scene_kick(state):1066 unmodified linesreturn resultdef _pick_page(basis, state, advance=False):from concurrent.futures import ThreadPoolExecutorpool = _library_pool() # Read the current catalogue on every press.ranked = _shortlist_loras(basis, pool, limit=len(pool))7 unmodified linessame = state.get("basis") == basisstart = int(state.get("cursor", 0)) % count if count and advance and same else 0ordered = unique[start:] + unique[:start]page, checked, skipped = [], 0, 0# Bound each refresh even if an entire remote catalogue is unavailable.with ThreadPoolExecutor(max_workers=LORA_PICK_PAGE) as workers:for offset in range(0, min(len(ordered), 20), LORA_PICK_PAGE):52 unmodified linesold_picks = list(state.get("applied") or [])if ticked is None:basis = prompt_text if mode == "prompt" else (str(idea_text or "").strip() + "\n" + sheet_text).strip()page, cursor, skipped, available = _pick_page(basis, state, advance)chosen = _ask_which_loras(space_id, basis, page)state.update(basis=basis, cursor=cursor, page=page)detail = f"{len(page)} suggestions shown; {skipped} unavailable entries skipped."if available > len(page):detail += " Refresh shows the next group of up to 5."else:4708 unmodified lines470947104711471247134714471547164717471895 unmodified lines481448154816481748184819482048214822482348243 unmodified lines482848294830483148324833483414 unmodified lines48494850485148524853485448551066 unmodified lines59225923592459255926592759287 unmodified lines59365937593859395940594159425943594459455946594759485949595059515952595359545955595652 unmodified lines6009601060116012601360146015601660176018601960206021602260234708 unmodified linestotal = int(state.get("total", left))index = total - leftvalues = list(state.get("values") or ui_values)# The image the scene was started from. Kept aside so the box can be put back to it# once the scene is joined - otherwise it is left holding the last frame of the last# clip, and the next scene silently starts from the wrong picture.opening_frame = (state.get("values") or list(ui_values) or [None])[0]if ui_values:values[0] = ui_values[0] # Last frame from the preceding completed clip.95 unmodified lines# Commit the file and next frame before CPU stitching or a second audio booking.# If either operation fails, the finished clips remain accessible and resumable.stage = "Joining the completed scene…" if state["left"] == 0 else "Clip saved; next clip starting…"closing_frame = next_frame if state["left"] > 0 else (opening_frame if opening_frame is not None else next_frame)yield (state, video, file_path, seed,_scene_progress(done, total, label=stage, running=True, note=trimmed_note),gr.update(), gr.update(), queue, _queue_status(len(queue)), closing_frame,1 if state["left"] == 0 else done + 1)if state["left"] > 0:return3 unmodified linesyield (state, video, file_path, seed,"<div class='status-idle'><b>Clips completed; joining failed.</b>""<span>All clips are in the queue. Use Join to retry without generating again.</span></div>",gr.update(), gr.update(), queue, _queue_status(len(queue)), closing_frame, 1)returnif sound_on and merged:yield (state, gr.update(), gr.update(), gr.update(),14 unmodified linesnote = _scene_progress(done, total, label="Scene finished", running=False,note=f"{len(queue)} clip(s) joined{trimmed_note}")yield (state, video, file_path, seed, note, merged, _copy_update(merged), queue,_queue_status(len(queue), merged), closing_frame, 1)def scene_kick(state):1066 unmodified linesreturn resultdef _pick_page(basis, state, advance=False, keep=None):from concurrent.futures import ThreadPoolExecutorpool = _library_pool() # Read the current catalogue on every press.ranked = _shortlist_loras(basis, pool, limit=len(pool))7 unmodified linessame = state.get("basis") == basisstart = int(state.get("cursor", 0)) % count if count and advance and same else 0ordered = unique[start:] + unique[:start]# A ticked entry stays where it is. Refresh replaces only the ones that were not# chosen, so browsing for a second effect never drops the first one.page, held = [], set()for item in (keep or []):key = _pick_key(item)if key in held or _health_read(key).get("status") == "bad":continueheld.add(key)page.append(item)if len(page) >= LORA_PICK_PAGE:breakordered = [item for item in ordered if _pick_key(item) not in held]checked, skipped = 0, 0# Bound each refresh even if an entire remote catalogue is unavailable.with ThreadPoolExecutor(max_workers=LORA_PICK_PAGE) as workers:for offset in range(0, min(len(ordered), 20), LORA_PICK_PAGE):52 unmodified linesold_picks = list(state.get("applied") or [])if ticked is None:basis = prompt_text if mode == "prompt" else (str(idea_text or "").strip() + "\n" + sheet_text).strip()held = old_picks if advance else []page, cursor, skipped, available = _pick_page(basis, state, advance, keep=held)held_keys = {_pick_key(item) for item in held}kept = [i for i, item in enumerate(page) if _pick_key(item) in held_keys]chosen = kept if kept else _ask_which_loras(space_id, basis, page)state.update(basis=basis, cursor=cursor, page=page)detail = f"{len(page)} suggestions shown; {skipped} unavailable entries skipped."if kept:detail += f" {len(kept)} kept ticked; only the unticked ones were replaced."if available > len(page):detail += " Refresh shows the next group of up to 5."else:
app.py+32-7