Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 1cf17cc

Browse files
Add support for ML Kit's Natural Language and Language Identification #1127
1 parent 794467a commit 1cf17cc

23 files changed

Lines changed: 119 additions & 60 deletions

File tree

demo-ng/firebase.nativescript.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
2+
"external_push_client_only": false,
23
"using_ios": true,
34
"using_android": true,
4-
"realtimedb": false,
55
"firestore": true,
6+
"realtimedb": false,
7+
"authentication": true,
68
"remote_config": false,
79
"performance_monitoring": true,
810
"messaging": false,
9-
"crash_reporting": false,
11+
"in_app_messaging": false,
1012
"crashlytics": false,
13+
"crash_reporting": false,
1114
"storage": false,
15+
"functions": false,
1216
"facebook_auth": false,
1317
"google_auth": false,
1418
"admob": false,
@@ -19,5 +23,6 @@
1923
"ml_kit_barcode_scanning": true,
2024
"ml_kit_face_detection": true,
2125
"ml_kit_image_labeling": true,
22-
"ml_kit_custom_model": true
23-
}
26+
"ml_kit_custom_model": true,
27+
"ml_kit_natural_language_identification": true
28+
}

publish/scripts/installer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ function promptQuestions() {
250250
name: 'ml_kit_custom_model',
251251
description: 'With Ml Kit, do you want to use a custom TensorFlow Lite model? (y/n)',
252252
default: 'n'
253+
// }, {
254+
// name: 'ml_kit_natural_language_identification',
255+
// description: 'With Ml Kit, do you want to use recognize natural languages? (y/n)',
256+
// default: 'n'
253257
}], function (mlkitErr, mlkitResult) {
254258
if (mlkitErr) {
255259
return console.log(mlkitErr);
@@ -422,6 +426,8 @@ end`) + `
422426
` + (isSelected(result.ml_kit) && isSelected(result.ml_kit_face_detection) ? `` : `#`) + `pod 'Firebase/MLVisionFaceModel'
423427
` + (isSelected(result.ml_kit) && isSelected(result.ml_kit_image_labeling) ? `` : `#`) + `pod 'Firebase/MLVisionLabelModel'
424428
` + (isSelected(result.ml_kit) && isSelected(result.ml_kit_custom_model) ? `` : `#`) + `pod 'Firebase/MLModelInterpreter'
429+
# Natural Language is commented for now, because of (likely) this issue: https://github.com/firebase/firebase-ios-sdk/issues/2324
430+
` + (isSelected(result.ml_kit) && isSelected(result.ml_kit_natural_language_identification) ? `#` : `#`) + `pod 'Firebase/MLNLLanguageID'
425431
426432
# Facebook Authentication
427433
` + (isSelected(result.facebook_auth) ? `` : `#`) + `pod 'FBSDKCoreKit', '~> 4.38.0'
@@ -775,6 +781,8 @@ dependencies {
775781
` + (isSelected(result.ml_kit) ? `` : `//`) + ` compile "com.google.firebase:firebase-ml-vision:18.0.2"
776782
` + (isSelected(result.ml_kit_image_labeling) ? `` : `//`) + ` compile "com.google.firebase:firebase-ml-vision-image-label-model:17.0.2"
777783
` + (isSelected(result.ml_kit_custom_model) ? `` : `//`) + ` compile "com.google.firebase:firebase-ml-model-interpreter:16.2.4"
784+
` + (isSelected(result.ml_kit_natural_language_identification) ? `//` : `//`) + ` compile "com.google.firebase:firebase-ml-natural-language:18.1.1"
785+
` + (isSelected(result.ml_kit_natural_language_identification) ? `//` : `//`) + ` compile "com.google.firebase:firebase-ml-natural-language-language-id-model:18.0.2"
778786
779787
// Facebook Authentication
780788
` + (isSelected(result.facebook_auth) ? `` : `//`) + ` compile ("com.facebook.android:facebook-android-sdk:4.35.0"){ exclude group: 'com.google.zxing' }

src/mlkit/barcodescanning/index.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ImageSource } from "tns-core-modules/image-source";
22
import { MLKitScanBarcodesOnDeviceOptions, MLKitScanBarcodesOnDeviceResult } from "./";
3-
import { MLKitOptions } from "../index";
3+
import { MLKitVisionOptions } from "../index";
44
import { BarcodeFormat, MLKitBarcodeScanner as MLKitBarcodeScannerBase } from "./barcodescanning-common";
55

66
export { BarcodeFormat };
@@ -105,7 +105,7 @@ export function scanBarcodesOnDevice(options: MLKitScanBarcodesOnDeviceOptions):
105105
});
106106
}
107107

108-
function getImage(options: MLKitOptions): any /* com.google.firebase.ml.vision.common.FirebaseVisionImage */ {
108+
function getImage(options: MLKitVisionOptions): any /* com.google.firebase.ml.vision.common.FirebaseVisionImage */ {
109109
const image: android.graphics.Bitmap = options.image instanceof ImageSource ? options.image.android : options.image.imageSource.android;
110110
return com.google.firebase.ml.vision.common.FirebaseVisionImage.fromBitmap(image);
111111
}

src/mlkit/barcodescanning/index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { MLKitOptions } from "../";
1+
import { MLKitCameraView, MLKitVisionOptions, MLKitVisionResult } from "../";
22
import { BarcodeFormat } from "./barcodescanning-common";
3-
import { MLKitResult, MLKitCameraView } from "../index";
43

54
export { BarcodeFormat };
65

@@ -12,11 +11,11 @@ export interface MLKitScanBarcodesResultBarcode {
1211
// TODO details
1312
}
1413

15-
export interface MLKitScanBarcodesOnDeviceResult extends MLKitResult {
14+
export interface MLKitScanBarcodesOnDeviceResult extends MLKitVisionResult {
1615
barcodes: Array<MLKitScanBarcodesResultBarcode>;
1716
}
1817

19-
export interface MLKitScanBarcodesOnDeviceOptions extends MLKitOptions {
18+
export interface MLKitScanBarcodesOnDeviceOptions extends MLKitVisionOptions {
2019
/**
2120
* Limit to only what you need to speed up processing.
2221
* If not set, we'll detect all supported formats.
@@ -26,4 +25,5 @@ export interface MLKitScanBarcodesOnDeviceOptions extends MLKitOptions {
2625

2726
export declare function scanBarcodesOnDevice(options: MLKitScanBarcodesOnDeviceOptions): Promise<MLKitScanBarcodesOnDeviceResult>;
2827

29-
export declare class MLKitBarcodeScanner extends MLKitCameraView {}
28+
export declare class MLKitBarcodeScanner extends MLKitCameraView {
29+
}

src/mlkit/barcodescanning/index.ios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ImageSource } from "tns-core-modules/image-source";
22
import { MLKitScanBarcodesOnDeviceOptions, MLKitScanBarcodesOnDeviceResult } from "./index";
3-
import { MLKitOptions } from "../index";
3+
import { MLKitVisionOptions } from "../index";
44
import { BarcodeFormat, MLKitBarcodeScanner as MLKitBarcodeScannerBase } from "./barcodescanning-common";
55

66
export { BarcodeFormat };
@@ -92,7 +92,7 @@ export function scanBarcodesOnDevice(options: MLKitScanBarcodesOnDeviceOptions):
9292
});
9393
}
9494

95-
function getImage(options: MLKitOptions): FIRVisionImage {
95+
function getImage(options: MLKitVisionOptions): FIRVisionImage {
9696
const image: UIImage = options.image instanceof ImageSource ? options.image.ios : options.image.imageSource.ios;
9797
return FIRVisionImage.alloc().initWithImage(image);
9898
}

src/mlkit/custommodel/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { MLKitCameraView, MLKitOptions, MLKitResult } from "../index";
1+
import { MLKitCameraView, MLKitVisionOptions, MLKitVisionResult } from "../index";
22

33
export interface MLKitCustomModelResultValue {
44
text: string;
55
confidence: number;
66
}
77

8-
export interface MLKitCustomModelResult extends MLKitResult {
8+
export interface MLKitCustomModelResult extends MLKitVisionResult {
99
result: Array<MLKitCustomModelResultValue>;
1010
}
1111

@@ -17,7 +17,7 @@ export interface TNSCustomModelInput {
1717
}
1818

1919
// see https://firebase.google.com/docs/ml-kit/ios/use-custom-models
20-
export interface MLKitCustomModelOptions extends MLKitOptions {
20+
export interface MLKitCustomModelOptions extends MLKitVisionOptions {
2121
localModelFile?: string;
2222
labelsFile: string;
2323
/**

src/mlkit/facedetection/index.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ImageSource } from "tns-core-modules/image-source";
2+
import { MLKitVisionOptions } from "../";
23
import { MLKitDetectFacesOnDeviceOptions, MLKitDetectFacesOnDeviceResult } from "./";
3-
import { MLKitOptions } from "../index";
44
import { MLKitFaceDetection as MLKitFaceDetectionBase } from "./facedetection-common";
55

66
const gmsTasks = (<any>com.google.android.gms).tasks;
@@ -110,7 +110,7 @@ export function detectFacesOnDevice(options: MLKitDetectFacesOnDeviceOptions): P
110110
});
111111
}
112112

113-
function getImage(options: MLKitOptions): any /* com.google.firebase.ml.vision.common.FirebaseVisionImage */ {
113+
function getImage(options: MLKitVisionOptions): any /* com.google.firebase.ml.vision.common.FirebaseVisionImage */ {
114114
const image: android.graphics.Bitmap = options.image instanceof ImageSource ? options.image.android : options.image.imageSource.android;
115115
return com.google.firebase.ml.vision.common.FirebaseVisionImage.fromBitmap(image);
116116
}

src/mlkit/facedetection/index.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { MLKitOptions } from "../";
2-
import { MLKitCameraView, MLKitResult } from "../index";
1+
import { MLKitCameraView, MLKitVisionOptions, MLKitVisionResult } from "../";
32

43
export interface MLKitDetectFacesResultFace {
54
smilingProbability?: number;
@@ -10,13 +9,13 @@ export interface MLKitDetectFacesResultFace {
109
android?: any;
1110
}
1211

13-
export interface MLKitDetectFacesOnDeviceResult extends MLKitResult {
12+
export interface MLKitDetectFacesOnDeviceResult extends MLKitVisionResult {
1413
faces: Array<MLKitDetectFacesResultFace>;
1514
}
1615

1716
export type MLKitFaceDetectionMode = "fast" | "accurate";
1817

19-
export interface MLKitDetectFacesOnDeviceOptions extends MLKitOptions {
18+
export interface MLKitDetectFacesOnDeviceOptions extends MLKitVisionOptions {
2019
/**
2120
* Favor speed or accuracy when detecting faces.
2221
* Default "fast".
@@ -27,8 +26,8 @@ export interface MLKitDetectFacesOnDeviceOptions extends MLKitOptions {
2726
* Whether or not to attempt to identify facial "landmarks": eyes, ears, nose, cheeks, mouth.
2827
* Default "none".
2928
*
30-
// detectLandmarks?: "none" | "all";
31-
*/
29+
// detectLandmarks?: "none" | "all";
30+
*/
3231

3332
/**
3433
* The minimum size, relative to the image, of faces to detect.
@@ -45,4 +44,5 @@ export interface MLKitDetectFacesOnDeviceOptions extends MLKitOptions {
4544

4645
export declare function detectFacesOnDevice(options: MLKitDetectFacesOnDeviceOptions): Promise<MLKitDetectFacesOnDeviceResult>;
4746

48-
export declare class MLKitFaceDetection extends MLKitCameraView {}
47+
export declare class MLKitFaceDetection extends MLKitCameraView {
48+
}

src/mlkit/facedetection/index.ios.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ImageSource } from "tns-core-modules/image-source";
2+
import { ios as iosUtils } from "tns-core-modules/utils/utils";
3+
import { MLKitVisionOptions } from "../";
24
import { MLKitDetectFacesOnDeviceOptions, MLKitDetectFacesOnDeviceResult } from "./";
3-
import { MLKitOptions } from "../index";
45
import { MLKitFaceDetection as MLKitFaceDetectionBase } from "./facedetection-common";
5-
import { ios as iosUtils } from "tns-core-modules/utils/utils";
66

77
export class MLKitFaceDetection extends MLKitFaceDetectionBase {
88

@@ -99,7 +99,7 @@ export function detectFacesOnDevice(options: MLKitDetectFacesOnDeviceOptions): P
9999
});
100100
}
101101

102-
function getImage(options: MLKitOptions): FIRVisionImage {
102+
function getImage(options: MLKitVisionOptions): FIRVisionImage {
103103
const image = options.image instanceof ImageSource ? options.image.ios : options.image.imageSource.ios;
104104
const newImage = UIImage.alloc().initWithCGImageScaleOrientation(image.CGImage, 1, UIImageOrientation.Up);
105105
return FIRVisionImage.alloc().initWithImage(newImage);

src/mlkit/imagelabeling/index.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImageSource } from "tns-core-modules/image-source";
2-
import { MLKitOptions, } from "../";
2+
import { MLKitVisionOptions, } from "../";
33
import { MLKitImageLabelingOptions, MLKitImageLabelingCloudResult, MLKitImageLabelingOnDeviceResult } from "./";
44
import { MLKitImageLabeling as MLKitImageLabelingBase } from "./imagelabeling-common";
55

@@ -144,7 +144,7 @@ export function labelImageCloud(options: MLKitImageLabelingOptions): Promise<MLK
144144
});
145145
}
146146

147-
function getImage(options: MLKitOptions): any /* com.google.firebase.ml.vision.common.FirebaseVisionImage */ {
147+
function getImage(options: MLKitVisionOptions): any /* com.google.firebase.ml.vision.common.FirebaseVisionImage */ {
148148
const image: android.graphics.Bitmap = options.image instanceof ImageSource ? options.image.android : options.image.imageSource.android;
149149
return com.google.firebase.ml.vision.common.FirebaseVisionImage.fromBitmap(image);
150150
}

0 commit comments

Comments
 (0)