
    sg                         d dl mZ ddlmZmZmZmZ ddlmZ ddl	m
Z
  ej                  e      ZdefdZd	 Z G d
 de
      Zy)    )ArgumentParser   )PipelinePipelineDataFormatget_supported_taskspipeline)logging   )BaseTransformersCLICommandpathc                     | syt         j                  D ]  }| j                  |      s|c S  t        d|  dt         j                         )Npipez4Unable to determine file format from file extension z-. Please provide the format through --format )r   SUPPORTED_FORMATSendswith	Exception)r   exts     L/var/www/html/venv/lib/python3.12/site-packages/transformers/commands/run.pytry_infer_format_from_extr      s\    !33 ==J 
>tf E66H6Z6Z5[	]     c                    t        | j                  | j                  r| j                  nd | j                  | j                  | j
                        }| j                  dk(  rt        | j                        n| j                  }t        j                  || j                  | j                  | j                  r| j                  n|j                  | j                        }t        ||      S )N)taskmodelconfig	tokenizerdeviceinfer)formatoutput_path
input_pathcolumn	overwrite)r   r   r   r   r   r   r   r   inputr   from_stroutputr    default_input_namesr!   
RunCommand)argsnlpr   readers       r   run_command_factoryr*   '   s    
YY JJdjjD{{..{{C 7;kkW6L&tzz2RVR]R]F((KK::"kkt{{s/F/F..F c6""r   c                   8    e Zd ZdedefdZedefd       Zd Z	y)r&   r(   r)   c                      || _         || _        y )N)_nlp_reader)selfr(   r)   s      r   __init__zRunCommand.__init__;   s    	r   parserc                 X   | j                  dd      }|j                  dt               d       |j                  dt        d	       |j                  d
t        d	       |j                  dt        d	       |j                  dt        d	       |j                  dt        d	       |j                  dt        d	       |j                  dt        dt        j
                  d       |j                  dt        dd       |j                  ddd       |j                  t                y )!NrunzRun a pipeline through the CLI)helpz--taskzTask to run)choicesr4   z--inputz%Path to the file to use for inference)typer4   z--outputz9Path to the file that will be used post to write results.z--modelz)Name or path to the model to instantiate.z--configz2Name or path to the model's config to instantiate.z--tokenizerz?Name of the tokenizer to use. (default: same as the model name)z--columnzXName of the column to use as input. (For multi columns input as QA use column1,columns2)z--formatr   zInput format to read from)r6   defaultr5   r4   z--devicezSIndicate the device to run onto, -1 indicates CPU, >= 0 indicates GPU (default: -1))r6   r7   r4   z--overwrite
store_truez"Allow overwriting the output file.)actionr4   )func)	
add_parseradd_argumentr   strr   r   intset_defaultsr*   )r1   
run_parsers     r   register_subcommandzRunCommand.register_subcommand?   s7   &&u3S&T
2E2Gm\	:ab
;vw	:ef
;op*k 	  	
 	k 	  	

 	&88, 	  	
 	f	 	  	
 	lImn%89r   c                    | j                   g }}| j                  D ]O  }| j                  j                  r |di |n ||      }t        |t              r|j                  |       K||z  }Q | j                   j                  r4| j                  j                  |      }t        j                  d|        y | j                  j                  |       y )NzCCurrent pipeline requires output to be in binary format, saving at  )r-   r.   is_multi_columns
isinstancedictappendbinary_outputsave_binaryloggerwarningsave)r/   r(   outputsentryr$   binary_paths         r   r3   zRunCommand.run_   s    yy"W\\ 	"E%)\\%B%BS\5\E
F&$'v&6!	" 99"",,227;KNN`al`mnoLLg&r   N)
__name__
__module____qualname__r   r   r0   staticmethodr   rB   r3   rD   r   r   r&   r&   :   s6    H .@  :N : :>'r   r&   N)argparser   	pipelinesr   r   r   r   utilsr	    r   
get_loggerrQ   rK   r>   r   r*   r&   rD   r   r   <module>rZ      sH    $ S S  ( 
		H	%C #&4'+ 4'r   