Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import insightface
|
|
8 |
import onnxruntime as ort
|
9 |
import huggingface_hub
|
10 |
from SegCloth import segment_clothing
|
|
|
11 |
|
12 |
app = Flask(__name__)
|
13 |
|
@@ -67,13 +68,26 @@ def detect_and_segment_persons(image, clothes):
|
|
67 |
pil_img = Image.fromarray(person_img[:, :, ::-1]) # BGR -> RGB
|
68 |
|
69 |
# Segment clothing for the detected person
|
70 |
-
|
|
|
71 |
|
72 |
# Combine the segmented images for all persons
|
73 |
all_segmented_images.extend(segmented_result)
|
74 |
|
75 |
return all_segmented_images
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
@app.route('/api/detect', methods=['POST'])
|
78 |
def detect():
|
79 |
try:
|
|
|
8 |
import onnxruntime as ort
|
9 |
import huggingface_hub
|
10 |
from SegCloth import segment_clothing
|
11 |
+
from transparent_background import Remover
|
12 |
|
13 |
app = Flask(__name__)
|
14 |
|
|
|
68 |
pil_img = Image.fromarray(person_img[:, :, ::-1]) # BGR -> RGB
|
69 |
|
70 |
# Segment clothing for the detected person
|
71 |
+
img_rm_background = remove_background(pil_img)
|
72 |
+
segmented_result = segment_clothing(img_rm_background, clothes)
|
73 |
|
74 |
# Combine the segmented images for all persons
|
75 |
all_segmented_images.extend(segmented_result)
|
76 |
|
77 |
return all_segmented_images
|
78 |
|
79 |
+
@spaces.GPU
|
80 |
+
def remove_background(image):
|
81 |
+
remover = Remover()
|
82 |
+
if isinstance(image, Image.Image):
|
83 |
+
output = remover.process(image)
|
84 |
+
elif isinstance(image, np.ndarray):
|
85 |
+
image_pil = Image.fromarray(image)
|
86 |
+
output = remover.process(image_pil)
|
87 |
+
else:
|
88 |
+
raise TypeError("Unsupported image type")
|
89 |
+
return output
|
90 |
+
|
91 |
@app.route('/api/detect', methods=['POST'])
|
92 |
def detect():
|
93 |
try:
|