gangweix commited on
Commit
3bfe529
·
verified ·
1 Parent(s): 38ace0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -64,6 +64,8 @@ with gr.Blocks(css=css) as demo:
64
  input_image = gr.Image(label="Input Image", type='numpy', elem_id='img-display-input')
65
  depth_image_slider = ImageSlider(label="Depth Map with Slider View", elem_id='img-display-output', position=0.5)
66
  submit = gr.Button(value="Predict Depth")
 
 
67
  raw_file = gr.File(label="Raw depth output (saved as .npy)", elem_id="download",)
68
 
69
  cmap = matplotlib.colormaps.get_cmap('Spectral')
@@ -82,12 +84,17 @@ with gr.Blocks(css=css) as demo:
82
  depth_vis = depth_vis.astype(np.uint8)
83
  colored_depth = (cmap(depth_vis)[:, :, :3] * 255).astype(np.uint8)
84
 
85
- return [(original_image, colored_depth), tmp_raw_depth.name]
 
 
 
 
 
86
 
87
  submit.click(
88
  on_submit,
89
  inputs=[input_image],
90
- outputs=[depth_image_slider, raw_file]
91
  )
92
 
93
  example_files = os.listdir('assets/examples')
@@ -96,7 +103,7 @@ with gr.Blocks(css=css) as demo:
96
  examples = gr.Examples(
97
  examples=example_files,
98
  inputs=[input_image],
99
- outputs=[depth_image_slider, raw_file],
100
  fn=on_submit
101
  )
102
 
 
64
  input_image = gr.Image(label="Input Image", type='numpy', elem_id='img-display-input')
65
  depth_image_slider = ImageSlider(label="Depth Map with Slider View", elem_id='img-display-output', position=0.5)
66
  submit = gr.Button(value="Predict Depth")
67
+
68
+ concat_file = gr.File(label="Concatenated visualization (image+depth)", elem_id="image-depth-download")
69
  raw_file = gr.File(label="Raw depth output (saved as .npy)", elem_id="download",)
70
 
71
  cmap = matplotlib.colormaps.get_cmap('Spectral')
 
84
  depth_vis = depth_vis.astype(np.uint8)
85
  colored_depth = (cmap(depth_vis)[:, :, :3] * 255).astype(np.uint8)
86
 
87
+ split_region = np.ones((image.shape[0], 50, 3), dtype=np.uint8) * 255
88
+ combined_result = cv2.hconcat([image[:, :, ::-1], split_region, colored_depth[:, :, ::-1]])
89
+ tmp_concat = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
90
+ cv2.imwrite(tmp_concat.name, combined_result)
91
+
92
+ return [(original_image, colored_depth), tmp_concat.name, tmp_raw_depth.name]
93
 
94
  submit.click(
95
  on_submit,
96
  inputs=[input_image],
97
+ outputs=[depth_image_slider, concat_file, raw_file]
98
  )
99
 
100
  example_files = os.listdir('assets/examples')
 
103
  examples = gr.Examples(
104
  examples=example_files,
105
  inputs=[input_image],
106
+ outputs=[depth_image_slider, concat_file, raw_file],
107
  fn=on_submit
108
  )
109