import { spawn } from 'child_process'; export function runPythonScript(scriptPath, args = []) { return new Promise((resolve, reject) => { const pythonProcess = spawn('python', [scriptPath, ...args]); let stdout = ''; let stderr = ''; pythonProcess.stdout.on('data', (data) => { stdout += data.toString(); }); pythonProcess.stderr.on('data', (data) => { stderr += data.toString(); }); pythonProcess.on('close', (code) => { if (code === 0) { resolve(stdout); } else { reject(new Error(`Python script exited with code ${code}: ${stderr}`)); } }); }); }