§
    \zni´B  ã                   ó’  — d dl Z d dlZddlmZ ddlmZmZmZmZ ddl	m
Z
mZ  e¦   «         r
d dlZddlmZ  e¦   «         rddlmZ  ej        e¦  «        Z G d	„ d
e j        ¦  «        Z ee
¦  «         G d„ de¦  «        ¦   «         Z ee
¦  «         G d„ de¦  «        ¦   «         Z ee
¦  «         G d„ de¦  «        ¦   «         ZdS )é    Né   )ÚTruncationStrategy)Úadd_end_docstringsÚis_tf_availableÚis_torch_availableÚloggingé   )ÚPIPELINE_INIT_ARGSÚPipeline)Ú/TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES)Ú,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMESc                   ó   — e Zd ZdZdZdS )Ú
ReturnTyper   r	   N)Ú__name__Ú
__module__Ú__qualname__ÚTENSORSÚTEXT© ó    ú‹/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/transformers/pipelines/text2text_generation.pyr   r      s   € € € € € Ø€GØ€D€D€Dr   r   c                   óŽ   ‡ — e Zd ZdZdZˆ fd„Z	 	 	 	 	 	 dd„Zdededefd	„Zd
„ Z	ˆ fd„Z
ej        fd„Zd„ Zej        dfd„Zˆ xZS )ÚText2TextGenerationPipelineaW  
    Pipeline for text to text generation using seq2seq models.

    Example:

    ```python
    >>> from transformers import pipeline

    >>> generator = pipeline(model="mrm8488/t5-base-finetuned-question-generation-ap")
    >>> generator(
    ...     "answer: Manuel context: Manuel has created RuPERTa-base with the support of HF-Transformers and Google"
    ... )
    [{'generated_text': 'question: Who created the RuPERTa-base?'}]
    ```

    Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial). You can pass text
    generation parameters to this pipeline to control stopping criteria, decoding strategy, and more. Learn more about
    text generation parameters in [Text generation strategies](../generation_strategies) and [Text
    generation](text_generation).

    This Text2TextGenerationPipeline pipeline can currently be loaded from [`pipeline`] using the following task
    identifier: `"text2text-generation"`.

    The models that this pipeline can use are models that have been fine-tuned on a translation task. See the
    up-to-date list of available models on
    [huggingface.co/models](https://huggingface.co/models?filter=text2text-generation). For a list of available
    parameters, see the [following
    documentation](https://huggingface.co/docs/transformers/en/main_classes/text_generation#transformers.generation.GenerationMixin.generate)

    Usage:

    ```python
    text2text_generator = pipeline("text2text-generation")
    text2text_generator("question: What is 42 ? context: 42 is the answer to life, the universe and everything")
    ```Ú	generatedc                 ó’   •—  t          ¦   «         j        |i |¤Ž |                      | j        dk    rt          nt
          ¦  «         d S )NÚtf)ÚsuperÚ__init__Úcheck_model_typeÚ	frameworkr   r   ©ÚselfÚargsÚkwargsÚ	__class__s      €r   r   z$Text2TextGenerationPipeline.__init__B   sY   ø€ Ø�‰ŒÔ˜$Ð) &Ð)Ð)Ð)à×ÒàŒ~ Ò%Ð%õ <Ð;å=ñ	
ô 	
ð 	
ð 	
ð 	
r   Nc                 ó  — i }|�||d<   |}	i }
|�|€|rt           j        nt           j        }|�||
d<   |�||
d<   |�N| j                             |d¬¦  «        }t          |¦  «        dk    rt          j        d¦  «         |d         |d	<   ||	|
fS )
NÚ
truncationÚreturn_typeÚclean_up_tokenization_spacesF)Úadd_special_tokensr	   z©Stopping on a multiple token sequence is not yet supported on transformers. The first token of the stop sequence will be used as the stop sequence string in the interim.r   Úeos_token_id)r   r   r   Ú	tokenizerÚencodeÚlenÚwarningsÚwarn)r"   Úreturn_tensorsÚreturn_textr(   r)   r'   Ústop_sequenceÚgenerate_kwargsÚpreprocess_paramsÚforward_paramsÚpostprocess_paramsÚstop_sequence_idss               r   Ú_sanitize_parametersz0Text2TextGenerationPipeline._sanitize_parametersK   sØ   € ð ÐØÐ!Ø.8Ð˜lÑ+à(ˆàÐØÐ%¨+Ð*=Ø0>ÐS�*Ô,Ð,ÅJÄOˆKØÐ"Ø0;Ð˜}Ñ-à'Ð3ØA]ÐÐ=Ñ>àÐ$Ø $¤× 5Ò 5°mÐX]Ð 5Ñ ^Ô ^ÐÝÐ$Ñ%Ô%¨Ò)Ð)Ý”ðbñô ð ð /@ÀÔ.BˆO˜NÑ+à  .Ð2DÐDÐDr   Úinput_lengthÚ
min_lengthÚ
max_lengthc                 ó   — dS )új
        Checks whether there might be something wrong with given input with regard to the model.
        Tr   ©r"   r:   r;   r<   s       r   Úcheck_inputsz(Text2TextGenerationPipeline.check_inputso   s	   € ð ˆtr   c                ó¨  ‡— | j         j        j        �| j         j        j        ndŠt          |d         t          ¦  «        r3| j        j        €t          d¦  «        ‚ˆfd„|d         D ¦   «         f}d}nCt          |d         t          ¦  «        r‰|d         z   f}d}nt          d|d         › d�¦  «        ‚ | j        |||| j	        d	œŽ}d
|v r|d
= |S )NÚ r   zOPlease make sure that the tokenizer has a pad_token_id when using a batch inputc                 ó   •— g | ]}‰|z   ‘ŒS r   r   )Ú.0ÚargÚprefixs     €r   ú
<listcomp>zCText2TextGenerationPipeline._parse_and_tokenize.<locals>.<listcomp>z   s   ø€ Ð5Ð5Ð5 c�V˜c‘\Ð5Ð5Ð5r   TFz `args[0]`: zI have the wrong format. The should be either of type `str` or type `list`)Úpaddingr'   r1   Útoken_type_ids)
ÚmodelÚconfigrF   Ú
isinstanceÚlistr,   Úpad_token_idÚ
ValueErrorÚstrr    )r"   r'   r#   rH   ÚinputsrF   s        @r   Ú_parse_and_tokenizez/Text2TextGenerationPipeline._parse_and_tokenizeu   s  ø€ Ø-1¬ZÔ->Ô-EÐ-Q�”Ô"Ô)Ð)ÐWYˆÝ�d˜1”g�tÑ$Ô$ð 	ØŒ~Ô*Ð2Ý Ð!rÑsÔsÐsØ5Ð5Ð5Ð5¨T°!¬WÐ5Ñ5Ô5Ð7ˆDØˆGˆGå˜˜Qœ¥Ñ%Ô%ð 	Ø˜T !œWÑ$Ð&ˆDØˆGˆGåØq˜t AœwÐqÐqÐqñô ð ð  �” ¨wÀ:Ð^bÔ^lÐmÐmÐmˆà˜vÐ%Ð%ØÐ'Ð(Øˆr   c                 óø   •—  t          ¦   «         j        |i |¤Ž}t          |d         t          ¦  «        rDt	          d„ |d         D ¦   «         ¦  «        r%t	          d„ |D ¦   «         ¦  «        rd„ |D ¦   «         S |S )a¢  
        Generate the output text(s) using text(s) given as inputs.

        Args:
            args (`str` or `List[str]`):
                Input text for the encoder.
            return_tensors (`bool`, *optional*, defaults to `False`):
                Whether or not to include the tensors of predictions (as token indices) in the outputs.
            return_text (`bool`, *optional*, defaults to `True`):
                Whether or not to include the decoded texts in the outputs.
            clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`):
                Whether or not to clean up the potential extra spaces in the text output.
            truncation (`TruncationStrategy`, *optional*, defaults to `TruncationStrategy.DO_NOT_TRUNCATE`):
                The truncation strategy for the tokenization within the pipeline. `TruncationStrategy.DO_NOT_TRUNCATE`
                (default) will never truncate, but it is sometimes desirable to truncate the input to fit the model's
                max_length instead of throwing an error down the line.
            generate_kwargs:
                Additional keyword arguments to pass along to the generate method of the model (see the generate method
                corresponding to your framework [here](./model#generative-models)).

        Return:
            A list or a list of list of `dict`: Each result comes as a dictionary with the following keys:

            - **generated_text** (`str`, present when `return_text=True`) -- The generated text.
            - **generated_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) -- The token
              ids of the generated text.
        r   c              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S )N)rL   rP   )rD   Úels     r   ú	<genexpr>z7Text2TextGenerationPipeline.__call__.<locals>.<genexpr>ª   s,   è è € Ð:Ð:¨B•J˜r¥3Ñ'Ô'Ð:Ð:Ð:Ð:Ð:Ð:r   c              3   ó<   K  — | ]}t          |¦  «        d k    V — ŒdS )r	   N)r.   ©rD   Úress     r   rV   z7Text2TextGenerationPipeline.__call__.<locals>.<genexpr>«   s,   è è € Ð4Ð4 c•C˜‘H”H ’MÐ4Ð4Ð4Ð4Ð4Ð4r   c                 ó   — g | ]
}|d          ‘ŒS )r   r   rX   s     r   rG   z8Text2TextGenerationPipeline.__call__.<locals>.<listcomp>­   s   € Ð-Ð-Ð-˜s�C˜”FÐ-Ð-Ð-r   )r   Ú__call__rL   rM   Úall)r"   r#   r$   Úresultr%   s       €r   r[   z$Text2TextGenerationPipeline.__call__Š   s•   ø€ ð: "•‘”Ô! 4Ð2¨6Ð2Ð2ˆå�t˜A”w¥Ñ%Ô%ð	.åÐ:Ð:°$°q´'Ð:Ñ:Ô:Ñ:Ô:ð	.õ Ð4Ð4¨VÐ4Ñ4Ô4Ñ4Ô4ð	.ð
 .Ð- fÐ-Ñ-Ô-Ð-Øˆr   c                 ó&   —  | j         |fd|i|¤Ž}|S )Nr'   )rR   )r"   rQ   r'   r$   s       r   Ú
preprocessz&Text2TextGenerationPipeline.preprocess°   s&   € Ø)�Ô)¨&ÐRÐR¸ZÐRÈ6ÐRÐRˆØˆr   c                 ór  — | j         dk    r|d         j        \  }}n:| j         dk    r/t          j        |d         ¦  «                             ¦   «         \  }}|                      ||                     d| j        j        j        ¦  «        |                     d| j        j        j	        ¦  «        ¦  «          | j        j
        d	i |¤|¤Ž}|j        d         }| j         dk    r  |j        |||z  g|j        dd …         ¢R Ž }n5| j         dk    r*t          j        ||||z  g|j        dd …         ¢R ¦  «        }d|iS )
NÚptÚ	input_idsr   r;   r<   r   r	   Ú
output_idsr   )r    Úshaper   Únumpyr@   ÚgetrJ   rK   r;   r<   ÚgenerateÚreshape)r"   Úmodel_inputsr4   Úin_br:   rc   Úout_bs          r   Ú_forwardz$Text2TextGenerationPipeline._forward´   s[  € ØŒ>˜TÒ!Ð!Ø!-¨kÔ!:Ô!@ÑˆD�,�,ØŒ^˜tÒ#Ð#Ý!#¤¨,°{Ô*CÑ!DÔ!D×!JÒ!JÑ!LÔ!LÑˆD�,à×ÒØØ×Ò ¨d¬jÔ.?Ô.JÑKÔKØ×Ò ¨d¬jÔ.?Ô.JÑKÔKñ	
ô 	
ð 	
ð
 )�T”ZÔ(ÐKÐK¨<ÐK¸?ÐKÐKˆ
ØÔ  Ô#ˆØŒ>˜TÒ!Ð!Ø+˜Ô+¨D°%¸4±-ÐWÀ*ÔBRÐSTÐSUÐSUÔBVÐWÐWÐWˆJˆJØŒ^˜tÒ#Ð#Ýœ J°°uÀ±}Ð0\ÀzÔGWÐXYÐXZÐXZÔG[Ð0\Ð0\Ñ]Ô]ˆJØ˜jÐ)Ð)r   Fc                 óþ   — g }|d         d         D ]k}|t           j        k    r| j        › d�|i}n7|t           j        k    r'| j        › d�| j                             |d|¬¦  «        i}|                     |¦  «         Œl|S )Nrc   r   Ú
_token_idsÚ_textT)Úskip_special_tokensr)   )r   r   Úreturn_namer   r,   ÚdecodeÚappend)r"   Úmodel_outputsr(   r)   Úrecordsrc   Úrecords          r   Úpostprocessz'Text2TextGenerationPipeline.postprocessÇ   s¨   € ØˆØ'¨Ô5°aÔ8ð 	#ð 	#ˆJØ�jÔ0Ò0Ð0Ø!Ô-Ð9Ð9Ð9¸:ÐF��Ø¥
¤Ò/Ð/àÔ'Ð.Ð.Ð.°´×0EÒ0EØ"Ø,0Ø5Qð 1Fñ 1ô 1ð�ð �NŠN˜6Ñ"Ô"Ð"Ð"Øˆr   )NNNNNN)r   r   r   Ú__doc__rq   r   r9   Úintr@   rR   r[   r   ÚDO_NOT_TRUNCATEr_   rl   r   r   rw   Ú__classcell__©r%   s   @r   r   r      s  ø€ € € € € ð"ð "ðJ €Kð
ð 
ð 
ð 
ð 
ð ØØØ%)ØØð"Eð "Eð "Eð "EðH¨ð ¸#ð È3ð ð ð ð ðð ð ð*$ð $ð $ð $ð $ðL -?Ô,Nð ð ð ð ð*ð *ð *ð& 6@´_Ðchð ð ð ð ð ð ð ð r   r   c                   ó>   ‡ — e Zd ZdZdZˆ fd„Zdedededefd„Zˆ xZ	S )	ÚSummarizationPipelinea[  
    Summarize news articles and other documents.

    This summarizing pipeline can currently be loaded from [`pipeline`] using the following task identifier:
    `"summarization"`.

    The models that this pipeline can use are models that have been fine-tuned on a summarization task, which is
    currently, '*bart-large-cnn*', '*t5-small*', '*t5-base*', '*t5-large*', '*t5-3b*', '*t5-11b*'. See the up-to-date
    list of available models on [huggingface.co/models](https://huggingface.co/models?filter=summarization). For a list
    of available parameters, see the [following
    documentation](https://huggingface.co/docs/transformers/en/main_classes/text_generation#transformers.generation.GenerationMixin.generate)

    Usage:

    ```python
    # use bart in pytorch
    summarizer = pipeline("summarization")
    summarizer("An apple a day, keeps the doctor away", min_length=5, max_length=20)

    # use t5 in tf
    summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base", framework="tf")
    summarizer("An apple a day, keeps the doctor away", min_length=5, max_length=20)
    ```Úsummaryc                 ó6   •—  t          ¦   «         j        |i |¤ŽS )a  
        Summarize the text(s) given as inputs.

        Args:
            documents (*str* or `List[str]`):
                One or several articles (or one list of articles) to summarize.
            return_text (`bool`, *optional*, defaults to `True`):
                Whether or not to include the decoded texts in the outputs
            return_tensors (`bool`, *optional*, defaults to `False`):
                Whether or not to include the tensors of predictions (as token indices) in the outputs.
            clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`):
                Whether or not to clean up the potential extra spaces in the text output.
            generate_kwargs:
                Additional keyword arguments to pass along to the generate method of the model (see the generate method
                corresponding to your framework [here](./model#generative-models)).

        Return:
            A list or a list of list of `dict`: Each result comes as a dictionary with the following keys:

            - **summary_text** (`str`, present when `return_text=True`) -- The summary of the corresponding input.
            - **summary_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) -- The token
              ids of the summary.
        ©r   r[   r!   s      €r   r[   zSummarizationPipeline.__call__õ   s!   ø€ ð0  �u‰wŒwÔ Ð0¨Ð0Ð0Ð0r   r:   r;   r<   Úreturnc           	      ó²   — ||k     r!t                                d|› d|› d�¦  «         ||k     r)t                                d|› d|› d|dz  › d�¦  «         d	S d	S )
r>   zYour min_length=z' must be inferior than your max_length=ú.zYour max_length is set to z , but your input_length is only z¶. Since this is a summarization task, where outputs shorter than the input are typically wanted, you might consider decreasing max_length manually, e.g. summarizer('...', max_length=r   ú)N©ÚloggerÚwarningr?   s       r   r@   z"SummarizationPipeline.check_inputs  s§   € ð ˜
Ò"Ð"Ý�NŠNÐn¨jÐnÐnÐakÐnÐnÐnÑoÔoÐoà˜*Ò$Ð$Ý�NŠNðq¨Zð qð qÐYeð qð qà^jÐlmÑ^mðqð qð qñô ð ð ð ð %Ð$r   )
r   r   r   rx   rq   r[   ry   Úboolr@   r{   r|   s   @r   r~   r~   Ø   sz   ø€ € € € € ðð ð2 €Kð1ð 1ð 1ð 1ð 1ð4¨ð ¸#ð È3ð ÐSWð ð ð ð ð ð ð ð r   r~   c                   ód   ‡ — e Zd ZdZdZdededefd„Zej        dddœˆ fd	„
Z	dˆ fd
„	Z
ˆ fd„Zˆ xZS )ÚTranslationPipelineaë  
    Translates from one language to another.

    This translation pipeline can currently be loaded from [`pipeline`] using the following task identifier:
    `"translation_xx_to_yy"`.

    The models that this pipeline can use are models that have been fine-tuned on a translation task. See the
    up-to-date list of available models on [huggingface.co/models](https://huggingface.co/models?filter=translation).
    For a list of available parameters, see the [following
    documentation](https://huggingface.co/docs/transformers/en/main_classes/text_generation#transformers.generation.GenerationMixin.generate)

    Usage:

    ```python
    en_fr_translator = pipeline("translation_en_to_fr")
    en_fr_translator("How old are you?")
    ```Útranslationr:   r;   r<   c                 óZ   — |d|z  k    r!t                                d|› d|› d�¦  «         dS )NgÍÌÌÌÌÌì?zYour input_length: z" is bigger than 0.9 * max_length: z`. You might consider increasing your max_length manually, e.g. translator('...', max_length=400)Tr†   r?   s       r   r@   z TranslationPipeline.check_inputs5  sX   € Ø˜# 
Ñ*Ò*Ð*Ý�NŠNð^ lð ^ð ^ÐV`ð ^ð ^ð ^ñô ð ð ˆtr   N)r'   Úsrc_langÚtgt_langc                ó–   •— t          | j        dd ¦  «        r | j        j        || j        |||dœŽS  t	          ¦   «         j        |d|iŽS )NÚ_build_translation_inputs)r1   r'   rŽ   r�   r'   )Úgetattrr,   r‘   r    r   rR   )r"   r'   rŽ   r�   r#   r%   s        €r   r_   zTranslationPipeline.preprocess=  sf   ø€ Ý�4”>Ð#>ÀÑEÔEð 	MØ;�4”>Ô;Ø d¤nÀÐV^Ðiqðð ð ð ð /•5‘7”7Ô.°ÐLÀÐLÐLÐLr   c                 ó"  •—  t          ¦   «         j        di |¤Ž\  }}}|�||d<   |�||d<   |€]|€[|                     d| j        ¦  «        }|                     d¦  «        }|r)t          |¦  «        dk    r|d         |d<   |d         |d<   |||fS )	NrŽ   r�   ÚtaskÚ_é   r	   é   r   )r   r9   rf   r”   Úsplitr.   )
r"   rŽ   r�   r$   r5   r6   r7   r”   Úitemsr%   s
            €r   r9   z(TranslationPipeline._sanitize_parametersE  s¼   ø€ Ø@\ÅÁÄÔ@\Ð@fÐ@fÐ_eÐ@fÐ@fÑ=Ð˜>Ð+=ØÐØ,4Ð˜jÑ)ØÐØ,4Ð˜jÑ)ØÐ Ð 0à—:’:˜f d¤iÑ0Ô0ˆDØ—J’J˜s‘O”OˆEØð 9�˜E™
œ
 aš˜à05°a´Ð! *Ñ-Ø05°a´Ð! *Ñ-Ø  .Ð2DÐDÐDr   c                 ó6   •—  t          ¦   «         j        |i |¤ŽS )aˆ  
        Translate the text(s) given as inputs.

        Args:
            args (`str` or `List[str]`):
                Texts to be translated.
            return_tensors (`bool`, *optional*, defaults to `False`):
                Whether or not to include the tensors of predictions (as token indices) in the outputs.
            return_text (`bool`, *optional*, defaults to `True`):
                Whether or not to include the decoded texts in the outputs.
            clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`):
                Whether or not to clean up the potential extra spaces in the text output.
            src_lang (`str`, *optional*):
                The language of the input. Might be required for multilingual models. Will not have any effect for
                single pair translation models
            tgt_lang (`str`, *optional*):
                The language of the desired output. Might be required for multilingual models. Will not have any effect
                for single pair translation models
            generate_kwargs:
                Additional keyword arguments to pass along to the generate method of the model (see the generate method
                corresponding to your framework [here](./model#generative-models)).

        Return:
            A list or a list of list of `dict`: Each result comes as a dictionary with the following keys:

            - **translation_text** (`str`, present when `return_text=True`) -- The translation.
            - **translation_token_ids** (`torch.Tensor` or `tf.Tensor`, present when `return_tensors=True`) -- The
              token ids of the translation.
        r�   r!   s      €r   r[   zTranslationPipeline.__call__U  s!   ø€ ð<  �u‰wŒwÔ Ð0¨Ð0Ð0Ð0r   )NN)r   r   r   rx   rq   ry   r@   r   rz   r_   r9   r[   r{   r|   s   @r   r‹   r‹     sÎ   ø€ € € € € ðð ð&  €Kð¨ð ¸#ð È3ð ð ð ð ð ,>Ô+MÐX\Ðgkð Mð Mð Mð Mð Mð Mð MðEð Eð Eð Eð Eð Eð 1ð 1ð 1ð 1ð 1ð 1ð 1ð 1ð 1r   r‹   )Úenumr/   Útokenization_utilsr   Úutilsr   r   r   r   Úbaser
   r   Ú
tensorflowr   Úmodels.auto.modeling_tf_autor   Úmodels.auto.modeling_autor   Ú
get_loggerr   r‡   ÚEnumr   r   r~   r‹   r   r   r   ú<module>r¤      sé  ðØ €€€Ø €€€à 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TØ .Ð .Ð .Ð .Ð .Ð .Ð .Ð .ð €?ÑÔð _ØÐÐÐà^Ð^Ð^Ð^Ð^Ð^àÐÑÔð YØXÐXÐXÐXÐXÐXà	ˆÔ	˜HÑ	%Ô	%€ðð ð ð ð �”ñ ô ð ð
 ÐÐ&Ñ'Ô'ð{ð {ð {ð {ð { (ñ {ô {ñ (Ô'ð{ð| ÐÐ&Ñ'Ô'ðBð Bð Bð Bð BÐ7ñ Bô Bñ (Ô'ðBðJ ÐÐ&Ñ'Ô'ðT1ð T1ð T1ð T1ð T1Ð5ñ T1ô T1ñ (Ô'ðT1ð T1ð T1r   