Add Windows batch file support for cross-platform compatibility

- Create build.bat, start.bat, setup.bat, and clean.bat equivalents
- Update compatibility module with Windows-specific functions
- Add platform detection and script execution utilities
- Update README with Windows-specific instructions
- Ensure full Windows compatibility without requiring bash
parent 4b590a0b
...@@ -32,6 +32,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -32,6 +32,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Mixed Local/Remote Processing**: Seamless combination of local and remote workers - **Mixed Local/Remote Processing**: Seamless combination of local and remote workers
- **Comprehensive Documentation**: README, architecture guide, API documentation, and changelog - **Comprehensive Documentation**: README, architecture guide, API documentation, and changelog
- **GPLv3 Licensing**: Full license compliance with copyright notices on all source files - **GPLv3 Licensing**: Full license compliance with copyright notices on all source files
- **Cross-Platform Support**: Full compatibility with both Linux and Windows platforms
- **Platform-Specific Optimizations**: Unix sockets on Linux, TCP sockets on Windows
- **Universal Build Scripts**: Cross-platform build, setup, and startup scripts
- **Path Abstraction**: Automatic handling of platform-specific path conventions
- **Process Management**: Platform-aware process spawning and management
### Changed ### Changed
- Refactored monolithic Flask app into distributed multi-process architecture - Refactored monolithic Flask app into distributed multi-process architecture
......
...@@ -17,8 +17,19 @@ A comprehensive multi-process web-based tool for analyzing images and videos usi ...@@ -17,8 +17,19 @@ A comprehensive multi-process web-based tool for analyzing images and videos usi
- **Configuration Management**: SQLite database for persistent settings and system prompts - **Configuration Management**: SQLite database for persistent settings and system prompts
- **Self-Contained**: No external dependencies beyond Python and system libraries - **Self-Contained**: No external dependencies beyond Python and system libraries
## Platform Support
This application is designed to work on both **Linux** and **Windows**:
- **Linux**: Full support with Unix sockets for optimal performance
- **Windows**: Full support with TCP sockets (Unix sockets not available)
- **Cross-platform**: All scripts and tools work on both platforms
- **Path handling**: Automatic path normalization for each platform
- **Process management**: Platform-specific process spawning and management
## Quick Start ## Quick Start
### Linux/macOS
1. **Setup Environment**: 1. **Setup Environment**:
```bash ```bash
./setup.sh cuda # or ./setup.sh rocm ./setup.sh cuda # or ./setup.sh rocm
...@@ -29,6 +40,17 @@ A comprehensive multi-process web-based tool for analyzing images and videos usi ...@@ -29,6 +40,17 @@ A comprehensive multi-process web-based tool for analyzing images and videos usi
./start.sh cuda # or ./start.sh rocm ./start.sh cuda # or ./start.sh rocm
``` ```
### Windows
1. **Setup Environment**:
```batch
setup.bat cuda
```
2. **Start Application**:
```batch
start.bat cuda
```
3. **Access Web Interface**: 3. **Access Web Interface**:
- Open http://localhost:5000 - Open http://localhost:5000
- Login with admin/admin (change password after first login) - Login with admin/admin (change password after first login)
......
@echo off
REM Video AI Build Script (Windows)
REM Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me>
REM
REM This program is free software: you can redistribute it and/or modify
REM it under the terms of the GNU General Public License as published by
REM the Free Software Foundation, either version 3 of the License, or
REM (at your option) any later version.
REM
REM This program is distributed in the hope that it will be useful,
REM but WITHOUT ANY WARRANTY; without even the implied warranty of
REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
REM GNU General Public License for more details.
REM
REM You should have received a copy of the GNU General Public License
REM along with this program. If not, see <https://www.gnu.org/licenses/>.
REM Cross-platform build script for Video AI Analysis Tool
REM Creates self-contained executables for each component using PyInstaller
if "%1"=="" (
set TARGET=cuda
) else (
set TARGET=%1
)
echo Building Video AI Analysis Tool for %TARGET% on Windows...
REM Check if pyinstaller is installed
pyinstaller --version >nul 2>&1
if errorlevel 1 (
echo PyInstaller not found. Installing...
pip install pyinstaller
)
REM Build backend
echo Building backend...
pyinstaller --onedir --name vidai-backend --hidden-import torch --hidden-import transformers vidai/backend.py
REM Build web interface
echo Building web interface...
pyinstaller --onedir --name vidai-web --add-data "templates;templates" --add-data "static;static" --hidden-import flask vidai/web.py
REM Build analysis worker
echo Building analysis worker...
pyinstaller --onedir --name vidai-analysis-%TARGET% --hidden-import torch --hidden-import transformers --hidden-import cv2 vidai/worker_analysis.py
REM Build training worker
echo Building training worker...
pyinstaller --onedir --name vidai-training-%TARGET% --hidden-import torch --hidden-import transformers vidai/worker_training.py
echo Build complete for %TARGET%!
echo Executables created in dist/:
echo - vidai-backend
echo - vidai-web
echo - vidai-analysis-%TARGET%
echo - vidai-training-%TARGET%
\ No newline at end of file
#!/bin/bash #!/bin/bash
# Video AI Build Script (Cross-platform)
# Video AI Build Script
# Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me> # Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
...@@ -16,12 +15,19 @@ ...@@ -16,12 +15,19 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Build script for Video AI Analysis Tool # Cross-platform build script for Video AI Analysis Tool
# Creates self-contained executables for each component using PyInstaller # Creates self-contained executables for each component using PyInstaller
# Detect platform
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
IS_WINDOWS=1
else
IS_WINDOWS=0
fi
TARGET=${1:-cuda} # Default to cuda TARGET=${1:-cuda} # Default to cuda
echo "Building Video AI Analysis Tool for $TARGET..." echo "Building Video AI Analysis Tool for $TARGET on $(uname -s)..."
# Check if pyinstaller is installed # Check if pyinstaller is installed
if ! command -v pyinstaller &> /dev/null; then if ! command -v pyinstaller &> /dev/null; then
...@@ -29,23 +35,40 @@ if ! command -v pyinstaller &> /dev/null; then ...@@ -29,23 +35,40 @@ if ! command -v pyinstaller &> /dev/null; then
pip install pyinstaller pip install pyinstaller
fi fi
# Platform-specific settings
if [ $IS_WINDOWS -eq 1 ]; then
PYINSTALLER_ARGS="--onedir" # Use --onedir on Windows for better compatibility
else
PYINSTALLER_ARGS="--onefile"
fi
# Build backend # Build backend
pyinstaller --onefile \ pyinstaller $PYINSTALLER_ARGS \
--name vidai-backend \ --name vidai-backend \
--hidden-import torch \ --hidden-import torch \
--hidden-import transformers \ --hidden-import transformers \
vidai/backend.py vidai/backend.py
# Build web interface # Build web interface
pyinstaller --onefile \ if [ $IS_WINDOWS -eq 1 ]; then
--name vidai-web \ # On Windows, handle template and static data differently
--add-data "templates:templates" \ pyinstaller $PYINSTALLER_ARGS \
--add-data "static:static" \ --name vidai-web \
--hidden-import flask \ --add-data "templates;templates" \
vidai/web.py --add-data "static;static" \
--hidden-import flask \
vidai/web.py
else
pyinstaller $PYINSTALLER_ARGS \
--name vidai-web \
--add-data "templates:templates" \
--add-data "static:static" \
--hidden-import flask \
vidai/web.py
fi
# Build analysis worker # Build analysis worker
pyinstaller --onefile \ pyinstaller $PYINSTALLER_ARGS \
--name vidai-analysis-$TARGET \ --name vidai-analysis-$TARGET \
--hidden-import torch \ --hidden-import torch \
--hidden-import transformers \ --hidden-import transformers \
...@@ -53,7 +76,7 @@ pyinstaller --onefile \ ...@@ -53,7 +76,7 @@ pyinstaller --onefile \
vidai/worker_analysis.py vidai/worker_analysis.py
# Build training worker # Build training worker
pyinstaller --onefile \ pyinstaller $PYINSTALLER_ARGS \
--name vidai-training-$TARGET \ --name vidai-training-$TARGET \
--hidden-import torch \ --hidden-import torch \
--hidden-import transformers \ --hidden-import transformers \
......
@echo off
REM Video AI Clean Script (Windows)
REM Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me>
REM
REM This program is free software: you can redistribute it and/or modify
REM it under the terms of the GNU General Public License as published by
REM the Free Software Foundation, either version 3 of the License, or
REM (at your option) any later version.
REM
REM This program is distributed in the hope that it will be useful,
REM but WITHOUT ANY WARRANTY; without even the implied warranty of
REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
REM GNU General Public License for more details.
REM
REM You should have received a copy of the GNU General Public License
REM along with this program. If not, see <https://www.gnu.org/licenses/>.
REM Cross-platform clean script for Video AI Analysis Tool
REM Removes PyInstaller build artifacts
echo Cleaning build artifacts on Windows...
REM Remove PyInstaller directories
if exist "dist" (
rmdir /s /q dist
echo Removed dist/ directory
)
if exist "build" (
rmdir /s /q build
echo Removed build/ directory
)
REM Remove .spec file
if exist "vidai.spec" (
del vidai.spec
echo Removed vidai.spec
)
REM Remove virtual environments
for %%v in (venv venv-cpu venv-cuda venv-rocm) do (
if exist "%%v" (
rmdir /s /q %%v
echo Removed %%v/ directory
)
)
REM Remove __pycache__ directories
for /d /r . %%d in (__pycache__) do (
if exist "%%d" (
rmdir /s /q "%%d"
)
)
echo Removed __pycache__ directories
REM Remove result files
if exist "%TEMP%\vidai_results" (
rmdir /s /q "%TEMP%\vidai_results"
echo Removed result files
)
echo Clean complete!
\ No newline at end of file
#!/bin/bash #!/bin/bash
# Video AI Clean Script (Cross-platform)
# Video AI Clean Script
# Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me> # Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
...@@ -16,38 +15,68 @@ ...@@ -16,38 +15,68 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Clean script for Video AI Analysis Tool # Cross-platform clean script for Video AI Analysis Tool
# Removes PyInstaller build artifacts # Removes PyInstaller build artifacts
echo "Cleaning build artifacts..." # Detect platform
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
IS_WINDOWS=1
RM_CMD="rmdir /s /q"
FIND_CMD="dir /s /b"
else
IS_WINDOWS=0
RM_CMD="rm -rf"
FIND_CMD="find . -type d -name"
fi
echo "Cleaning build artifacts on $(uname -s)..."
# Remove PyInstaller directories # Remove PyInstaller directories
if [ -d "dist" ]; then if [ -d "dist" ]; then
rm -rf dist $RM_CMD dist
echo "Removed dist/ directory" echo "Removed dist/ directory"
fi fi
if [ -d "build" ]; then if [ -d "build" ]; then
rm -rf build $RM_CMD build
echo "Removed build/ directory" echo "Removed build/ directory"
fi fi
# Remove .spec file # Remove .spec file
if [ -f "vidai.spec" ]; then if [ -f "vidai.spec" ]; then
rm vidai.spec rm vidai.spec 2>/dev/null || del vidai.spec 2>/dev/null || true
echo "Removed vidai.spec" echo "Removed vidai.spec"
fi fi
# Remove virtual environments # Remove virtual environments
for venv in venv venv-cpu venv-cuda venv-rocm; do for venv in venv venv-cpu venv-cuda venv-rocm; do
if [ -d "$venv" ]; then if [ -d "$venv" ]; then
rm -rf "$venv" $RM_CMD "$venv"
echo "Removed $venv/ directory" echo "Removed $venv/ directory"
fi fi
done done
# Remove __pycache__ directories # Remove __pycache__ directories
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true if [ $IS_WINDOWS -eq 1 ]; then
# On Windows
for /d /r . %d in (__pycache__) do @if exist "%d" rmdir /s /q "%d" 2>nul
else
# On Unix-like systems
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
fi
echo "Removed __pycache__ directories" echo "Removed __pycache__ directories"
# Remove result files
if [ $IS_WINDOWS -eq 1 ]; then
if [ -d "%TEMP%/vidai_results" ]; then
$RM_CMD "%TEMP%/vidai_results"
echo "Removed result files"
fi
else
if [ -d "/tmp/vidai_results" ]; then
$RM_CMD /tmp/vidai_results
echo "Removed result files"
fi
fi
echo "Clean complete!" echo "Clean complete!"
\ No newline at end of file
@echo off
REM Video AI Setup Script (Windows)
REM Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me>
REM
REM This program is free software: you can redistribute it and/or modify
REM it under the terms of the GNU General Public License as published by
REM the Free Software Foundation, either version 3 of the License, or
REM (at your option) any later version.
REM
REM This program is distributed in the hope that it will be useful,
REM but WITHOUT ANY WARRANTY; without even the implied warranty of
REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
REM GNU General Public License for more details.
REM
REM You should have received a copy of the GNU General Public License
REM along with this program. If not, see <https://www.gnu.org/licenses/>.
REM Cross-platform setup script for Video AI Analysis Tool
REM Creates a virtual environment and installs dependencies
REM Parse arguments
if "%1"=="cuda" (
set TARGET=cuda
) else if "%1"=="rocm" (
set TARGET=rocm
) else (
set TARGET=cpu
)
echo Setting up Video AI Analysis Tool for %TARGET% on Windows...
REM Create virtual environment
if not exist "venv-%TARGET%" (
python -m venv venv-%TARGET%
echo Created virtual environment in venv-%TARGET/
) else (
echo Virtual environment venv-%TARGET% already exists
)
REM Activate virtual environment
call venv-%TARGET%\Scripts\activate.bat
REM Upgrade pip
python -m pip install --upgrade pip
REM Install requirements based on target
if "%TARGET%"=="cuda" (
if exist "requirements-cuda.txt" (
pip install -r requirements-cuda.txt
echo Installed dependencies from requirements-cuda.txt
) else (
echo requirements-cuda.txt not found
exit /b 1
)
) else if "%TARGET%"=="rocm" (
if exist "requirements-rocm.txt" (
pip install -r requirements-rocm.txt
echo Installed dependencies from requirements-rocm.txt
) else (
echo requirements-rocm.txt not found
exit /b 1
)
) else (
if exist "requirements.txt" (
pip install -r requirements.txt
echo Installed dependencies from requirements.txt
) else (
echo requirements.txt not found
exit /b 1
)
)
echo Setup complete for %TARGET%!
echo To activate the environment: venv-%TARGET%\Scripts\activate.bat
echo To run the application: python vidai.py --help
\ No newline at end of file
#!/bin/bash #!/bin/bash
# Video AI Setup Script (Cross-platform)
# Video AI Setup Script
# Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me> # Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
...@@ -16,9 +15,22 @@ ...@@ -16,9 +15,22 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Setup script for Video AI Analysis Tool # Cross-platform setup script for Video AI Analysis Tool
# Creates a virtual environment and installs dependencies # Creates a virtual environment and installs dependencies
# Detect platform
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
IS_WINDOWS=1
PYTHON_CMD="python"
ACTIVATE_CMD="venv-$TARGET/Scripts/activate"
PIP_CMD="pip"
else
IS_WINDOWS=0
PYTHON_CMD="python3"
ACTIVATE_CMD="venv-$TARGET/bin/activate"
PIP_CMD="pip3"
fi
# Parse arguments # Parse arguments
TARGET="cpu" TARGET="cpu"
if [ "$1" = "cuda" ]; then if [ "$1" = "cuda" ]; then
...@@ -27,21 +39,27 @@ elif [ "$1" = "rocm" ]; then ...@@ -27,21 +39,27 @@ elif [ "$1" = "rocm" ]; then
TARGET="rocm" TARGET="rocm"
fi fi
echo "Setting up Video AI Analysis Tool for $TARGET..." echo "Setting up Video AI Analysis Tool for $TARGET on $(uname -s)..."
# Create virtual environment # Create virtual environment
if [ ! -d "venv-$TARGET" ]; then if [ ! -d "venv-$TARGET" ]; then
python3 -m venv venv-$TARGET $PYTHON_CMD -m venv venv-$TARGET
echo "Created virtual environment in venv-$TARGET/" echo "Created virtual environment in venv-$TARGET/"
else else
echo "Virtual environment venv-$TARGET already exists" echo "Virtual environment venv-$TARGET already exists"
fi fi
# Activate virtual environment # Activate virtual environment
source venv-$TARGET/bin/activate if [ $IS_WINDOWS -eq 1 ]; then
# On Windows, we need to use call for batch files
echo "To activate on Windows: venv-$TARGET\\Scripts\\activate.bat"
source $ACTIVATE_CMD 2>/dev/null || call $ACTIVATE_CMD 2>/dev/null || true
else
source $ACTIVATE_CMD
fi
# Upgrade pip # Upgrade pip
pip install --upgrade pip $PIP_CMD install --upgrade pip
# Install requirements based on target # Install requirements based on target
REQ_FILE="requirements.txt" REQ_FILE="requirements.txt"
...@@ -52,7 +70,7 @@ elif [ "$TARGET" = "rocm" ] && [ -f "requirements-rocm.txt" ]; then ...@@ -52,7 +70,7 @@ elif [ "$TARGET" = "rocm" ] && [ -f "requirements-rocm.txt" ]; then
fi fi
if [ -f "$REQ_FILE" ]; then if [ -f "$REQ_FILE" ]; then
pip install -r $REQ_FILE $PIP_CMD install -r $REQ_FILE
echo "Installed dependencies from $REQ_FILE" echo "Installed dependencies from $REQ_FILE"
else else
echo "$REQ_FILE not found" echo "$REQ_FILE not found"
...@@ -60,5 +78,10 @@ else ...@@ -60,5 +78,10 @@ else
fi fi
echo "Setup complete for $TARGET!" echo "Setup complete for $TARGET!"
echo "To activate the environment: source venv-$TARGET/bin/activate" if [ $IS_WINDOWS -eq 1 ]; then
echo "To run the application: python vidai.py --help" echo "To activate the environment: venv-$TARGET\\Scripts\\activate.bat"
\ No newline at end of file echo "To run the application: python vidai.py --help"
else
echo "To activate the environment: source venv-$TARGET/bin/activate"
echo "To run the application: python3 vidai.py --help"
fi
\ No newline at end of file
@echo off
REM Video AI Startup Script (Windows)
REM Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me>
REM
REM This program is free software: you can redistribute it and/or modify
REM it under the terms of the GNU General Public License as published by
REM the Free Software Foundation, either version 3 of the License, or
REM (at your option) any later version.
REM
REM This program is distributed in the hope that it will be useful,
REM but WITHOUT ANY WARRANTY; without even the implied warranty of
REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
REM GNU General Public License for more details.
REM
REM You should have received a copy of the GNU General Public License
REM along with this program. If not, see <https://www.gnu.org/licenses/>.
REM Cross-platform startup script for Video AI Analysis Tool
REM Launches all processes in the correct order
if "%1"=="" (
set TARGET=cuda
) else (
set TARGET=%1
)
echo Starting Video AI Analysis Tool for %TARGET% on Windows...
REM Create result directory
if not exist "%TEMP%\vidai_results" mkdir "%TEMP%\vidai_results"
REM Start backend
echo Starting backend...
start "VideoAI Backend" python -m vidai.backend
timeout /t 2 /nobreak >nul
REM Start workers
echo Starting analysis worker...
start "VideoAI Analysis Worker" python -m vidai.worker_analysis %TARGET%
echo Starting training worker...
start "VideoAI Training Worker" python -m vidai.worker_training %TARGET%
timeout /t 2 /nobreak >nul
REM Start web interface
echo Starting web interface...
start "VideoAI Web Interface" python -m vidai.web
echo All processes started!
echo Web interface available at http://localhost:5000
echo Press any key to stop all processes...
pause >nul
echo Stopping processes...
REM Note: On Windows, background processes need to be manually closed
REM or use Task Manager to end python.exe processes
\ No newline at end of file
#!/bin/bash #!/bin/bash
# Video AI Startup Script (Cross-platform)
# Video AI Startup Script
# Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me> # Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
...@@ -16,43 +15,76 @@ ...@@ -16,43 +15,76 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Startup script for Video AI Analysis Tool # Cross-platform startup script for Video AI Analysis Tool
# Launches all processes in the correct order # Launches all processes in the correct order
# Detect platform
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
IS_WINDOWS=1
PYTHON_CMD="python"
SLEEP_CMD="timeout"
else
IS_WINDOWS=0
PYTHON_CMD="python3"
SLEEP_CMD="sleep"
fi
TARGET=${1:-cuda} # Default to cuda TARGET=${1:-cuda} # Default to cuda
echo "Starting Video AI Analysis Tool for $TARGET..." echo "Starting Video AI Analysis Tool for $TARGET on $(uname -s)..."
# Create result directory # Create result directory (cross-platform)
mkdir -p /tmp/vidai_results if [ $IS_WINDOWS -eq 1 ]; then
mkdir -p "%TEMP%/vidai_results" 2>/dev/null || true
else
mkdir -p /tmp/vidai_results
fi
# Function to start process and store PID
start_process() {
local name=$1
local cmd=$2
echo "Starting $name..."
if [ $IS_WINDOWS -eq 1 ]; then
# On Windows, use start command to run in background
start "$name" $cmd
# Note: Windows doesn't give us easy access to PIDs from batch files
echo "Started $name in background"
else
# On Unix-like systems
$cmd &
local pid=$!
eval "${name}_PID=$pid"
echo "Started $name (PID: $pid)"
fi
}
# Start backend # Start backend
echo "Starting backend..." start_process "backend" "$PYTHON_CMD -m vidai.backend"
python vidai/backend.py &
BACKEND_PID=$!
sleep 2 $SLEEP_CMD 2
# Start workers # Start workers
echo "Starting analysis worker..." start_process "analysis_worker" "$PYTHON_CMD -m vidai.worker_analysis $TARGET"
python vidai/worker_analysis.py $TARGET & start_process "training_worker" "$PYTHON_CMD -m vidai.worker_training $TARGET"
ANALYSIS_PID=$!
echo "Starting training worker..."
python vidai/worker_training.py $TARGET &
TRAINING_PID=$!
sleep 2 $SLEEP_CMD 2
# Start web interface # Start web interface
echo "Starting web interface..." start_process "web_interface" "$PYTHON_CMD -m vidai.web"
python vidai/web.py &
WEB_PID=$!
echo "All processes started!" echo "All processes started!"
echo "Web interface available at http://localhost:5000" echo "Web interface available at http://localhost:5000"
echo "Press Ctrl+C to stop all processes" echo "Press Ctrl+C to stop all processes"
# Wait for interrupt # Wait for interrupt
trap "echo 'Stopping all processes...'; kill $WEB_PID $TRAINING_PID $ANALYSIS_PID $BACKEND_PID; exit" INT if [ $IS_WINDOWS -eq 1 ]; then
wait echo "Press any key to stop..."
\ No newline at end of file read -n 1
echo "Stopping processes..."
# On Windows, we can't easily kill background processes from batch
# User will need to manually close windows or use Task Manager
else
trap "echo 'Stopping all processes...'; kill \$WEB_PID \$TRAINING_PID \$ANALYSIS_PID \$BACKEND_PID 2>/dev/null; exit" INT
wait
fi
\ No newline at end of file
...@@ -26,6 +26,7 @@ import argparse ...@@ -26,6 +26,7 @@ import argparse
import sys import sys
import os import os
import subprocess import subprocess
from vidai.compat import run_command, get_python_command
# Add current directory to path for vidai module # Add current directory to path for vidai module
sys.path.insert(0, os.path.dirname(__file__)) sys.path.insert(0, os.path.dirname(__file__))
...@@ -202,13 +203,13 @@ Examples: ...@@ -202,13 +203,13 @@ Examples:
print("Press Ctrl+C to stop") print("Press Ctrl+C to stop")
# Start backend process # Start backend process
backend_cmd = [sys.executable, '-m', 'vidai.backend'] backend_cmd = get_python_command(module='vidai.backend')
backend_proc = subprocess.Popen(backend_cmd) backend_proc = subprocess.Popen(backend_cmd)
# Start web process # Start web process
web_cmd = [sys.executable, '-m', 'vidai.web'] web_cmd = get_python_command(module='vidai.web')
web_proc = subprocess.Popen(web_cmd) web_proc = subprocess.Popen(web_cmd)
try: try:
# Wait for processes # Wait for processes
backend_proc.wait() backend_proc.wait()
......
...@@ -23,6 +23,7 @@ import time ...@@ -23,6 +23,7 @@ import time
import threading import threading
from .comm import SocketServer, Message from .comm import SocketServer, Message
from .config import get_analysis_backend, get_training_backend, set_analysis_backend, set_training_backend, get_comm_type from .config import get_analysis_backend, get_training_backend, set_analysis_backend, set_training_backend, get_comm_type
from .compat import get_socket_path, get_default_comm_type
from .queue import queue_manager from .queue import queue_manager
...@@ -74,8 +75,14 @@ def backend_process() -> None: ...@@ -74,8 +75,14 @@ def backend_process() -> None:
if comm_type == 'unix': if comm_type == 'unix':
# Start web server on Unix socket # Start web server on Unix socket
web_server = SocketServer(socket_path='/tmp/vidai_web.sock', comm_type='unix') socket_path = get_socket_path('web')
web_server.start(handle_web_message) if socket_path:
web_server = SocketServer(socket_path=socket_path, comm_type='unix')
web_server.start(handle_web_message)
else:
# Fall back to TCP on Windows
web_server = SocketServer(host='localhost', port=5001, comm_type='tcp')
web_server.start(handle_web_message)
else: else:
# Start web server on TCP # Start web server on TCP
web_server = SocketServer(host='localhost', port=5001, comm_type='tcp') web_server = SocketServer(host='localhost', port=5001, comm_type='tcp')
......
...@@ -23,8 +23,10 @@ import socket ...@@ -23,8 +23,10 @@ import socket
import json import json
import threading import threading
import time import time
import os
from typing import Dict, Any, Optional from typing import Dict, Any, Optional
from dataclasses import dataclass from dataclasses import dataclass
from .compat import get_socket_path, is_unix_sockets_supported
@dataclass @dataclass
......
# Video AI Cross-Platform Compatibility Module
# Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
Cross-platform compatibility utilities for Video AI.
Handles differences between Linux and Windows platforms.
"""
import os
import sys
import platform
import subprocess
import tempfile
from pathlib import Path
# Platform detection
IS_WINDOWS = platform.system() == 'Windows'
IS_LINUX = platform.system() == 'Linux'
IS_MACOS = platform.system() == 'Darwin'
# Python executable
PYTHON_EXECUTABLE = sys.executable
# Path separators
PATH_SEP = os.sep
PATH_LIST_SEP = os.pathsep
def get_user_config_dir() -> str:
"""Get user-specific configuration directory (cross-platform)."""
if IS_WINDOWS:
# Windows: %APPDATA%\vidai
appdata = os.environ.get('APPDATA', '')
if appdata:
return os.path.join(appdata, 'vidai')
else:
# Fallback to user home
return os.path.join(os.path.expanduser('~'), 'AppData', 'Roaming', 'vidai')
else:
# Linux/macOS: ~/.config/vidai
return os.path.join(os.path.expanduser('~'), '.config', 'vidai')
def get_temp_dir() -> str:
"""Get system temporary directory (cross-platform)."""
return tempfile.gettempdir()
def get_user_cache_dir() -> str:
"""Get user cache directory (cross-platform)."""
if IS_WINDOWS:
# Windows: %LOCALAPPDATA%\vidai\cache
local_appdata = os.environ.get('LOCALAPPDATA', '')
if local_appdata:
return os.path.join(local_appdata, 'vidai', 'cache')
else:
return os.path.join(get_user_config_dir(), 'cache')
else:
# Linux/macOS: ~/.cache/vidai
return os.path.join(os.path.expanduser('~'), '.cache', 'vidai')
def ensure_dir(path: str) -> None:
"""Ensure directory exists (cross-platform)."""
Path(path).mkdir(parents=True, exist_ok=True)
def get_socket_path(name: str) -> str:
"""Get socket path - returns None on Windows (use TCP instead)."""
if IS_WINDOWS:
return None # Windows doesn't support Unix sockets
else:
temp_dir = get_temp_dir()
return os.path.join(temp_dir, f'vidai_{name}.sock')
def is_unix_sockets_supported() -> bool:
"""Check if Unix sockets are supported on this platform."""
return not IS_WINDOWS
def get_default_comm_type() -> str:
"""Get default communication type for this platform."""
return 'unix' if is_unix_sockets_supported() else 'tcp'
def normalize_path(path: str) -> str:
"""Normalize path for current platform."""
return os.path.normpath(path)
def join_path(*parts) -> str:
"""Join path components (cross-platform)."""
return os.path.join(*parts)
def splitext(path: str) -> tuple:
"""Split extension from path (cross-platform)."""
return os.path.splitext(path)
def get_executable_name(name: str) -> str:
"""Get executable name with proper extension for platform."""
if IS_WINDOWS:
return f'{name}.exe'
else:
return name
def run_command(cmd: list, **kwargs) -> subprocess.CompletedProcess:
"""Run command with proper handling for platform."""
# On Windows, we might need to handle shell=True for some commands
if IS_WINDOWS and isinstance(cmd, str):
kwargs.setdefault('shell', True)
return subprocess.run(cmd, **kwargs)
def get_python_command(module: str = None, script: str = None) -> list:
"""Get Python command for running modules or scripts."""
cmd = [PYTHON_EXECUTABLE]
if module:
cmd.extend(['-m', module])
elif script:
cmd.append(script)
return cmd
def get_shell_script_extension() -> str:
"""Get shell script extension for platform."""
return '.bat' if IS_WINDOWS else '.sh'
def create_shell_script(name: str, content: str) -> str:
"""Create a shell script with proper content for platform."""
if IS_WINDOWS:
# Create .bat file
script_content = f'@echo off\r\n{content}'
else:
# Create .sh file
script_content = f'#!/bin/bash\n{content}'
script_path = f'{name}{get_shell_script_extension()}'
with open(script_path, 'w', newline='' if IS_WINDOWS else None) as f:
f.write(script_content)
# Make executable on Unix-like systems
if not IS_WINDOWS:
os.chmod(script_path, 0o755)
return script_path
def get_script_runner() -> str:
"""Get the appropriate script runner for the platform."""
if IS_WINDOWS:
return 'call' # Use 'call' for batch files
else:
return 'bash' # Use 'bash' for shell scripts
def run_script(script_path: str, args: list = None) -> int:
"""Run a script with platform-specific handling."""
if args is None:
args = []
if IS_WINDOWS:
# Run batch file
cmd = ['cmd', '/c', script_path] + args
else:
# Run shell script
cmd = ['bash', script_path] + args
result = run_command(cmd)
return result.returncode
def get_ffmpeg_command() -> str:
"""Get ffmpeg executable name for platform."""
return 'ffmpeg.exe' if IS_WINDOWS else 'ffmpeg'
def get_ffprobe_command() -> str:
"""Get ffprobe executable name for platform."""
return 'ffprobe.exe' if IS_WINDOWS else 'ffprobe'
def get_environment_variable(name: str, default: str = '') -> str:
"""Get environment variable (cross-platform)."""
return os.environ.get(name, default)
def set_environment_variable(name: str, value: str) -> None:
"""Set environment variable (cross-platform)."""
os.environ[name] = value
def get_pid() -> int:
"""Get current process ID."""
return os.getpid()
def kill_process(pid: int) -> None:
"""Kill process by PID (cross-platform)."""
if IS_WINDOWS:
subprocess.run(['taskkill', '/PID', str(pid), '/F'], capture_output=True)
else:
os.kill(pid, 9) # SIGKILL
def is_process_running(pid: int) -> bool:
"""Check if process is running (cross-platform)."""
try:
os.kill(pid, 0) # Signal 0 doesn't kill, just checks
return True
except OSError:
return False
def get_platform_info() -> dict:
"""Get platform information."""
return {
'system': platform.system(),
'release': platform.release(),
'version': platform.version(),
'machine': platform.machine(),
'processor': platform.processor(),
'python_version': sys.version,
'is_windows': IS_WINDOWS,
'is_linux': IS_LINUX,
'is_macos': IS_MACOS,
'supports_unix_sockets': is_unix_sockets_supported()
}
# Initialize directories
ensure_dir(get_user_config_dir())
ensure_dir(get_user_cache_dir())
\ No newline at end of file
...@@ -23,14 +23,15 @@ import sqlite3 ...@@ -23,14 +23,15 @@ import sqlite3
import os import os
import json import json
from typing import Dict, Any, Optional, List from typing import Dict, Any, Optional, List
from .compat import get_user_config_dir, ensure_dir
DB_PATH = os.path.expanduser("~/.config/vidai/vidai.db") DB_PATH = os.path.join(get_user_config_dir(), 'vidai.db')
def get_db_connection() -> sqlite3.Connection: def get_db_connection() -> sqlite3.Connection:
"""Get database connection, creating database if it doesn't exist.""" """Get database connection, creating database if it doesn't exist."""
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True) ensure_dir(os.path.dirname(DB_PATH))
conn = sqlite3.connect(DB_PATH) conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row conn.row_factory = sqlite3.Row
init_db(conn) init_db(conn)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment