1414
1515"""Firebase ML module.
1616
17+ .. deprecated::
18+ Firebase ML is deprecated and will be shut down on June 15, 2027.
19+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
20+ Firebase as an alternative for hosting custom models. For more info, see
21+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
22+
1723This module contains functions for creating, updating, getting, listing,
1824deleting, publishing and unpublishing Firebase ML models.
1925"""
2026
27+ # pylint: disable=too-many-lines
2128
2229import datetime
30+ import os
2331import re
32+ import sys
2433import time
25- import os
2634from urllib import parse
35+ import warnings
2736
2837import requests
2938
4655except ImportError :
4756 _TF_ENABLED = False
4857
58+ _DEPRECATION_WARNING = (
59+ 'Firebase ML is deprecated and will be shut down on June 15, 2027. '
60+ 'To host custom models, you must migrate to another solution. You can use Cloud Storage for '
61+ 'Firebase as an alternative for hosting custom models. For more info, see '
62+ 'https://firebase.google.com/docs/ml/migrate-to-cloud-storage'
63+ )
64+
65+
66+ def _is_internal_call ():
67+ """Checks if the current call originated from within the ML module."""
68+ try :
69+ # pylint: disable=protected-access
70+ frame = sys ._getframe (2 )
71+ while frame :
72+ if frame .f_code .co_name in (
73+ 'from_dict' , '_update_from_dict' , 'handle_operation' , 'list_models'
74+ ):
75+ return True
76+ frame = frame .f_back
77+ except (AttributeError , ValueError ):
78+ pass
79+ return False
80+
81+
4982_ML_ATTRIBUTE = '_ml'
5083_MAX_PAGE_SIZE = 100
5184_MODEL_ID_PATTERN = re .compile (r'^[A-Za-z0-9_-]{1,60}$' )
@@ -77,34 +110,56 @@ def _get_ml_service(app):
77110def create_model (model , app = None ):
78111 """Creates a model in the current Firebase project.
79112
113+ .. deprecated::
114+ Firebase ML is deprecated and will be shut down on June 15, 2027.
115+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
116+ Firebase as an alternative for hosting custom models. For more info, see
117+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
118+
80119 Args:
81120 model: An ml.Model to create.
82121 app: A Firebase app instance (or None to use the default app).
83122
84123 Returns:
85124 Model: The model that was created in Firebase ML.
86125 """
126+ if not _is_internal_call ():
127+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
87128 ml_service = _get_ml_service (app )
88129 return Model .from_dict (ml_service .create_model (model ), app = app )
89130
90131
91132def update_model (model , app = None ):
92133 """Updates a model's metadata or model file.
93134
135+ .. deprecated::
136+ Firebase ML is deprecated and will be shut down on June 15, 2027.
137+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
138+ Firebase as an alternative for hosting custom models. For more info, see
139+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
140+
94141 Args:
95142 model: The ml.Model to update.
96143 app: A Firebase app instance (or None to use the default app).
97144
98145 Returns:
99146 Model: The updated model.
100147 """
148+ if not _is_internal_call ():
149+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
101150 ml_service = _get_ml_service (app )
102151 return Model .from_dict (ml_service .update_model (model ), app = app )
103152
104153
105154def publish_model (model_id , app = None ):
106155 """Publishes a Firebase ML model.
107156
157+ .. deprecated::
158+ Firebase ML is deprecated and will be shut down on June 15, 2027.
159+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
160+ Firebase as an alternative for hosting custom models. For more info, see
161+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
162+
108163 A published model can be downloaded to client apps.
109164
110165 Args:
@@ -114,41 +169,65 @@ def publish_model(model_id, app=None):
114169 Returns:
115170 Model: The published model.
116171 """
172+ if not _is_internal_call ():
173+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
117174 ml_service = _get_ml_service (app )
118175 return Model .from_dict (ml_service .set_published (model_id , publish = True ), app = app )
119176
120177
121178def unpublish_model (model_id , app = None ):
122179 """Unpublishes a Firebase ML model.
123180
181+ .. deprecated::
182+ Firebase ML is deprecated and will be shut down on June 15, 2027.
183+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
184+ Firebase as an alternative for hosting custom models. For more info, see
185+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
186+
124187 Args:
125188 model_id: The id of the model to unpublish.
126189 app: A Firebase app instance (or None to use the default app).
127190
128191 Returns:
129192 Model: The unpublished model.
130193 """
194+ if not _is_internal_call ():
195+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
131196 ml_service = _get_ml_service (app )
132197 return Model .from_dict (ml_service .set_published (model_id , publish = False ), app = app )
133198
134199
135200def get_model (model_id , app = None ):
136201 """Gets the model specified by the given ID.
137202
203+ .. deprecated::
204+ Firebase ML is deprecated and will be shut down on June 15, 2027.
205+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
206+ Firebase as an alternative for hosting custom models. For more info, see
207+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
208+
138209 Args:
139210 model_id: The id of the model to get.
140211 app: A Firebase app instance (or None to use the default app).
141212
142213 Returns:
143214 Model: The requested model.
144215 """
216+ if not _is_internal_call ():
217+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
145218 ml_service = _get_ml_service (app )
146219 return Model .from_dict (ml_service .get_model (model_id ), app = app )
147220
148221
149222def list_models (list_filter = None , page_size = None , page_token = None , app = None ):
150223 """Lists the current project's models.
151224
225+ .. deprecated::
226+ Firebase ML is deprecated and will be shut down on June 15, 2027.
227+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
228+ Firebase as an alternative for hosting custom models. For more info, see
229+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
230+
152231 Args:
153232 list_filter: a list filter string such as ``tags:'tag_1'``. None will return all models.
154233 page_size: A number between 1 and 100 inclusive that specifies the maximum
@@ -160,6 +239,8 @@ def list_models(list_filter=None, page_size=None, page_token=None, app=None):
160239 Returns:
161240 ListModelsPage: A (filtered) list of models.
162241 """
242+ if not _is_internal_call ():
243+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
163244 ml_service = _get_ml_service (app )
164245 return ListModelsPage (
165246 ml_service .list_models , list_filter , page_size , page_token , app = app )
@@ -168,23 +249,39 @@ def list_models(list_filter=None, page_size=None, page_token=None, app=None):
168249def delete_model (model_id , app = None ):
169250 """Deletes a model from the current project.
170251
252+ .. deprecated::
253+ Firebase ML is deprecated and will be shut down on June 15, 2027.
254+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
255+ Firebase as an alternative for hosting custom models. For more info, see
256+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
257+
171258 Args:
172259 model_id: The id of the model you wish to delete.
173260 app: A Firebase app instance (or None to use the default app).
174261 """
262+ if not _is_internal_call ():
263+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
175264 ml_service = _get_ml_service (app )
176265 ml_service .delete_model (model_id )
177266
178267
179268class Model :
180269 """A Firebase ML Model object.
181270
271+ .. deprecated::
272+ Firebase ML is deprecated and will be shut down on June 15, 2027.
273+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
274+ Firebase as an alternative for hosting custom models. For more info, see
275+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
276+
182277 Args:
183278 display_name: The display name of your model - used to identify your model in code.
184279 tags: Optional list of strings associated with your model. Can be used in list queries.
185280 model_format: A subclass of ModelFormat. (e.g. TFLiteFormat) Specifies the model details.
186281 """
187282 def __init__ (self , display_name = None , tags = None , model_format = None ):
283+ if not _is_internal_call ():
284+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
188285 self ._app = None # Only needed for wait_for_unlo
189286 self ._data = {}
190287 self ._model_format = None
@@ -342,7 +439,14 @@ def as_dict(self, for_upload=False):
342439
343440
344441class ModelFormat :
345- """Abstract base class representing a Model Format such as TFLite."""
442+ """Abstract base class representing a Model Format such as TFLite.
443+
444+ .. deprecated::
445+ Firebase ML is deprecated and will be shut down on June 15, 2027.
446+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
447+ Firebase as an alternative for hosting custom models. For more info, see
448+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
449+ """
346450 def as_dict (self , for_upload = False ):
347451 """Returns a serializable representation of the object."""
348452 raise NotImplementedError
@@ -351,10 +455,18 @@ def as_dict(self, for_upload=False):
351455class TFLiteFormat (ModelFormat ):
352456 """Model format representing a TFLite model.
353457
458+ .. deprecated::
459+ Firebase ML is deprecated and will be shut down on June 15, 2027.
460+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
461+ Firebase as an alternative for hosting custom models. For more info, see
462+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
463+
354464 Args:
355465 model_source: A TFLiteModelSource sub class. Specifies the details of the model source.
356466 """
357467 def __init__ (self , model_source = None ):
468+ if not _is_internal_call ():
469+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
358470 self ._data = {}
359471 self ._model_source = None
360472
@@ -412,7 +524,14 @@ def as_dict(self, for_upload=False):
412524
413525
414526class TFLiteModelSource :
415- """Abstract base class representing a model source for TFLite format models."""
527+ """Abstract base class representing a model source for TFLite format models.
528+
529+ .. deprecated::
530+ Firebase ML is deprecated and will be shut down on June 15, 2027.
531+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
532+ Firebase as an alternative for hosting custom models. For more info, see
533+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
534+ """
416535 def as_dict (self , for_upload = False ):
417536 """Returns a serializable representation of the object."""
418537 raise NotImplementedError
@@ -466,11 +585,20 @@ def sign_uri(gcs_tflite_uri, app):
466585
467586
468587class TFLiteGCSModelSource (TFLiteModelSource ):
469- """TFLite model source representing a tflite model file stored in GCS."""
588+ """TFLite model source representing a tflite model file stored in GCS.
589+
590+ .. deprecated::
591+ Firebase ML is deprecated and will be shut down on June 15, 2027.
592+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
593+ Firebase as an alternative for hosting custom models. For more info, see
594+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
595+ """
470596
471597 _STORAGE_CLIENT = _CloudStorageClient ()
472598
473599 def __init__ (self , gcs_tflite_uri , app = None ):
600+ if not _is_internal_call ():
601+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
474602 self ._app = app
475603 self ._gcs_tflite_uri = _validate_gcs_tflite_uri (gcs_tflite_uri )
476604
@@ -600,12 +728,20 @@ def as_dict(self, for_upload=False):
600728class ListModelsPage :
601729 """Represents a page of models in a Firebase project.
602730
731+ .. deprecated::
732+ Firebase ML is deprecated and will be shut down on June 15, 2027.
733+ To host custom models, you must migrate to another solution. You can use Cloud Storage for
734+ Firebase as an alternative for hosting custom models. For more info, see
735+ https://firebase.google.com/docs/ml/migrate-to-cloud-storage
736+
603737 Provides methods for traversing the models included in this page, as well as
604738 retrieving subsequent pages of models. The iterator returned by
605739 ``iterate_all()`` can be used to iterate through all the models in the
606740 Firebase project starting from this page.
607741 """
608742 def __init__ (self , list_models_func , list_filter , page_size , page_token , app ):
743+ if not _is_internal_call ():
744+ warnings .warn (_DEPRECATION_WARNING , DeprecationWarning , stacklevel = 2 )
609745 self ._list_models_func = list_models_func
610746 self ._list_filter = list_filter
611747 self ._page_size = page_size
0 commit comments