gliner-node-wrapper
Version:
Node.js wrapper around Python-based GlinER NER library
43 lines (38 loc) • 1.21 kB
JavaScript
const { execSync } = require('child_process');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function isInstalled(pkg) {
try {
execSync(`python3 -m pip show ${pkg}`, { stdio: 'ignore' });
return true;
} catch {
return false;
}
}
function uninstallPackages() {
try {
console.log('Uninstalling Python dependencies...');
execSync('python3 -m pip uninstall -y gliner torch transformers', { stdio: 'inherit' });
console.log('Python dependencies removed.');
} catch (err) {
console.error('Failed to uninstall Python dependencies:', err.message);
}
}
const installedPkgs = ['gliner', 'torch', 'transformers'].filter(isInstalled);
if (installedPkgs.length === 0) {
console.log('No related Python packages are currently installed.');
rl.close();
} else {
console.log(`The following Python packages will be uninstalled: ${installedPkgs.join(', ')}`);
rl.question('Are you sure you want to remove them? (y/N): ', (answer) => {
if (answer.trim().toLowerCase() === 'y') {
uninstallPackages();
} else {
console.log('Uninstall canceled.');
}
rl.close();
});
}