vivekchakraverty Claude Opus 4.8 commited on
Commit
024d653
·
1 Parent(s): 85b485a

Add per-image delete from the frames pool

Browse files

Click a gallery image to select it, then '🗑️ Delete selected' removes it
(and deletes its file). 'Clear frames' renamed to 'Clear all'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +32 -4
app.py CHANGED
@@ -146,8 +146,26 @@ def on_auto(session: str, frames: list[dict], video_path: str, progress=gr.Progr
146
  )
147
 
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  def on_clear():
150
- return [], [], "Cleared all frames."
151
 
152
 
153
  def on_transcribe(session: str, video_path: str, progress=gr.Progress()):
@@ -245,6 +263,7 @@ def build_ui() -> gr.Blocks:
245
 
246
  session_state = gr.State("")
247
  frames_state = gr.State([])
 
248
  video_state = gr.State("")
249
  transcript_state = gr.State(None)
250
  draft_state = gr.State(None)
@@ -267,9 +286,12 @@ def build_ui() -> gr.Blocks:
267
  with gr.Column(scale=2):
268
  gr.Markdown("### Captured frames")
269
  gallery = gr.Gallery(
270
- label="Frames pool", columns=3, height=320, object_fit="contain", allow_preview=True
 
271
  )
272
- clear_btn = gr.Button("🗑️ Clear frames")
 
 
273
 
274
  gr.Markdown("### 2 · Transcribe → 3 · Generate guide")
275
  with gr.Row():
@@ -308,7 +330,13 @@ def build_ui() -> gr.Blocks:
308
  js=CAPTURE_JS,
309
  )
310
  auto_btn.click(on_auto, [session_state, frames_state, video_state], [gallery, frames_state, status])
311
- clear_btn.click(on_clear, None, [gallery, frames_state, status])
 
 
 
 
 
 
312
 
313
  transcribe_btn.click(
314
  on_transcribe, [session_state, video_state], [transcript_box, transcript_state, status]
 
146
  )
147
 
148
 
149
+ def on_select_frame(evt: gr.SelectData):
150
+ """Remember which gallery image the user clicked, for deletion."""
151
+ return evt.index, f"Selected frame #{evt.index + 1}. Click '🗑️ Delete selected' to remove it."
152
+
153
+
154
+ def on_delete_frame(frames: list[dict], selected):
155
+ frames = frames or []
156
+ if selected is None or selected < 0 or selected >= len(frames):
157
+ return _gallery_value(frames), frames, None, "Click an image in the pool first, then delete."
158
+ removed = frames[selected]
159
+ try: # remove the file too (it isn't referenced once out of the pool)
160
+ Path(removed["path"]).unlink(missing_ok=True)
161
+ except OSError:
162
+ pass
163
+ frames = [f for i, f in enumerate(frames) if i != selected]
164
+ return _gallery_value(frames), frames, None, f"Deleted 1 frame — {len(frames)} remaining."
165
+
166
+
167
  def on_clear():
168
+ return [], [], None, "Cleared all frames."
169
 
170
 
171
  def on_transcribe(session: str, video_path: str, progress=gr.Progress()):
 
263
 
264
  session_state = gr.State("")
265
  frames_state = gr.State([])
266
+ selected_state = gr.State(None) # index of the gallery image the user clicked
267
  video_state = gr.State("")
268
  transcript_state = gr.State(None)
269
  draft_state = gr.State(None)
 
286
  with gr.Column(scale=2):
287
  gr.Markdown("### Captured frames")
288
  gallery = gr.Gallery(
289
+ label="Frames pool — click an image to select it",
290
+ columns=3, height=320, object_fit="contain", allow_preview=False,
291
  )
292
+ with gr.Row():
293
+ delete_btn = gr.Button("🗑️ Delete selected")
294
+ clear_btn = gr.Button("Clear all")
295
 
296
  gr.Markdown("### 2 · Transcribe → 3 · Generate guide")
297
  with gr.Row():
 
330
  js=CAPTURE_JS,
331
  )
332
  auto_btn.click(on_auto, [session_state, frames_state, video_state], [gallery, frames_state, status])
333
+ gallery.select(on_select_frame, None, [selected_state, status])
334
+ delete_btn.click(
335
+ on_delete_frame,
336
+ [frames_state, selected_state],
337
+ [gallery, frames_state, selected_state, status],
338
+ )
339
+ clear_btn.click(on_clear, None, [gallery, frames_state, selected_state, status])
340
 
341
  transcribe_btn.click(
342
  on_transcribe, [session_state, video_state], [transcript_box, transcript_state, status]