
    q6jj                    V   U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZmZ d dlmZmZmZ d dlmZ ddlmZmZmZmZmZmZmZmZ  ee                                          j        d         Zed	z  Z ed
z  Z!edz  Z" edd          Z#e#$                    d e e%e"                    d           da&de'd<   d7dZ(e#)                    d          d             Z*e#)                    de          d             Z+d8dZ,e#-                    d            e	d!          fd9d$            Z.e#-                    d%           e
d!           e
d&           e
d'           e
d           fd:d-            Z/e#-                    d.           e
d!           e
d&           e
d'           e
d/          fd;d1            Z0e#-                    d2           e	d!           e
d&           e
d'           e
d/          fd<d3            Z1e#)                    d4          d=d6            Z2dS )>    )annotationsN)Path)FastAPIFileFormHTTPException
UploadFile)FileResponseHTMLResponseJSONResponse)StaticFiles   )
IMAGE_EXTS
VIDEO_EXTSSensitiveDetectoris_imageis_videopreview_frameprocess_imageprocess_videouploadsoutputsstaticzAuto Intimate Blurz1.0.0)titleversionz/static)	directory)namezSensitiveDetector | None	_detectorreturnr   c                 >    t           t          d          a t           S )Ng      ?)score_threshold)r   r        ,/home/wildlama/intimate-blur-app/app/main.pydetectorr%      s    %d;;;	r#   z/healthc                     dddS )Nokzauto-intimate-blur)statusappr"   r"   r#   r$   healthr*      s    #7888r#   /)response_classc                 0    t          t          dz            S )Nz
index.html)r
   
STATIC_DIRr"   r#   r$   indexr/   $   s    
\1222r#   file_idstrr   c                    t          |           j        }t          t                              | d                    }|st          dd          |d         S )Nz.*  zUpload introuvablestatus_codedetailr   )r   stemlist
UPLOAD_DIRglobr   )r0   safe_idmatchess      r$   _find_uploadr=   )   sV    7mm G:??g>>>2233G J4HIIII1:r#   z/api/upload.filer	   c                  K   t          | j        pd          j        }t          |          j                                        }|t
          t          z  vrt          dd|           t          	                    dd           t          t          j                               dt          j                    j        d d          }t          | | z  }|                    d	          5 }|                     d
           d {V x}r2|                    |           |                     d
           d {V x}2d d d            n# 1 swxY w Y   t%          d|||t
          v rdndd          S )Nupload  u   Format non supporté: r4   T)parentsexist_ok_   wbi   imagevideo)r'   r0   filenamekind)r   rI   r   suffixlowerr   r   r   r9   mkdirinttimeuuiduuid4hexopenreadwriter   )r>   original_nameextr0   
input_pathfchunks          r$   upload_filer[   1   s     2(338M
}


$
*
*
,
,C
*z)))4RS4R4RSSSSTD111TY[[!!::DJLL$4RaR$8::G/#///J			 !!YY{333333333e 	GGENNN "YY{333333333e 	               !*,,'	    s   +AEEEz/api/previewG   g?blur_strengthrN   marginfloatframe_indexc                @  K   t          |           }t          t          |           j         dz  }	 t	          ||t                      |||          }n1# t          $ r$}t          dt          |                    |d }~ww xY wt          dd|j
         |d          S )Nz_preview.png)r]   r^   r`     r4   T
/download/)r'   preview_urlmeta)r=   
OUTPUT_DIRr   r7   r   r%   	Exceptionr   r1   r   r   )r0   r]   r^   r`   rX   preview_pathre   excs           r$   preview_uploadrj   E   s       g&&J4==#5 C C CCLGZxzzQ^gm  |G  H  H  H G G GCHH===3FG7L$577    s   !A 
BA==Bz/api/render   detect_everyc                  K   t          |           }t          |          rdnd}t          t          |           j         d| z  }	 t                      }t          |          rt          |||||          }n6t          |          rt          ||||||          }nt          dd          n1# t          $ r$}	t          d	t          |	                    |	d }	~	ww xY wt          d
|j        d|j         d|j         |d          S )Nz.pngz.mp4_blurred)r]   r^   )r]   r^   rl   rA   u   Type non supportér4   rb   Trc   )r'   rI   download_urlrd   re   )r=   r   rf   r   r7   r%   r   r   r   r   rg   r1   r   r   )
r0   r]   r^   rl   rX   out_extoutput_pathdetre   ri   s
             r$   render_uploadrs   Y   sZ      g&&J ,,8ff&G$w--"4GGgGGGK	GjjJ 	N [#]cijjjDDj!! 	N [#]ci  yE  F  F  FDDC8LMMMM G G GCHH===3FG$7[%5776K$466    s   A(B0 0
C:CCz/api/processc                   K   t          |            d {V }|j        }dd l}|                    |          d         }t	          ||||           d {V S )Nr   r0   )r0   r]   r^   rl   )r[   bodyjsonloadsrs   )r>   r]   r^   rl   uploadeddatarv   r0   s           r$   process_upload_legacyrz   v   sx       !&&&&&&&&H=DKKKjjy)GwmTZiuvvvvvvvvvvr#   z/download/{filename}rI   c                    t          |           j        }t          |z  }|                                st	          dd          t          j        t          |                    d         pd}t          |||          S )Nr3   zFichier introuvabler4   r   zapplication/octet-stream)
media_typerI   )	r   r   rf   existsr   	mimetypes
guess_typer1   r
   )rI   safepathr|   s       r$   downloadr      su    >>DD;;== K4IJJJJ%c$ii003Q7QJdCCCCr#   )r   r   )r0   r1   r   r   )r>   r	   )r0   r1   r]   rN   r^   r_   r`   rN   )r0   r1   r]   rN   r^   r_   rl   rN   )r>   r	   r]   rN   r^   r_   rl   rN   )rI   r1   )3
__future__r   r~   rO   rP   pathlibr   fastapir   r   r   r   r	   fastapi.responsesr
   r   r   fastapi.staticfilesr   blur_enginer   r   r   r   r   r   r   r   __file__resolverB   BASE_DIRr9   rf   r.   r)   mountr1   r   __annotations__r%   getr*   r/   r=   postr[   rj   rs   rz   r   r"   r#   r$   <module>r      s   " " " " " " "             B B B B B B B B B B B B B B F F F F F F F F F F + + + + + + D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D4>>!!##+A.	!
	!
 
g('::: 		)[[33z??;;;(	 K K K&*	 * * * *    9 9 9 \**3 3 +*3    -)-c     & .499bDJJtAww	    & -499bDJJQ	    8 .tCyybDJJQ	
w 
w 
w 
w 
w 	  D D D ! D D Dr#   