
    9i                         S SK Jr  S SKJrJrJr  S SKJr  S SK	J
r
  S SKJr  S SKJrJr  S SKJr  \" 5       rS r\4S	\\\4   S
\\   4S jjrS	\\\4   4S jrS rg)    N)ListOptionalUnion)HubApi)model_file_download)Config)DEFAULT_MODEL_REVISION	ModelFile)
get_loggerc                      [         R                  " U 5      n[        US5      =(       d    [        US5      $ ! [         a%  n[        R                  SU  SU 35         S nAgS nAff = f)Nmodel
model_typezparse config file z	 failed: F)r   	from_filehasattr	Exceptionloggererror)cfg_filecfges      Y/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/util.pyis_config_has_modelr      s]    x(sG$B\(BB )(9QC@As   47 
A&A!!A&pathrevisionc                    ^ U4S jn[        U [        5      (       a  U" U 5      $ U  Vs/ s H
  o2" U5      PM     nn[        U5      n[        U5      nU(       a  U(       d  [	        SU  35      eU$ s  snf )zVWhether path is an official hub name or a valid local
path to official hub directory.
c                 $  > [         R                  " U 5      (       a;  [         R                  " U [        R                  5      n[         R                  " U5      $  [        5       R                  U TS9ng! [         a  n[        SU 35      eS nAff = f)N)r   Tzinvalid model repo path )	ospexistsjoinr
   CONFIGURATIONr   	get_modelr   
ValueError)r   r   _r   r   s       r   is_official_hub_impl2is_official_hub_path.<locals>.is_official_hub_impl   s|    ::dxxi&=&=>H::h''AH&&th&? A #;A3!?@@As   A2 2
B<B

Bz6some model are hub address, some are not, model list: 
isinstancestrallanyr"   )r   r   r$   mresultsall_trueany_trues    `     r   is_official_hub_pathr/      sw    	A $#D))489Dq'*D9w<w<HHO   :s   A0c                     S n[        U [        5      (       a  U" U 5      $ U  Vs/ s H
  o!" U5      PM     nn[        U5      n[        U5      nU(       a  U(       d  [	        SU  35      eU$ s  snf )zFwhether path is a valid modelhub path and containing model config
    c                 (   [         R                  " U 5      (       a  [         R                  " U [        R                  5      n[         R                  " U [        R
                  5      n[         R                  " U5      (       a  [        U5      $ [         R                  " U5      (       a  [        U5      $ g [        U [        R                  5      n[        U5      (       a  g[        U [        R
                  5      n[        U5      $ ! [         a     gf = f)NFT)	r   r   r   r
   r    CONFIGr   r   r   )r   r   hf_cfg_files      r   is_modelhub_path_impl'is_model.<locals>.is_modelhub_path_impl:   s    ::dxxi&=&=>H((4)9)9:Kzz(##*844K((*;77.tY5L5LM&x00"5dI<L<L"MK.{;; s   4*D $D 
DDz7some models are hub address, some are not, model list: r&   )r   r4   r+   r,   r-   r.   s         r   is_modelr6   6   su    * $$T**59:T(+T:w<w<HI$P   ;s   A,c                 8   SS K nU R                  R                  S:X  a  [        U[        5      (       d   e[        U5      U Vs/ s H
  o3S   S   PM     sn0 S.nUS   S   R                  5        H0  nUR                  U Vs/ s H
  o3S   U   PM     sn5      US   U'   M2     SUS   ;   a'  UR                  U Vs/ s H  o3S   PM	     sn5      US'   SUS   ;   a'  UR                  U Vs/ s H  o3S   PM	     sn5      US'   U$ g s  snf s  snf s  snf s  snf )Nr   OfaForAllTaskssamples)
nsentencesr9   	net_inputr;   w_resize_ratiosh_resize_ratios)torch	__class____name__r'   listlenkeyscat)r   datar>   d
batch_dataks         r   batch_processrI   ]   s2   #33$%%%%d)156A)Q6


 a%**,A).,01Dq;"D1*3J{#A& - Q',1II/34t!$%t4-6J()Q',1II/34t!$%t4-6J() % 4
 7
 2 5 5s   DD
=D-D)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(   r/   r6   rI        r   <module>rS      sk     ( ( % < * G .	 4JuS$Y/ #+C=>$5d# $NrR   