Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
import os
|
2 |
os.system("wget https://huggingface.co/akhaliq/lama/resolve/main/best.ckpt")
|
3 |
-
|
4 |
import cv2
|
5 |
import paddlehub as hub
|
6 |
import gradio as gr
|
7 |
import torch
|
8 |
from PIL import Image, ImageOps
|
9 |
import numpy as np
|
|
|
10 |
os.mkdir("data")
|
11 |
os.rename("best.ckpt", "models/best.ckpt")
|
12 |
os.mkdir("dataout")
|
@@ -16,11 +17,7 @@ def infer(img,option):
|
|
16 |
print(type(img["image"]))
|
17 |
print(type(img["mask"]))
|
18 |
print(type(Image.fromarray(img["image"]))
|
19 |
-
|
20 |
-
mask = Image.fromarray(img["mask"])
|
21 |
-
img = ImageOps.contain(img, (700,700))
|
22 |
-
width, height = img.size
|
23 |
-
img.save("./data/data.png")
|
24 |
if option == "automatic (U2net)":
|
25 |
result = model.Segmentation(
|
26 |
images=[cv2.cvtColor(img["image"], cv2.COLOR_RGB2BGR)],
|
@@ -30,9 +27,9 @@ def infer(img,option):
|
|
30 |
output_dir='output',
|
31 |
visualization=True)
|
32 |
im = Image.fromarray(result[0]['mask'])
|
|
|
33 |
else:
|
34 |
-
|
35 |
-
mask.save("./data/data_mask.png")
|
36 |
os.system('python predict.py model.path=/home/user/app/ indir=/home/user/app/data/ outdir=/home/user/app/dataout/ device=cpu')
|
37 |
return "./dataout/data_mask.png",mask
|
38 |
|
|
|
1 |
import os
|
2 |
os.system("wget https://huggingface.co/akhaliq/lama/resolve/main/best.ckpt")
|
3 |
+
os.system("pip install imageio")
|
4 |
import cv2
|
5 |
import paddlehub as hub
|
6 |
import gradio as gr
|
7 |
import torch
|
8 |
from PIL import Image, ImageOps
|
9 |
import numpy as np
|
10 |
+
import imageio
|
11 |
os.mkdir("data")
|
12 |
os.rename("best.ckpt", "models/best.ckpt")
|
13 |
os.mkdir("dataout")
|
|
|
17 |
print(type(img["image"]))
|
18 |
print(type(img["mask"]))
|
19 |
print(type(Image.fromarray(img["image"]))
|
20 |
+
imageio.imwrite("./data/data.png", img["image"])
|
|
|
|
|
|
|
|
|
21 |
if option == "automatic (U2net)":
|
22 |
result = model.Segmentation(
|
23 |
images=[cv2.cvtColor(img["image"], cv2.COLOR_RGB2BGR)],
|
|
|
27 |
output_dir='output',
|
28 |
visualization=True)
|
29 |
im = Image.fromarray(result[0]['mask'])
|
30 |
+
im.save("./data/data_mask.png")
|
31 |
else:
|
32 |
+
imageio.imwrite("./data/data_mask.png", img["mask"])
|
|
|
33 |
os.system('python predict.py model.path=/home/user/app/ indir=/home/user/app/data/ outdir=/home/user/app/dataout/ device=cpu')
|
34 |
return "./dataout/data_mask.png",mask
|
35 |
|