Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -184,11 +184,9 @@ def laplacian_blend(img1: np.ndarray, img2: np.ndarray, mask: np.ndarray, depth:
|
|
184 |
|
185 |
return np.clip(imgs[-1], 0, 1)
|
186 |
|
187 |
-
|
188 |
-
|
189 |
def get_image(img_input, mask=False, scale=True):
|
190 |
-
if isinstance(img_input, dict)
|
191 |
-
img = img_input
|
192 |
elif isinstance(img_input, np.ndarray):
|
193 |
img = img_input
|
194 |
elif isinstance(img_input, str):
|
@@ -226,28 +224,32 @@ def blend_images(bg_img, obj_img, mask_img, method):
|
|
226 |
|
227 |
return (blend_img * 255).astype(np.uint8)
|
228 |
|
|
|
|
|
|
|
229 |
with gr.Blocks(theme='bethecloud/storj_theme') as iface:
|
230 |
gr.HTML("<h1>Image Blending with Multiple Methods</h1>")
|
231 |
|
232 |
with gr.Row():
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
method = gr.Radio(["Poisson", "Mixed Gradient", "Laplacian"], label="Blending Method", value="Poisson")
|
246 |
|
247 |
blend_button = gr.Button("Blend Images")
|
248 |
|
249 |
output_image = gr.Image(label="Blended Image")
|
250 |
|
|
|
|
|
251 |
blend_button.click(
|
252 |
blend_images,
|
253 |
inputs=[bg_img, obj_img, mask_img, method],
|
@@ -255,11 +257,11 @@ with gr.Blocks(theme='bethecloud/storj_theme') as iface:
|
|
255 |
)
|
256 |
|
257 |
gr.Examples(
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
inputs=[bg_img, obj_img, mask_img, method],
|
264 |
outputs=output_image,
|
265 |
fn=blend_images,
|
|
|
184 |
|
185 |
return np.clip(imgs[-1], 0, 1)
|
186 |
|
|
|
|
|
187 |
def get_image(img_input, mask=False, scale=True):
|
188 |
+
if isinstance(img_input, dict):
|
189 |
+
img = img_input.get('composite') or img_input.get('background')
|
190 |
elif isinstance(img_input, np.ndarray):
|
191 |
img = img_input
|
192 |
elif isinstance(img_input, str):
|
|
|
224 |
|
225 |
return (blend_img * 255).astype(np.uint8)
|
226 |
|
227 |
+
def predict(im):
|
228 |
+
return im["composite"]
|
229 |
+
|
230 |
with gr.Blocks(theme='bethecloud/storj_theme') as iface:
|
231 |
gr.HTML("<h1>Image Blending with Multiple Methods</h1>")
|
232 |
|
233 |
with gr.Row():
|
234 |
+
bg_img = gr.Image(label="Background Image", type="numpy")
|
235 |
+
obj_img = gr.Image(label="Object Image", type="numpy")
|
236 |
+
|
237 |
+
with gr.Row():
|
238 |
+
mask_img = gr.ImageEditor(
|
239 |
+
label="Mask Image",
|
240 |
+
type="numpy",
|
241 |
+
crop_size="1:1",
|
242 |
+
)
|
243 |
+
mask_preview = gr.Image(label="Mask Preview")
|
244 |
+
|
245 |
+
method = gr.Radio(["Poisson", "Mixed Gradient", "Laplacian"], label="Blending Method", value="Poisson")
|
|
|
246 |
|
247 |
blend_button = gr.Button("Blend Images")
|
248 |
|
249 |
output_image = gr.Image(label="Blended Image")
|
250 |
|
251 |
+
mask_img.change(predict, outputs=mask_preview, inputs=mask_img, show_progress="hidden")
|
252 |
+
|
253 |
blend_button.click(
|
254 |
blend_images,
|
255 |
inputs=[bg_img, obj_img, mask_img, method],
|
|
|
257 |
)
|
258 |
|
259 |
gr.Examples(
|
260 |
+
examples=[
|
261 |
+
["img1.jpg", "img2.jpg", "mask1.jpg", "Poisson"],
|
262 |
+
["img3.jpg", "img4.jpg", "mask2.jpg", "Mixed Gradient"],
|
263 |
+
["img6.jpg", "img9.jpg", "mask3.jpg", "Laplacian"]
|
264 |
+
],
|
265 |
inputs=[bg_img, obj_img, mask_img, method],
|
266 |
outputs=output_image,
|
267 |
fn=blend_images,
|