Ë
    »dæj)&  ã            	       ón  — d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ej2                  Zej6                  Ze
j8                  Zej:                  Zej<                   G d„ d«      «       Z G d„ dej@                  «      Z! G d„ dej@                  «      Z"de"defd„Z# G d„ dej@                  «      Z$ej<                   G d„ d«      «       Z% ejL                  d ejN                  e$«       ejN                  ejP                  «      f«       ejL                  dejP                  ejR                   ejN                  e"«      f«       ejL                  dejP                  f«       ejT                  d ejN                  e"«      gd«      fZ+ G d„ d«      Z,y) z!MediaPipe language detector task.é    N)ÚListÚOptional)Úcategory)Úclassification_result)Úclassifier_options)Úclassifier_options_c©Úbase_options)Úbase_options_c)Úmediapipe_c_bindings)Úmediapipe_c_utils)Úserial_dispatcherc                   óP   — e Zd ZU ej                   G d„ d«      «       Zee   ed<   y)ÚLanguageDetectorResultc                   ó&   — e Zd ZU dZeed<   eed<   y)ú LanguageDetectorResult.Detectionú$A language code and its probability.Úlanguage_codeÚprobabilityN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__Úfloat© ó    úp/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/mediapipe/tasks/python/text/language_detector.pyÚ	Detectionr   &   s   … á.ð ÓØÔr   r    Ú
detectionsN)r   r   r   ÚdataclassesÚ	dataclassr    r   r   r   r   r   r   r   #   s-   … ð ×Ñ÷ð ó ðð �9‰oÔr   r   c                   óH   — e Zd ZdZdej
                  fdej                  fgZy)ÚLanguageDetectorPredictionCr   r   r   N)r   r   r   r   ÚctypesÚc_char_pÚc_floatÚ_fields_r   r   r   r%   r%   2   s&   „ Ù,ð ˜Ÿ™Ð(Ø�f—n‘nÐ%ð�(r   r%   c                   óT   — e Zd ZdZd ej
                  e«      fdej                  fgZy)ÚLanguageDetectorResultCzLanguage detector output.ÚpredictionsÚpredictions_countN)	r   r   r   r   r&   ÚPOINTERr%   Úc_uint32r)   r   r   r   r+   r+   ;   s.   „ Ù!ð �n�f—n‘nÐ%@ÓAÐBØ˜FŸO™OÐ,ð�(r   r+   Úc_resultÚreturnc                 ó  — t        g ¬«      }t        | j                  «      D ]f  }| j                  |   }t         j	                  |j
                  j                  d«      |j                  ¬«      }|j                  j                  |«       Œh |S )zGConverts a C LanguageDetectorResult to a Python LanguageDetectorResult.)r!   úutf-8)r   r   )
r   Úranger-   r,   r    r   Údecoder   r!   Úappend)r0   Ú	py_resultÚiÚc_predictionÚpy_predictions        r   Ú+_convert_to_python_language_detector_resultr;   D   sˆ   € ô %°Ô3€)Ü�×+Ñ+Ó,ò /€aØ×'Ñ'¨Ñ*€LÜ*×4Ñ4Ø"×0Ñ0×7Ñ7¸Ó@Ø ×,Ñ,ð 5ó €Mð ×Ñ×Ñ Õ.ð/ð 
Ðr   c                   óD   — e Zd Zdej                  fdej                  fgZy)ÚLanguageDetectorOptionsCr
   r   N)r   r   r   Úbase_options_c_moduleÚBaseOptionsCÚclassifier_options_c_moduleÚClassifierOptionsCr)   r   r   r   r=   r=   S   s'   „ àÐ,×9Ñ9Ð:ØÐ8×KÑKÐLð�(r   r=   c                   ó˜   — e Zd ZU dZeed<   dZee   ed<   dZ	ee
   ed<   dZee   ed<   dZeee      ed<   dZeee      ed<   d	efd
„Zy)ÚLanguageDetectorOptionsaÁ  Options for the language detector task.

  Attributes:
    base_options: Base options for the language detector task.
    display_names_locale: The locale to use for display names specified through
      the TFLite Model Metadata.
    max_results: The maximum number of top-scored classification results to
      return.
    score_threshold: Overrides the ones provided in the model metadata. Results
      below this value are rejected.
    category_allowlist: Allowlist of category names. If non-empty,
      classification results whose category name is not in this set will be
      filtered out. Duplicate or unknown category names are ignored. Mutually
      exclusive with `category_denylist`.
    category_denylist: Denylist of category names. If non-empty, classification
      results whose category name is in this set will be filtered out. Duplicate
      or unknown category names are ignored. Mutually exclusive with
      `category_allowlist`.
  r
   NÚdisplay_names_localeÚmax_resultsÚscore_thresholdÚcategory_allowlistÚcategory_denylistr1   c           	      ó(  — | j                   j                  «       }t        j                  t	        j
                  | j                  | j                  | j                  | j                  | j                  ¬«      «      }t        «       }||_         ||_        |S )z,Generates a ctypes LanguageDetectorOptionsC.)rD   rE   rF   rG   rH   )r
   Ú	to_ctypesr@   Úconvert_to_classifier_options_cÚclassifier_options_moduleÚClassifierOptionsrD   rE   rF   rG   rH   r=   r   )Úselfr   r   Ú	c_optionss       r   rJ   z!LanguageDetectorOptions.to_ctypesv   s„   € à×&Ñ&×0Ñ0Ó2€Nä#×CÑCÜ%×7Ñ7Ø%)×%>Ñ%>Ø ×,Ñ,Ø $× 4Ñ 4Ø#'×#:Ñ#:Ø"&×"8Ñ"8ôó	
ð ô )Ó*€IØ+€IÔØ#7€IÔ ØÐr   )r   r   r   r   Ú_BaseOptionsr   rD   r   r   rE   ÚintrF   r   rG   r   rH   r=   rJ   r   r   r   rC   rC   Z   so   … ñð& ÓØ(,Ð˜ ™Ó,Ø#€+ˆx˜‰}Ó#Ø%)€/�8˜E‘?Ó)Ø,0Ð�h˜t C™yÑ)Ó0Ø+/Ð�X˜d 3™iÑ(Ó/ðÐ1ô r   rC   ÚMpLanguageDetectorCreateÚMpLanguageDetectorDetectÚMpLanguageDetectorCloseÚMpLanguageDetectorCloseResultc                   óâ   — e Zd ZU dZej
                  ed<   ej                  ed<   dej
                  dej                  fd„Z	e
dedd fd	„«       Ze
d
edd fd„«       Zdedefd„Zd„ Zd„ Zd„ Zd„ Zy)ÚLanguageDetectoraâ  Class that predicts the language of an input text.

  This API expects a TFLite model with TFLite Model Metadata that contains the
  mandatory (described below) input tensors, output tensor, and the language
  codes in an AssociatedFile.

  Input tensors:
    (kTfLiteString)
    - 1 input tensor that is scalar or has shape [1] containing the input
      string.
  Output tensor:
    (kTfLiteFloat32)
    - 1 output tensor of shape`[1 x N]` where `N` is the number of languages.
  Ú_libÚ_handleÚlibÚhandlec                 ó    — || _         || _        y ©N)rX   Ú_detector_handle)rN   rZ   r[   s      r   Ú__init__zLanguageDetector.__init__»   s   € ð €D„IØ"€DÕr   Ú
model_pathr1   c                 óL   — | j                  t        t        |¬«      ¬«      «      S )aæ  Creates an `LanguageDetector` object from a TensorFlow Lite model and the default `LanguageDetectorOptions`.

    Args:
      model_path: Path to the model.

    Returns:
      `LanguageDetector` object that's created from the model file and the
      default `LanguageDetectorOptions`.

    Raises:
      ValueError: If failed to create `LanguageDetector` object from the
      provided
        file such as invalid file path.
      RuntimeError: If other types of error occurred.
    )Úmodel_asset_pathr	   )Úcreate_from_optionsrC   rP   )Úclsr`   s     r   Úcreate_from_model_pathz'LanguageDetector.create_from_model_pathÁ   s'   € ð" ×"Ñ"ÜÜ%°zÔBô	
óð r   Úoptionsc                 ó  — t        j                  t        «      }|j                  «       }t	        j
                  «       }|j                  t	        j                  |«      t	        j                  |«      «       t        ||¬«      S )až  Creates the `LanguageDetector` object from language detector options.

    Args:
      options: Options for the language detector task.

    Returns:
      `LanguageDetector` object that's created from `options`.

    Raises:
      ValueError: If failed to create `LanguageDetector` object from
        `LanguageDetectorOptions` such as missing the model.
      RuntimeError: If other types of error occurred.
    )rZ   r[   )	Úmediapipe_c_bindings_moduleÚload_shared_libraryÚ_CTYPES_SIGNATURESrJ   r&   Úc_void_prR   ÚbyrefrW   )rd   rf   rZ   Úctypes_optionsÚdetector_handles        r   rc   z$LanguageDetector.create_from_optionsØ   sd   € ô" &×
9Ñ
9Ô:LÓ
M€Cà×&Ñ&Ó(€Nä—o‘oÓ'€OØ× Ñ Ü�‰�^Ó$Ü�‰�_Ó%ôô  ¨OÔ<Ð<r   Útextc                 ó  — t        «       }| j                  j                  | j                  |j	                  d«      t        j                  |«      «       t        |«      }| j                  j                  t        j                  |«      «       |S )aB  Predicts the language of the input `text`.

    Args:
      text: The input text.

    Returns:
      A `LanguageDetectorResult` object that contains a list of languages and
      scores.

    Raises:
      ValueError: If any of the input arguments is invalid.
      RuntimeError: If language detection failed to run.
    r3   )	r+   rX   rS   r^   Úencoder&   rl   r;   rU   )rN   ro   Úctypes_resultÚpython_results       r   ÚdetectzLanguageDetector.detectô   sm   € ô ,Ó-€Mà‡I�I×&Ñ&Ø×ÑØ�‰�GÓÜ�‰�]Ó#ôô
 @ÀÓN€MØ‡I�I×+Ñ+¬F¯L©L¸Ó,GÔHØÐr   c                 óª   — | j                   sy| j                  j                  | j                   «       d| _         | j                  j                  «        y)z'Shuts down the MediaPipe task instance.N)r^   rX   rT   Úclose©rN   s    r   rv   zLanguageDetector.close  s<   € à× Ò ØØ‡I�I×%Ñ% d×&;Ñ&;Ô<Ø €DÔØ‡I�I‡O�OÕr   c                 ó   — | S )z1Returns `self` upon entering the runtime context.r   rw   s    r   Ú	__enter__zLanguageDetector.__enter__  s   € à€Kr   c                 ó$   — | j                  «        y)z¤Shuts down the MediaPipe task instance on exit of the context manager.

    Raises:
      RuntimeError: If the MediaPipe LanguageDetector task failed to close.
    N©rv   )rN   Úunused_exc_typeÚunused_exc_valueÚunused_tracebacks       r   Ú__exit__zLanguageDetector.__exit__  s   € ð 	‡J�J…Lr   c                 ó$   — | j                  «        y r]   r{   rw   s    r   Ú__del__zLanguageDetector.__del__!  s   € Ø‡J�J…Lr   N)r   r   r   r   r   ÚSerialDispatcherr   r&   rk   r_   Úclassmethodr   re   rC   rc   r   rt   rv   ry   r   r�   r   r   r   rW   rW   ©   s­   … ñð 	×*Ñ*Ó*Ø�?‰?Óð#Ø"×3Ñ3ð#Ø=C¿_¹_ó#ð ð¨cð Ð6Hò ó ðð, ð=Ø+ð=àò=ó ð=ð6˜ð Ð!7ó ò2òòór   rW   )-r   r&   r"   Útypingr   r   Ú,mediapipe.tasks.python.components.containersr   Úcategory_moduler   Úclassification_result_moduleÚ,mediapipe.tasks.python.components.processorsr   rL   r   r@   Úmediapipe.tasks.python.corer
   Úbase_options_moduler   r>   r   rh   r   r   ÚBaseOptionsrP   ÚCategoryÚClassificationsrM   r#   r   Ú	Structurer%   r+   r;   r=   rC   ÚCStatusFunctionr.   rk   r'   Ú	CFunctionrj   rW   r   r   r   ú<module>r‘      sº  ðñ (ã Û ß !Ý TÝ nÝ hÝ lÝ KÝ OÝ [Ý 9Ý 9à"×.Ñ.€Ø×#Ñ#€Ø.×>Ñ>€Ø-×?Ñ?Ð ð ×Ñ÷ð ó ðô &×"2Ñ"2ô ô˜f×.Ñ.ô ðØ%ðàóô˜v×/Ñ/ô ð ×Ñ÷-ð -ó ð-ðb &Ð×%Ñ%Ø"àˆF�N‰NÐ3Ó4ØˆF�N‰N˜6Ÿ?™?Ó+ð	
óð &Ð×%Ñ%Ø"à�O‰OØ�O‰OØˆF�N‰NÐ2Ó3ð	
óð &Ð×%Ñ%Ø!à�O‰Oð	
óð  Ð×ÑØ'Ø	ˆ�‰Ð/Ó	0Ð1Øóð-Ð ÷<yò yr   