diff --git a/README.md b/README.md index 6c057cc..faaf3d0 100644 --- a/README.md +++ b/README.md @@ -55,28 +55,63 @@ https://github.com/user-attachments/assets/6b8c08a8-c84f-4fc3-83ad-5703f474fc1b ## Requirements +### Windows - **Python 3.11+** - **CUDA-compatible GPU** (4GB+ VRAM for lite mode, 12GB+ for full mode) - **CUDA 12.6** (recommended) - **Node.js 18+** (for frontend) -> 💡 FFmpeg and Redis are automatically installed by the installer. +### macOS +- **Python 3.11+** +- **Apple Silicon (M1/M2/M3/M4)** or Intel Mac +- **Node.js 18+** (for frontend) +- **Homebrew** (for Redis installation) + +> 💡 **Note for Mac users**: The application uses CPU processing to avoid MPS (Metal Performance Shaders) compatibility issues. This is slower but more stable. + +### Linux +- **Python 3.11+** +- **CUDA-compatible GPU** (4GB+ VRAM for lite mode, 12GB+ for full mode) or CPU +- **CUDA 12.6** (recommended for GPU) +- **Node.js 18+** (for frontend) + +> 💡 FFmpeg and Redis are automatically installed by the installer on all platforms. ## 🚀 One-Click Installation (Recommended) -### First Time Setup +### Windows + +**First Time Setup:** ```bash # Run installer (creates Conda env, downloads Redis, installs all dependencies) -install.bat +windows\install.bat +``` + +**Daily Usage:** +```bash +# Start all services with one click +windows\start.bat + +# Stop all services +windows\stop.bat +``` + +### macOS / Linux + +**First Time Setup:** +```bash +# Run installer (creates Conda env, installs Redis, installs all dependencies) +chmod +x unix/*.sh +./unix/install.sh ``` -### Daily Usage +**Daily Usage:** ```bash # Start all services with one click -start.bat +./unix/start.sh # Stop all services -stop.bat +./unix/stop.sh ``` --- @@ -233,12 +268,20 @@ audioghost-ai/ │ │ └── separate.py # Separation endpoints │ └── workers/ │ ├── celery_app.py # Celery config -│ └── tasks.py # SAM Audio Lite worker +│ └── tasks.py # SAM Audio Lite worker (with Mac CPU fix) ├── frontend/ │ ├── src/ │ │ ├── app/ # Next.js app │ │ └── components/ # React components │ └── package.json +├── windows/ # Windows-specific scripts +│ ├── install.bat # One-click installer for Windows +│ ├── start.bat # Start all services (Windows) +│ └── stop.bat # Stop all services (Windows) +├── unix/ # macOS/Linux scripts +│ ├── install.sh # One-click installer for Unix +│ ├── start.sh # Start all services (Unix) +│ └── stop.sh # Stop all services (Unix) ├── sam_audio_lite.py # Standalone lite version ├── QUICKSTART.md # Quick setup guide └── README.md diff --git a/backend/workers/tasks.py b/backend/workers/tasks.py index 7b11b4e..265a8f4 100644 --- a/backend/workers/tasks.py +++ b/backend/workers/tasks.py @@ -194,7 +194,17 @@ def separate_audio_task( from huggingface_hub import login task_id = self.request.id - device = "cuda" if torch.cuda.is_available() else "cpu" + + # Force CPU on Mac to avoid MPS memory issues + # MPS (Metal Performance Shaders) can cause SIGABRT crashes with large models + # Windows/Linux: Use CUDA if available, otherwise CPU + if sys.platform == "darwin": # macOS + device = "cpu" + print(f"[DEBUG] Detected macOS - forcing CPU to avoid MPS issues") + else: + device = "cuda" if torch.cuda.is_available() else "cpu" + print(f"[DEBUG] Using device: {device}") + video_path = None # Will be set if input is video # Debug: Show received parameter diff --git a/unix/install.sh b/unix/install.sh new file mode 100755 index 0000000..6fcade7 --- /dev/null +++ b/unix/install.sh @@ -0,0 +1,112 @@ +#!/bin/bash +set -e + +echo "" +echo "╔══════════════════════════════════════════════════════════════╗" +echo "║ AudioGhost AI - One-Click Installer ║" +echo "║ v1.0 MVP ║" +echo "╚══════════════════════════════════════════════════════════════╝" +echo "" + +# Get the project root directory (parent of the script directory) +PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" +cd "$PROJECT_ROOT" + +# Check if Conda is installed +if ! command -v conda &> /dev/null; then + echo "[ERROR] Conda not found. Please install Anaconda or Miniconda first." + echo "Download from: https://www.anaconda.com/download" + exit 1 +fi + +# Detect OS and install Redis if needed +echo "[1/8] Checking Redis..." +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS - use Homebrew + if ! command -v redis-server &> /dev/null; then + echo "Installing Redis via Homebrew..." + if ! command -v brew &> /dev/null; then + echo "[ERROR] Homebrew not found. Install from: https://brew.sh" + exit 1 + fi + brew install redis + else + echo "Redis already installed, skipping..." + fi +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Linux - use package manager + if ! command -v redis-server &> /dev/null; then + echo "Installing Redis..." + if command -v apt-get &> /dev/null; then + sudo apt-get update && sudo apt-get install -y redis-server + elif command -v yum &> /dev/null; then + sudo yum install -y redis + else + echo "[WARN] Could not install Redis automatically. Please install manually." + fi + else + echo "Redis already installed, skipping..." + fi +fi + +echo "" +echo "[2/8] Creating Conda environment 'audioghost' (Python 3.11)..." +conda create -n audioghost python=3.11 -y || echo "[WARN] Environment may already exist, continuing..." + +echo "" +echo "[3/8] Activating environment..." +eval "$(conda shell.bash hook)" +conda activate audioghost + +echo "" +echo "[4/8] Installing PyTorch..." +echo "This may take several minutes..." + +# Detect platform and install appropriate PyTorch +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS - use CPU/MPS build + echo "Detected macOS - installing PyTorch with MPS support..." + pip install torch torchvision torchaudio +else + # Linux - install CUDA build + echo "Detected Linux - installing PyTorch with CUDA 12.6..." + pip install torch==2.9.0+cu126 torchvision==0.24.0+cu126 torchaudio==2.9.0+cu126 \ + --index-url https://download.pytorch.org/whl/cu126 \ + --extra-index-url https://pypi.org/simple +fi + +echo "" +echo "[5/8] Installing FFmpeg..." +conda install -c conda-forge ffmpeg -y + +echo "" +echo "[6/8] Installing SAM Audio..." +pip install git+https://github.com/facebookresearch/sam-audio.git + +echo "" +echo "[7/8] Installing Backend dependencies..." +cd backend +pip install -r requirements.txt +cd .. + +echo "" +echo "[8/8] Installing Frontend dependencies..." +cd frontend +npm install +cd .. + +echo "" +echo "╔══════════════════════════════════════════════════════════════╗" +echo "║ Installation Complete! ✓ ║" +echo "╠══════════════════════════════════════════════════════════════╣" +echo "║ ║" +echo "║ To start AudioGhost, run: ./start.sh ║" +echo "║ ║" +if [[ "$OSTYPE" == "darwin"* ]]; then + echo "║ On macOS, Redis is managed by Homebrew. ║" +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + echo "║ On Linux, Redis is installed as a system service. ║" +fi +echo "║ ║" +echo "╚══════════════════════════════════════════════════════════════╝" +echo "" diff --git a/unix/start.sh b/unix/start.sh new file mode 100755 index 0000000..167c4a4 --- /dev/null +++ b/unix/start.sh @@ -0,0 +1,110 @@ +#!/bin/bash +set -e + +echo "" +echo "╔══════════════════════════════════════════════════════════════╗" +echo "║ AudioGhost AI - Launcher ║" +echo "║ v1.0 MVP ║" +echo "╚══════════════════════════════════════════════════════════════╝" +echo "" + +# Get the project root directory (parent of the script directory) +PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" +cd "$PROJECT_ROOT" + +# Function to wait for a service to be ready +wait_for_service() { + local port=$1 + local service_name=$2 + local max_attempts=30 + local attempt=0 + + echo " Waiting for $service_name to be ready..." + while ! nc -z localhost $port 2>/dev/null; do + attempt=$((attempt + 1)) + if [ $attempt -ge $max_attempts ]; then + echo " [WARN] $service_name didn't start in time, continuing anyway..." + return 1 + fi + sleep 1 + done + echo " $service_name is ready! ✓" +} + +# Check if Redis is running +echo "[1/4] Checking Redis..." +if nc -z localhost 6379 2>/dev/null; then + echo " Redis detected - using existing instance" +else + echo " Starting Redis..." + if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS - use Homebrew + brew services start redis 2>/dev/null || redis-server --daemonize yes + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Linux - try systemd or docker + if command -v systemctl &> /dev/null; then + sudo systemctl start redis-server 2>/dev/null || sudo systemctl start redis 2>/dev/null || docker-compose up -d + else + docker-compose up -d + fi + fi + sleep 2 +fi + +echo "[2/4] Starting Backend API..." +# Start backend in background with proper conda activation +(cd "$PROJECT_ROOT/backend" && eval "$(conda shell.bash hook)" && conda activate audioghost && uvicorn main:app --reload --port 8000 > /tmp/audioghost-backend.log 2>&1) & +BACKEND_PID=$! +echo " Backend starting (PID: $BACKEND_PID, logs: /tmp/audioghost-backend.log)" +wait_for_service 8000 "Backend API" + +echo "[3/4] Starting Celery Worker..." +# Start celery in background with proper conda activation +(cd "$PROJECT_ROOT/backend" && eval "$(conda shell.bash hook)" && conda activate audioghost && celery -A workers.celery_app worker --loglevel=info > /tmp/audioghost-celery.log 2>&1) & +CELERY_PID=$! +echo " Celery starting (PID: $CELERY_PID, logs: /tmp/audioghost-celery.log)" +sleep 3 # Give Celery time to connect to Redis + +echo "[4/4] Starting Frontend..." +# Start frontend in background +(cd "$PROJECT_ROOT/frontend" && npm run dev > /tmp/audioghost-frontend.log 2>&1) & +FRONTEND_PID=$! +echo " Frontend starting (PID: $FRONTEND_PID, logs: /tmp/audioghost-frontend.log)" +wait_for_service 3000 "Frontend" + +echo "" +echo "╔══════════════════════════════════════════════════════════════╗" +echo "║ All Services Started! ✓ ║" +echo "╠══════════════════════════════════════════════════════════════╣" +echo "║ ║" +echo "║ Frontend: http://localhost:3000 ║" +echo "║ Backend: http://localhost:8000 ║" +echo "║ API Docs: http://localhost:8000/docs ║" +echo "║ ║" +echo "║ Services running in background: ║" +echo "║ - Redis: PID $(lsof -ti :6379 2>/dev/null | head -1 || echo 'N/A') ║" +echo "║ - Backend: PID $BACKEND_PID ║" +echo "║ - Celery: PID $CELERY_PID ║" +echo "║ - Frontend: PID $FRONTEND_PID ║" +echo "║ ║" +echo "║ View logs: ║" +echo "║ - Backend: tail -f /tmp/audioghost-backend.log ║" +echo "║ - Celery: tail -f /tmp/audioghost-celery.log ║" +echo "║ - Frontend: tail -f /tmp/audioghost-frontend.log ║" +echo "║ ║" +echo "║ Run ./stop.sh to stop all services. ║" +echo "╚══════════════════════════════════════════════════════════════╝" +echo "" +echo "Opening browser in 3 seconds..." +sleep 3 + +# Open browser automatically +if [[ "$OSTYPE" == "darwin"* ]]; then + open http://localhost:3000 +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + xdg-open http://localhost:3000 2>/dev/null || echo "Please open http://localhost:3000 in your browser" +fi + +echo "" +echo "All services are running! Press Ctrl+C to return to shell." +echo "(Services will continue running in background)" diff --git a/unix/stop.sh b/unix/stop.sh new file mode 100755 index 0000000..c2585e0 --- /dev/null +++ b/unix/stop.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +echo "" +echo "╔══════════════════════════════════════════════════════════════╗" +echo "║ AudioGhost AI - Shutdown ║" +echo "╚══════════════════════════════════════════════════════════════╝" +echo "" + +echo "Stopping all AudioGhost services..." +echo "" + +# Kill Frontend (Node.js/npm) +echo "[1/4] Stopping Frontend..." +pkill -f "npm run dev" 2>/dev/null || true +pkill -f "next-router-worker" 2>/dev/null || true + +# Kill Celery Worker +echo "[2/4] Stopping Celery Worker..." +pkill -f "celery.*audioghost" 2>/dev/null || true + +# Kill Backend (Uvicorn) +echo "[3/4] Stopping Backend API..." +pkill -f "uvicorn main:app" 2>/dev/null || true + +# Stop Redis (Docker) +echo "[4/4] Stopping Redis..." +if command -v docker-compose &> /dev/null; then + docker-compose down 2>/dev/null || true +fi + +# Stop Redis (Homebrew on Mac) +if [[ "$OSTYPE" == "darwin"* ]]; then + brew services stop redis 2>/dev/null || true +fi + +echo "" +echo "╔══════════════════════════════════════════════════════════════╗" +echo "║ All Services Stopped! ✓ ║" +echo "╚══════════════════════════════════════════════════════════════╝" +echo "" + diff --git a/windows/install.bat b/windows/install.bat new file mode 100644 index 0000000..fb00959 --- /dev/null +++ b/windows/install.bat @@ -0,0 +1,84 @@ +@echo off +chcp 65001 >nul +title AudioGhost AI - One-Click Installer + +echo. +echo ╔══════════════════════════════════════════════════════════════╗ +echo ║ AudioGhost AI - One-Click Installer ║ +echo ║ v1.0 MVP ║ +echo ╚══════════════════════════════════════════════════════════════╝ +echo. + +:: Get the project root directory (parent of the script directory) +set "PROJECT_ROOT=%~dp0.." +cd /d "%PROJECT_ROOT%" + +:: Check if Conda is installed +where conda >nul 2>&1 +if %errorlevel% neq 0 ( + echo [ERROR] Conda not found. Please install Anaconda or Miniconda first. + echo Download from: https://www.anaconda.com/download + pause + exit /b 1 +) + +echo [1/8] Downloading Redis for Windows... +if not exist "redis\redis-server.exe" ( + echo Downloading from GitHub... + powershell -Command "Invoke-WebRequest -Uri 'https://github.com/tporadowski/redis/releases/download/v5.0.14.1/Redis-x64-5.0.14.1.zip' -OutFile 'redis.zip'" + echo Extracting... + powershell -Command "Expand-Archive -Path 'redis.zip' -DestinationPath 'redis' -Force" + del redis.zip + echo Redis installed to ./redis/ +) else ( + echo Redis already exists, skipping... +) + +echo. +echo [2/8] Creating Conda environment 'audioghost' (Python 3.11)... +call conda create -n audioghost python=3.11 -y +if %errorlevel% neq 0 ( + echo [WARN] Environment may already exist, continuing... +) + +echo. +echo [3/8] Activating environment... +call conda activate audioghost + +echo. +echo [4/8] Installing PyTorch (CUDA 12.6)... +echo This may take several minutes... +pip install torch==2.9.0+cu126 torchvision==0.24.0+cu126 torchaudio==2.9.0+cu126 --index-url https://download.pytorch.org/whl/cu126 --extra-index-url https://pypi.org/simple + +echo. +echo [5/8] Installing FFmpeg... +call conda install -c conda-forge ffmpeg -y + +echo. +echo [6/8] Installing SAM Audio... +pip install git+https://github.com/facebookresearch/sam-audio.git + +echo. +echo [7/8] Installing Backend dependencies... +cd backend +pip install -r requirements.txt +cd .. + +echo. +echo [8/8] Installing Frontend dependencies... +cd frontend +call npm install +cd .. + +echo. +echo ╔══════════════════════════════════════════════════════════════╗ +echo ║ Installation Complete! ✓ ║ +echo ╠══════════════════════════════════════════════════════════════╣ +echo ║ ║ +echo ║ To start AudioGhost, run: start.bat ║ +echo ║ ║ +echo ║ No Docker required! Redis is included. ║ +echo ║ ║ +echo ╚══════════════════════════════════════════════════════════════╝ +echo. +pause diff --git a/windows/start.bat b/windows/start.bat new file mode 100644 index 0000000..b52d57b --- /dev/null +++ b/windows/start.bat @@ -0,0 +1,74 @@ +@echo off +chcp 65001 >nul +title AudioGhost AI - Launcher + +echo. +echo ╔══════════════════════════════════════════════════════════════╗ +echo ║ AudioGhost AI - Launcher ║ +echo ║ v1.0 MVP ║ +echo ╚══════════════════════════════════════════════════════════════╝ +echo. + +:: Get the project root directory (parent of the script directory) +set "PROJECT_ROOT=%~dp0.." +cd /d "%PROJECT_ROOT%" + +:: Check if Docker Redis is already running on port 6379 +echo [1/4] Checking Redis... +netstat -an | findstr ":6379.*LISTENING" >nul 2>&1 +if %ERRORLEVEL%==0 ( + echo Docker Redis detected - using existing instance + goto :redis_ready +) + +:: Docker Redis not running, try offline Redis +if exist "redis\redis-server.exe" ( + echo Starting offline Redis... + start "AudioGhost Redis" /min cmd /c "cd /d %PROJECT_ROOT%\redis && redis-server.exe" + timeout /t 2 /nobreak >nul + goto :redis_ready +) + +:: Neither available +echo [ERROR] Redis not available. Either: +echo - Start Docker: docker-compose up -d +echo - Or run install.bat to download offline Redis +pause +exit /b 1 + +:redis_ready + +echo [2/4] Starting Backend API... +start "AudioGhost Backend" cmd /k "cd /d %PROJECT_ROOT% && conda activate audioghost && cd backend && uvicorn main:app --reload --port 8000" + +echo [3/4] Starting Celery Worker... +timeout /t 2 /nobreak >nul +start "AudioGhost Worker" cmd /k "cd /d %PROJECT_ROOT% && conda activate audioghost && cd backend && celery -A workers.celery_app worker --loglevel=info --pool=solo" + +echo [4/4] Starting Frontend... +timeout /t 2 /nobreak >nul +start "AudioGhost Frontend" cmd /k "cd /d %PROJECT_ROOT% && cd frontend && npm run dev" + +echo. +echo ╔══════════════════════════════════════════════════════════════╗ +echo ║ All Services Started! ✓ ║ +echo ╠══════════════════════════════════════════════════════════════╣ +echo ║ ║ +echo ║ Frontend: http://localhost:3000 ║ +echo ║ Backend: http://localhost:8000 ║ +echo ║ API Docs: http://localhost:8000/docs ║ +echo ║ ║ +echo ║ Four windows opened: ║ +echo ║ - AudioGhost Redis (minimized) ║ +echo ║ - AudioGhost Backend (FastAPI) ║ +echo ║ - AudioGhost Worker (Celery) ║ +echo ║ - AudioGhost Frontend (Next.js) ║ +echo ║ ║ +echo ║ Run stop.bat or close all windows to stop services. ║ +echo ╚══════════════════════════════════════════════════════════════╝ +echo. +echo Opening browser in 3 seconds... +timeout /t 3 /nobreak >nul + +:: Open browser automatically +start http://localhost:3000 diff --git a/windows/stop.bat b/windows/stop.bat new file mode 100644 index 0000000..bc96fd7 --- /dev/null +++ b/windows/stop.bat @@ -0,0 +1,36 @@ +@echo off +chcp 65001 >nul +title AudioGhost AI - Stop All Services + +echo. +echo ╔══════════════════════════════════════════════════════════════╗ +echo ║ AudioGhost AI - Shutdown ║ +echo ╚══════════════════════════════════════════════════════════════╝ +echo. + +echo Stopping all AudioGhost services... +echo. + +:: Kill Node.js (Frontend) +echo [1/4] Stopping Frontend... +taskkill /FI "WINDOWTITLE eq AudioGhost Frontend*" /F >nul 2>&1 +taskkill /IM "node.exe" /F >nul 2>&1 + +:: Kill Celery (Worker) +echo [2/4] Stopping Celery Worker... +taskkill /FI "WINDOWTITLE eq AudioGhost Worker*" /F >nul 2>&1 + +:: Kill Uvicorn (Backend) +echo [3/4] Stopping Backend API... +taskkill /FI "WINDOWTITLE eq AudioGhost Backend*" /F >nul 2>&1 + +:: Stop Redis +echo [4/4] Stopping Redis... +docker-compose down >nul 2>&1 + +echo. +echo ╔══════════════════════════════════════════════════════════════╗ +echo ║ All Services Stopped! ✓ ║ +echo ╚══════════════════════════════════════════════════════════════╝ +echo. +pause