-
Notifications
You must be signed in to change notification settings - Fork 3
/
renderer.js
51 lines (45 loc) · 1.65 KB
/
renderer.js
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
document.getElementById('model').addEventListener('change', (event) => {
const selectedModel = event.target.value;
document.querySelectorAll('.model-params').forEach((elem) => {
elem.style.display = 'none';
});
if (selectedModel === 'random_forest') {
document.getElementById('random_forest_params').style.display = 'block';
} else if (selectedModel === 'adaboost') {
document.getElementById('adaboost_params').style.display = 'block';
}
});
document.getElementById('ml-form').addEventListener('submit', (event) => {
event.preventDefault();
const file = document.getElementById('file-input').files[0];
const model = document.getElementById('model').value;
const maxDepth = document.getElementById('max_depth').value;
const nEstimators = document.getElementById('n_estimators').value;
const formData = new FormData();
formData.append('file', file);
formData.append('model', model);
if (maxDepth) {
formData.append('max_depth', maxDepth);
}
if (nEstimators) {
formData.append('n_estimators', nEstimators);
}
fetch('http://localhost:5000/upload', {
method: 'POST',
body: formData,
})
.then((response) => response.json())
.then((data) => {
const { exec } = require('child_process');
const fs = require('fs');
const ejs = require('ejs');
ejs.renderFile('index.ejs', { results: data }, {}, (err, str) => {
if (err) {
console.error(err);
return;
}
fs.writeFileSync('index.html', str);
exec('npx electron .');
});
});
});