Update app.py
Browse files766 unmodified lines76776876977077177242 unmodified lines81581681781881982082182282382482582682782882983083183283383483583683783883984084184284363 unmodified lines90790890991091191291310 unmodified lines924925926927928929291 unmodified lines12211222122312241225122614 unmodified lines12411242124312441245124612471248124926 unmodified lines127612771278127912801281766 unmodified linesstage_enabled=False,target_steps=DEFAULT_TARGET_STEPS,stage_state=None,progress=gr.Progress(track_tqdm=True),*,advance: bool = False,42 unmodified lineselse:this_stage_steps = int(steps)progress(0.0,desc=(f"Upsampling the prompt on {CONDITIONER_SPACE} ..."if upsampleelse f"Conditioning on {CONDITIONER_SPACE} ..."),)conditioned = time.time()prompt_embeds, text_token_tags, metadata, plan = encode_remote(prompt, first_frame, last_frame, canvas, num_frames, rewrite_prompt=upsample)condition_seconds = time.time() - conditionedheight, width, num_frames = (int(metadata[key]) for key in ("height", "width", "num_frames"))refined = plan.get("refined_prompt") or ""if advance and (height, width, num_frames) != (int(stage_state["height"]), int(stage_state["width"]), int(stage_state["num_frames"])):raise gr.Error("Canvas or duration resolved differently than the staged sequence's first stage — both have to stay ""fixed across a staged sequence, since they determine the saved latents' shape.")def keyframe(path):# The conditioning latents encoded here have to be of the image the conditioner looked at, which it63 unmodified linesreport = (f"`{width}x{height}`, {num_frames} frames ({num_frames / FPS:.3f} s) -> {out_frames} frames at {fps} fps · "f"{' · '.join(info)}\n\n"f"conditioner {condition_seconds:.0f}s ({plan['num_text_tokens']} tokens"f"{', upsampled' if refined else ''}) · denoise + decode {denoise_seconds:.0f}s "f"({denoise_seconds / max(1, this_stage_steps):.1f} s/step) · post {post_seconds:.0f}s · "f"GPU {gpu_seconds:.0f}s of {booked_seconds}s booked"10 unmodified lines"width": width,"num_frames": num_frames,"steps_done": steps_done_after,}if stage_enabledelse None291 unmodified linesvisible=False,info="The fixed schedule's total length — 'Steps' above is how many of these one press runs.",)advance_btn = gr.Button("Advance", variant="secondary", visible=False)stage_state = gr.State(None)14 unmodified lines)stage_enabled.change(lambda enabled: (gr.update(visible=enabled), gr.update(visible=enabled)),stage_enabled,[target_steps, advance_btn],api_name=False,)26 unmodified linesstage_enabled,target_steps,stage_state,]# `functools.partial` binds `advance` by keyword regardless of its position in `generate`'s signature — the766 unmodified lines76776876977077177277342 unmodified lines81681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885963 unmodified lines92392492592692792892910 unmodified lines940941942943944945946947948949950291 unmodified lines124212431244124512461247124812491250125112521253125412551256125714 unmodified lines12721273127412751276127712781279128026 unmodified lines1307130813091310131113121313766 unmodified linesstage_enabled=False,target_steps=DEFAULT_TARGET_STEPS,stage_state=None,recondition=True,progress=gr.Progress(track_tqdm=True),*,advance: bool = False,42 unmodified lineselse:this_stage_steps = int(steps)skip_recondition = advance and stage_state is not None and not reconditionif skip_recondition:# "Re-condition" off: reuses this sequence's cached conditioning verbatim. Safe specifically because# nothing sampler/schedule/shift/steps/seed/sharpen/interpolation/LoRA-related is an input to the# conditioner at all — only prompt, the two keyframes, canvas, and "Upsample prompt" are. Height/width/# num_frames come from that same cached conditioning, so there's nothing new to compare for the# shape-consistency check below.prompt_embeds = stage_state["prompt_embeds"]text_token_tags = stage_state["text_token_tags"]metadata = stage_state["metadata"]plan = stage_state["plan"]condition_seconds = 0.0height, width, num_frames = stage_state["height"], stage_state["width"], stage_state["num_frames"]refined = stage_state.get("refined") or ""else:progress(0.0,desc=(f"Upsampling the prompt on {CONDITIONER_SPACE} ..."if upsampleelse f"Conditioning on {CONDITIONER_SPACE} ..."),)conditioned = time.time()prompt_embeds, text_token_tags, metadata, plan = encode_remote(prompt, first_frame, last_frame, canvas, num_frames, rewrite_prompt=upsample)condition_seconds = time.time() - conditionedheight, width, num_frames = (int(metadata[key]) for key in ("height", "width", "num_frames"))refined = plan.get("refined_prompt") or ""if advance and (height, width, num_frames) != (int(stage_state["height"]), int(stage_state["width"]), int(stage_state["num_frames"])):raise gr.Error("Canvas or duration resolved differently than the staged sequence's first stage — both have to ""stay fixed across a staged sequence, since they determine the saved latents' shape.")def keyframe(path):# The conditioning latents encoded here have to be of the image the conditioner looked at, which it63 unmodified linesreport = (f"`{width}x{height}`, {num_frames} frames ({num_frames / FPS:.3f} s) -> {out_frames} frames at {fps} fps · "f"{' · '.join(info)}\n\n"f"conditioner {condition_seconds:.0f}s{' (cached)' if skip_recondition else ''} ({plan['num_text_tokens']} tokens"f"{', upsampled' if refined else ''}) · denoise + decode {denoise_seconds:.0f}s "f"({denoise_seconds / max(1, this_stage_steps):.1f} s/step) · post {post_seconds:.0f}s · "f"GPU {gpu_seconds:.0f}s of {booked_seconds}s booked"10 unmodified lines"width": width,"num_frames": num_frames,"steps_done": steps_done_after,"prompt_embeds": prompt_embeds,"text_token_tags": text_token_tags,"metadata": metadata,"plan": plan,"refined": refined,}if stage_enabledelse None291 unmodified linesvisible=False,info="The fixed schedule's total length — 'Steps' above is how many of these one press runs.",)recondition = gr.Checkbox(label="Re-condition",value=True,visible=False,info=("When turned off skips the conditioner on 'Advance' and reuses this sequence's cached prompt/keyframe ""encoding — safe as long as the prompt, keyframes, target dimension, and 'Upsample prompt' haven't ""changed since the first stage."),)advance_btn = gr.Button("Advance", variant="secondary", visible=False)stage_state = gr.State(None)14 unmodified lines)stage_enabled.change(lambda enabled: tuple(gr.update(visible=enabled) for _ in range(3)),stage_enabled,[target_steps, recondition, advance_btn],api_name=False,)26 unmodified linesstage_enabled,target_steps,stage_state,recondition,]# `functools.partial` binds `advance` by keyword regardless of its position in `generate`'s signature — the
app.py+57-25