Skip to content

Commit 58daaf6

Browse files
tried to fix bugs
1 parent 1d73e86 commit 58daaf6

4 files changed

Lines changed: 180 additions & 37 deletions

File tree

README.md

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,84 @@ VisionixAI is a computer vision platform for detecting presence in room zones an
1111
- `cli/` — Node.js CLI tool for interacting with the system
1212
- `ml-core/` — Python-based computer vision core
1313

14-
## Setup
1514

16-
### 1. Install CLI dependencies
15+
## Quick Start (Production Install)
16+
17+
### Prerequisites
18+
- Node.js (for CLI)
19+
- Python 3.7+ and pip (for ML core)
20+
21+
### Global Install (Recommended)
1722
```bash
18-
cd cli
19-
npm install
23+
npm install -g @visionix/cli
2024
```
25+
This will:
26+
- Install the CLI globally as `visionix`
27+
- Automatically install all required Python dependencies (OpenCV, MediaPipe, etc.)
28+
- Write detailed install logs to `~/visionix_postinstall.log`
2129

22-
### 2. (Optional) Link CLI globally
30+
> **Note:** Python dependency installation may take several minutes depending on your internet speed.
31+
32+
### Local Development/Testing
2333
```bash
24-
npm link
34+
cd cli
35+
npm install
36+
npm pack
37+
npm install -g ./visionix-cli-*.tgz
2538
```
2639

27-
### 3. Install Python dependencies
40+
### Manual Python Dependency Install (if needed)
41+
If the postinstall step fails, run:
2842
```bash
29-
cd ../ml-core
30-
pip install -r requirements.txt
43+
pip3 install -r cli/ml-core/requirements.txt
3144
```
3245

3346
## Usage
3447

35-
### Run the CLI (analyze a video file)
48+
49+
## Usage
50+
51+
### Analyze a video file
3652
```bash
3753
visionix analyze path/to/video.mp4
3854
```
55+
3956
Or, if not linked globally:
4057
```bash
41-
node bin/visionix.js analyze path/to/video.mp4
58+
node cli/bin/visionix.js analyze path/to/video.mp4
4259
```
4360

61+
### What to expect
62+
- The CLI will show a spinner/progress indicator while analyzing.
63+
- On success, you'll see a completion message.
64+
- On error, you'll get a clear message and troubleshooting hints.
65+
4466
### What happens?
4567
- The CLI calls the Python ML core, which processes the video, divides it into zones, and prints ON/OFF triggers for each zone based on presence.
4668

47-
## Requirements
48-
- Node.js (for CLI)
49-
- Python 3.7+ (for ML core)
50-
- OpenCV, MediaPipe (installed via requirements.txt)
69+
70+
## Troubleshooting
71+
72+
- **Install stuck or fails?**
73+
- Check `~/visionix_postinstall.log` for detailed logs.
74+
- Ensure Python 3 and pip are installed and available in your PATH.
75+
- Try installing Python dependencies manually (see above).
76+
- **Input video not found?**
77+
- Double-check the path you provide to `visionix analyze`.
78+
- **Permission errors?**
79+
- Try running the install with elevated permissions (e.g., `sudo`).
80+
- **Still stuck?**
81+
- Open an issue and attach your `visionix_postinstall.log`.
82+
5183

5284
## Development
5385
- Add new features to `ml-core/app.py` and expose them via the CLI.
5486
- See `ml-core/README.md` for ML core details.
87+
88+
---
89+
90+
**Logs:**
91+
- All install logs are written to `~/visionix_postinstall.log` for easy debugging.
92+
93+
**Testing Locally:**
94+
- Use `npm pack` and `npm install -g ./visionix-cli-*.tgz` to test the full install process as a user would experience it.

cli/bin/postinstall.js

Lines changed: 93 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,101 @@
1+
console.log("hi there")
2+
13

24
const { execSync } = require('child_process');
35
const path = require('path');
6+
const fs = require('fs');
7+
const logFile = path.resolve(process.env.HOME || process.env.USERPROFILE || __dirname, 'visionix_postinstall.log');
8+
9+
function logToFile(msg) {
10+
try {
11+
fs.appendFileSync(logFile, msg + '\n');
12+
} catch (e) {
13+
// ignore file write errors
14+
}
15+
}
16+
17+
function flushLog(msg) {
18+
process.stdout.write(msg + '\n');
19+
logToFile(msg);
20+
}
421

522
console.log('[VisionixAI] 🧠 Installing Python dependencies...');
623

7-
try {
8-
// Find the path to requirements.txt relative to this script
9-
const reqPath = path.resolve(__dirname, '../ml-core/requirements.txt');
10-
execSync(`pip install -r "${reqPath}"`, { stdio: 'inherit' });
11-
console.log('\n[VisionixAI] Python dependencies installed!');
12-
} catch (err) {
13-
console.error('\n[VisionixAI] Failed to install Python dependencies. Please ensure Python and pip are installed.');
24+
25+
function flushLog(msg) {
26+
process.stdout.write(msg + '\n');
27+
process.stdout.write('');
28+
}
29+
30+
function tryCommand(cmd, desc, timeoutMs = 60000) {
31+
flushLog(`[VisionixAI] [ENTER] tryCommand: ${desc || cmd}`);
32+
flushLog(`\n[VisionixAI] $ ${cmd}`);
33+
try {
34+
flushLog(`[VisionixAI] [RUNNING] ${cmd}`);
35+
const output = execSync(cmd, { stdio: 'inherit', timeout: timeoutMs });
36+
flushLog(`[VisionixAI] [SUCCESS] ${cmd}`);
37+
if (desc) flushLog(`[VisionixAI] ${desc} succeeded.`);
38+
flushLog(`[VisionixAI] [EXIT] tryCommand: ${desc || cmd}`);
39+
return true;
40+
} catch (err) {
41+
flushLog(`[VisionixAI] [ERROR] ${desc || cmd} failed.`);
42+
if (err.stdout) flushLog('[VisionixAI] [STDOUT] ' + err.stdout.toString());
43+
if (err.stderr) flushLog('[VisionixAI] [STDERR] ' + err.stderr.toString());
44+
flushLog(`[VisionixAI] [EXIT] tryCommand: ${desc || cmd}`);
45+
return false;
46+
}
47+
}
48+
49+
function printPythonPipInstructions() {
50+
flushLog(`[VisionixAI] [ENTER] printPythonPipInstructions`);
51+
flushLog(`\n[VisionixAI] ❌ Python and pip are required to install ML dependencies.\n`);
52+
flushLog(`[VisionixAI] Please install Python (https://www.python.org/downloads/) and ensure pip is available in your PATH.\n`);
53+
flushLog(`[VisionixAI] After installing, run the following command to finish setup:`);
54+
flushLog(` pip install -r <path-to-requirements.txt>\n`);
55+
flushLog(`[VisionixAI] [EXIT] printPythonPipInstructions`);
56+
}
57+
58+
59+
flushLog('[VisionixAI] [ENTER] postinstall main');
60+
flushLog(`[VisionixAI] CWD: ${process.cwd()}`);
61+
flushLog(`[VisionixAI] Log file: ${logFile}`);
62+
flushLog('[VisionixAI] NOTE: Installing Python dependencies (like opencv-python, mediapipe) can take several minutes depending on your internet speed. Please be patient.');
63+
flushLog('[VisionixAI] Checking for Python and pip...');
64+
const hasPython = tryCommand('python --version', 'Python version') || tryCommand('python3 --version', 'Python3 version');
65+
flushLog(`[VisionixAI] hasPython: ${hasPython}`);
66+
const hasPip = tryCommand('pip --version', 'pip version') || tryCommand('pip3 --version', 'pip3 version');
67+
flushLog(`[VisionixAI] hasPip: ${hasPip}`);
68+
69+
if (!hasPython || !hasPip) {
70+
flushLog('[VisionixAI] Python or pip not found. Exiting.');
71+
printPythonPipInstructions();
72+
flushLog('[VisionixAI] [EXIT] postinstall main');
73+
process.exit(1);
74+
}
75+
76+
flushLog('[VisionixAI] Python and pip found. Installing ML dependencies...');
77+
const reqPath = path.resolve(__dirname, '../ml-core/requirements.txt');
78+
let installed = false;
79+
flushLog(`[VisionixAI] Installing requirements from: ${reqPath}`);
80+
if (!installed) {
81+
flushLog('[VisionixAI] [BEFORE] pip install');
82+
installed = tryCommand(`pip install -r "${reqPath}"`, 'pip install', 120000);
83+
flushLog('[VisionixAI] [AFTER] pip install');
84+
}
85+
if (!installed) {
86+
flushLog('[VisionixAI] [BEFORE] pip3 install');
87+
installed = tryCommand(`pip3 install -r "${reqPath}"`, 'pip3 install', 120000);
88+
flushLog('[VisionixAI] [AFTER] pip3 install');
89+
}
90+
91+
if (installed) {
92+
flushLog('\n[VisionixAI] ✅ Python dependencies installed!');
93+
} else {
94+
flushLog('\n[VisionixAI] ❌ Failed to install Python dependencies. Please ensure Python and pip are installed and available in your PATH.');
95+
printPythonPipInstructions();
1496
}
1597

16-
console.log(`\n[VisionixAI] Installation complete!\n`);
98+
flushLog(`[VisionixAI] [EXIT] postinstall main`);
99+
flushLog(`\n[VisionixAI] Installation complete!\n`);
100+
flushLog(`[VisionixAI] CWD: ${process.cwd()}`);
101+
flushLog(`[VisionixAI] Log file: ${logFile}`);

cli/bin/visionix.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,66 @@ const fs = require('fs');
77
const args = process.argv.slice(2);
88

99
if (args.length < 1 || args.includes('--help')) {
10-
console.log(`
11-
VisionixAI CLI
12-
13-
Usage:
14-
visionix analyze <video-path>
15-
16-
Description:
17-
Streams video, detects presence in zones, triggers responses.
18-
`);
10+
console.log(`\nVisionixAI CLI\n\nUsage:\n visionix analyze <video-path>\n\nDescription:\n Streams video, detects presence in zones, triggers responses.\n\nOptions:\n --help Show this help message\n`);
1911
process.exit(0);
2012
}
2113

2214
const command = args[0];
2315
const input = args[1];
2416

2517
if (command === 'analyze') {
26-
// Always resolve relative to this script, not cwd
2718
const scriptPath = path.resolve(__dirname, '..', 'ml-core', 'start.py');
2819

2920
if (!fs.existsSync(scriptPath)) {
3021
console.error(`❌ start.py not found at: ${scriptPath}`);
22+
console.error('➡️ Please reinstall the CLI or contact support.');
3123
process.exit(1);
3224
}
3325

34-
if (!input || !fs.existsSync(input)) {
26+
if (!input) {
27+
console.error('❌ No input video path provided.');
28+
console.error('➡️ Usage: visionix analyze <video-path>');
29+
process.exit(1);
30+
}
31+
if (!fs.existsSync(input)) {
3532
console.error(`❌ Input video not found: ${input}`);
33+
console.error('➡️ Please provide a valid path to a video file.');
3634
process.exit(1);
3735
}
3836

3937
console.log('📦 Launching Python:', scriptPath);
38+
let spinnerInterval;
39+
let spinnerFrames = ['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏'];
40+
let spinnerIndex = 0;
41+
function startSpinner() {
42+
process.stdout.write('⏳ Processing... ');
43+
spinnerInterval = setInterval(() => {
44+
process.stdout.write(`\r${spinnerFrames[spinnerIndex++ % spinnerFrames.length]} Processing... `);
45+
}, 120);
46+
}
47+
function stopSpinner() {
48+
if (spinnerInterval) clearInterval(spinnerInterval);
49+
process.stdout.write('\r');
50+
}
4051

52+
startSpinner();
4153
const subprocess = spawn('python3', ['-u', scriptPath, input], {
4254
stdio: 'inherit'
4355
});
4456

4557
subprocess.on('exit', (code) => {
46-
console.log(`\n✅ Process exited with code ${code}`);
58+
stopSpinner();
59+
if (code === 0) {
60+
console.log(`\n✅ Analysis complete! Process exited with code ${code}`);
61+
} else {
62+
console.error(`\n❌ Analysis failed. Process exited with code ${code}`);
63+
console.error('➡️ Please check your Python environment and logs for details.');
64+
}
4765
process.exit(code);
4866
});
4967
} else if (command === 'setup-ml') {
5068
require('./scripts/setup-ml'); // install venv, pip install, etc.
51-
}
52-
else {
69+
} else {
5370
console.log(`❌ Unknown command: ${command}`);
71+
console.log('➡️ Use --help to see available commands.');
5472
}

cli/visionix-cli-1.0.6.tgz

3.77 KB
Binary file not shown.

0 commit comments

Comments
 (0)