Ë
    S^(h™  ã                   óŒ   — 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     úW/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/commands/run.pyÚtry_infer_format_from_extr      s\   € ÙØä!×3Ñ3ò ˆØ�=‰=˜ÕØŠJðô Ø
>¸t¸fð E6Ü6H×6ZÑ6ZÐ5[ð	]óð ó    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¨   € Ü
Ø�Y‰YØ ŸJšJˆd�jŠj¨DØ�{‰{Ø—.‘.Ø�{‰{ô€Cð 7;·k±kÀWÒ6LÔ& t§z¡zÔ2ÐRV×R]ÑR]€FÜ×(Ñ(ØØ—K‘KØ—:‘:Ø"Ÿkškˆt�{Š{¨s×/FÑ/FØ—.‘.ô€Fô �c˜6Ó"Ð"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--deviceéÿÿÿÿzSIndicate 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  € à×&Ñ& uÐ3SÐ&ÓTˆ
Ø×Ñ Ô2EÓ2GÈmÐÔ\Ø×Ñ 	´Ð:aÐÔbØ×Ñ 
´Ð;vÐÔwØ×Ñ 	´Ð:eÐÔfØ×Ñ 
´Ð;oÐÔpØ×ÑØ¤Ð*kð 	 ô 	
ð 	×ÑØÜØkð 	 ô 	
ð
 	×ÑØÜØÜ&×8Ñ8Ø,ð 	 ô 	
ð 	×ÑØÜØØfð	 	 ô 	
ð 	×Ñ °lÐImÐÔ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ª   € Ø—y‘y "ˆWˆà—\‘\ò 	"ˆEØ%)§\¡\×%BÒ%B‘S‘\˜5’\ÉÈEË
ˆFÜ˜&¤$Ô'Ø—‘˜vÕ&à˜6Ñ!‘ð	"ð �9‰9×"Ò"ØŸ,™,×2Ñ2°7Ó;ˆKÜ�N‰NÐ`ÐalÐ`mÐnÕoà�L‰L×Ñ˜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   