Ë
    i›¾jäd  ã                  óæ  — U d dl mZ d dlZd dlmZ d dlZd dlmZ d dlmZm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZ  G d
„ d«      Z G d„ d«      Z G d„ d«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      ZeZ G d„ de«      Z 	 d&	 	 	 	 	 	 	 	 	 	 	 d'd„Z! G d„ d«      Z"g Z#de$d <    ejJ                  «       d(d!„«       Z&d(d"„Z'd)d#„Z(d*d$„Z)d+d%„Z*y),é    )ÚannotationsN)ÚList)Ú
Translator)ÚapisÚfewshotÚpackageÚsbdÚsettings)ÚILanguageModel)ÚPackage)ÚSpacySentencizerSmallÚStanzaSentencizerÚMiniSBDSentencizer)Úinfoc                  ó@   — e Zd ZU dZded<   ded<   dd„Zd„ Zd„ Zd	„ Zy
)Ú
Hypothesisz°Represents a translation hypothesis

    Attributes:
        value: The hypothetical translation value
        score: The score representing the quality of the translation
    ÚstrÚvalueÚfloatÚscorec                ó    — || _         || _        y ©N)r   r   )Úselfr   r   s      úb/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/argostranslate/translate.pyÚ__init__zHypothesis.__init__   s   € ØˆŒ
Øˆ�
ó    c                ó4   — | j                   |j                   k  S r   )r   )r   Úothers     r   Ú__lt__zHypothesis.__lt__    s   € Ø�z‰z˜EŸK™KÑ'Ð'r   c                óN   — dt        | j                  «      › d| j                  › d�S )Nú(z, ú))Úreprr   r   ©r   s    r   Ú__repr__zHypothesis.__repr__#   s%   € Ø”4˜Ÿ
™
Ó#Ð$ B t§z¡z l°!Ð4Ð4r   c                ó   — t        | «      S r   )r#   r$   s    r   Ú__str__zHypothesis.__str__&   s   € Ü�D‹zÐr   N)r   r   r   r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r%   r'   © r   r   r   r      s'   … ñð ƒJØƒLóò(ò5ór   r   c                  óh   — e Zd ZU dZded<   ded<   dd„Zddd„Zedd„«       Zedd„«       Z	d	„ Z
d
„ Zy)ÚITranslationzÅRepresents a translation between two Languages

    Attributes:
        from_lang: The Language this Translation translates from.
        to_lang: The Language this Translation translates to.

    ÚLanguageÚ	from_langÚto_langc                óB   — | j                  |d¬«      d   j                  S )z¸Translates a string from self.from_lang to self.to_lang

        Args:
            input_text: The text to be translated.

        Returns:
            input_text translated.

        é   )Únum_hypothesesr   )Ú
hypothesesr   )r   Ú
input_texts     r   Ú	translatezITranslation.translate6   s"   € ð �‰˜z¸!ˆÓ<¸QÑ?×EÑEÐEr   c                ó   — t        «       ‚)a  Translates a string from self.from_lang to self.to_lang

        Args:
            input_text: The text to be translated.
            num_hypotheses: Number of hypothetical results expected

        Returns:
            List of translation hypotheses

        )ÚNotImplementedError)r   r7   r5   s      r   r6   zITranslation.hypothesesB   s   € ô "Ó#Ð#r   c                ó$   — | j                  d«      S )z¾Splits input_text into paragraphs and returns a list of paragraphs.

        Args:
            input_text: The text to be split.

        Returns:
            A list of paragraphs.

        ú
)Úsplit)r7   s    r   Úsplit_into_paragraphsz"ITranslation.split_into_paragraphsO   s   € ð ×Ñ Ó%Ð%r   c                ó$   — dj                  | «      S )z»Combines a list of paragraphs together.

        Args:
            paragraphs: A list of paragraphs.

        Returns:
            list of n paragraphs combined into one string.

        r<   )Újoin)Ú
paragraphss    r   Úcombine_paragraphszITranslation.combine_paragraphs\   s   € ð �y‰y˜Ó$Ð$r   c                ó^   — t        | j                  «      dz   t        | j                  «      z   S )Nz -> )r   r1   r2   r$   s    r   r%   zITranslation.__repr__i   s$   € Ü�4—>‘>Ó" VÑ+¬c°$·,±,Ó.?Ñ?Ð?r   c                ó8   — t        | «      j                  dd«      S )Nz->u   â†’)r#   Úreplacer$   s    r   r'   zITranslation.__str__l   s   € Ü�D‹z×!Ñ! $¨Ó.Ð.r   N)r7   r   Úreturnr   ©é   ©r7   r   r5   ÚintrF   úlist[Hypothesis])r7   r   rF   ú	list[str])rA   rL   rF   r   )r(   r)   r*   r+   r,   r8   r6   Ústaticmethodr>   rB   r%   r'   r-   r   r   r/   r/   *   sS   … ñð ÓØÓó
Fô$ð ò
&ó ð
&ð ò
%ó ð
%ò@ó/r   r/   c                  óD   — e Zd ZU dZg Zded<   g Zded<   d	d„Zd„ Zd
d„Z	y)r0   az  Represents a language that can be translated from/to.

    Attributes:
        code: The code representing the language.
        name: The human-readable name of the language.
        translations_from: A list of the translations
            that translate from this language.
        translations_to: A list of the translations
            that translate to this language

    zlist[ITranslation]Útranslations_fromÚtranslations_toc                ó<   — || _         || _        g | _        g | _        y r   )ÚcodeÚnamerO   rP   )r   rR   rS   s      r   r   zLanguage.__init__€   s    € ØˆŒ	ØˆŒ	Ø!#ˆÔØ!ˆÕr   c                ó   — | j                   S r   ©rS   r$   s    r   r'   zLanguage.__str__†   s   € Ø�y‰yÐr   c                óp   ‡— t        t        ˆfd„| j                  «      «      }t        |«      dkD  r|d   S y)a   Gets a translation from this Language to another Language.

        Args:
            to: The Language to look for a Translation to.

        Returns:
            A valid Translation if there is one in translations_from
                else None.

        c                óJ   •— | j                   j                  ‰j                  k(  S r   )r2   rR   )ÚxÚtos    €r   ú<lambda>z*Language.get_translation.<locals>.<lambda>•   s   ø€ ˜QŸY™YŸ^™^¨r¯w©wÑ6€ r   r   N)ÚlistÚfilterrO   Úlen)r   rY   Úvalid_translationss    ` r   Úget_translationzLanguage.get_translation‰   s?   ø€ ô "ÜÓ6¸×8NÑ8NÓOó
Ðô Ð!Ó" QÒ&Ø% aÑ(Ð(Ør   N)rR   r   rS   r   )rY   r0   rF   zITranslation | None)
r(   r)   r*   r+   rO   r,   rP   r   r'   r_   r-   r   r   r0   r0   p   s/   … ñ
ð -/ÐÐ)Ó.Ø*,€OÐ'Ó,ó"òôr   r0   c                  ó"   — e Zd ZdZdd„Zddd„Zy)ÚPackageTranslationz.A Translation that is installed with a packagec                óª  — || _         || _        || _        d | _        d }t        j
                  t        j                  j                  t        j                  j                  fv rCdt        |j                  «      v rt        }nºdt        |j                  «      v rt        }nœt        }n•t        j
                  t        j                  j                  k(  rt        }nct        j
                  t        j                  j                  k(  rt        }n1t        j
                  t        j                  j                  k(  rt         }|� ||«      | _        y t%        «       ‚)NÚstanzaÚminisbd)r1   r2   ÚpkgÚ
translatorr
   Ú
chunk_typeÚ	ChunkTypeÚARGOSTRANSLATEÚDEFAULTr   Úpackaged_sbd_pathr   r   ÚSTANZAÚMINISBDÚSPACYr   Úsentencizerr:   )r   r1   r2   re   ÚSentencizers        r   r   zPackageTranslation.__init__Ÿ   sþ   € Ø"ˆŒØˆŒØˆŒØˆŒàˆÜ×Ñ¤8×#5Ñ#5×#DÑ#DÄh×FXÑFX×F`ÑF`Ð"aÑaØœ3˜s×4Ñ4Ó5Ñ5Ü/‘Øœc #×"7Ñ"7Ó8Ñ8Ü0‘ä0‘Ü× Ñ ¤H×$6Ñ$6×$=Ñ$=Ò=Ü+‰KÜ× Ñ ¤H×$6Ñ$6×$>Ñ$>Ò>Ü,‰KÜ× Ñ ¤H×$6Ñ$6×$<Ñ$<Ò<Ü/ˆKàÐ"Ù*¨3Ó/ˆDÕô &Ó'Ð'r   c           
     ó’  — | j                   €yt        | j                  j                  dz  «      }t	        j
                  |t        j                  t        j                  t        j                  t        j                  ¬«      | _         t        j                  |«      }t        d|«       g }|D ]>  }|j                  t        | j                  || j                   | j                   |«      «       Œ@ t        d|«       t#        |«      D �cg c]  }t%        dd«      ‘Œ }}t#        |«      D ]Ž  }|D ]a  }	t        j'                  ||   j(                  |	|   j(                  g«      }
||   j*                  |	|   j*                  z   }t%        |
|«      ||<   Œc ||   j(                  j-                  d«      ||   _        Œ� t        d|«       |S c c}w )	NÚmodel)ÚdeviceÚinter_threadsÚintra_threadsÚcompute_typezparagraphs:ztranslated_paragraphs:Ú r   r<   zhypotheses_to_return:)rf   r   re   Úpackage_pathÚctranslate2r   r
   rs   rt   ru   rv   r/   r>   r   ÚappendÚapply_packaged_translationro   Úranger   rB   r   r   Úlstrip)r   r7   r5   Ú
model_pathrA   Útranslated_paragraphsÚ	paragraphÚiÚhypotheses_to_returnÚtranslated_paragraphr   r   s               r   r6   zPackageTranslation.hypothesesº   s¿  € Ø�?‰?Ð"Ü˜TŸX™X×2Ñ2°WÑ<Ó=ˆJÜ)×4Ñ4ØÜ—‘Ü&×4Ñ4Ü&×4Ñ4Ü%×2Ñ2ôˆDŒOô "×7Ñ7¸
ÓCˆ
Üˆ]˜JÔ'Ø "ÐØ#ò 		ˆIØ!×(Ñ(Ü*Ø—H‘HØØ—O‘OØ×$Ñ$Ø"óõð		ô 	Ð%Ð'<Ô=ô <AÀÓ;PÖQ°a¤
¨2¨qÕ 1ÐQÐÐQÜ�~Ó&ò 	WˆAØ(=ò CÐ$Ü$×7Ñ7Ø)¨!Ñ,×2Ñ2Ð4HÈÑ4K×4QÑ4QÐRó�ð -¨QÑ/×5Ñ5Ð8LÈQÑ8O×8UÑ8UÑU�Ü*4°U¸EÓ*BÐ$ QÒ'ðCð -AÀÑ,C×,IÑ,I×,PÑ,PÐQUÓ,VÐ  Ñ#Õ)ð	Wô 	Ð$Ð&:Ô;Ø#Ð#ùò  Rs   ÄGN)r1   r0   r2   r0   re   r   rG   rI   ©r(   r)   r*   r+   r   r6   r-   r   r   ra   ra   œ   s   „ Ù8ó(õ6$$r   ra   c                  ó"   — e Zd ZdZdd„Zddd„Zy)ÚIdentityTranslationz-A Translation that doesn't modify input_text.c                ó    — || _         || _        y)z�Creates an IdentityTranslation.

        Args:
            lang: The Language this Translation translates
                from and to.

        N)r1   r2   )r   Úlangs     r   r   zIdentityTranslation.__init__ä   s   € ð ˆŒØˆ�r   c                óR   — t        |«      D �cg c]  }t        |d«      ‘Œ c}S c c}w )Nr   )r|   r   )r   r7   r5   r�   s       r   r6   zIdentityTranslation.hypothesesï   s"   € Ü38¸Ó3HÖI¨a”
˜: qÕ)ÒIÐIùÒIs   Ž$N)rˆ   r0   rG   )r7   r   r5   rJ   r„   r-   r   r   r†   r†   á   s   „ Ù7ó	õJr   r†   c                  óL   — e Zd ZU dZded<   ded<   ded<   ded<   dd„Zddd	„Zy
)ÚCompositeTranslationz­A ITranslation that is performed by chaining two Translations

    Attributes:
        t1: The first Translation to apply.
        t2: The second Translation to apply.

    r/   Út1Út2r0   r1   r2   c                ód   — || _         || _        |j                  | _        |j                  | _        y)z˜Creates a CompositeTranslation.

        Args:
            t1: The first Translation to apply.
            t2: The second Translation to apply.
        N)rŒ   r�   r1   r2   )r   rŒ   r�   s      r   r   zCompositeTranslation.__init__  s(   € ð ˆŒØˆŒØŸ™ˆŒØ—z‘zˆ�r   c           	     óL  — | j                   j                  ||«      }g }|D ]k  }| j                  j                  |j                  |«      }|D ]>  }|j	                  t        |j                  |j                  |j                  z   «      «       Œ@ Œm |j                  d¬«       |d| S )NT)Úreverser   )rŒ   r6   r�   r   rz   r   r   Úsort)r   r7   r5   Út1_hypothesesÚ	to_returnÚt1_hypothesisÚt2_hypothesesÚt2_hypothesiss           r   r6   zCompositeTranslation.hypotheses  s¨   € ØŸ™×*Ñ*¨:°~ÓFˆð ˆ	Ø*ò 	ˆMØ ŸG™G×.Ñ.¨}×/BÑ/BÀNÓSˆMØ!.ò �Ø× Ñ ÜØ%×+Ñ+¨]×-@Ñ-@À=×CVÑCVÑ-Vóõñð	ð 	�‰˜tˆÔ$Ø˜˜>Ð*Ð*r   N)rŒ   r/   r�   r/   rG   rI   ©r(   r)   r*   r+   r,   r   r6   r-   r   r   r‹   r‹   ó   s+   … ñð 	ÓØÓØÓØÓó
"õ+r   r‹   c                  óL   — e Zd ZU dZded<   ded<   ded<   ded<   dd	„Zddd
„Zy)ÚCachedTranslationaØ  Caches a translation to improve performance.

    This is done by splitting up the text passed for translation
    into paragraphs and translating each paragraph individually.
    A hash of the paragraphs and their corresponding translations
    are saved from the previous translation and used to improve
    performance on the next one. This is especially useful if you
    are repeatedly translating nearly identical text with a small
    change at the end of it.

    r/   Ú
underlyingr0   r1   r2   ÚdictÚcachec                ót   — || _         |j                  | _        |j                  | _        t        «       | _        y)zqCreates a CachedTranslation.

        Args:
            underlying: The underlying translation to cache.
        N)rš   r1   r2   r›   rœ   )r   rš   s     r   r   zCachedTranslation.__init__1  s.   € ð %ˆŒØ#×-Ñ-ˆŒØ!×)Ñ)ˆŒÜ“Vˆ�
r   c                óÔ  — t        «       }t        j                  |«      }g }|D ]_  }| j                  j	                  |«      }|�t        |«      |k7  r| j                  j                  ||«      }|||<   |j                  |«       Œa || _        t        |«      D �cg c]  }t        dd«      ‘Œ }	}t        |«      D ]¦  }t        t        |«      «      D ]g  }
t        j                  |	|   j                  ||
   |   j                  g«      }|	|   j                  ||
   |   j                  z   }t        ||«      |	|<   Œi |	|   j                  j                  d«      |	|   _        Œ¨ |	S c c}w )Nrw   r   r<   )r›   r/   r>   rœ   Úgetr]   rš   r6   rz   r|   r   rB   r   r   r}   )r   r7   r5   Ú	new_cacherA   r   r€   rƒ   r�   r‚   Újr   r   s                r   r6   zCachedTranslation.hypotheses<  s“  € Ü“Fˆ	Ü!×7Ñ7¸
ÓCˆ
Ø "ÐØ#ò 	?ˆIØ#'§:¡:§>¡>°)Ó#<Ð ð %Ð,ÜÐ+Ó,°Ò>à'+§¡×'AÑ'AØ˜~ó(Ð$ð $8ˆI�iÑ Ø!×(Ñ(Ð)=Õ>ð	?ð ˆŒ
ô <AÀÓ;PÖQ°a¤
¨2¨qÕ 1ÐQÐÐQÜ�~Ó&ò 		WˆAÜœ3Ð4Ó5Ó6ò C�Ü$×7Ñ7Ø)¨!Ñ,×2Ñ2Ð4IÈ!Ñ4LÈQÑ4O×4UÑ4UÐVó�ð )¨Ñ+×1Ñ1Ð4IÈ!Ñ4LÈQÑ4O×4UÑ4UÑUð ô +5°U¸EÓ*BÐ$ QÒ'ðCð -AÀÑ,C×,IÑ,I×,PÑ,PÐQUÓ,VÐ  Ñ#Õ)ð		Wð $Ð#ùò  Rs   ÂE%N)rš   r/   rG   rI   r—   r-   r   r   r™   r™     s*   … ñ
ð ÓØÓØÓØƒKó	õ$r   r™   c                  ó8   — e Zd ZU dZded<   ded<   dd„Zd	d
d„Zy)ÚRemoteTranslationz8A translation provided by a remote LibreTranslate serverr0   r1   r2   c                ó.   — || _         || _        || _        y r   )r1   r2   Úapi)r   r1   r2   r¥   s       r   r   zRemoteTranslation.__init__d  s   € Ø"ˆŒØˆŒØˆ�r   c                ó¬   — | j                   j                  || j                  j                  | j                  j                  «      }t        |d«      g|z  S )z�LibreTranslate only supports single hypotheses.

        A list of length num_hypotheses will be returned with identical hypotheses.
        r   )r¥   r8   r1   rR   r2   r   )r   r7   r5   Úresults       r   r6   zRemoteTranslation.hypothesesi  sE   € ð
 —‘×#Ñ# J°·±×0CÑ0CÀTÇ\Á\×EVÑEVÓWˆÜ˜6 1Ó%Ð&¨Ñ7Ð7r   N)r1   r0   r2   r0   ©r4   rI   r—   r-   r   r   r£   r£   ^  s   … ÙBàÓØÓóõ
8r   r£   c                  óN   — e Zd ZU dZded<   ded<   ded<   	 	 	 	 	 	 d
d„Zddd„Zy	)ÚFewShotTranslationz6A translation performed with a few shot language modelr0   r1   r2   r   Úlanguage_modelc                ó.   — || _         || _        || _        y r   )r1   r2   r«   )r   r1   r2   r«   s       r   r   zFewShotTranslation.__init__}  s   € ð #ˆŒØˆŒØ,ˆÕr   c                ó`  — d}g }d}|t        |«      dz
  k  r½t        j                  ||d  «      }t        j                  | j                  j                  |«      «      }t        j                  ||d  |«      }|dk(  r||z   }	n||z   }	|j                  |||	 «       t        d|«       t        d|	«       t        |||	 «       |	}|t        |«      dz
  k  rŒ½d}
|D ]Ä  }t        j                  || j                  j                  | j                  j                  | j                  j                  | j                  j                  «      }t        d|«       | j                  j                  |«      }t        d	|«       t        j                  |«      }t        d
|«       |
|z  }
ŒÆ t!        |
d«      g|z  S )Néú   r   r4   éÿÿÿÿÚstart_indexÚ	sbd_indexrw   zfewshot promptzfewshot responsezfewshot result)r]   r	   Úgenerate_fewshot_sbd_promptÚparse_fewshot_responser«   ÚinferÚprocess_seq2seq_sbdrz   r   r   Úgenerate_promptr1   rS   rR   r2   Úparse_inferencer   )r   r7   r5   ÚDEFAULT_SENTENCE_LENGTHÚ	sentencesr°   ÚpromptÚresponseÚdetected_sentence_indexr±   r“   Úsentencer§   s                r   r6   zFewShotTranslation.hypotheses„  s¯  € à"%ÐØˆ	ØˆØœC 
›O¨aÑ/Ò/Ü×4Ñ4°ZÀÀÐ5MÓNˆFÜ×1Ñ1°$×2EÑ2E×2KÑ2KÈFÓ2SÓTˆHÜ&)×&=Ñ&=Ø˜;˜<Ð(¨(ó'Ð#ð '¨"Ò,à'Ð*AÑA‘	à'Ð*AÑA�	Ø×Ñ˜Z¨°IÐ>Ô?Ü� Ô,Ü�˜iÔ(Ü�˜K¨	Ð2Ô3Ø#ˆKð œC 
›O¨aÑ/Ó/ð" ˆ	Ø!ò 	 ˆHÜ×,Ñ,ØØ—‘×#Ñ#Ø—‘×#Ñ#Ø—‘×!Ñ!Ø—‘×!Ñ!óˆFô Ð! 6Ô*Ø×*Ñ*×0Ñ0°Ó8ˆHÜÐ# XÔ.Ü×,Ñ,¨XÓ6ˆFÜÐ! 6Ô*Ø˜Ñ‰Ið	 ô ˜9 aÓ(Ð)¨NÑ:Ð:r   N)r1   r0   r2   r0   r«   r   r¨   rI   r—   r-   r   r   rª   rª   v  s9   … Ù@àÓØÓØ"Ó"ð-Ø!ð-Ø,4ð-ØFTó-õ%;r   rª   c                ó–  — t        d|«       |j                  |«      }t        d|«       	 |D �cg c]  }| j                  j                  |«      ‘Œ }}t        d|«       d}| j                  dk7  r| j                  ggt        |«      z  }|j                  ||dt        j                  dt        |t        j                  «      |dd¬	«	      }	t        d
|	«       g }
t        |«      D ]Ò  }g }d}|	D ]2  }|j                  |j                  |   «       ||j                  |   z  }Œ4 | j                  j                  |«      }| j                  dk7  r3|j!                  | j                  «      r|t        | j                  «      d }t        |«      dkD  r|d   dk(  r|dd }t#        ||«      }|
j%                  |«       ŒÔ t        d|
«       |
S c c}w )a¥  Applies the translation in pkg to translate input_text.

    Args:
        pkg: The package that provides the translation.
        input_text: The text to be translated.
        translator: The CTranslate2 Translator
        sentencizer: The Sentence Boundary Detection package
        num_hypotheses: The number of hypotheses to generate

    Returns:
        A list of Hypotheses objects for translated input_text.
    r{   r¹   Ú	tokenizedNrw   TÚtokensgš™™™™™É?)Útarget_prefixÚreplace_unknownsÚmax_batch_sizeÚ
batch_typeÚ	beam_sizer5   Úlength_penaltyÚreturn_scoresÚtranslated_batchesr   ú r4   zvalue_hypotheses:)r   Úsplit_sentencesÚ	tokenizerÚencoderÁ   r]   Útranslate_batchr
   Ú
batch_sizeÚmaxrÅ   r|   Úextendr6   ÚscoresÚdecodeÚ
startswithr   rz   )re   r7   rf   ro   r5   r¹   r½   r¿   rÁ   rÈ   Úvalue_hypothesesr�   Útranslated_tokensÚcumulative_scoreÚtranslated_batchr   Ú
hypothesiss                    r   r{   r{   ¬  só  € ô( 	Ð	% zÔ2ð ×+Ñ+¨JÓ7€IÜˆ�iÔ ð'ðT AJÖJ°H�—‘×%Ñ% hÕ/ÐJ€IÐJÜˆ�iÔ ð €Mà
×Ñ˜BÒØ×+Ñ+Ð,Ð-´°I³Ñ>ˆà#×3Ñ3ØØ#ØÜ×*Ñ*ØÜ�n¤h×&8Ñ&8Ó9Ø%ØØð 4ó 
Ðô 	Ð	Ð1Ô2ð ÐÜ�>Ó"ò ,ˆØÐØÐØ 2ò 	;ÐØ×$Ñ$Ð%5×%@Ñ%@ÀÑ%CÔDØÐ 0× 7Ñ 7¸Ñ :Ñ:Ñð	;ð —‘×$Ñ$Ð%6Ó7ˆà×Ñ Ò" u×'7Ñ'7¸×8IÑ8IÔ'Jàœ#˜c×/Ñ/Ó0Ð2Ð3ˆEäˆu‹:˜Š>˜e A™h¨#šoð ˜!˜"�IˆEä Ð'7Ó8ˆ
Ø×Ñ 
Õ+ð',ô( 	Ð	Ð.Ô/ØÐùò[ Ks   ¯"Gc                  ó&   — e Zd ZU dZded<   ded<   y)ÚInstalledTranslatez‰
    Global storage of instances of the CachedTranslation class by unique keys.
    To avoid creating unnecessary objects in memory.
    r   Úpackage_keyr™   Úcached_translationN)r(   r)   r*   r+   r,   r-   r   r   rÚ   rÚ     s   … ñð
 ÓØ)Ô)r   rÚ   zList[InstalledTranslate]Úinstalled_translatesc                 óÄ	  ‡— t        d«       t        j                  t        j                  j                  k(  �r«t        j                  «       } 	 t        t        d„ | «      «      } t        «       }| D �]f  }|j                  |vr-t        |j                  |j                  «      ||j                  <   |j                  |vr-t        |j                  |j                  «      ||j                  <   ||j                     }||j                     }|j                  › d|j                  › �Št        t        ˆfd„t        «      «      }t!        |«      dk(  rE	 t#        t%        |||«      «      }t'        «       }‰|_        ||_        t        j-                  |«       n|d   j*                  }|j0                  j-                  |«       |j2                  j-                  |«       �Œi t        |j5                  «       «      }	|	D ]C  }
t7        |
«      }|
j0                  j-                  |«       |
j2                  j-                  |«       ŒE |	D ]¢  }
d	}|sŒd
}|
j0                  D ]‡  }|j8                  j0                  D ]l  }|
j;                  |j8                  «      �Œd	}t=        ||«      }|
j0                  j-                  |«       |j8                  j2                  j-                  |«       Œn Œ‰ |rŒ›Œ¤ �nwt        j                  t        j                  j>                  k(  r•tA        jB                  «       }|jE                  «       }|D �cg c]  }t        |d   |d   «      ‘Œ }	}|	D ]L  }|	D ]E  }tG        |||«      }|j0                  j-                  |«       |j2                  j-                  |«       ŒG ŒN n·t        j                  t        j                  jH                  k(  rŒtA        jJ                  t        jL                  «      }t        dd«      t        dd«      g}	|	D ]L  }|	D ]E  }tO        |||«      }|j0                  j-                  |«       |j2                  j-                  |«       ŒG ŒN d}tQ        	«      D ]  \  }}
|
jR                  dk(  sŒ|} n d}|�|	jU                  |«      }|	jW                  d„ ¬«       |�|g|	z   }	|	S # t.        $ r}t        d‰› d|› �«       Y d}~�Œed}~ww xY wc c}w )z3Returns a list of Languages installed from packagesÚget_installed_languagesc                ó    — | j                   dk(  S )Nr8   )Útype©rX   s    r   rZ   z)get_installed_languages.<locals>.<lambda>A  s   € ¨¯©°;Ñ)>€ r   ú-c                ó"   •— | j                   ‰k(  S r   )rÛ   )rX   rÛ   s    €r   rZ   z)get_installed_languages.<locals>.<lambda>O  s   ø€  §¡°+Ñ!=€ r   r   zSkipping package z: NTFrR   rS   ÚenÚEnglishÚesÚSpanishc                ó   — | j                   S r   rU   râ   s    r   rZ   z)get_installed_languages.<locals>.<lambda>¢  s
   €  §¡€ r   )Úkey),r   r
   Úmodel_providerÚModelProviderÚOPENNMTr   Úget_installed_packagesr[   r\   r›   Ú	from_coder0   Ú	from_nameÚto_codeÚto_namerÝ   r]   r™   ra   rÚ   rÛ   rÜ   rz   r:   rO   rP   Úvaluesr†   r2   r_   r‹   ÚLIBRETRANSLATEr   ÚLibreTranslateAPIÚ	languagesÚLibreTranslateTranslationÚOPENAIÚ	OpenAIAPIÚopenai_api_keyrª   Ú	enumeraterR   Úpopr‘   )ÚpackagesÚlanguage_of_codere   r1   r2   ÚcontainÚtranslation_to_addÚsaved_cacheÚerö   ÚlanguageÚidentity_translationÚkeep_adding_translationsÚtranslationÚtranslation_2Úcomposite_translationÚlibretranslate_apiÚsupported_languagesÚlr«   Úen_indexr�   ÚenglishrÛ   s                          @r   rß   rß   ,  sª  ø€ ô 	Ð	"Ô#ä×Ñ¤(×"8Ñ"8×"@Ñ"@Ó@Ü×1Ñ1Ó3ˆð	ô œÑ>ÀÓIÓJˆô  ›6ÐØó 	?ˆCØ�}‰}Ð$4Ñ4Ü2:¸3¿=¹=È#Ï-É-Ó2XÐ  §¡Ñ/Ø�{‰{Ð"2Ñ2Ü08¸¿¹ÀcÇkÁkÓ0RÐ  §¡Ñ-Ø(¨¯©Ñ7ˆIØ& s§{¡{Ñ3ˆGà Ÿ]™]˜O¨1¨S¯[©[¨MÐ:ˆKÜÜÓ=Ô?SÓTóˆGô �7‹|˜qÒ ð
Ü):Ü*¨9°g¸sÓCó*Ð&ô #5Ó"6�KØ.9�KÔ+Ø5G�KÔ2Ü(×/Ñ/°Õ<ð
 &-¨Q¡Z×%BÑ%BÐ"à×'Ñ'×.Ñ.Ð/AÔBØ×#Ñ#×*Ñ*Ð+=Ö>ð;	?ô> Ð)×0Ñ0Ó2Ó3ˆ	ð "ò 	BˆHÜ#6°xÓ#@Ð Ø×&Ñ&×-Ñ-Ð.BÔCØ×$Ñ$×+Ñ+Ð,@ÕAð	Bð "ò 	ˆHØ'+Ð$Ú*Ø+0Ð(Ø#+×#=Ñ#=ò �KØ)4×)<Ñ)<×)NÑ)Nò ˜Ø#×3Ñ3°M×4IÑ4IÓJÑRð 8<Ð4Ü4HØ +¨]ó5Ð1ð %×6Ñ6×=Ñ=Ð>SÔTØ)×1Ñ1×AÑA×HÑHØ 5õñðó +ò	ô$ 
×	 Ñ	 ¤H×$:Ñ$:×$IÑ$IÒ	Iä!×3Ñ3Ó5Ðà×(Ñ(Ó*ð 	ð >QÖQ¸”X˜a ™i¨¨6©Õ3ÐQˆ	ÐQØ"ò 	<ˆIØ$ò <�Ü7Ø˜wÐ(:ó�ð ×+Ñ+×2Ñ2°;Ô?Ø×'Ñ'×.Ñ.¨{Õ;ñ<ñ	<ô 
×	 Ñ	 ¤H×$:Ñ$:×$AÑ$AÒ	AÜŸ™¬×(?Ñ(?Ó@ˆä˜d IÓ.´¸¸yÓ0IÐJˆ	Ø"ò 	<ˆIØ$ò <�Ü0°¸GÀ^ÓT�Ø×+Ñ+×2Ñ2°;Ô?Ø×'Ñ'×.Ñ.¨{Õ;ñ<ð	<ð €HÜ  Ó+ò ‰ˆˆ8Ø�=‰=˜DÓ ØˆHÙðð €GØÐØ—-‘- Ó)ˆØ‡N�NÑ'€NÔ(ØÐØ�I 	Ñ)ˆ	àÐøôW +ò ÜÐ,¨[¨M¸¸A¸3Ð?Ô@ÝûðüòV Rs   ÅAR5Ì7SÒ5	SÒ>SÓSc                 ó   — t        «       S )z+Deprecated 1.2, use get_installed_languages)rß   r-   r   r   Úload_installed_languagesr  ©  s   € ä"Ó$Ð$r   c                óF   ‡ — t        t        ˆ fd„t        «       «      d«      S )zêGets a language object from a code

    An exception will be thrown if an installed language with this
    code can not be found.

    Args:
        code: The ISO 639 code of the language

    Returns:
        The language object
    c                ó"   •— | j                   ‰k(  S r   ©rR   )rX   rR   s    €r   rZ   z(get_language_from_code.<locals>.<lambda>º  s   ø€  §¡¨4¡€ r   N)Únextr\   rß   r  s   `r   Úget_language_from_coder  ®  s   ø€ ô ”Ó/Ô1HÓ1JÓKÈTÓRÐRr   c                óP   — t        | «      }t        |«      }|j                  |«      S )ad  Gets a translation object from codes for from and to languages

    An exception will be thrown if an installed translation between the from lang
    and to lang can not be found.

    Args:
        from_code: The ISO 639 code of the source language
        to_code: The ISO 639 code of the target language

    Returns:
        The translation object
    )r  r_   )rï   rñ   r1   r2   s       r   Úget_translation_from_codesr  ½  s)   € ô ' yÓ1€IÜ$ WÓ-€GØ×$Ñ$ WÓ-Ð-r   c                ó<   — t        ||«      }|j                  | «      S )zéTranslate a string of text

    Args:
        q: The text to translate
        from_code: The ISO 639 code of the source language
        to_code: The ISO 639 code of the target language

    Returns:
        The translated text
    )r  r8   )Úqrï   rñ   r  s       r   r8   r8   Ï  s!   € ô -¨Y¸Ó@€KØ× Ñ  Ó#Ð#r   rG   )re   r   r7   r   rf   r   ro   z#sbd.ISentenceBoundaryDetectionModelr5   rJ   rF   rK   )rF   zlist[Language])rR   r   rF   zLanguage | None)rï   r   rñ   r   rF   r/   )r  r   rï   r   rñ   r   rF   r   )+Ú
__future__r   Ú	functoolsÚtypingr   ry   r   Úargostranslater   r   r   r	   r
   Úargostranslate.modelsr   Úargostranslate.packager   Úargostranslate.sbdr   r   r   Úargostranslate.utilsr   r   r/   r0   ra   r†   r‹   r™   r£   r÷   rª   r{   rÚ   rÝ   r,   Ú	lru_cacherß   r  r  r  r8   r-   r   r   ú<module>r"     s<  ðÞ "ã Ý ã å "ç @Õ @Ý 0Ý *ß [Ñ [Ý %÷ñ ÷2C/ñ C/÷L)ñ )ôXB$˜ô B$ôJJ˜,ô Jô$)+˜<ô )+ôX<$˜ô <$ô~8˜ô 8ð* .Ð ô3;˜ô 3;ðv ðpØ	ðpàðpð ðpð 5ð	pð
 ðpð óp÷f*ñ *ð 24Ð Ð.Ó 3ð €×ÑÓòyó ðyóx%ó
Só.ô$$r   