Spaces:
Runtime error
Runtime error
gokaygokay
commited on
Commit
•
c3faeca
1
Parent(s):
6424be8
Update app.py
Browse files
app.py
CHANGED
@@ -193,7 +193,10 @@ def get_image(img_input, mask=False, scale=True):
|
|
193 |
img = cv2.imread(img_input)
|
194 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
195 |
else:
|
196 |
-
raise ValueError("Unsupported image input type")
|
|
|
|
|
|
|
197 |
|
198 |
if mask:
|
199 |
if len(img.shape) == 3:
|
@@ -209,8 +212,12 @@ def blend_images(bg_img, obj_img, mask_img, method):
|
|
209 |
bg_img = get_image(bg_img)
|
210 |
obj_img = get_image(obj_img)
|
211 |
|
212 |
-
|
|
|
|
|
|
|
213 |
mask_img = cv2.imread(mask_img, cv2.IMREAD_GRAYSCALE)
|
|
|
214 |
mask_img = get_image(mask_img, mask=True)
|
215 |
|
216 |
if method == "Poisson":
|
@@ -259,12 +266,19 @@ with gr.Blocks(theme='bethecloud/storj_theme') as iface:
|
|
259 |
outputs=output_image
|
260 |
)
|
261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
gr.Examples(
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
inputs=[bg_img, obj_img, mask_img, method],
|
269 |
outputs=output_image,
|
270 |
fn=blend_images,
|
|
|
193 |
img = cv2.imread(img_input)
|
194 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
195 |
else:
|
196 |
+
raise ValueError(f"Unsupported image input type: {type(img_input)}")
|
197 |
+
|
198 |
+
if img is None:
|
199 |
+
raise ValueError("Failed to load image")
|
200 |
|
201 |
if mask:
|
202 |
if len(img.shape) == 3:
|
|
|
212 |
bg_img = get_image(bg_img)
|
213 |
obj_img = get_image(obj_img)
|
214 |
|
215 |
+
# Handle different input types for mask_img
|
216 |
+
if isinstance(mask_img, dict):
|
217 |
+
mask_img = mask_img.get('composite') or mask_img.get('background')
|
218 |
+
elif isinstance(mask_img, str):
|
219 |
mask_img = cv2.imread(mask_img, cv2.IMREAD_GRAYSCALE)
|
220 |
+
|
221 |
mask_img = get_image(mask_img, mask=True)
|
222 |
|
223 |
if method == "Poisson":
|
|
|
266 |
outputs=output_image
|
267 |
)
|
268 |
|
269 |
+
def create_image_editor_input(image_path):
|
270 |
+
return {
|
271 |
+
"background": image_path,
|
272 |
+
"layers": [],
|
273 |
+
"composite": image_path
|
274 |
+
}
|
275 |
+
|
276 |
gr.Examples(
|
277 |
+
examples=[
|
278 |
+
["img1.jpg", "img2.jpg", create_image_editor_input("mask1.jpg"), "Poisson"],
|
279 |
+
["img3.jpg", "img4.jpg", create_image_editor_input("mask2.jpg"), "Mixed Gradient"],
|
280 |
+
["img6.jpg", "img9.jpg", create_image_editor_input("mask3.jpg"), "Laplacian"]
|
281 |
+
],
|
282 |
inputs=[bg_img, obj_img, mask_img, method],
|
283 |
outputs=output_image,
|
284 |
fn=blend_images,
|