Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -535,15 +535,28 @@ def process_image(image_mask_dict):
|
|
535 |
|
536 |
# 新しいGradioバージョンに対応(background, layers, compositeのキー)
|
537 |
background = image_mask_dict.get("background")
|
538 |
-
layers = image_mask_dict.get("layers")
|
539 |
|
540 |
-
if background is None
|
541 |
return None
|
542 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
543 |
# 背景画像を取得
|
544 |
img_array = np.array(background)
|
545 |
|
546 |
-
# レイヤー(マスク)を取得
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
547 |
mask_array = np.array(layers[0])
|
548 |
|
549 |
# マスクを2値化(閾値は0より大きい値を全て255に)
|
|
|
535 |
|
536 |
# 新しいGradioバージョンに対応(background, layers, compositeのキー)
|
537 |
background = image_mask_dict.get("background")
|
|
|
538 |
|
539 |
+
if background is None:
|
540 |
return None
|
541 |
|
542 |
+
# 背景画像がPIL形式でない場合はPILに変換
|
543 |
+
if not isinstance(background, Image.Image):
|
544 |
+
if isinstance(background, np.ndarray):
|
545 |
+
background = Image.fromarray(background.astype(np.uint8))
|
546 |
+
else:
|
547 |
+
return None
|
548 |
+
|
549 |
# 背景画像を取得
|
550 |
img_array = np.array(background)
|
551 |
|
552 |
+
# レイヤー(マスク)を取得
|
553 |
+
layers = image_mask_dict.get("layers")
|
554 |
+
|
555 |
+
# マスクがない場合、元の画像をそのままPIL形式で返す
|
556 |
+
if layers is None or not layers:
|
557 |
+
return background
|
558 |
+
|
559 |
+
# マスク処理を行う(マスクが存在する場合)
|
560 |
mask_array = np.array(layers[0])
|
561 |
|
562 |
# マスクを2値化(閾値は0より大きい値を全て255に)
|