ashawkey commited on
Commit
4c2da87
·
1 Parent(s): b703ea2
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -68,11 +68,14 @@ def get_random_seed(randomize_seed, seed):
68
 
69
  # process image
70
  @spaces.GPU(duration=10)
71
- def process_image(image):
72
- image = np.array(image) # uint8
73
  image = cv2.resize(image, (518, 518), interpolation=cv2.INTER_AREA)
74
- # bg removal if there is no alpha channel
75
- if image.shape[-1] == 3:
 
 
 
76
  image = rembg.remove(image, session=bg_remover) # [H, W, 4]
77
  mask = image[..., -1] > 0
78
  image = recenter_foreground(image, mask, border_ratio=0.1)
@@ -163,7 +166,7 @@ with block:
163
  with gr.Column(scale=1):
164
  with gr.Row():
165
  # input image
166
- input_image = gr.Image(label="Input Image", type="numpy")
167
  seg_image = gr.Image(label="Segmentation Result", type="numpy", interactive=False)
168
  with gr.Accordion("Settings", open=True):
169
  # inference steps
 
68
 
69
  # process image
70
  @spaces.GPU(duration=10)
71
+ def process_image(image_path):
72
+ image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED)
73
  image = cv2.resize(image, (518, 518), interpolation=cv2.INTER_AREA)
74
+ if image.shape[-1] == 4:
75
+ image = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
76
+ else:
77
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
78
+ # bg removal if there is no alpha channel
79
  image = rembg.remove(image, session=bg_remover) # [H, W, 4]
80
  mask = image[..., -1] > 0
81
  image = recenter_foreground(image, mask, border_ratio=0.1)
 
166
  with gr.Column(scale=1):
167
  with gr.Row():
168
  # input image
169
+ input_image = gr.Image(label="Input Image", type="file_path") # use file_path and load manually
170
  seg_image = gr.Image(label="Segmentation Result", type="numpy", interactive=False)
171
  with gr.Accordion("Settings", open=True):
172
  # inference steps