Skip to content

feat(ml): Adding Firebase ML management APIs #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f69e14c
Introduced the exceptions module (#296)
hiranya911 Jun 12, 2019
2879a22
Migrating FCM Send APIs to the New Exceptions (#297)
hiranya911 Jun 20, 2019
fa843f3
Migrated remaining messaging APIs to new error types (#298)
hiranya911 Jun 26, 2019
b27216b
Introducing TokenSignError to represent custom token creation errors …
hiranya911 Jul 5, 2019
99929ed
Raising FirebaseError from create_session_cookie() API (#306)
hiranya911 Jul 18, 2019
9fb0766
Introducing UserNotFoundError type (#309)
hiranya911 Jul 18, 2019
8a0cf08
New error handling support in create/update/delete user APIs (#311)
hiranya911 Jul 26, 2019
29c8b7a
Error handling improvements in email action link APIs (#312)
hiranya911 Jul 31, 2019
3361452
Project management API migrated to new error types (#314)
hiranya911 Jul 31, 2019
dbb6970
Error handling updated for remaining user_mgt APIs (#315)
hiranya911 Aug 2, 2019
baf4991
Merged with master
hiranya911 Aug 3, 2019
1210723
Migrated token verification APIs to new exception types (#317)
hiranya911 Aug 5, 2019
299e808
Migrated the db module to the new exception types (#318)
hiranya911 Aug 5, 2019
030f6e6
Adding a few overlooked error types (#319)
hiranya911 Aug 8, 2019
7974c05
Removing the ability to delete user properties by passing None (#320)
hiranya911 Aug 9, 2019
dd3c4bd
Adding beginning of _MLKitService (#323)
ifielker Aug 14, 2019
65f64c0
Firebase ML Kit Get Model API implementation (#326)
ifielker Aug 19, 2019
a84d3f6
Firebase ML Kit Delete Model API implementation (#327)
ifielker Aug 19, 2019
a247f13
Firebase ML Kit List Models API implementation (#331)
ifielker Aug 21, 2019
4618b1e
Implementation of Model, ModelFormat, TFLiteModelSource and subclasse…
ifielker Aug 29, 2019
e5cf14a
Firebase ML Kit Create Model API implementation (#337)
ifielker Sep 11, 2019
2a3be77
Firebase ML Kit Update Model API implementation (#343)
ifielker Sep 11, 2019
0344172
Firebase ML Kit Publish and Unpublish Implementation (#345)
ifielker Sep 11, 2019
cd5e82a
Firebase ML Kit TFLiteGCSModelSource.from_tflite_model implementation…
ifielker Sep 17, 2019
7b4731f
Quick pass at filling in missing docstrings (#367)
kevinthecheung Nov 18, 2019
c6dafbb
Modify Operation Handling to not require a name for Done Operations (…
ifielker Dec 10, 2019
079c7e1
rename from mlkit to ml (#373)
ifielker Dec 10, 2019
a13d2a7
Adding File naming capability to from_saved_model and from_keras_mode…
ifielker Dec 13, 2019
b133bbb
Firebase ML Modify Operation Handling Code to match rpc codes not htm…
ifielker Jan 23, 2020
8770448
Mlkit fix date handling2 (#391)
ifielker Jan 27, 2020
cf748c8
Firebase Ml Fix upload file naming (#392)
ifielker Jan 27, 2020
0b70687
Integration tests for Firebase ML (#394)
ifielker Jan 30, 2020
c0094ed
Merged with master
hiranya911 Jan 30, 2020
7295ea4
Fixing lint errors for Py3 (#401)
hiranya911 Jan 30, 2020
bcefca8
Modifying operation handling to support backend changes (#423)
ifielker Mar 20, 2020
e49add8
Firebase ML Changing service endpoint (#421)
ifielker Mar 20, 2020
f90a021
Mlkit add headers (#445)
ifielker Apr 14, 2020
1060146
Merge branch 'master' into mlkit
hiranya911 Apr 14, 2020
5521fd4
fixed test (#448)
ifielker Apr 15, 2020
564078d
Adding tensorflow and keras so we don't skip tests (#449)
ifielker Apr 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install setuptools wheel
pip install tensorflow
pip install keras

- name: Run unit tests
run: pytest
Expand Down
9 changes: 6 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,17 @@ Then set up your Firebase/GCP project as follows:
Firebase Console. Select the "Sign-in method" tab, and enable the
"Email/Password" sign-in method, including the Email link (passwordless
sign-in) option.

3. Enable the IAM API: Go to the
3. Enable the Firebase ML API: Go to the
[Google Developers Console](
https://console.developers.google.com/apis/api/firebaseml.googleapis.com/overview)
and make sure your project is selected. If the API is not already enabled, click Enable.
4. Enable the IAM API: Go to the
[Google Cloud Platform Console](https://console.cloud.google.com) and make
sure your Firebase/GCP project is selected. Select "APIs & Services >
Dashboard" from the main menu, and click the "ENABLE APIS AND SERVICES"
button. Search for and enable the "Identity and Access Management (IAM)
API".
4. Grant your service account the 'Firebase Authentication Admin' role. This is
5. Grant your service account the 'Firebase Authentication Admin' role. This is
required to ensure that exported user records contain the password hashes of
the user accounts:
1. Go to [Google Cloud Platform Console / IAM & admin](https://console.cloud.google.com/iam-admin).
Expand Down
45 changes: 45 additions & 0 deletions firebase_admin/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@
}


# See https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
_RPC_CODE_TO_ERROR_CODE = {
1: exceptions.CANCELLED,
2: exceptions.UNKNOWN,
3: exceptions.INVALID_ARGUMENT,
4: exceptions.DEADLINE_EXCEEDED,
5: exceptions.NOT_FOUND,
6: exceptions.ALREADY_EXISTS,
7: exceptions.PERMISSION_DENIED,
8: exceptions.RESOURCE_EXHAUSTED,
9: exceptions.FAILED_PRECONDITION,
10: exceptions.ABORTED,
11: exceptions.OUT_OF_RANGE,
13: exceptions.INTERNAL,
14: exceptions.UNAVAILABLE,
15: exceptions.DATA_LOSS,
16: exceptions.UNAUTHENTICATED,
}


def _get_initialized_app(app):
"""Returns a reference to an initialized App instance."""
if app is None:
Expand All @@ -75,6 +95,7 @@ def _get_initialized_app(app):
' firebase_admin.App, but given "{0}".'.format(type(app)))



def get_app_service(app, name, initializer):
app = _get_initialized_app(app)
return app._get_service(name, initializer) # pylint: disable=protected-access
Expand Down Expand Up @@ -108,6 +129,27 @@ def handle_platform_error_from_requests(error, handle_func=None):
return exc if exc else _handle_func_requests(error, message, error_dict)


def handle_operation_error(error):
"""Constructs a ``FirebaseError`` from the given operation error.

Args:
error: An error returned by a long running operation.

Returns:
FirebaseError: A ``FirebaseError`` that can be raised to the user code.
"""
if not isinstance(error, dict):
return exceptions.UnknownError(
message='Unknown error while making a remote service call: {0}'.format(error),
cause=error)

rpc_code = error.get('code')
message = error.get('message')
error_code = _rpc_code_to_error_code(rpc_code)
err_type = _error_code_to_exception_type(error_code)
return err_type(message=message)


def _handle_func_requests(error, message, error_dict):
"""Constructs a ``FirebaseError`` from the given GCP error.

Expand Down Expand Up @@ -264,6 +306,9 @@ def _http_status_to_error_code(status):
"""Maps an HTTP status to a platform error code."""
return _HTTP_STATUS_TO_ERROR_CODE.get(status, exceptions.UNKNOWN)

def _rpc_code_to_error_code(rpc_code):
"""Maps an RPC code to a platform error code."""
return _RPC_CODE_TO_ERROR_CODE.get(rpc_code, exceptions.UNKNOWN)

def _error_code_to_exception_type(code):
"""Maps a platform error code to an exception type."""
Expand Down
Loading