-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_part.js
41 lines (33 loc) · 1.15 KB
/
python_part.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
const spawner = require('child_process').spawn;
const data_to_pass_in = [19,1,26,2,89,1,1];
const python_process = spawner('python',['model.py',JSON.stringify(data_to_pass_in)])
python_process.stdout.on('data',(data)=>{
// places=(data.toString().split('\r\n'))
// console.log(places)
console.log(typeof(JSON.parse(data)))
});
// const { PythonShell } = require('python-shell');
// const modelPath = 'C:/Users/DELL/Desktop/Indian Railways/model.pkl';
// // Define the input data
// const inputData = [19, 1, 26, 2, 89, 1, 1];
// // Configure the PythonShell options
// const options = {
// mode: 'text',
// pythonPath: 'python',
// pythonOptions: ['-u'], // Unbuffered output
// scriptPath: '',
// args: [JSON.stringify(inputData)]
// };
// // Create a new PythonShell instance
// const pyShell = new PythonShell('model.py', options);
// // Run the Python script and handle the output
// pyShell.on('message', (message) => {
// // Parse the result as a JSON string
// const result = JSON.parse(message);
// // Log the result
// console.log(result);
// });
// // Handle errors
// pyShell.on('error', (err) => {
// console.error(err);
// });