hysts HF Staff commited on
Commit
6e55bf4
·
1 Parent(s): 1b591cd
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -123,7 +123,11 @@ def run(
123
  trimap: PIL.Image.Image,
124
  apply_background_replacement: bool,
125
  background_image: PIL.Image.Image | None,
126
- ) -> tuple[np.ndarray, PIL.Image.Image, PIL.Image.Image | None]:
 
 
 
 
127
  if image.size != trimap.size:
128
  raise gr.Error("Image and trimap must have the same size.")
129
  if max(image.size) > MAX_IMAGE_SIZE:
@@ -147,7 +151,11 @@ def run(
147
 
148
  res_bg_replacement = replace_background(image, alpha, background_image) if apply_background_replacement else None
149
 
150
- return alpha, foreground, res_bg_replacement
 
 
 
 
151
 
152
 
153
  with gr.Blocks(css_paths="style.css") as demo:
@@ -179,9 +187,9 @@ with gr.Blocks(css_paths="style.css") as demo:
179
  run_button = gr.Button("Run")
180
  with gr.Column():
181
  with gr.Group():
182
- out_alpha = gr.Image(label="Alpha")
183
- out_foreground = gr.Image(label="Foreground")
184
- out_background_replacement = gr.Image(label="Background replacement", visible=False)
185
 
186
  inputs = [
187
  image,
 
123
  trimap: PIL.Image.Image,
124
  apply_background_replacement: bool,
125
  background_image: PIL.Image.Image | None,
126
+ ) -> tuple[
127
+ tuple[PIL.Image.Image, np.ndarray],
128
+ tuple[PIL.Image.Image, PIL.Image.Image],
129
+ tuple[PIL.Image.Image, PIL.Image.Image] | None,
130
+ ]:
131
  if image.size != trimap.size:
132
  raise gr.Error("Image and trimap must have the same size.")
133
  if max(image.size) > MAX_IMAGE_SIZE:
 
151
 
152
  res_bg_replacement = replace_background(image, alpha, background_image) if apply_background_replacement else None
153
 
154
+ return (
155
+ (image, alpha),
156
+ (image, foreground),
157
+ ((image, res_bg_replacement) if res_bg_replacement is not None else None),
158
+ )
159
 
160
 
161
  with gr.Blocks(css_paths="style.css") as demo:
 
187
  run_button = gr.Button("Run")
188
  with gr.Column():
189
  with gr.Group():
190
+ out_alpha = gr.ImageSlider(label="Alpha")
191
+ out_foreground = gr.ImageSlider(label="Foreground")
192
+ out_background_replacement = gr.ImageSlider(label="Background replacement", visible=False)
193
 
194
  inputs = [
195
  image,