Add vidai.sh launcher script for Linux development

- Create executable launcher script for non-PyInstaller builds
- Automatically detects and uses appropriate virtual environments
- Launches backend, web interface, and workers with correct CUDA/ROCm environments
- Reads configuration to determine backend selection
- Provides process management and cleanup on exit
parent 92ab2baa
#!/bin/bash
# Video AI Launcher Script (Linux)
# 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/>.
# Launcher script for Video AI Analysis Tool
# Manages subprocess launching with appropriate virtual environments
# Detect Python command
if command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
else
PYTHON_CMD="python"
fi
# Function to get config value
get_config() {
local key=$1
local default=$2
$PYTHON_CMD -c "
import sys
sys.path.insert(0, '.')
try:
from vidai.config import get_config
print(get_config('$key', '$default'))
except:
print('$default')
" 2>/dev/null
}
# Read configuration
ANALYSIS_BACKEND=$(get_config 'analysis_backend' 'cuda')
TRAINING_BACKEND=$(get_config 'training_backend' 'cuda')
WEB_HOST=$(get_config 'web_host' '0.0.0.0')
WEB_PORT=$(get_config 'web_port' '5000')
echo "Video AI Analysis Tool Launcher"
echo "================================"
echo "Analysis Backend: $ANALYSIS_BACKEND"
echo "Training Backend: $TRAINING_BACKEND"
echo "Web Interface: http://$WEB_HOST:$WEB_PORT"
echo ""
# Function to launch process in specific venv
launch_in_venv() {
local venv_path=$1
local process_name=$2
local command=$3
if [ -d "$venv_path" ]; then
echo "Starting $process_name in $venv_path..."
(
source "$venv_path/bin/activate"
$command &
echo "$process_name started (PID: $!)"
) &
eval "${process_name}_PID=\$!"
else
echo "Warning: Virtual environment $venv_path not found for $process_name"
echo "Starting $process_name without virtual environment..."
(
$command &
echo "$process_name started (PID: $!)"
) &
eval "${process_name}_PID=\$!"
fi
}
# Create result directory
mkdir -p /tmp/vidai_results
# Launch backend (common for all)
launch_in_venv "venv-cuda" "backend" "$PYTHON_CMD vidai/backend.py"
# Wait a moment for backend to start
sleep 2
# Launch analysis worker
ANALYSIS_VENV="venv-$ANALYSIS_BACKEND"
launch_in_venv "$ANALYSIS_VENV" "analysis_worker" "$PYTHON_CMD -c \"from vidai.worker_analysis import worker_process; worker_process('$ANALYSIS_BACKEND')\""
# Launch training worker
TRAINING_VENV="venv-$TRAINING_BACKEND"
launch_in_venv "$TRAINING_VENV" "training_worker" "$PYTHON_CMD -c \"from vidai.worker_training import worker_process; worker_process('$TRAINING_BACKEND')\""
# Wait a moment for workers to start
sleep 2
# Launch web interface (common for all)
launch_in_venv "venv-cuda" "web_interface" "$PYTHON_CMD vidai/web.py"
echo ""
echo "All processes started!"
echo "Web interface available at http://$WEB_HOST:$WEB_PORT"
echo ""
echo "Process PIDs:"
echo " Backend: $backend_PID"
echo " Analysis Worker: $analysis_worker_PID"
echo " Training Worker: $training_worker_PID"
echo " Web Interface: $web_interface_PID"
echo ""
echo "Press Ctrl+C to stop all processes"
# Function to cleanup processes
cleanup() {
echo ""
echo "Stopping all processes..."
kill $web_interface_PID $training_worker_PID $analysis_worker_PID $backend_PID 2>/dev/null
wait $web_interface_PID $training_worker_PID $analysis_worker_PID $backend_PID 2>/dev/null
echo "All processes stopped."
exit 0
}
# Set trap for cleanup
trap cleanup INT TERM
# Wait for processes
wait $backend_PID $analysis_worker_PID $training_worker_PID $web_interface_PID
\ No newline at end of file
......@@ -382,26 +382,51 @@ def set_db_mysql_config(host: str, port: int, user: str, password: str, database
# Network settings
def get_web_host() -> str:
"""Get web interface host."""
return get_config('web_host', '0.0.0.0')
def set_web_host(host: str) -> None:
"""Set web interface host."""
set_config('web_host', host)
def get_web_port() -> int:
"""Get web interface port."""
return int(get_config('web_port', '5000'))
def set_web_port(port: int) -> None:
"""Set web interface port."""
set_config('web_port', str(port))
def get_backend_host() -> str:
"""Get backend host."""
return get_config('backend_host', 'localhost')
def set_backend_host(host: str) -> None:
"""Set backend host."""
set_config('backend_host', host)
def get_backend_web_port() -> int:
"""Get backend web communication port."""
return int(get_config('backend_web_port', '5001'))
def set_backend_web_port(port: int) -> None:
"""Set backend web communication port."""
set_config('backend_web_port', str(port))
def get_backend_worker_port() -> int:
"""Get backend worker communication port."""
return int(get_config('backend_worker_port', '5002'))
def set_backend_worker_port(port: int) -> None:
"""Set backend worker communication port."""
set_config('backend_worker_port', str(port))
\ No newline at end of file
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