
    g                         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dS )    )ArgumentParser   )PipelinePipelineDataFormatget_supported_taskspipeline)logging   )BaseTransformersCLICommandpathc                     | sdS t           j        D ]}|                     |          r|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     U/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/commands/run.pytry_infer_format_from_extr      s}     v!3  == 	JJJ	 	]t 	] 	]6H6Z	] 	]      c                 P   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    
Y J0djjD{.{  C 7;kW6L6L&tz222RVR]F(K:"kFt{{s/F.  F c6"""r   c                   @    e Zd ZdedefdZedefd            Zd Z	dS )r&   r(   r)   c                 "    || _         || _        d S )N)_nlp_reader)selfr(   r)   s      r   __init__zRunCommand.__init__;   s    	r   parserc                    |                      dd          }|                    dt                      d           |                    dt          d	           |                    d
t          d	           |                    dt          d	           |                    dt          d	           |                    dt          d	           |                    dt          d	           |                    dt          dt          j        d           |                    dt          dd           |                    ddd           |                    t                      d S )!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?   s   &&u3S&TT
2E2G2Gm\\\	:abbb
;vwww	:efff
;oppp*k 	  	
 	
 	
 	k 	  	
 	
 	

 	&8, 	  	
 	
 	
 	f	 	  	
 	
 	
 	lImnnn%899999r   c                    | j         g }}| j        D ]Q}| j        j        r |di |n
 ||          }t          |t                    r|                    |           L||z  }R| j         j        r9| j                            |          }t          	                    d|            d S | j        
                    |           d S )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    y"W\ 	" 	"E%)\%BRSS\\5\\\E

F&$'' "v&&&&6! 9" 	',227;;KNNnalnnoooooLg&&&&&r   N)
__name__
__module____qualname__r   r   r0   staticmethodr   rB   r3   rD   r   r   r&   r&   :   sm        H .@     :N : : : \:>' ' ' ' 'r   r&   N)argparser   	pipelinesr   r   r   r   utilsr	    r   
get_loggerrQ   rK   r>   r   r*   r&   rD   r   r   <module>rZ      s    $ # # # # # S S S S S S S S S S S S       ( ( ( ( ( ( 
	H	%	%C    # # #&4' 4' 4' 4' 4'+ 4' 4' 4' 4' 4'r   