-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy-mediapipe-assets.mjs
74 lines (69 loc) · 2.2 KB
/
copy-mediapipe-assets.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import axios from "axios";
import fs from "fs";
import colors from "@colors/colors";
import isCi from "is-ci";
const FILES_TO_COPY = [
"drawing_utils/drawing_utils.js",
"pose/pose.js",
"pose/pose_landmark_full.tflite",
"pose/pose_landmark_heavy.tflite",
"pose/pose_landmark_lite.tflite",
"pose/pose_solution_packed_assets.data",
"pose/pose_solution_packed_assets_loader.js",
"pose/pose_solution_simd_wasm_bin.data",
"pose/pose_solution_simd_wasm_bin.js",
"pose/pose_solution_simd_wasm_bin.wasm",
"pose/pose_solution_wasm_bin.js",
"pose/pose_solution_wasm_bin.wasm",
"pose/pose_web.binarypb",
];
console.log(
colors.blue(`Copying AI asset files to public/scripts
View the following issue to know why this is a relevant step:
https://github.com/google/mediapipe/issues/1812`)
);
if (!fs.existsSync("public/scripts")) {
fs.mkdirSync("public/scripts");
}
if (isCi) {
async function fetchFiles() {
await Promise.all(
FILES_TO_COPY.map(async (file) => {
const target = `public/scripts/${file.split("/").at(-1)}`;
try {
console.log(colors.yellow(`Fetching: ${file}...`));
const url = `https://cdn.jsdelivr.net/npm/@mediapipe/${file}`
const response = (
await axios.get(url, {
responseType: "arraybuffer",
headers: {
"Content-Type": "application/gzip",
},
})
).data;
await fs.promises.writeFile(target, Buffer.from(response));
console.log(colors.green(`Fetched to: ${url} !\n`));
} catch (error) {
console.error(
colors.red(
`Error fetching file to: ${target}!\n${error?.message ?? ""}`
)
);
console.error(error.response);
}
})
);
}
fetchFiles();
} else {
FILES_TO_COPY.forEach((file) => {
const src = `node_modules/@mediapipe/${file}`;
const target = `public/scripts/${file.split("/").at(-1)}`;
console.log(colors.yellow(`Copying: ${src}...`));
fs.promises.copyFile(src, target);
console.log(colors.green(`Copied to: ${target} !\n`));
});
console.log(
colors.green(colors.bold("Copied all assets into public/scripts!"))
);
}