Skip to content

Commit 6b69cce

Browse files
authored
Merge pull request #4 from pivanov/master
[patch] - issue #3
2 parents a7ba30a + 7f53b10 commit 6b69cce

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ const retryOperation = (operation, delay, times) => new Promise((resolve, reject
3030
});
3131
});
3232

33+
const getHTMLCanvasElement = (imageUrl) => {
34+
return new Promise((resolve, reject) => {
35+
const image = new canvas.Image();
36+
image.onload = () => resolve(image);
37+
image.onerror = (e) => reject(e);
38+
image.src = imageUrl;
39+
});
40+
}
41+
3342
const byProbabilty = (predictionA, predictionB) => {
3443
if (predictionA.probability > predictionB.probability) return -1;
3544
if (predictionA.probability < predictionB.probability) return 1;
@@ -83,9 +92,7 @@ class SashiDoTeachableMachine {
8392

8493
async inference({ imageUrl }) {
8594
try {
86-
const image = new canvas.Image();
87-
image.src = imageUrl;
88-
95+
const image = await getHTMLCanvasElement(imageUrl);
8996
const predictions = await this.model.predict(image);
9097
return predictions.sort(byProbabilty);
9198
} catch (error) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sashido/teachablemachine-node",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Simplifies integration with Teachable Machine models from Google",
55
"author": {
66
"name": "Team SashiDo",

0 commit comments

Comments
 (0)