Krokodilpirat commited on
Commit
6d6b641
·
verified ·
1 Parent(s): 0dae7a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -5,6 +5,7 @@ import cv2
5
  import gradio as gr
6
  import numpy as np
7
  import matplotlib.cm as cm
 
8
  import subprocess
9
 
10
  from video_depth_anything.video_depth import VideoDepthAnything
@@ -101,17 +102,18 @@ def infer_video_depth(
101
  # Generate depth visualization:
102
  if grayscale:
103
  if convert_from_color:
104
- # Generate a color depth image first, then convert it to grayscale.
105
- cmap = cm.get_cmap("inferno")
 
106
  depth_color = (cmap(depth_norm / 255.0)[..., :3] * 255).astype(np.uint8)
107
  depth_gray = cv2.cvtColor(depth_color, cv2.COLOR_RGB2GRAY)
108
  depth_vis = np.stack([depth_gray] * 3, axis=-1)
109
  else:
110
- # Directly generate a grayscale image from normalized depth.
111
  depth_vis = np.stack([depth_norm] * 3, axis=-1)
112
  else:
113
  # Generate a color depth image using the inferno colormap.
114
- cmap = cm.get_cmap("inferno")
115
  depth_vis = (cmap(depth_norm / 255.0)[..., :3] * 255).astype(np.uint8)
116
  # Apply Gaussian blur if requested.
117
  if blur > 0:
@@ -189,7 +191,7 @@ def construct_demo():
189
  outputs=[processed_video, depth_vis_video, stitched_video],
190
  fn=infer_video_depth,
191
  cache_examples=True,
192
- cache_mode="sync",
193
  )
194
 
195
  generate_btn.click(
 
5
  import gradio as gr
6
  import numpy as np
7
  import matplotlib.cm as cm
8
+ import matplotlib # New import for the updated colormap API
9
  import subprocess
10
 
11
  from video_depth_anything.video_depth import VideoDepthAnything
 
102
  # Generate depth visualization:
103
  if grayscale:
104
  if convert_from_color:
105
+ # First, generate a color depth image using the inferno colormap,
106
+ # then convert that color image to grayscale.
107
+ cmap = matplotlib.colormaps.get_cmap("inferno")
108
  depth_color = (cmap(depth_norm / 255.0)[..., :3] * 255).astype(np.uint8)
109
  depth_gray = cv2.cvtColor(depth_color, cv2.COLOR_RGB2GRAY)
110
  depth_vis = np.stack([depth_gray] * 3, axis=-1)
111
  else:
112
+ # Directly generate a grayscale image from the normalized depth values.
113
  depth_vis = np.stack([depth_norm] * 3, axis=-1)
114
  else:
115
  # Generate a color depth image using the inferno colormap.
116
+ cmap = matplotlib.colormaps.get_cmap("inferno")
117
  depth_vis = (cmap(depth_norm / 255.0)[..., :3] * 255).astype(np.uint8)
118
  # Apply Gaussian blur if requested.
119
  if blur > 0:
 
191
  outputs=[processed_video, depth_vis_video, stitched_video],
192
  fn=infer_video_depth,
193
  cache_examples=True,
194
+ cache_mode="lazy",
195
  )
196
 
197
  generate_btn.click(