Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,6 +44,9 @@ transform = transforms.Compose([GOSNormalize([0.5,0.5,0.5],[1.0,1.0,1.0])])
|
|
| 44 |
|
| 45 |
def load_image(im_path, hypar):
|
| 46 |
im = im_reader(im_path)
|
|
|
|
|
|
|
|
|
|
| 47 |
im, im_shp = im_preprocess(im, hypar["cache_size"])
|
| 48 |
im = torch.divide(im,255.0)
|
| 49 |
shape = torch.from_numpy(np.array(im_shp))
|
|
@@ -153,7 +156,8 @@ def remove_background():
|
|
| 153 |
|
| 154 |
return jsonify({
|
| 155 |
'rgba_image': f"/results/rgba_{file.filename}",
|
| 156 |
-
'mask_image': f"/results/mask_{file.filename}"
|
|
|
|
| 157 |
})
|
| 158 |
except Exception as e:
|
| 159 |
return jsonify({'error': str(e)}), 500
|
|
|
|
| 44 |
|
| 45 |
def load_image(im_path, hypar):
|
| 46 |
im = im_reader(im_path)
|
| 47 |
+
# Convert to RGB if image has alpha channel
|
| 48 |
+
if im.mode == 'RGBA':
|
| 49 |
+
im = im.convert('RGB')
|
| 50 |
im, im_shp = im_preprocess(im, hypar["cache_size"])
|
| 51 |
im = torch.divide(im,255.0)
|
| 52 |
shape = torch.from_numpy(np.array(im_shp))
|
|
|
|
| 156 |
|
| 157 |
return jsonify({
|
| 158 |
'rgba_image': f"/results/rgba_{file.filename}",
|
| 159 |
+
'mask_image': f"/results/mask_{file.filename}",
|
| 160 |
+
'original_filename': file.filename
|
| 161 |
})
|
| 162 |
except Exception as e:
|
| 163 |
return jsonify({'error': str(e)}), 500
|