Update app.py
Browse files866 unmodified lines86786886987087187212 unmodified lines88588688788888989088 unmodified lines97998098198298398498574 unmodified lines106010611062106310641065866 unmodified linesreturn gr.update(value=image_path), gr.update(value=label)load_models()INTRO = """# PlagueKind · MiniMax-H312 unmodified lines.main.fillable {max-width: 1250px !important}.dark .gradio-container { color: var(--body-text-color); }.status p {font-size: 0.8rem; opacity: 0.65; text-align: center;}"""with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:88 unmodified lines)with gr.Column():video = gr.Video(label="Video + soundtrack")report = gr.Markdown()with gr.Accordion("Distilled / Turbo LoRAs", open=False):lora_1_strength = gr.Slider(74 unmodified linesfirst_frame.upload(_fit_keyframe, [first_frame, canvas], [first_frame, canvas])last_frame.upload(_fit_keyframe, [last_frame, canvas], [last_frame, canvas])controls = [prompt,canvas,866 unmodified lines86786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190212 unmodified lines91591691791891992092192292392492592692792892993088 unmodified lines10191020102110221023102410251026102710281029103074 unmodified lines110511061107110811091110111111121113111411151116111711181119112011211122866 unmodified linesreturn gr.update(value=image_path), gr.update(value=label)# Client-side only (`fn=None`, no server round-trip): reads the real `<video>` element's current playback# position, not a property of the file — so "grab this frame" means whatever's on screen when the button is# pressed, paused or scrubbed to, not automatically the clip's last frame._FRAME_GRAB_JS = """function() {const video = document.querySelector('#h3-generated-video video');return video ? video.currentTime : 0;}"""def _extract_frame(video_path, timestamp):"""The frame at `timestamp` seconds into `video_path`, as a numpy RGB array — Gradio converts it to a PILimage for whichever `gr.Image` this is wired to. Runs on CPU; no GPU time, no interaction with `_generate`."""if not video_path:return Noneimport cv2cap = cv2.VideoCapture(video_path)if not cap.isOpened():return Nonefps = cap.get(cv2.CAP_PROP_FPS) or FPStotal_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))target_frame = min(int(float(timestamp) * fps), max(0, total_frames - 1))cap.set(cv2.CAP_PROP_POS_FRAMES, target_frame)ok, frame = cap.read()cap.release()return cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) if ok else Noneload_models()INTRO = """# PlagueKind · MiniMax-H312 unmodified lines.main.fillable {max-width: 1250px !important}.dark .gradio-container { color: var(--body-text-color); }.status p {font-size: 0.8rem; opacity: 0.65; text-align: center;}.h3-hidden-timestamp {opacity: 0;height: 0px;width: 0px;margin: 0px;padding: 0px;overflow: hidden;position: absolute;pointer-events: none;}"""with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:88 unmodified lines)with gr.Column():video = gr.Video(label="Video + soundtrack", elem_id="h3-generated-video")with gr.Row():grab_first_btn = gr.Button("📸 Use current frame as First frame", size="sm", variant="secondary")grab_last_btn = gr.Button("📸 Use current frame as Last frame", size="sm", variant="secondary")first_frame_timestamp = gr.Number(value=0, visible=True, elem_classes="h3-hidden-timestamp")last_frame_timestamp = gr.Number(value=0, visible=True, elem_classes="h3-hidden-timestamp")report = gr.Markdown()with gr.Accordion("Distilled / Turbo LoRAs", open=False):lora_1_strength = gr.Slider(74 unmodified linesfirst_frame.upload(_fit_keyframe, [first_frame, canvas], [first_frame, canvas])last_frame.upload(_fit_keyframe, [last_frame, canvas], [last_frame, canvas])# Grabbing the currently-displayed frame: the button's own click runs only the JS above (`fn=None`, no# server round-trip) to read the real `<video>` element's playback position into a hidden number box; that# box's `.change()` is what actually decodes and writes the frame, server-side.grab_first_btn.click(fn=None, inputs=None, outputs=[first_frame_timestamp], js=_FRAME_GRAB_JS)first_frame_timestamp.change(_extract_frame, [video, first_frame_timestamp], first_frame, show_progress="hidden")grab_last_btn.click(fn=None, inputs=None, outputs=[last_frame_timestamp], js=_FRAME_GRAB_JS)last_frame_timestamp.change(_extract_frame, [video, last_frame_timestamp], last_frame, show_progress="hidden")controls = [prompt,canvas,
app.py+58-1