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

Commit b0f999c

Browse files
Demo UI++
1 parent 5ead746 commit b0f999c

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed

demo-ng/app/app.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Label.mlkit-result {
7979
margin: 5;
8080
text-align: left;
8181
color: white;
82+
font-size: 17;
8283
}
8384

8485
.mask {

demo-ng/app/tabs/mlkit/facedetection/facedetection.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</GridLayout>
4141
<Label row="0" col="1" class="text-center c-white" textWrap="true" color="white" verticalAlignment="center" text="The scanner has been configured to detect faces every 30th frame (default is 10). You can tweak this in your usage of the plugin."></Label>
4242
<StackLayout row="2" col="0" colSpan="3">
43-
<Label [text]="mlKitAllOK" textWrap="true" class="m-t-5 c-purple"></Label>
43+
<Label [text]="mlKitAllOK" textWrap="true" class="m-t-5 font-weight-bold c-white" [class.c-blue]="allSmilingAndEyesOpen"></Label>
4444
<GridLayout row="auto" columns="60, *, *, *" class="m-t-5">
4545
<Label row="0" col="0" class="mlkit-result font-weight-bold" textWrap="true" text="ID"></Label>
4646
<Label row="0" col="1" class="mlkit-result font-weight-bold" textWrap="true" text="Smiling"></Label>

demo-ng/app/tabs/mlkit/facedetection/facedetection.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ export class FaceDetectionComponent extends AbstractMLKitViewComponent {
1111
faces: Array<MLKitDetectFacesResultFace>;
1212

1313
mlKitAllOK: string;
14+
allSmilingAndEyesOpen: boolean = false;
1415

1516
onFaceDetectionResult(scanResult: any): any {
1617
const value: MLKitDetectFacesOnDeviceResult = scanResult.value;
1718
if (value.faces.length > 0) {
1819
this.faces = value.faces;
1920
console.log("this.faces: " + JSON.stringify(this.faces));
2021

21-
let allSmilingAndEyesOpen = true;
22+
this.allSmilingAndEyesOpen = true;
2223
value.faces.forEach(face => {
23-
allSmilingAndEyesOpen = allSmilingAndEyesOpen && face.smilingProbability && face.leftEyeOpenProbability && face.rightEyeOpenProbability &&
24+
this.allSmilingAndEyesOpen = this.allSmilingAndEyesOpen && face.smilingProbability && face.leftEyeOpenProbability && face.rightEyeOpenProbability &&
2425
face.smilingProbability > 0.7 && face.leftEyeOpenProbability > 0.7 && face.rightEyeOpenProbability > 0.7;
2526
});
26-
this.mlKitAllOK = `All smiling and eyes open? ${allSmilingAndEyesOpen ? 'Yes!' : 'Nope'}`;
27+
this.mlKitAllOK = `All smiling and eyes open? ${this.allSmilingAndEyesOpen ? 'Yes!' : 'Nope'}`;
2728
}
2829
}
2930
}

demo-ng/app/tabs/mlkit/imagelabeling/imagelabeling.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
width="100%"
88
height="100%"
99
confidenceThreshold="0.6"
10+
[torchOn]="torchOn"
1011
(scanResult)="onImageLabelingResult($event)">
1112
</MLKitImageLabeling>
1213

demo-ng/app/tabs/mlkit/imagelabeling/imagelabeling.component.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ export class ImageLabelingComponent extends AbstractMLKitViewComponent {
1313
confidence: number;
1414
}>;
1515

16-
constructor() {
17-
super();
18-
// let's start with the torch on, just for show
19-
this.torchOn = true;
20-
}
21-
2216
onImageLabelingResult(scanResult: any): void {
2317
const value: MLKitImageLabelingOnDeviceResult = scanResult.value;
2418
this.labels = value.labels;

demo-ng/app/tabs/mlkit/mlkit.component.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class MLKitComponent {
4040
"Custom model",
4141
"Landmark recognition (cloud)",
4242
"Language identification",
43-
"Smart Reply"
43+
"Smart reply"
4444
];
4545

4646
private mlkitOnDeviceFeatures: Array<string> = [
@@ -268,22 +268,36 @@ export class MLKitComponent {
268268
firebase.mlkit.textrecognition.recognizeTextOnDevice({
269269
image: imageSource
270270
}).then((result: MLKitRecognizeTextResult) => {
271-
const messages: Array<MLKitSmartReplyConversationMessage> = [];
272-
result.blocks.forEach(block => messages.push({
271+
const conversation: Array<MLKitSmartReplyConversationMessage> = [];
272+
let personId = 0;
273+
274+
// just faking a conversation based on the text blocks we got from the image :)
275+
result.blocks.forEach(block => conversation.push({
273276
text: block.text,
274-
userId: "abc",
275-
localUser: false,
276-
timestamp: new Date().getTime()
277+
userId: "person" + (++personId % 2 === 0 ? 1 : 2),
278+
localUser: (personId % 2 === 0),
279+
timestamp: new Date().getTime() - 500000 + (personId * 5000)
277280
}));
281+
282+
console.log(JSON.stringify(conversation));
283+
278284
firebase.mlkit.smartreply.suggestReplies({
279-
messages
285+
conversation
280286
}).then((result: Array<string>) => {
287+
console.log("result1: " + JSON.stringify(result));
281288
alert({
282289
title: `Suggestions`,
283290
message: JSON.stringify(result),
284291
okButtonText: "OK"
285292
});
286-
}).catch(errorMessage => console.log("ML Kit error: " + errorMessage));
293+
}).catch(errorMessage => {
294+
console.log("ML Kit error: " + errorMessage);
295+
alert({
296+
title: `Error getting suggestions`,
297+
message: errorMessage,
298+
okButtonText: "Pity.."
299+
});
300+
});
287301
}).catch(errorMessage => console.log("ML Kit error: " + errorMessage));
288302
}
289303

0 commit comments

Comments
 (0)