o
    @Tj.                  
   @   s   d Z ddlmZmZmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ eddgd	Zejd
e
dededddeefdededede
fddZdS )u4   Background removal (segmentation / 누끼) endpoint.    )	APIRouterDependsFileQuery
UploadFile)get_segmentation_service)RemoveBackgroundResponse)SegmentationService)save_segmentation_imagez/api/v1/segmentationsegmentation)prefixtagsz
/remove-bg)response_model.Fz'Center-crop person in 9:16 aspect ratio)descriptionimagecenter_cropseg_svcreturnc                 C   s0   | j  }|j||d}t|}td| dS )a&  Remove background from uploaded image.

    Accepts any common image format (JPEG, PNG, WebP).
    Saves the result as PNG with transparent background and returns the URL.
    When center_crop=true, the result is cropped to 9:16 with the person
    centered and minimal top/bottom margins.
    )r   z	/storage/)	image_url)filereadremove_backgroundr
   r   )r   r   r   image_bytesresult_bytesrelative_path r   8/home/ubuntu/htdocs/ootd-api/app/routers/segmentation.pyr      s   
r   N)__doc__fastapir   r   r   r   r   app.dependenciesr   app.schemas.segmentationr   !app.services.segmentation_servicer	   app.utils.imager
   routerpostboolr   r   r   r   r   <module>   s,    