PhyscalX commited on
Commit
8eb7787
1 Parent(s): 805ce53

Fix empty sketch issue

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -137,7 +137,6 @@ class ServingCommand(object):
137
 
138
  def build_gradio_app(queues, command):
139
  """Build the gradio application."""
140
- import cv2
141
  import gradio as gr
142
  import gradio_image_prompter as gr_ext
143
 
@@ -186,12 +185,14 @@ def build_gradio_app(queues, command):
186
  img, points = mask_img["background"], []
187
  for layer in mask_img["layers"]:
188
  ys, xs = np.nonzero(layer[:, :, 0])
189
- keep = np.linspace(0, ys.shape[0], 11, dtype="int64")[1:-1]
190
- points.append(np.stack([xs[keep][None, :], ys[keep][None, :]], 2))
191
- points = np.concatenate(points).astype("float32")
192
- points = np.pad(points, [(0, 0), (0, 0), (0, 1)], constant_values=1)
193
- pad_points = np.array([[[0, 0, 4]]], "float32").repeat(points.shape[0], 0)
194
- points = np.concatenate([points, pad_points], axis=1)
 
 
195
  img = img[:, :, (2, 1, 0)] if img is not None else img
196
  img = np.zeros((480, 640, 3), dtype="uint8") if img is None else img
197
  points = (np.array([[[0, 0, 4]]]) if len(points) == 0 else points).astype("float32")
 
137
 
138
  def build_gradio_app(queues, command):
139
  """Build the gradio application."""
 
140
  import gradio as gr
141
  import gradio_image_prompter as gr_ext
142
 
 
185
  img, points = mask_img["background"], []
186
  for layer in mask_img["layers"]:
187
  ys, xs = np.nonzero(layer[:, :, 0])
188
+ if len(ys) > 0:
189
+ keep = np.linspace(0, ys.shape[0], 11, dtype="int64")[1:-1]
190
+ points.append(np.stack([xs[keep][None, :], ys[keep][None, :]], 2))
191
+ if len(points) > 0:
192
+ points = np.concatenate(points).astype("float32")
193
+ points = np.pad(points, [(0, 0), (0, 0), (0, 1)], constant_values=1)
194
+ pad_points = np.array([[[0, 0, 4]]], "float32").repeat(points.shape[0], 0)
195
+ points = np.concatenate([points, pad_points], axis=1)
196
  img = img[:, :, (2, 1, 0)] if img is not None else img
197
  img = np.zeros((480, 640, 3), dtype="uint8") if img is None else img
198
  points = (np.array([[[0, 0, 4]]]) if len(points) == 0 else points).astype("float32")