Ë
    ¹ÿjŸ£  ã                   óô  — d Z ddlZddlZddlZddlZddlZddlmZ ddlZddl	Z	ddl
Z
ddl
mZ ddl
mZ ddl
mZ 	 ddl
mZ dZ	 ddlZdZd
Zd„ ZdZdZ ej0                  d«      Z ej0                  d«      Z ej0                  d«      Z ej0                  d«      Z ej0                  d«      Z ej0                  d«      Zd„ Zd8d„Z d8d„Z!d8d„Z"d8d„Z#d8d„Z$d9d„Z%d8d„Z& G d„ d«      Z' G d„ d«      Z( G d„ d e(«      Z) G d!„ d"«      Z* G d#„ d$«      Z+ G d%„ d&e*«      Z, G d'„ d(«      Z- G d)„ d*«      Z.d+„ Z/d8d,„Z0d-„ Z1d.„ Z2d/„ Z3d0„ Z4d1„ Z5d2„ Z6d3„ Z7d4„ Z8d5„ Z9 G d6„ d7«      Z:y# e$ r d	ZY �Œ$w xY w# e$ r d	ZY �Œ+w xY w):aÜ  Firebase ML module.

.. deprecated::
    Firebase ML is deprecated and will be shut down on June 15, 2027.
    To host custom models, you must migrate to another solution. You can use Cloud Storage for
    Firebase as an alternative for hosting custom models. For more info, see
    https://firebase.google.com/docs/ml/migrate-to-cloud-storage

This module contains functions for creating, updating, getting, listing,
deleting, publishing and unpublishing Firebase ML models.
é    N)Úparse)Ú_http_client)Ú_utils)Ú
exceptions)ÚstorageTFa"  Firebase ML is deprecated and will be shut down on June 15, 2027. To host custom models, you must migrate to another solution. You can use Cloud Storage for Firebase as an alternative for hosting custom models. For more info, see https://firebase.google.com/docs/ml/migrate-to-cloud-storagec                  ó®   — 	 t        j                  d«      } | r(| j                  j                  dv ry| j                  } | rŒ(y# t
        t        f$ r Y yw xY w)z@Checks if the current call originated from within the ML module.é   )Ú	from_dictÚ_update_from_dictÚhandle_operationÚlist_modelsTF)ÚsysÚ	_getframeÚf_codeÚco_nameÚf_backÚAttributeErrorÚ
ValueError)Úframes    úK/root/telegram-saas/.venv/lib/python3.12/site-packages/firebase_admin/ml.pyÚ_is_internal_callr   B   sc   € ð
ä—‘˜aÓ ˆÙØ�|‰|×#Ñ#ð (ñ ð Ø—L‘LˆEò ð øô œJÐ'ò ØØðús   ‚/A ²A ÁAÁAÚ_mléd   z^[A-Za-z0-9_-]{1,60}$z^[A-Za-z0-9_-]{1,32}$z;^gs://(?P<bucket_name>[a-z0-9_.-]{3,63})/(?P<blob_name>.+)$zS^projects/(?P<project_id>[a-z0-9-]{6,30})/models/(?P<model_id>[A-Za-z0-9_-]{1,60})$z;^projects/(?P<project_id>[a-z0-9-]{6,30})/operations/[^/]+$c                 ó@   — t        j                  | t        t        «      S )a   Returns an _MLService instance for an App.

    Args:
      app: A Firebase App instance (or None to use the default App).

    Returns:
      _MLService: An _MLService for the specified App instance.

    Raises:
      ValueError: If the app argument is invalid.
    )r   Úget_app_serviceÚ_ML_ATTRIBUTEÚ
_MLService©Úapps    r   Ú_get_ml_servicer    _   s   € ô ×!Ñ! #¤}´jÓAÐAó    c                 ó¸   — t        «       s t        j                  t        t        d¬«       t        |«      }t        j                  |j                  | «      |¬«      S )aM  Creates a model in the current Firebase project.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage

    Args:
        model: An ml.Model to create.
        app: A Firebase app instance (or None to use the default app).

    Returns:
        Model: The model that was created in Firebase ML.
    r	   ©Ú
stacklevelr   )	r   ÚwarningsÚwarnÚ_DEPRECATION_WARNINGÚDeprecationWarningr    ÚModelr
   Úcreate_model©Úmodelr   Ú
ml_services      r   r*   r*   n   óD   € ô  ÔÜ�‰Ô*Ô,>È1ÕMÜ  Ó%€JÜ�?‰?˜:×2Ñ2°5Ó9¸sˆ?ÓCÐCr!   c                 ó¸   — t        «       s t        j                  t        t        d¬«       t        |«      }t        j                  |j                  | «      |¬«      S )a/  Updates a model's metadata or model file.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage

    Args:
        model: The ml.Model to update.
        app: A Firebase app instance (or None to use the default app).

    Returns:
        Model: The updated model.
    r	   r#   r   )	r   r%   r&   r'   r(   r    r)   r
   Úupdate_modelr+   s      r   r0   r0   „   r.   r!   c                 ó¼   — t        «       s t        j                  t        t        d¬«       t        |«      }t        j                  |j                  | d¬«      |¬«      S )aj  Publishes a Firebase ML model.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage

    A published model can be downloaded to client apps.

    Args:
        model_id: The id of the model to publish.
        app: A Firebase app instance (or None to use the default app).

    Returns:
        Model: The published model.
    r	   r#   T©Úpublishr   ©	r   r%   r&   r'   r(   r    r)   r
   Úset_published©Úmodel_idr   r-   s      r   Úpublish_modelr8   š   sJ   € ô$ ÔÜ�‰Ô*Ô,>È1ÕMÜ  Ó%€JÜ�?‰?˜:×3Ñ3°HÀdÐ3ÓKÐQTˆ?ÓUÐUr!   c                 ó¼   — t        «       s t        j                  t        t        d¬«       t        |«      }t        j                  |j                  | d¬«      |¬«      S )a7  Unpublishes a Firebase ML model.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage

    Args:
        model_id: The id of the model to unpublish.
        app: A Firebase app instance (or None to use the default app).

    Returns:
        Model: The unpublished model.
    r	   r#   Fr2   r   r4   r6   s      r   Úunpublish_modelr:   ²   sJ   € ô  ÔÜ�‰Ô*Ô,>È1ÕMÜ  Ó%€JÜ�?‰?˜:×3Ñ3°HÀeÐ3ÓLÐRUˆ?ÓVÐVr!   c                 ó¸   — t        «       s t        j                  t        t        d¬«       t        |«      }t        j                  |j                  | «      |¬«      S )a5  Gets the model specified by the given ID.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage

    Args:
        model_id: The id of the model to get.
        app: A Firebase app instance (or None to use the default app).

    Returns:
     Model: The requested model.
    r	   r#   r   )	r   r%   r&   r'   r(   r    r)   r
   Ú	get_modelr6   s      r   r<   r<   È   sD   € ô  ÔÜ�‰Ô*Ô,>È1ÕMÜ  Ó%€JÜ�?‰?˜:×/Ñ/°Ó9¸sˆ?ÓCÐCr!   c                 ó    — t        «       s t        j                  t        t        d¬«       t        |«      }t        |j                  | |||¬«      S )aˆ  Lists the current project's models.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage

    Args:
        list_filter: a list filter string such as ``tags:'tag_1'``. None will return all models.
        page_size: A number between 1 and 100 inclusive that specifies the maximum
            number of models to return per page. None for default.
        page_token: A next page token returned from a previous page of results. None
            for first page of results.
        app: A Firebase app instance (or None to use the default app).

    Returns:
        ListModelsPage: A (filtered) list of models.
    r	   r#   r   )r   r%   r&   r'   r(   r    ÚListModelsPager   )Úlist_filterÚ	page_sizeÚ
page_tokenr   r-   s        r   r   r   Þ   sF   € ô( ÔÜ�‰Ô*Ô,>È1ÕMÜ  Ó%€JÜØ×Ñ ¨Y¸
ÈôMð Mr!   c                 ó�   — t        «       s t        j                  t        t        d¬«       t        |«      }|j                  | «       y)a  Deletes a model from the current project.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage

    Args:
        model_id: The id of the model you wish to delete.
        app: A Firebase app instance (or None to use the default app).
    r	   r#   N)r   r%   r&   r'   r(   r    Údelete_modelr6   s      r   rC   rC   ù   s4   € ô ÔÜ�‰Ô*Ô,>È1ÕMÜ  Ó%€JØ×Ñ˜HÕ%r!   c                   óx  — e Zd ZdZdd„Zedd„«       Zd„ Zd„ Zd„ Z	e
d„ «       Ze
d	„ «       Zej                  d
„ «       Zed„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Ze
d„ «       Zej                  d„ «       Ze
d„ «       Zdd„Ze
d„ «       Zej                  d„ «       Zdd„Zy)r)   a¡  A Firebase ML Model object.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage

    Args:
        display_name: The display name of your model - used to identify your model in code.
        tags: Optional list of strings associated with your model. Can be used in list queries.
        model_format: A subclass of ModelFormat. (e.g. TFLiteFormat) Specifies the model details.
    Nc                 óº   — t        «       s t        j                  t        t        d¬«       d | _        i | _        d | _        |�|| _        |�|| _	        |�|| _
        y y ©Nr	   r#   )r   r%   r&   r'   r(   Ú_appÚ_dataÚ_model_formatÚdisplay_nameÚtagsÚmodel_format)ÚselfrJ   rK   rL   s       r   Ú__init__zModel.__init__  s^   € Ü Ô"Ü�M‰MÔ.Ô0BÈqÕQØˆŒ	ØˆŒ
Ø!ˆÔàÐ#Ø ,ˆDÔØÐØˆDŒIØÐ#Ø ,ˆDÕð $r!   c                 óÊ   — t        |«      }d}|j                  dd«      }|j                  dd«       |rt        j                  |«      }t	        |¬«      }||_        ||_        |S )ú-Create an instance of the object from a dict.NÚtfliteModelú@type©rL   )ÚdictÚpopÚTFLiteFormatr
   r)   rH   rG   )ÚclsÚdatar   Ú	data_copyÚtflite_formatÚtflite_format_datar,   s          r   r
   zModel.from_dict(  sb   € ô ˜“Jˆ	ØˆØ&Ÿ]™]¨=¸$Ó?ÐØ�‰�g˜tÔ$ÙÜ(×2Ñ2Ð3EÓFˆMÜ =Ô1ˆØˆŒØˆŒ
Øˆr!   c                 ór   — t         j                  |«      }|j                  | _        |j                  | _        y ©N)r)   r
   rL   rH   )rM   rX   Úcopys      r   r   zModel._update_from_dict6  s)   € Ü�‰˜tÓ$ˆØ ×-Ñ-ˆÔØ—Z‘Zˆ�
r!   c                 ó˜   — t        || j                  «      r4| j                  |j                  k(  xr | j                  |j                  k(  S y©NF)Ú
isinstanceÚ	__class__rH   rI   ©rM   Úothers     r   Ú__eq__zModel.__eq__;  ó<   € Ü�e˜TŸ^™^Ô,à—:‘: §¡Ñ,ÒZ°×1CÑ1CÀu×GZÑGZÑ1ZÐZØr!   c                 ó&   — | j                  |«       S r]   ©re   rc   s     r   Ú__ne__zModel.__ne__A  ó   € Ø—;‘;˜uÓ%Ð%Ð%r!   c                 óŒ   — | j                   j                  d«      syt        | j                   j                  d«      «      \  }}|S )z&The model's ID, unique to the project.ÚnameN)rH   ÚgetÚ_validate_and_parse_name)rM   Ú_r7   s      r   r7   zModel.model_idD  s7   € ð �z‰z�~‰~˜fÔ%ØÜ.¨t¯z©z¯~©~¸fÓ/EÓF‰ˆˆ8Øˆr!   c                 ó8   — | j                   j                  d«      S )zaThe model's display name, used to refer to the model in code and in
        the Firebase console.ÚdisplayName©rH   rm   ©rM   s    r   rJ   zModel.display_nameL  s   € ð �z‰z�~‰~˜mÓ,Ð,r!   c                 ó6   — t        |«      | j                  d<   | S )Nrq   )Ú_validate_display_namerH   )rM   rJ   s     r   rJ   zModel.display_nameR  s   € ä$:¸<Ó$Hˆ�
‰
�=Ñ!Øˆr!   c                 óÌ   — | sy d}t         j                   j                  d«      }t         j                   j                  | |«      }t        ||z
  j	                  «       dz  «      }|S )Nz%Y-%m-%dT%H:%M:%S.%fZr   iè  )ÚdatetimeÚutcfromtimestampÚstrptimeÚintÚtotal_seconds)Údate_stringÚ
format_strÚepochÚdatetime_objectÚmilliss        r   Ú_convert_to_milliszModel._convert_to_millisW  s]   € áØØ,ˆ
Ü×!Ñ!×2Ñ2°1Ó5ˆÜ"×+Ñ+×4Ñ4°[À*ÓMˆÜ�o¨Ñ-×<Ñ<Ó>ÀÑEÓFˆØˆr!   c                 ó`   — t         j                  | j                  j                  dd«      «      S )zThe time the model was created.Ú
createTimeN©r)   r�   rH   rm   rs   s    r   Úcreate_timezModel.create_timea  ó$   € ô ×'Ñ'¨¯
©
¯©°|ÀTÓ(JÓKÐKr!   c                 ó`   — t         j                  | j                  j                  dd«      «      S )z$The time the model was last updated.Ú
updateTimeNr„   rs   s    r   Úupdate_timezModel.update_timef  r†   r!   c                 óx   — | j                   j                  di «      j                  di «      j                  d«      S )zValidation error message.ÚstateÚvalidationErrorÚmessagerr   rs   s    r   Úvalidation_errorzModel.validation_errork  s2   € ð �z‰z�~‰~˜g rÓ*×.Ñ.Ð/@À"ÓE×IÑIÈ)ÓTÐTr!   c                 ój   — t        | j                  j                  di «      j                  d«      «      S )zMTrue if the model is published and available for clients to
        download.r‹   Ú	published)ÚboolrH   rm   rs   s    r   r�   zModel.publishedp  s)   € ô �D—J‘J—N‘N 7¨BÓ/×3Ñ3°KÓ@ÓAÐAr!   c                 ó8   — | j                   j                  d«      S )z,The entity tag (ETag) of the model resource.Úetagrr   rs   s    r   r“   z
Model.etagv  ó   € ð �z‰z�~‰~˜fÓ%Ð%r!   c                 ó8   — | j                   j                  d«      S )z SHA256 hash of the model binary.Ú	modelHashrr   rs   s    r   Ú
model_hashzModel.model_hash{  ó   € ð �z‰z�~‰~˜kÓ*Ð*r!   c                 ó8   — | j                   j                  d«      S )z.Tag strings, used for filtering query results.rK   rr   rs   s    r   rK   z
Model.tags€  r”   r!   c                 ó6   — t        |«      | j                  d<   | S )NrK   )Ú_validate_tagsrH   )rM   rK   s     r   rK   z
Model.tags…  s   € ä+¨DÓ1ˆ�
‰
�6ÑØˆr!   c                 óœ   — t        | j                  j                  d«      xr' t        | j                  j                  d«      «      dkD  «      S )z:True if the Model object is locked by an active operation.ÚactiveOperationsr   )r‘   rH   rm   Úlenrs   s    r   ÚlockedzModel.lockedŠ  sD   € ô �D—J‘J—N‘NÐ#5Ó6ò @Ü˜Ÿ
™
Ÿ™Ð'9Ó:Ó;¸aÑ?óAð 	Ar!   c                 ó
  — | j                   syt        | j                  «      }| j                  j	                  d«      d   j	                  d«      }|j                  |j                  |«      d|¬«      }| j                  |«       y)aQ  Waits for the model to be unlocked. (All active operations complete)

        Args:
            max_time_seconds: The maximum number of seconds to wait for the model to unlock.
                (None for no limit)

        Raises:
            exceptions.DeadlineExceeded: If max_time_seconds passed and the model is still locked.
        Nr�   r   rl   T)Úwait_for_operationÚmax_time_seconds)rŸ   r    rG   rH   rm   r   Úget_operationr   )rM   r¢   r-   Úop_nameÚ
model_dicts        r   Úwait_for_unlockedzModel.wait_for_unlocked�  sx   € ð �{Š{ØÜ$ T§Y¡YÓ/ˆ
Ø—*‘*—.‘.Ð!3Ó4°QÑ7×;Ñ;¸FÓCˆØ×0Ñ0Ø×$Ñ$ WÓ-Ø#Ø-ð 1ó /ˆ
ð 	×Ñ˜zÕ*r!   c                 ó   — | j                   S )zeThe model's ``ModelFormat`` object, which represents the model's
        format and storage location.)rI   rs   s    r   rL   zModel.model_format¤  s   € ð ×!Ñ!Ð!r!   c                 ó.   — |�t        |«       || _        | S r]   )Ú_validate_model_formatrI   )rM   rL   s     r   rL   zModel.model_formatª  s   € àÐ#Ü" <Ô0Ø)ˆÔØˆr!   c                 óž   — t        | j                  «      }| j                  r+|j                  | j                  j	                  |¬«      «       |S )ú4Returns a serializable representation of the object.©Ú
for_upload)rT   rH   rI   ÚupdateÚas_dict©rM   r­   r^   s      r   r¯   zModel.as_dict±  s>   € ä�D—J‘JÓˆØ×ÒØ�K‰K˜×*Ñ*×2Ñ2¸jÐ2ÓIÔJØˆr!   )NNNr]   ©F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rN   Úclassmethodr
   r   re   ri   Úpropertyr7   rJ   ÚsetterÚstaticmethodr�   r…   r‰   rŽ   r�   r“   r—   rK   rŸ   r¦   rL   r¯   © r!   r   r)   r)     s  „ ñó-ð òó ðò ò
ò&ð ñó ðð ñ-ó ð-ð
 ×Ññó ðð ñó ðð ñLó ðLð ñLó ðLð ñUó ðUð ñBó ðBð
 ñ&ó ð&ð ñ+ó ð+ð ñ&ó ð&ð 
‡[�[ñó ðð ñAó ðAó
+ð( ñ"ó ð"ð
 ×Ññó ðôr!   r)   c                   ó   — e Zd ZdZdd„Zy)ÚModelFormataœ  Abstract base class representing a Model Format such as TFLite.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage
    c                 ó   — t         ‚©r«   ©ÚNotImplementedError©rM   r­   s     r   r¯   zModelFormat.as_dictÂ  ó   € ä!Ð!r!   Nr±   ©r²   r³   r´   rµ   r¯   rº   r!   r   r¼   r¼   ¹  ó   „ ñô"r!   r¼   c                   ó�   — e Zd ZdZdd„Zed„ «       Zd„ Zd„ Ze	d„ «       Z
ed„ «       Zej                  d	„ «       Zed
„ «       Zdd„Zy)rV   añ  Model format representing a TFLite model.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage

    Args:
        model_source: A TFLiteModelSource sub class. Specifies the details of the model source.
    Nc                 óˆ   — t        «       s t        j                  t        t        d¬«       i | _        d | _        |�|| _        y y rF   )r   r%   r&   r'   r(   rH   Ú_model_sourceÚmodel_source©rM   rÈ   s     r   rN   zTFLiteFormat.__init__Ó  s<   € Ü Ô"Ü�M‰MÔ.Ô0BÈqÕQØˆŒ
Ø!ˆÔàÐ#Ø ,ˆDÕð $r!   c                 ó`   — t        |«      }t        | j                  |«      ¬«      }||_        |S )rP   )rÈ   )rT   rV   Ú_init_model_sourcerH   )rW   rX   rY   rZ   s       r   r
   zTFLiteFormat.from_dictÜ  s0   € ô ˜“Jˆ	Ü$°#×2HÑ2HÈÓ2SÔTˆØ'ˆÔØÐr!   c                 ó˜   — t        || j                  «      r4| j                  |j                  k(  xr | j                  |j                  k(  S yr`   )ra   rb   rH   rÇ   rc   s     r   re   zTFLiteFormat.__eq__ä  rf   r!   c                 ó&   — | j                  |«       S r]   rh   rc   s     r   ri   zTFLiteFormat.__ne__ê  rj   r!   c                 óD   — | j                  dd«      }|rt        |¬«      S y)zInitialize the ML model source.ÚgcsTfliteUriN)Úgcs_tflite_uri)rU   ÚTFLiteGCSModelSource)rX   rÐ   s     r   rË   zTFLiteFormat._init_model_sourceí  s%   € ð Ÿ™ .°$Ó7ˆÙÜ'°~ÔFÐFØr!   c                 ó   — | j                   S )zThe TF Lite model's location.)rÇ   rs   s    r   rÈ   zTFLiteFormat.model_sourceõ  s   € ð ×!Ñ!Ð!r!   c                 óL   — |�t        |t        «      st        d«      ‚|| _        y )Nz0Model source must be a TFLiteModelSource object.)ra   ÚTFLiteModelSourceÚ	TypeErrorrÇ   rÉ   s     r   rÈ   zTFLiteFormat.model_sourceú  s'   € àÐ#Ü˜lÔ,=Ô>ÜÐ RÓSÐSØ)ˆÕr!   c                 ó8   — | j                   j                  d«      S )z'The size in bytes of the TF Lite model.Ú	sizeBytesrr   rs   s    r   Ú
size_byteszTFLiteFormat.size_bytes  r˜   r!   c                 ó¢   — t        | j                  «      }| j                  r+|j                  | j                  j	                  |¬«      «       d|iS )r«   r¬   rQ   )rT   rH   rÇ   r®   r¯   r°   s      r   r¯   zTFLiteFormat.as_dict  sD   € ä�D—J‘JÓˆØ×ÒØ�K‰K˜×*Ñ*×2Ñ2¸jÐ2ÓIÔJØ˜tÐ$Ð$r!   r]   r±   )r²   r³   r´   rµ   rN   r¶   r
   re   ri   r¹   rË   r·   rÈ   r¸   rØ   r¯   rº   r!   r   rV   rV   Ç  s…   „ ñ
ó-ð ñó ðòò&ð ñó ðð ñ"ó ð"ð ×Ññ*ó ð*ð ñ+ó ð+ô%r!   rV   c                   ó   — e Zd ZdZdd„Zy)rÔ   a¦  Abstract base class representing a model source for TFLite format models.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage
    c                 ó   — t         ‚r¾   r¿   rÁ   s     r   r¯   zTFLiteModelSource.as_dict  rÂ   r!   Nr±   rÃ   rº   r!   r   rÔ   rÔ     rÄ   r!   rÔ   c                   óX   — e Zd ZdZdZdZed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
y)	Ú_CloudStorageClientzCloud Storage helper classzgs://{0}/{1}zFirebase/ML/Models/{0}c                  ó&   — t         st        d«      ‚y )NznFailed to import the Cloud Storage library for Python. Make sure to install the "google-cloud-storage" module.)Ú_GCS_ENABLEDÚImportErrorrº   r!   r   Ú_assert_gcs_enabledz'_CloudStorageClient._assert_gcs_enabled"  s   € åÜð Nó Oð Oð r!   c                 óŠ   — t         j                  | «      }|st        d«      ‚|j                  d«      |j                  d«      fS )Nú!GCS TFLite URI format is invalid.Úbucket_nameÚ	blob_name)Ú_GCS_TFLITE_URI_PATTERNÚmatchr   Úgroup)ÚuriÚmatchers     r   Ú_parse_gcs_tflite_uriz)_CloudStorageClient._parse_gcs_tflite_uri(  s@   € ô *×/Ñ/°Ó4ˆÙÜÐ@ÓAÐAØ�}‰}˜]Ó+¨W¯]©]¸;Ó-GÐGÐGr!   c                 ól  — t         j                  «        t        j                  j	                  |«      }t        j                  | |¬«      }t         j                  j                  |«      }|j                  |«      }|j                  |«       t         j                  j                  |j                  |«      S )z4Upload a model file to the specified Storage bucket.r   )rÝ   rá   ÚosÚpathÚbasenamer   ÚbucketÚ	BLOB_NAMEÚformatÚblobÚupload_from_filenameÚGCS_URIrl   )rä   Úmodel_file_namer   Ú	file_namerð   rå   ró   s          r   Úuploadz_CloudStorageClient.upload1  sƒ   € ô 	×/Ñ/Ô1ä—G‘G×$Ñ$ _Ó5ˆ	Ü—‘ °Ô5ˆÜ'×1Ñ1×8Ñ8¸ÓCˆ	Ø�{‰{˜9Ó%ˆØ×!Ñ! /Ô2Ü"×*Ñ*×1Ñ1°&·+±+¸yÓIÐIr!   c                 óú   — t         j                  «        t         j                  | «      \  }}t        j                  ||¬«      }|j                  |«      }|j                  dt        j                  d¬«      d¬«      S )zHMakes the gcs_tflite_uri readable for GET for 10 minutes via signed_uri.r   Úv4é
   )ÚminutesÚGET)ÚversionÚ
expirationÚmethod)	rÝ   rá   rë   r   rð   ró   Úgenerate_signed_urlrw   Ú	timedelta)rÐ   r   rä   rå   rð   ró   s         r   Úsign_uriz_CloudStorageClient.sign_uri=  so   € ô 	×/Ñ/Ô1Ü!4×!JÑ!JÈ>Ó!ZÑˆ�YÜ—‘ °Ô5ˆØ�{‰{˜9Ó%ˆØ×'Ñ'ØÜ×)Ñ)°"Ô5Øð (ó 
ð 	
r!   N)r²   r³   r´   rµ   rõ   rñ   r¹   rá   rë   rø   r  rº   r!   r   rÝ   rÝ     sc   „ Ù$à€GØ(€IàñOó ðOð
 ñHó ðHð ñ	Jó ð	Jð ñ

ó ñ

r!   rÝ   c                   óâ   — e Zd ZdZ e«       Zdd„Zd„ Zd„ Ze	dd„«       Z
ed„ «       Zed„ «       Zed	„ «       Ze		 	 dd
„«       Ze		 	 dd„«       Zed„ «       Zej&                  d„ «       Zd„ Zdd„Zy)rÑ   a   TFLite model source representing a tflite model file stored in GCS.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage
    Nc                 ó†   — t        «       s t        j                  t        t        d¬«       || _        t        |«      | _        y rF   )r   r%   r&   r'   r(   rG   Ú_validate_gcs_tflite_uriÚ_gcs_tflite_uri)rM   rÐ   r   s      r   rN   zTFLiteGCSModelSource.__init__W  s.   € Ü Ô"Ü�M‰MÔ.Ô0BÈqÕQØˆŒ	Ü7¸ÓGˆÕr!   c                 ób   — t        || j                  «      r| j                  |j                  k(  S yr`   )ra   rb   r  rc   s     r   re   zTFLiteGCSModelSource.__eq__]  s*   € Ü�e˜TŸ^™^Ô,Ø×'Ñ'¨5×+@Ñ+@Ñ@Ð@Ør!   c                 ó&   — | j                  |«       S r]   rh   rc   s     r   ri   zTFLiteGCSModelSource.__ne__b  rj   r!   c                 ó^   — t         j                  j                  |||«      }t        ||¬«      S )a  Uploads the model file to an existing Google Cloud Storage bucket.

        Args:
            model_file_name: The name of the model file.
            bucket_name: The name of an existing bucket. None to use the default bucket configured
                in the app.
            app: A Firebase app instance (or None to use the default app).

        Returns:
            TFLiteGCSModelSource: The source created from the model_file

        Raises:
            ImportError: If the Cloud Storage Library has not been installed.
        )rÐ   r   )rÑ   Ú_STORAGE_CLIENTrø   )rW   rö   rä   r   Úgcs_uris        r   Úfrom_tflite_model_filez+TFLiteGCSModelSource.from_tflite_model_filee  s,   € ô  '×6Ñ6×=Ñ=¸kÈ?Ð\_Ó`ˆÜ#°7ÀÔDÐDr!   c                  ó  — t         st        d«      ‚t        j                  j                  j                  d«      sPt        j                  j                  j                  d«      s&t        dt        j                  j                  › �«      ‚y y )Nz_Failed to import the tensorflow library for Python. Make sure to install the tensorflow module.ú1.z2.z2Expected tensorflow version 1.x or 2.x, but found )Ú_TF_ENABLEDrà   Útfrþ   ÚVERSIONÚ
startswithrº   r!   r   Ú_assert_tf_enabledz'TFLiteGCSModelSource._assert_tf_enabledx  sw   € åÜð Bó Cð Cä�z‰z×!Ñ!×,Ñ,¨TÔ2¼2¿:¹:×;MÑ;M×;XÑ;XÐY]Ô;^ÜØDÄRÇZÁZ×EWÑEWÐDXÐYó[ð [ð <_Ð2r!   c                 ót   — t         j                  j                  j                  | «      }|j	                  «       S r]   )r  ÚliteÚTFLiteConverterÚfrom_saved_modelÚconvert)Úsaved_model_dirÚ	converters     r   Ú_tf_convert_from_saved_modelz1TFLiteGCSModelSource._tf_convert_from_saved_model�  s-   € ô —G‘G×+Ñ+×<Ñ<¸_ÓMˆ	Ø× Ñ Ó"Ð"r!   c                 ó�  — t         j                  j                  j                  d«      red}t         j                  j
                  j                  | |«       t         j                  j                  j                  |«      }|j                  «       S t         j                  j                  j                  | «      }|j                  «       S )z4Converts the given Keras model into a TF Lite model.r  zfirebase_keras_model.h5)r  rþ   r  r  ÚkerasÚmodelsÚ
save_modelr  r  Úfrom_keras_model_fileÚfrom_keras_modelr  )Úkeras_modelÚ
keras_filer  s      r   Ú_tf_convert_from_keras_modelz1TFLiteGCSModelSource._tf_convert_from_keras_model‡  s�   € ô �:‰:×Ñ×(Ñ(¨Ô.Ø2ˆJÜ�H‰H�O‰O×&Ñ& {°JÔ?ÜŸ™×/Ñ/×EÑEÀjÓQˆIð × Ñ Ó"Ð"ô Ÿ™×/Ñ/×@Ñ@ÀÓMˆIà× Ñ Ó"Ð"r!   c                 óæ   — t         j                  «        t         j                  |«      }t        |d«      5 }|j	                  |«       ddd«       t         j                  |||«      S # 1 sw Y   Œ xY w)a§  Creates a Tensor Flow Lite model from the saved model, and uploads the model to GCS.

        Args:
            saved_model_dir: The saved model directory.
            model_file_name: The name that the tflite model will be saved as in Cloud Storage.
            bucket_name: The name of an existing bucket. None to use the default bucket configured
                in the app.
            app: Optional. A Firebase app instance (or None to use the default app)

        Returns:
            TFLiteGCSModelSource: The source created from the saved_model_dir

        Raises:
            ImportError: If the Tensor Flow or Cloud Storage Libraries have not been installed.
        ÚwbN)rÑ   r  r  ÚopenÚwriter  )rW   r  rö   rä   r   Útflite_modelÚ
model_files          r   r  z%TFLiteGCSModelSource.from_saved_model”  se   € ô$ 	×/Ñ/Ô1Ü+×HÑHÈÓYˆÜ�/ 4Ó(ð 	+¨JØ×Ñ˜\Ô*÷	+ä#×:Ñ:¸?ÈKÐY\Ó]Ð]÷	+ð 	+úó   ¶A'Á'A0c                 óæ   — t         j                  «        t         j                  |«      }t        |d«      5 }|j	                  |«       ddd«       t         j                  |||«      S # 1 sw Y   Œ xY w)a–  Creates a Tensor Flow Lite model from the keras model, and uploads the model to GCS.

        Args:
            keras_model: A tf.keras model.
            model_file_name: The name that the tflite model will be saved as in Cloud Storage.
            bucket_name: The name of an existing bucket. None to use the default bucket configured
                in the app.
            app: Optional. A Firebase app instance (or None to use the default app)

        Returns:
            TFLiteGCSModelSource: The source created from the keras_model

        Raises:
            ImportError: If the Tensor Flow or Cloud Storage Libraries have not been installed.
        r'  N)rÑ   r  r%  r(  r)  r  )rW   r#  rö   rä   r   r*  r+  s          r   r"  z%TFLiteGCSModelSource.from_keras_model¬  se   € ô$ 	×/Ñ/Ô1Ü+×HÑHÈÓUˆÜ�/ 4Ó(ð 	+¨JØ×Ñ˜\Ô*÷	+ä#×:Ñ:¸?ÈKÐY\Ó]Ð]÷	+ð 	+úr,  c                 ó   — | j                   S )z'URI of the model file in Cloud Storage.)r  rs   s    r   rÐ   z#TFLiteGCSModelSource.gcs_tflite_uriÄ  s   € ð ×#Ñ#Ð#r!   c                 ó$   — t        |«      | _        y r]   )r  r  )rM   rÐ   s     r   rÐ   z#TFLiteGCSModelSource.gcs_tflite_uriÉ  s   € ä7¸ÓGˆÕr!   c                 ój   — t         j                  j                  | j                  | j                  «      S )zQSigns the GCS uri, so the model file can be uploaded to Firebase ML and verified.)rÑ   r  r  r  rG   rs   s    r   Ú_get_signed_gcs_tflite_uriz/TFLiteGCSModelSource._get_signed_gcs_tflite_uriÍ  s(   € ä#×3Ñ3×<Ñ<¸T×=QÑ=QÐSW×S\ÑS\Ó]Ð]r!   c                 óF   — |rd| j                  «       iS d| j                  iS )r«   rÏ   )r1  r  rÁ   s     r   r¯   zTFLiteGCSModelSource.as_dictÑ  s*   € áØ" D×$CÑ$CÓ$EÐFÐFà × 4Ñ 4Ð5Ð5r!   r]   )NN)zfirebase_ml_model.tfliteNNr±   )r²   r³   r´   rµ   rÝ   r  rN   re   ri   r¶   r  r¹   r  r  r%  r  r"  r·   rÐ   r¸   r1  r¯   rº   r!   r   rÑ   rÑ   K  sè   „ ññ *Ó+€OóHòò
&ð òEó ðEð$ ñ[ó ð[ð ñ#ó ð#ð
 ñ
#ó ð
#ð Ø?YØ/3ò^ó ð^ð. Ø;UØ/3ò^ó ð^ð. ñ$ó ð$ð ×ÑñHó ðHò^ô6r!   rÑ   c                   ób   — e Zd ZdZd„ Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	d„ Z
d„ Zy	)
r>   až  Represents a page of models in a Firebase project.

    .. deprecated::
        Firebase ML is deprecated and will be shut down on June 15, 2027.
        To host custom models, you must migrate to another solution. You can use Cloud Storage for
        Firebase as an alternative for hosting custom models. For more info, see
        https://firebase.google.com/docs/ml/migrate-to-cloud-storage

    Provides methods for traversing the models included in this page, as well as
    retrieving subsequent pages of models. The iterator returned by
    ``iterate_all()`` can be used to iterate through all the models in the
    Firebase project starting from this page.
    c                 ó¼   — t        «       s t        j                  t        t        d¬«       || _        || _        || _        || _        || _	         ||||«      | _
        y rF   )r   r%   r&   r'   r(   Ú_list_models_funcÚ_list_filterÚ
_page_sizeÚ_page_tokenrG   Ú_list_response)rM   Úlist_models_funcr?   r@   rA   r   s         r   rN   zListModelsPage.__init__æ  sQ   € Ü Ô"Ü�M‰MÔ.Ô0BÈqÕQØ!1ˆÔØ'ˆÔØ#ˆŒØ%ˆÔØˆŒ	Ù.¨{¸IÀzÓRˆÕr!   c                 óž   — | j                   j                  dg «      D �cg c]#  }t        j                  || j                  ¬«      ‘Œ% c}S c c}w )z A list of Models from this page.r  r   )r9  rm   r)   r
   rG   )rM   r,   s     r   r  zListModelsPage.modelsð  sI   € ð @D×?RÑ?R×?VÑ?VÐW_ÐacÓ?dö
Ø6;ŒE�O‰O˜E t§y¡yˆOÕ1ò
ð 	
ùò 
s   Ÿ(A
c                 ó   — | j                   S )z,The filter string used to filter the models.)r6  rs   s    r   r?   zListModelsPage.list_filter÷  s   € ð × Ñ Ð r!   c                 ó:   — | j                   j                  dd«      S )z+Token identifying the next page of results.ÚnextPageTokenÚ )r9  rm   rs   s    r   Únext_page_tokenzListModelsPage.next_page_tokenü  s   € ð ×"Ñ"×&Ñ& ¸Ó;Ð;r!   c                 ó,   — t        | j                  «      S )z!True if more pages are available.)r‘   r@  rs   s    r   Úhas_next_pagezListModelsPage.has_next_page  s   € ô �D×(Ñ(Ó)Ð)r!   c                 óž   — | j                   rAt        | j                  | j                  | j                  | j
                  | j                  «      S y)z�Retrieves the next page of models if available.

        Returns:
            ListModelsPage: Next page of models, or None if this is the last page.
        N)rB  r>   r5  r6  r7  r@  rG   rs   s    r   Úget_next_pagezListModelsPage.get_next_page  sH   € ð ×ÒÜ!Ø×&Ñ&Ø×!Ñ!Ø—‘Ø×$Ñ$Ø—	‘	óð ð r!   c                 ó   — t        | «      S )aC  Retrieves an iterator for Models.

        Returned iterator will iterate through all the models in the Firebase
        project starting from this page. The iterator will never buffer more than
        one page of models in memory at a time.

        Returns:
            iterator: An iterator of Model instances.
        )Ú_ModelIteratorrs   s    r   Úiterate_allzListModelsPage.iterate_all  s   € ô ˜dÓ#Ð#r!   N)r²   r³   r´   rµ   rN   r·   r  r?   r@  rB  rD  rG  rº   r!   r   r>   r>   Ø  sg   „ ñòSð ñ
ó ð
ð ñ!ó ð!ð ñ<ó ð<ð ñ*ó ð*òó
$r!   r>   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)rF  a  An iterator that allows iterating over models, one at a time.

    This implementation loads a page of models into memory, and iterates on them.
    When the whole page has been traversed, it loads another page. This class
    never keeps more than one page of entries in memory.
    c                 óV   — t        |t        «      st        d«      ‚|| _        d| _        y )Nz%Current page must be a ListModelsPager   )ra   r>   rÕ   Ú_current_pageÚ_index)rM   Úcurrent_pages     r   rN   z_ModelIterator.__init__)  s'   € Ü˜,¬Ô7ÜÐCÓDÐDØ)ˆÔØˆ�r!   c                 óª  — | j                   t        | j                  j                  «      k(  r<| j                  j                  r&| j                  j                  «       | _        d| _         | j                   t        | j                  j                  «      k  r:| j                  j                  | j                      }| xj                   dz  c_         |S t        ‚)Nr   é   )rK  rž   rJ  r  rB  rD  ÚStopIteration)rM   Úresults     r   Ú__next__z_ModelIterator.__next__/  sœ   € Ø�;‰;œ#˜d×0Ñ0×7Ñ7Ó8Ò8Ø×!Ñ!×/Ò/Ø%)×%7Ñ%7×%EÑ%EÓ%G�Ô"Ø�”Ø�;‰;œ˜T×/Ñ/×6Ñ6Ó7Ò7Ø×'Ñ'×.Ñ.¨t¯{©{Ñ;ˆFØ�KŠK˜1Ñ�KØˆMÜÐr!   c                 ó   — | S r]   rº   rs   s    r   Ú__iter__z_ModelIterator.__iter__:  s   € Øˆr!   N)r²   r³   r´   rµ   rN   rQ  rS  rº   r!   r   rF  rF  "  s   „ ñòò	ór!   rF  c                 óŠ   — t         j                  | «      }|st        d«      ‚|j                  d«      |j                  d«      fS )Nz&Model resource name format is invalid.Ú
project_idr7   )Ú_RESOURCE_NAME_PATTERNrç   r   rè   )rl   rê   s     r   rn   rn   >  s@   € ô %×*Ñ*¨4Ó0€GÙÜÐAÓBÐBØ�=‰=˜Ó&¨¯©°jÓ(AÐAÐAr!   c                 ón   — t        | t        «      st        d«      ‚|€| j                  st	        d«      ‚y y )NzModel must be an ml.Model.zModel must have a display name.)ra   r)   rÕ   rJ   r   )r,   Úupdate_masks     r   Ú_validate_modelrY  H  s:   € Ü�eœUÔ#ÜÐ4Ó5Ð5ØÐ 5×#5Ò#5ÜÐ:Ó;Ð;ð $6Ðr!   c                 óD   — t         j                  | «      st        d«      ‚y )NzModel ID format is invalid.)Ú_MODEL_ID_PATTERNrç   r   )r7   s    r   Ú_validate_model_idr\  O  s!   € Ü×"Ñ" 8Ô,ÜÐ6Ó7Ð7ð -r!   c                 óF   — t         j                  | «      st        d«      ‚| S )Nz!Operation name format is invalid.)Ú_OPERATION_NAME_PATTERNrç   r   )r¤   s    r   Ú_validate_operation_namer_  T  s!   € Ü"×(Ñ(¨Ô1ÜÐ<Ó=Ð=Ø€Nr!   c                 óF   — t         j                  | «      st        d«      ‚| S )NzDisplay name format is invalid.)Ú_DISPLAY_NAME_PATTERNrç   r   )rJ   s    r   ru   ru   Z  s"   € Ü ×&Ñ& |Ô4ÜÐ:Ó;Ð;ØÐr!   c                 óš   — t        | t        «      rt        d„ | D «       «      st        d«      ‚t        d„ | D «       «      st	        d«      ‚| S )Nc              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr]   )ra   Ústr©Ú.0Útags     r   ú	<genexpr>z!_validate_tags.<locals>.<genexpr>b  s   è ø€ Ò1 SŒJ�sœC× Ñ1ùs   ‚zTags must be a list of strings.c              3   óF   K  — | ]  }t         j                  |«      –— Œ y ­wr]   )Ú_TAG_PATTERNrç   re  s     r   rh  z!_validate_tags.<locals>.<genexpr>d  s   è ø€ Ò7¨3Œ|×!Ñ! #×&Ñ7ùs   ‚!zTag format is invalid.)ra   ÚlistÚallrÕ   r   )rK   s    r   r›   r›   `  sE   € Ü�dœDÔ!ÜÑ1¨DÔ1Ô1ÜÐ9Ó:Ð:ÜÑ7°$Ô7Ô7ÜÐ1Ó2Ð2Ø€Kr!   c                 óF   — t         j                  | «      st        d«      ‚| S )Nrã   )ræ   rç   r   )ré   s    r   r  r  i  s#   € ô #×(Ñ(¨Ô-ÜÐ<Ó=Ð=Ø€Jr!   c                 ó<   — t        | t        «      st        d«      ‚| S )Nz*Model format must be a ModelFormat object.)ra   r¼   rÕ   rS   s    r   r©   r©   q  s   € Ü�l¤KÔ0ÜÐDÓEÐEØÐr!   c                 ó@   — | �t        | t        «      st        d«      ‚y y )Nz%List filter must be a string or None.©ra   rd  rÕ   )r?   s    r   Ú_validate_list_filterrq  w  s(   € ØÐÜ˜+¤sÔ+ÜÐCÓDÐDð ,ð r!   c                 ó‚   — | �=t        | «      t        urt        d«      ‚| dk  s	| t        kD  rt	        dt        › �«      ‚y y )Nz#Page size must be a number or None.rN  z3Page size must be a positive integer between 1 and )Útyperz   rÕ   Ú_MAX_PAGE_SIZEr   )r@   s    r   Ú_validate_page_sizeru  }  sR   € ØÐÜ�	‹?¤#Ñ%äÐAÓBÐBØ�qŠ=˜I¬Ò6ÜØEÄnÐEUÐVóXð Xð 7ð	 r!   c                 ó@   — | �t        | t        «      st        d«      ‚y y )Nz$Page token must be a string or None.rp  )rA   s    r   Ú_validate_page_tokenrw  ‡  s(   € ØÐÜ˜*¤cÔ*ÜÐBÓCÐCð +ð r!   c                   ó`   — e Zd ZdZdZdZdZdZd„ Zd„ Z	d„ Z
dd
„Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zy	)r   zFirebase ML service.z7https://firebaseml.googleapis.com/v1beta2/projects/{0}/z*https://firebaseml.googleapis.com/v1beta2/g      ø?é   c                 óÞ  — |j                   | _        | j                  st        d«      ‚t        j                  j                  | j                  «      | _        ddt        j                  › �i}t        j                  |j                  j                  «       || j                  ¬«      | _        t        j                  |j                  j                  «       |t        j                  ¬«      | _        y )NzqProject ID is required to access ML service. Either set the projectId option, or use service account credentials.zX-FIREBASE-CLIENTzfire-admin-python/)Ú
credentialÚheadersÚbase_url)rU  Ú_project_idr   r   ÚPROJECT_URLrò   Ú_project_urlÚfirebase_adminÚ__version__r   ÚJsonHttpClientr{  Úget_credentialÚ_clientÚOPERATION_URLÚ_operation_client)rM   r   Ú
ml_headerss      r   rN   z_MLService.__init__•  sÉ   € ØŸ>™>ˆÔØ×ÒÜðHóIð Iô '×2Ñ2×9Ñ9¸$×:JÑ:JÓKˆÔàÐ#5´n×6PÑ6PÐ5QÐ!Rð
ˆ
ô $×2Ñ2Ø—~‘~×4Ñ4Ó6ØØ×&Ñ&ô(ˆŒô ".×!<Ñ!<Ø—~‘~×4Ñ4Ó6ØÜ×-Ñ-ô"/ˆÕr!   c                 óÈ   — t        |«       	 | j                  j                  d|¬«      S # t        j                  j
                  $ r}t        j                  |«      ‚d }~ww xY w)Nrm   ©Úurl)r_  r‡  ÚbodyÚrequestsr   ÚRequestExceptionr   Ú#handle_platform_error_from_requests)rM   r¤   Úerrors      r   r£   z_MLService.get_operation¨  s[   € Ü  Ô)ð	DØ×)Ñ)×.Ñ.¨u¸'Ð.ÓBÐBøÜ×"Ñ"×3Ñ3ò 	DÜ×<Ñ<¸UÓCÐCûð	Dús   �* ªA!ÁAÁA!c                 ó<  — t        t        j                  |«      }|t        j                  z  }|�X|t        j                  j                  «       z
  j                  «       }|dk  rt        j                  d«      ‚t        ||dz
  «      }t        j                  |«       y)zGSleeps for the appropriate amount of time. Or throws deadline exceeded.NrN  zPolling max time exceeded.)Úpowr   ÚPOLL_EXPONENTIAL_BACKOFF_FACTORÚPOLL_BASE_WAIT_TIME_SECONDSrw   Únowr{   r   ÚDeadlineExceededErrorÚminÚtimeÚsleep)rM   Úcurrent_attemptÚ	stop_timeÚdelay_factorÚwait_time_secondsÚmax_seconds_lefts         r   Ú_exponential_backoffz_MLService._exponential_backoff¯  s‰   € äœ:×EÑEÀÓWˆØ(¬:×+QÑ+QÑQÐàÐ Ø )¬H×,=Ñ,=×,AÑ,AÓ,CÑ C×RÑRÓTÐØ !Ò#Ü ×6Ñ6Ð7SÓTÐTÜ #Ð$5Ð7GÈ!Ñ7KÓ LÐÜ�
‰
Ð$Õ%r!   Nc                 ó<  — t        |t        «      st        d«      ‚|j                  d«      rm|j                  d«      r|j                  d«      S |j                  d«      r$t	        j
                  |j                  d«      «      ‚t        j                  d¬«      ‚t        |j                  d«      «      }|j                  di «      }|j                  d	d
«      }|j                  d«      st        d«      ‚t        |j                  d«      «      \  }}d}	t        j                  j                  «       }
|€dn|
t        j                  |¬«      z   }|rM|j                  d«      s<| j                  |	|«       | j                  |«      }|	dz  }	|r|j                  d«      sŒ<|j                  d«      rW|j                  d«      r|j                  d«      S |j                  d«      r$t	        j
                  |j                  d«      «      ‚t!        |«      j#                  «       S )aÿ  Handles long running operations.

        Args:
            operation: The operation to handle.
            wait_for_operation: Should we allow polling for the operation to complete.
                If no polling is requested, a locked model will be returned instead.
            max_time_seconds: The maximum seconds to try polling for operation complete.
                (None for no limit)

        Returns:
            dict: A dictionary of the returned model properties.

        Raises:
            TypeError: if the operation is not a dictionary.
            ValueError: If the operation is malformed.
            UnknownError: If the server responds with an unexpected response.
            err: If the operation exceeds polling attempts or stop_time
        zOperation must be a dictionary.ÚdoneÚresponser�  z$Internal Error: Malformed Operation.)r�   rl   ÚmetadatarR   r?  ÚModelOperationMetadataz#Unknown type of operation metadata.r   N)ÚsecondsrN  )ra   rT   rÕ   rm   r   Úhandle_operation_errorr   ÚUnknownErrorr_  Úendswithrn   rw   r•  r  rŸ  r£   r<   r¯   )rM   Ú	operationr¡   r¢   r¤   r£  Úmetadata_typero   r7   rš  Ú
start_timer›  s               r   r   z_MLService.handle_operation»  sÇ  € ô& ˜)¤TÔ*ÜÐ=Ó>Ð>à�=‰=˜Ô à�}‰}˜ZÔ(Ø —}‘} ZÓ0Ð0Ø�}‰}˜WÔ%Ü×3Ñ3°I·M±MÀ'Ó4JÓKÐKÜ×)Ñ)Ð2XÔYÐYä*¨9¯=©=¸Ó+@ÓAˆØ—=‘= ¨RÓ0ˆØ Ÿ™ W¨bÓ1ˆØ×%Ñ%Ð&>Ô?ÜÐAÓBÐBÜ.¨x¯|©|¸FÓ/CÓD‰ˆˆ8ØˆÜ×&Ñ&×*Ñ*Ó,ˆ
Ø-Ð5‘TØ¤(×"4Ñ"4Ð=MÔ"NÑNð 	á ¨¯©°vÔ)>ð ×%Ñ% o°yÔAØ×*Ñ*¨7Ó3ˆIØ˜qÑ ˆOñ !¨¯©°vÕ)>ð �=‰=˜Ô Ø�}‰}˜ZÔ(Ø —}‘} ZÓ0Ð0Ø�}‰}˜WÔ%Ü×3Ñ3°I·M±MÀ'Ó4JÓKÐKô ˜Ó"×*Ñ*Ó,Ð,r!   c           	      ó  — t        |«       	 | j                  | j                  j                  dd|j	                  d¬«      ¬«      «      S # t
        j                  j                  $ r}t        j                  |«      ‚d }~ww xY w)NÚpostr  Tr¬   ©r‹  Újson)
rY  r   r…  rŒ  r¯   r�  r   rŽ  r   r�  )rM   r,   r�  s      r   r*   z_MLService.create_modelô  sy   € Ü˜Ôð	DØ×(Ñ(Ø—‘×!Ñ! &¨h¸U¿]¹]ÐVZ¸]Ó=[Ð!Ó\ó^ð ^øä×"Ñ"×3Ñ3ò 	DÜ×<Ñ<¸UÓCÐCûð	Dús   �<A
 Á
BÁ'A<Á<Bc           	      ó<  — t        ||«       d|j                  › �}|�|d|› �z   }	 | j                  | j                  j	                  d||j                  d¬«      ¬«      «      S # t        j                  j                  $ r}t        j                  |«      ‚d }~ww xY w)Númodels/z?updateMask=ÚpatchTr¬   r®  )rY  r7   r   r…  rŒ  r¯   r�  r   rŽ  r   r�  )rM   r,   rX  rî   r�  s        r   r0   z_MLService.update_modelü  s£   € Ü˜˜{Ô+Ø˜Ÿ™Ð(Ð)ˆØÐ"Ø˜L¨¨Ð6Ñ6ˆDð	DØ×(Ñ(Ø—‘×!Ñ! '¨t¸%¿-¹-ÐSW¸-Ó:XÐ!ÓYó[ð [øä×"Ñ"×3Ñ3ò 	DÜ×<Ñ<¸UÓCÐCûð	Dús   §<A$ Á$BÂBÂBc                 ó–   — t        |«       d| j                  › d|› �}t        j                  |d|idœ«      }| j	                  |d¬«      S )Nz	projects/z/models/r�   )rl   r‹   zstate.published)rX  )r\  r~  r)   r
   r0   )rM   r7   r3   Ú
model_namer,   s        r   r5   z_MLService.set_published  s\   € Ü˜8Ô$Ø  ×!1Ñ!1Ð 2°(¸8¸*ÐEˆ
Ü—‘Øà˜Wðñ!
ó ˆð × Ñ  Ð4EÐ ÓFÐFr!   c                 óÎ   — t        |«       	 | j                  j                  dd|› �¬«      S # t        j                  j
                  $ r}t        j                  |«      ‚d }~ww xY w)Nrm   r±  rŠ  ©r\  r…  rŒ  r�  r   rŽ  r   r�  ©rM   r7   r�  s      r   r<   z_MLService.get_model  s`   € Ü˜8Ô$ð	DØ—<‘<×$Ñ$ U°'¸(¸Ð0DÐ$ÓEÐEøÜ×"Ñ"×3Ñ3ò 	DÜ×<Ñ<¸UÓCÐCûð	Dús   �- ­A$Á
AÁA$c                 ó”  — t        |«       t        |«       t        |«       i }|r||d<   |r||d<   |r||d<   d}|r5t        j                  t        |j                  «       «      d«      }|dz   |z   }	 | j                  j                  d|¬«      S # t        j                  j                  $ r}t        j                  |«      ‚d	}~ww xY w)
z lists Firebase ML models.Úfilterr@   rA   r  Tú?rm   rŠ  N)rq  ru  rw  r   Ú	urlencodeÚsortedÚitemsr…  rŒ  r�  r   rŽ  r   r�  )rM   r?   r@   rA   Úparamsrî   Ú	param_strr�  s           r   r   z_MLService.list_models  sÆ   € ä˜kÔ*Ü˜IÔ&Ü˜ZÔ(ØˆÙØ*ˆF�8ÑÙØ"+ˆF�;ÑÙØ#-ˆF�<Ñ ØˆÙÜŸ™¬¨v¯|©|«~Ó(>ÀÓEˆIØ˜#‘: 	Ñ)ˆDð	DØ—<‘<×$Ñ$ U°Ð$Ó5Ð5øÜ×"Ñ"×3Ñ3ò 	DÜ×<Ñ<¸UÓCÐCûð	Dús   Á3B ÂCÂ-CÃCc                 óÐ   — t        |«       	 | j                  j                  dd|› �¬«       y # t        j                  j
                  $ r}t        j                  |«      ‚d }~ww xY w)NÚdeleter±  rŠ  r¶  r·  s      r   rC   z_MLService.delete_model.  s]   € Ü˜8Ô$ð	DØ�L‰L×Ñ˜h¨g°h°ZÐ,@ÐÕAøÜ×"Ñ"×3Ñ3ò 	DÜ×<Ñ<¸UÓCÐCûð	Dús   � . ®A%ÁA Á A%)FNr]   )r²   r³   r´   rµ   r  r†  r“  r”  rN   r£   rŸ  r   r*   r0   r5   r<   r   rC   rº   r!   r   r   r   �  sU   „ ÙàK€KØ@€MØ&)Ð#Ø"#Ðò/ò&Dò
&ó6-òrDó	Dò	GòDòDó*Dr!   r   r]   )NNNN);rµ   rw   rí   Úrer   r˜  Úurllibr   r%   r�  r�  r   r   r   r   rß   rà   Ú
tensorflowr  r  r'   r   r   rt  Úcompiler[  ra  rj  ræ   rV  r^  r    r*   r0   r8   r:   r<   r   rC   r)   r¼   rV   rÔ   rÝ   rÑ   r>   rF  rn   rY  r\  r_  ru   r›   r  r©   rq  ru  rw  r   rº   r!   r   ú<module>rÆ     sà  ðñ
ó Û 	Û 	Û 
Û Ý Û ã ã Ý 'Ý !Ý %ðÝ&Ø€Lð
ÛØ€Kð
Cð òð  €Ø€Ø�B—J‘JÐ7Ó8Ð Ø"˜Ÿ
™
Ð#;Ó<Ð Øˆr�z‰zÐ2Ó3€Ø$˜"Ÿ*™*ØBóDÐ à#˜Ÿ™ØZó\Ð à$˜"Ÿ*™*ØBóDÐ òBóDó,Dó,Vó0Wó,Dó,Mó6&÷&jñ j÷Z"ñ "ôD%�;ô D%÷N"ñ "÷,
ñ ,
ô^K6Ð,ô K6÷ZG$ñ G$÷Tñ ò8Bó<ò8ò
òòòòòEòXòD÷fDò fDøð{ ò ØƒLðûð ò ØƒKðús#   ¼E ÁE, ÅE)Å(E)Å,E7Å6E7