-
Notifications
You must be signed in to change notification settings - Fork 0
/
DALLEJS_Node.js
34 lines (27 loc) · 911 Bytes
/
DALLEJS_Node.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
const { exec } = require('child_process');
const maxApi = require('max-api');
const pythonVersion = '/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10'; // Replace with the specific Python version you want to use
const pythonScript = 'script.py';
var inputString = 'winged horse';
maxApi.addHandler('text_input', (text) => {
inputString = text;
});
function runPythonWithArg() {
exec(`${pythonVersion} ${pythonScript} "${inputString}"`, (error, stdout, stderr) => {
if (error) {
maxApi.outlet(`Error: ${error.message}`);
return;
}
if (stderr) {
maxApi.outlet(`Error: ${stderr}`);
return;
}
maxApi.outlet(`Python script output:\n${stdout}`);
//maxApi.outlet(`${inoutString}`);
//maxApi.outlet(`done`);
});
}
// Add a message handler to listen for the 'start' message from Max
maxApi.addHandler('start', () => {
runPythonWithArg();
});