-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy-model.js
More file actions
74 lines (62 loc) · 2.1 KB
/
copy-model.js
File metadata and controls
74 lines (62 loc) · 2.1 KB
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
// This script copies the ONNX model files to various locations
// to ensure they can be found by the application
// Run this with Node.js: node copy-model.js
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Get the directory name (equivalent to __dirname in CommonJS)
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Source ONNX models
const modelFiles = [
{
source: path.join(__dirname, 'src', 'hooks', 'engagement_multitask_v4.onnx'),
filename: 'engagement_multitask_v4.onnx'
},
{
source: path.join(__dirname, 'public', 'models', 'engagement_multitask_v4_v2.onnx'),
filename: 'engagement_multitask_v4_v2.onnx'
},
{
source: path.join(__dirname, 'public', 'models', 'v1.onnx'),
filename: 'v1.onnx'
}
];
// Target directories
const targetDirs = [
path.join(__dirname, 'public', 'models'),
path.join(__dirname, 'dist', 'models'),
path.join(__dirname, 'models'),
path.join(__dirname, 'src', 'hooks')
];
// Ensure each target directory exists
targetDirs.forEach(dir => {
if (!fs.existsSync(dir)) {
console.log(`Creating directory: ${dir}`);
fs.mkdirSync(dir, { recursive: true });
}
});
// Copy each model file to each target directory
modelFiles.forEach(model => {
if (!fs.existsSync(model.source)) {
console.warn(`Source model not found: ${model.source}`);
return;
}
console.log(`\nProcessing model: ${model.filename}`);
targetDirs.forEach(dir => {
const targetFile = path.join(dir, model.filename);
// Skip copying to the same location
if (path.resolve(model.source) === path.resolve(targetFile)) {
console.log(`Skipping self-copy: ${targetFile}`);
return;
}
try {
fs.copyFileSync(model.source, targetFile);
console.log(`Copied ${model.filename} to: ${targetFile}`);
} catch (error) {
console.error(`Failed to copy ${model.filename} to ${targetFile}:`, error.message);
}
});
});
console.log('\nONNX models copy completed');
console.log('Available models should now be accessible from all required locations.');