freealise commited on
Commit
db53606
1 Parent(s): 97a4509

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -383,6 +383,15 @@ def switch_rows(v):
383
  print(frames[0])
384
  return frames
385
 
 
 
 
 
 
 
 
 
 
386
  def apply_mask(d, b):
387
  global frame_selected
388
  global masks
@@ -561,11 +570,13 @@ with gr.Blocks(css=css, js=js) as demo:
561
  input_url = gr.Textbox(elem_id="url_in", value="./examples/streetview.mp4", label="URL")
562
  input_video = gr.Video(label="Input Video", format="mp4")
563
  input_url.input(fn=loadfile, inputs=[input_url], outputs=[input_video])
 
564
  output_frame = gr.Gallery(label="Frames", preview=True, columns=8192, type="numpy")
565
  output_switch = gr.Checkbox(label="Show depths")
566
  output_switch.input(fn=switch_rows, inputs=[output_switch], outputs=[output_frame])
567
  output_mask = gr.ImageEditor(layers=False, sources=('upload', 'clipboard'), show_download_button=True, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=0, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="image_edit")
568
- selector = gr.HTML(value="""
 
569
  <a href='#' id='selector' onclick='if (this.style.fontWeight!=\"bold\") {
570
  this.style.fontWeight=\"bold\";
571
  document.getElementById(\"image_edit\").getElementsByTagName(\"canvas\")[0].oncontextmenu = function(e){e.preventDefault();}
@@ -602,8 +613,9 @@ with gr.Blocks(css=css, js=js) as demo:
602
 
603
  document.getElementById(\"mouse\").getElementsByTagName(\"textarea\")[0].value = \"[]\";
604
 
605
- ' title='Clear selection' style='text-decoration:none;color:white;'>✕ Clear selection</a>""")
606
- apply = gr.Button("Apply")
 
607
  depth_file = gr.File(label="Edited depth")
608
  with gr.Accordion(label="Edge", open=False):
609
  levels = gr.Slider(label="Color levels", value=16, maximum=32, minimum=2, step=1)
@@ -612,7 +624,7 @@ with gr.Blocks(css=css, js=js) as demo:
612
  mouse = gr.Textbox(elem_id="mouse", value="""[]""", interactive=False)
613
  mouse.input(fn=draw_mask, show_progress="minimal", inputs=[levels, tolerance, mouse, output_mask], outputs=[output_mask])
614
  apply.click(fn=apply_mask, inputs=[output_mask, bsize], outputs=[output_mask, depth_file])
615
- submit = gr.Button("Submit")
616
  with gr.Column():
617
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
618
  processed_video = gr.Video(label="Output Video", format="mp4")
 
383
  print(frames[0])
384
  return frames
385
 
386
+ def reset_mask():
387
+ global frame_selected
388
+ global masks
389
+ global depths
390
+
391
+ masks[frame_selected] = depths[frame_selected]
392
+ cv2.imwrite(f"f{frame_selected}_dmap.png", masks[frame_selected])
393
+ return masks[frame_selected], f"f{frame_selected}_dmap.png"
394
+
395
  def apply_mask(d, b):
396
  global frame_selected
397
  global masks
 
570
  input_url = gr.Textbox(elem_id="url_in", value="./examples/streetview.mp4", label="URL")
571
  input_video = gr.Video(label="Input Video", format="mp4")
572
  input_url.input(fn=loadfile, inputs=[input_url], outputs=[input_video])
573
+ submit = gr.Button("Submit")
574
  output_frame = gr.Gallery(label="Frames", preview=True, columns=8192, type="numpy")
575
  output_switch = gr.Checkbox(label="Show depths")
576
  output_switch.input(fn=switch_rows, inputs=[output_switch], outputs=[output_frame])
577
  output_mask = gr.ImageEditor(layers=False, sources=('upload', 'clipboard'), show_download_button=True, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=0, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="image_edit")
578
+ with gr.Row():
579
+ selector = gr.HTML(value="""
580
  <a href='#' id='selector' onclick='if (this.style.fontWeight!=\"bold\") {
581
  this.style.fontWeight=\"bold\";
582
  document.getElementById(\"image_edit\").getElementsByTagName(\"canvas\")[0].oncontextmenu = function(e){e.preventDefault();}
 
613
 
614
  document.getElementById(\"mouse\").getElementsByTagName(\"textarea\")[0].value = \"[]\";
615
 
616
+ ' title='Clear selection' style='text-decoration:none;color:white;'>✕ Clear</a>""")
617
+ apply = gr.Button("Apply", size='sm')
618
+ reset = gr.Button("Reset", size='sm')
619
  depth_file = gr.File(label="Edited depth")
620
  with gr.Accordion(label="Edge", open=False):
621
  levels = gr.Slider(label="Color levels", value=16, maximum=32, minimum=2, step=1)
 
624
  mouse = gr.Textbox(elem_id="mouse", value="""[]""", interactive=False)
625
  mouse.input(fn=draw_mask, show_progress="minimal", inputs=[levels, tolerance, mouse, output_mask], outputs=[output_mask])
626
  apply.click(fn=apply_mask, inputs=[output_mask, bsize], outputs=[output_mask, depth_file])
627
+ reset.click(fn=reset_mask, inputs=None, outputs=[output_mask, depth_file])
628
  with gr.Column():
629
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
630
  processed_video = gr.Video(label="Output Video", format="mp4")