Spaces:
Running
Running
File size: 809 Bytes
fb15271 ca23413 fb15271 ca23413 fb15271 ca23413 fb15271 ca23413 fb15271 ca23413 fb15271 ca23413 fb15271 ca23413 fb15271 ca23413 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from PIL import Image
from io import BytesIO
from models.vision import VisionModel
from utils.bg_removal import remove_background
vision = VisionModel()
def detect_clothing(image_input, do_bg_remove: bool = False):
# 1) If filepath, load; else assume PIL.Image
if isinstance(image_input, str):
img = Image.open(image_input).convert("RGB")
else:
img = image_input
# 2) Optional background removal
if do_bg_remove:
buf = BytesIO()
img.save(buf, format="JPEG")
img_bytes = buf.getvalue()
img = remove_background(img_bytes)
else:
img = img.convert("RGB")
# 3) Run detection
detections = vision.detect(img)
if not detections:
detections = [{"label": "outfit", "score": 1.0, "box": []}]
return detections
|