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

Enlarge selected frame in a full-screen lightbox

Browse files

Clicking a frame opens it full-screen (dismiss via click or Esc), alongside
selecting it for deletion. Injected via launch(head=...) since Gradio 6 moved
'head' out of the Blocks() constructor.

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

Files changed (1) hide show
  1. app.py +43 -1
app.py CHANGED
@@ -46,6 +46,46 @@ CAPTURE_JS = """
46
  }
47
  """
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  # --- Small helpers -----------------------------------------------------------
51
  def _fmt_ts(seconds: float | int | None) -> str:
@@ -286,7 +326,8 @@ def build_ui() -> gr.Blocks:
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():
@@ -380,6 +421,7 @@ if __name__ == "__main__":
380
  app = build_ui().queue()
381
  app.launch(
382
  theme=gr.themes.Soft(),
 
383
  allowed_paths=[str(config.WORK_DIR)],
384
  share=share and not on_spaces, # Spaces provides its own URL — no tunnel
385
  server_name=server_name,
 
46
  }
47
  """
48
 
49
+ # Injected into <head>: a full-screen lightbox. Clicking a frame in the gallery
50
+ # (elem_id "dm-gallery") opens it enlarged over the whole viewport; click anywhere
51
+ # or press Escape to dismiss. Selection (for deletion) still happens in parallel.
52
+ LIGHTBOX_HEAD = """
53
+ <style>
54
+ #dm-lightbox{display:none;position:fixed;inset:0;background:rgba(0,0,0,.9);z-index:99999;
55
+ align-items:center;justify-content:center;cursor:zoom-out;}
56
+ #dm-lightbox.dm-open{display:flex;}
57
+ #dm-lightbox img{max-width:95vw;max-height:95vh;object-fit:contain;border-radius:6px;
58
+ box-shadow:0 0 50px rgba(0,0,0,.7);}
59
+ #dm-lightbox-close{position:fixed;top:12px;right:24px;font-size:42px;color:#fff;
60
+ cursor:pointer;line-height:1;user-select:none;z-index:100000;}
61
+ </style>
62
+ <script>
63
+ (function(){
64
+ function ensure(){
65
+ var lb=document.getElementById('dm-lightbox');
66
+ if(lb) return lb;
67
+ lb=document.createElement('div');
68
+ lb.id='dm-lightbox';
69
+ lb.innerHTML='<span id="dm-lightbox-close">&times;</span><img id="dm-lightbox-img" alt="preview">';
70
+ lb.addEventListener('click', hide);
71
+ document.body.appendChild(lb);
72
+ return lb;
73
+ }
74
+ function show(src){var lb=ensure();document.getElementById('dm-lightbox-img').src=src;lb.classList.add('dm-open');}
75
+ function hide(){var lb=document.getElementById('dm-lightbox');if(lb)lb.classList.remove('dm-open');}
76
+ document.addEventListener('keydown',function(e){if(e.key==='Escape')hide();});
77
+ document.addEventListener('click',function(e){
78
+ if(!e.target||!e.target.closest) return;
79
+ var gal=document.getElementById('dm-gallery');
80
+ if(!gal||!gal.contains(e.target)) return;
81
+ var img=e.target.closest('img');
82
+ if(!img){var b=e.target.closest('button');if(b)img=b.querySelector('img');}
83
+ if(img&&img.getAttribute('src')) show(img.src);
84
+ }, true);
85
+ })();
86
+ </script>
87
+ """
88
+
89
 
90
  # --- Small helpers -----------------------------------------------------------
91
  def _fmt_ts(seconds: float | int | None) -> str:
 
326
  with gr.Column(scale=2):
327
  gr.Markdown("### Captured frames")
328
  gallery = gr.Gallery(
329
+ label="Frames pool — click an image to enlarge / select it",
330
+ elem_id="dm-gallery",
331
  columns=3, height=320, object_fit="contain", allow_preview=False,
332
  )
333
  with gr.Row():
 
421
  app = build_ui().queue()
422
  app.launch(
423
  theme=gr.themes.Soft(),
424
+ head=LIGHTBOX_HEAD, # full-screen lightbox CSS/JS (Gradio 6: head is a launch param)
425
  allowed_paths=[str(config.WORK_DIR)],
426
  share=share and not on_spaces, # Spaces provides its own URL — no tunnel
427
  server_name=server_name,