diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8ae88f3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,52 @@ +# Stage 1: Build Frontend (SvelteKit) +FROM node:20-slim AS frontend-builder +WORKDIR /app +COPY package.json package-lock.json ./ +# Install dependencies +RUN npm ci +# Copy source +COPY . . +# Build static files (outputs to build/) +RUN npm run build + +# Stage 2: Backend (Python Flask + GPU Support) +# Use official PyTorch image with CUDA 12.1 support +FROM pytorch/pytorch:2.2.0-cuda12.1-cudnn8-runtime + +# Install system dependencies for audio (libsndfile) and ffmpeg +# reliable ffmpeg install on debian-based images +RUN apt-get update && apt-get install -y \ + libsndfile1 \ + ffmpeg \ + git \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Copy python requirements +# We remove torch/torchaudio from requirements briefly during install to avoid re-installing CPU versions +# or we trust pip to see the installed version satisfies it. +COPY server/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy backend code +COPY server/ . + +# Copy built frontend from Stage 1 into the expected relative path +# app.py expects '../build', so we copy to /build and structure appropriately +# However, simpler is to copy build/ to /app/build and adjust app.py or folder structure. +# Let's mirror the structure: /app/server (WORKDIR) and /app/build +COPY --from=frontend-builder /app/build /app/build + +# Set working directory to server where app.py resides +WORKDIR /app/server + +# Environment variables +ENV PYTHONUNBUFFERED=1 +ENV PORT=5000 + +# Expose port +EXPOSE ${PORT} + +# Run the application +CMD ["python", "app.py"] diff --git a/README.md b/README.md index 5e33186..a7cbb0b 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,18 @@ AudioImage is a powerful web-based tool for Audio Spectrogram Art and Digital St ## Installation +### Method 1: Docker (Recommended for GPU) +The easiest way to run AudioImage with full GPU acceleration is using Docker. + +1. **Prerequisites**: Docker Desktop + NVIDIA Container Toolkit (for GPU). +2. **Run**: + ```bash + docker compose up --build + ``` +3. Open `http://localhost:5000`. + +### Method 2: Manual Setup + 1. **Backend Setup**: ```bash cd server @@ -29,12 +41,6 @@ AudioImage is a powerful web-based tool for Audio Spectrogram Art and Digital St pip install -r requirements.txt ``` - *Optional for GPU support:* - ```bash - pip install torch torchaudio --index-url https://download.pytorch.org/whl/cu118 - ``` - *(Adjust CUDA version as needed)* - 2. **Frontend Setup**: ```bash # Root directory @@ -42,15 +48,11 @@ AudioImage is a powerful web-based tool for Audio Spectrogram Art and Digital St npm run build ``` -## Running the Application - -1. Start the Flask server (which serves the frontend): +3. **Run**: ```bash cd server - source venv/bin/activate python app.py ``` -2. Open your browser to `http://127.0.0.1:5000`. ## Architecture diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2d4ceed --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +services: + audio-image: + build: . + container_name: audio-image + ports: + - "${PORT:-5000}:5000" + volumes: + - ./server/uploads:/app/server/uploads + environment: + - FLASK_APP=app.py + - FLASK_DEBUG=${FLASK_DEBUG:-false} + restart: unless-stopped + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [ gpu ] diff --git a/example.env b/example.env new file mode 100644 index 0000000..8a37733 --- /dev/null +++ b/example.env @@ -0,0 +1,12 @@ +# Server Configuration +PORT=5000 +FLASK_DEBUG=false +FLASK_ENV=production + +# Application Settings +# Max upload size in MB (default 40 in code) +MAX_UPLOAD_MB=40 + +# Optional: UID/GID for permission handling in Docker volume mapping +# PUID=1000 +# PGID=1000 diff --git a/server/app.py b/server/app.py index aecc89d..a1b5207 100644 --- a/server/app.py +++ b/server/app.py @@ -234,4 +234,4 @@ def get_result(result_id): return jsonify({"error": "Result not found"}), 404 if __name__ == '__main__': - app.run(debug=True, port=5000, threaded=True) + app.run(host='0.0.0.0', debug=True, port=5000, threaded=True) diff --git a/server/requirements.txt b/server/requirements.txt index b1f439f..f8656e3 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -1,3 +1,4 @@ +--extra-index-url https://download.pytorch.org/whl/cu121 Flask Flask-Cors numpy