zino36 commited on
Commit
2f78644
·
verified ·
1 Parent(s): beadcc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -8
app.py CHANGED
@@ -79,18 +79,39 @@ with gr.Blocks(css=css) as demo:
79
 
80
  cmap = matplotlib.colormaps.get_cmap('Spectral_r')
81
 
82
- def on_submit(image):
83
- if isinstance(image, np.ndarray):
84
- image = Image.fromarray(image)
85
 
86
- original_image = image.copy()
87
 
88
- h, w = image.size # For PIL images, use .size instead of .shape
89
 
90
- depth = predict_depth(image)
91
 
92
- raw_depth = Image.fromarray(depth)
93
- tmp_raw_depth = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  raw_depth.save(tmp_raw_depth.name)
95
 
96
  depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0
 
79
 
80
  cmap = matplotlib.colormaps.get_cmap('Spectral_r')
81
 
82
+ def on_submit(image):
83
+ if isinstance(image, np.ndarray):
84
+ image = Image.fromarray(image)
85
 
86
+ original_image = image.copy()
87
 
88
+ h, w = image.size # For PIL images, use .size instead of .shape
89
 
90
+ depth = predict_depth(image)
91
 
92
+ # Debugging info
93
+ print("Type of depth:", type(depth))
94
+ print("Shape of depth:", depth.shape if isinstance(depth, np.ndarray) else "N/A")
95
+
96
+ if isinstance(depth, np.ndarray):
97
+ print("Data type of depth:", depth.dtype)
98
+
99
+ # Ensure depth is a NumPy array and has the correct shape and dtype
100
+ if not isinstance(depth, np.ndarray):
101
+ raise TypeError("Expected a NumPy array for depth, but got {}".format(type(depth)))
102
+
103
+ # Adjust the depth array if needed
104
+ if depth.ndim == 2:
105
+ # 2D array: expected for grayscale depth maps
106
+ depth = depth.astype('uint16') # Convert to a suitable type
107
+ elif depth.ndim == 3 and depth.shape[2] == 1:
108
+ # 3D array with a single channel (e.g., shape (H, W, 1))
109
+ depth = depth[:, :, 0].astype('uint16')
110
+ else:
111
+ raise ValueError("Unsupported depth array shape: {}".format(depth.shape))
112
+
113
+ # Now convert to a PIL Image
114
+ raw_depth = Image.fromarray(depth) tmp_raw_depth = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
115
  raw_depth.save(tmp_raw_depth.name)
116
 
117
  depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0