
    vj                         d dl mZ d dl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mZ d dlmZ  e            Zd Zefd	eeef         d
ee         fdZd	eeef         fdZd ZdS )    N)ListOptionalUnion)HubApi)model_file_download)Config)DEFAULT_MODEL_REVISION	ModelFile)
get_loggerc                     	 t          j        |           }t          |d          pt          |d          S # t          $ r+}t                              d|  d|            Y d }~dS d }~ww xY w)Nmodel
model_typezparse config file z	 failed: F)r   	from_filehasattr	Exceptionloggererror)cfg_filecfges      i/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/modelscope/pipelines/util.pyis_config_has_modelr      s    x((sG$$B\(B(BB   @(@@Q@@AAAuuuuus   36 
A+  A&&A+pathrevisionc                     fdt          | t                    r |           S fd| D             }t          |          }t          |          }|r|st	          d|            |S )z_ Whether path is an official hub name or a valid local
    path to official hub directory.
    c                 &   t          j        |           r3t          j        | t          j                  }t          j        |          S 	 t                                          |           }dS # t          $ r}t          d|           d }~ww xY w)N)r   Tzinvalid model repo path )	ospexistsjoinr
   CONFIGURATIONr   	get_modelr   
ValueError)r   r   _r   r   s       r   is_official_hub_implz2is_official_hub_path.<locals>.is_official_hub_impl   s    :d 	Axi&=>>H:h'''AHH&&th&??t A A A !?A!?!?@@@As   
#A/ /
B9BBc                 &    g | ]} |          S  r&   ).0mr$   s     r   
<listcomp>z(is_official_hub_path.<locals>.<listcomp>+   s%    999q''**999    z6some model are hub address, some are not, model list: 
isinstancestrallanyr"   )r   r   resultsall_trueany_truer$   s    `   @r   is_official_hub_pathr3      s    	A 	A 	A 	A 	A $ ##D)))9999D999w<<w<< 	H 	OOO   r*   c                     d t          | t                    r |           S fd| D             }t          |          }t          |          }|r|st	          d|            |S )zG whether path is a valid modelhub path and containing model config
    c                    t          j        |           rt          j        | t          j                  }t          j        | t          j                  }t          j        |          rt          |          S t          j        |          rt          |          S dS 	 t          | t          j                  }t          |          rdS t          | t          j                  }t          |          S # t          $ r Y dS w xY w)NFT)	r   r   r   r
   r    CONFIGr   r   r   )r   r   hf_cfg_files      r   is_modelhub_path_implz'is_model.<locals>.is_modelhub_path_impl:   s    :d 	xi&=>>H(4)9::Kz(## *8444K(( *;777u.tY5LMM&x00 <4"5dI<L"M"MK.{;;;   uus   )C0 (C0 0
C>=C>c                 &    g | ]} |          S r&   r&   )r'   r(   r8   s     r   r)   zis_model.<locals>.<listcomp>R   s%    :::((++:::r*   z7some models are hub address, some are not, model list: r+   )r   r0   r1   r2   r8   s       @r   is_modelr:   6   s      * $ $$T***::::T:::w<<w<< 	H 	P$PP   r*   c                    dd l }| j        j        dk    rt          |t                    sJ t          |          d |D             i d}|d         d                                         D ],|                    fd|D                       |d         <   -d|d         v r"|                    d |D                       |d<   d	|d         v r"|                    d
 |D                       |d	<   |S d S )Nr   OfaForAllTasksc                 *    g | ]}|d          d         S )samplesr   r&   r'   ds     r   r)   z!batch_process.<locals>.<listcomp>d   s     666A)Q666r*   )
nsentencesr>   	net_inputrB   c                 ,    g | ]}|d                   S )rB   r&   )r'   r@   ks     r   r)   z!batch_process.<locals>.<listcomp>i   s"    111q;"111r*   w_resize_ratiosc                     g | ]
}|d          S )rE   r&   r?   s     r   r)   z!batch_process.<locals>.<listcomp>l       444!$%444r*   h_resize_ratiosc                     g | ]
}|d          S )rH   r&   r?   s     r   r)   z!batch_process.<locals>.<listcomp>o   rG   r*   )torch	__class____name__r,   listlenkeyscat)r   datarJ   
batch_datarD   s       @r   batch_processrS   ]   s;   LLL#333$%%%%%d))66666
 


 a%**,, 	3 	3A).1111D111*3 *3J{#A&&Q'',1II44t444-6 -6J()Q'',1II44t444-6 -6J() % 43r*   )os.pathr   r   typingr   r   r   modelscope.hub.apir   modelscope.hub.file_downloadr   modelscope.utils.configr   modelscope.utils.constantr	   r
   modelscope.utils.loggerr   r   r   r-   r3   r:   rS   r&   r*   r   <module>r[      s(         ( ( ( ( ( ( ( ( ( ( % % % % % % < < < < < < * * * * * * G G G G G G G G . . . . . .	   4J uS$Y/ #+C=   >$5d# $ $ $ $N    r*   