
    
3j                        S SK r S SKrS SKJrJr  S SKJrJr  S SKr	S SK
r	S SKrSSKJr  SSKJrJr   SS\\	R$                  R$                  -  S\\	R$                  R$                  /\	R$                  R$                  4   S-  S	\	R$                  R$                  4S
 jjr SS\S\\\	R$                  R$                     /\\	R$                  R$                     4   S-  S	\\	R$                  R$                     4S jjrS\S	\\\4   4S jrS\4S jrg)    N)AnyCallable)unquoteurlparse   )DIFFUSERS_REQUEST_TIMEOUT)BACKENDS_MAPPINGis_imageio_availableimageconvert_methodreturnc                    [        U [        5      (       a  U R                  S5      (       d  U R                  S5      (       aB  [        R                  R                  [        R                  " U S[        S9R                  5      n O[        R                  R                  U 5      (       a   [        R                  R                  U 5      n OF[        SU  S35      e[        U [        R                  R                  5      (       a  U n O[        S5      e[        R                  R                  U 5      n Ub
  U" U 5      n U $ U R!                  S5      n U $ )	a  
Loads `image` to a PIL Image.

Args:
    image (`str` or `PIL.Image.Image`):
        The image to convert to the PIL Image format.
    convert_method (Callable[[PIL.Image.Image], PIL.Image.Image], *optional*):
        A conversion method to apply to the image after loading it. When set to `None` the image will be converted
        "RGB".

Returns:
    `PIL.Image.Image`:
        A PIL Image.
http://https://T)streamtimeoutIIncorrect path or URL. URLs must start with `http://` or `https://`, and  is not a valid path.zgIncorrect format used for the image. Should be a URL linking to an image, a local path, or a PIL image.RGB)
isinstancestr
startswithPILImageopenrequestsgetr   rawospathisfile
ValueErrorImageOpsexif_transposeconvert)r   r   s     W/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/utils/loading_utils.py
load_imager'      s   " %I&&%*:*::*F*FIINN8<<dLe#f#j#jkEWW^^E""IINN5)E[\a[bbwx  
E399??	+	+u
 	
 LL''.E!u% L e$L    videoc                 ,   U R                  S5      =(       d    U R                  S5      n[        R                  R                  U 5      nSnU(       d  U(       d  [	        SU  S35      eU(       Ga  [
        R                  " U SS9nUR                  S:w  a  [	        S	UR                   35      e[        U 5      n[        R                  R                  [        UR                  5      5      n[        R                  R                  U5      S
   =(       d    Sn[        R                  " USS9R                  n	SnUR                  SS9n
[!        U	S5       nU
 H  nUR#                  U5        M     SSS5        U	n / nU R%                  S5      (       ad  [&        R(                  R!                  U 5      n  UR+                  UR-                  5       5        UR/                  UR1                  5       S
-   5        MC  [5        5       (       a  SSKnO$[9        [:        S   S
   R=                  S5      5      e UR>                  R@                  RC                  5         URG                  U 5       nU H1  nUR+                  [&        R(                  RI                  U5      5        M3     SSS5        U(       a  [        RJ                  " W	5        Ub  U" U5      nU$ ! , (       d  f       GNe= f! [2         a     NHf = f! [D         a    [E        S5      ef = f! , (       d  f       Ns= f)a  
Loads `video` to a list of PIL Image.

Args:
    video (`str`):
        A URL or Path to a video to convert to a list of PIL Image format.
    convert_method (Callable[[list[PIL.Image.Image]], list[PIL.Image.Image]], *optional*):
        A conversion method to apply to the video after loading it. When set to `None` the images will be converted
        to "RGB".

Returns:
    `list[PIL.Image.Image]`:
        The video as a list of PIL images.
r   r   Fr   r   T)r      z'Failed to download video. Status code: r   z.mp4)suffixdeletei    )
chunk_sizewbNz.gifr   imageio
load_videozf`Unable to find an ffmpeg installation on your machine. Please install via `pip install imageio-ffmpeg)&r   r   r    r!   r"   r   r   status_coder   basenamer   splitexttempfileNamedTemporaryFilenameiter_contentr   writeendswithr   r   appendcopyseektellEOFErrorr
   r0   ImportErrorr	   formatpluginsffmpegget_exeAttributeError
get_reader	fromarrayremove)r)   r   is_urlis_filewas_tempfile_createdresponse
parsed_url	file_namer,   
video_path
video_datafchunk
pil_imagesgifr0   readerframes                     r&   r1   r1   9   s   $ i(HE,<,<Z,HFggnnU#G gWX]W^^st
 	
 <<d33&FxG[G[F\]^^e_
GG$$WZ__%=>	!!),Q/9600uMRR
#**d*;
*d#q# $ $ J~~fiinnU#	!!#((*-a(   !!.y9!<CCLQRR	OO""**, &&!!#))"5"5e"<=   '
 
		*!#J/
Q $#  		  	 x 	
 '&s7   K
.AK +$K,  8L

K
K)(K),L
Ltensor_namec                     SU;   aC  UR                  S5      nUS S  H$  n[        X5      nUc  [        U  SU S35      eUn M&     US   nX4$ )N.z has no attribute )splitgetattrr"   )modulerW   splitsr[   
new_modules        r&   get_module_from_namer`      sl    
k""3'CR[E /J! F8+=eWA!FGGF	 !
 Rjr(   module_pathc                     U nUR                  S5      nU H4  nUR                  5       (       a  [        U5      nX%   nM)  [        X$5      nM6     U$ )NrY   )r[   isdigitintr\   )root_modulera   currentpartspartidxs         r&   get_submodule_by_namerj      sM    Gc"E<<>>d)ClGg,G  Nr(   )N)r   r5   typingr   r   urllib.parser   r   	PIL.Imager   PIL.ImageOpsr   	constantsr   import_utilsr	   r
   r   r   r'   listr1   tupler`   rj    r(   r&   <module>rt      s   	    *    0 @ im( (2:CIIOO;Lciioo;]2^ae2e(YY__(Z W[QQd399??34d399??6KKLtSQ 
#))//Qj	c 	eCHo 		C 	r(   