File size: 2,138 Bytes
c253ab5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# MusePlayer Backend Dockerfile
# Optimized for Hugging Face Spaces with GPU support
# -----------------------------------------------

FROM nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu22.04

WORKDIR /app

# Prevent interactive prompts and ensure consistent Python behavior
ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    HF_HOME=/tmp/huggingface_cache \
    TRANSFORMERS_CACHE=/tmp/huggingface_cache \
    PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True \
    GRADIO_ANALYTICS_ENABLED=0

# Install system dependencies
# ffmpeg + libsndfile1 are required for audio processing
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3.10 \
    python3-pip \
    python3-dev \
    ffmpeg \
    libsndfile1 \
    libsndfile1-dev \
    git \
    wget \
    curl \
    build-essential \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/* \
    && ln -sf /usr/bin/python3.10 /usr/bin/python \
    && ln -sf /usr/bin/python3.10 /usr/bin/python3

# Upgrade pip and install build tools
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel

# Install PyTorch with CUDA 12.1 support explicitly
# We pin this before requirements.txt to avoid CPU-only torch installation
RUN python -m pip install --no-cache-dir \
    torch==2.5.1 \
    torchvision==0.20.1 \
    torchaudio==2.5.1 \
    --index-url https://download.pytorch.org/whl/cu121

# Copy and install Python dependencies
# Note: torch is excluded from requirements.txt since it's pre-installed above
COPY requirements.txt .
RUN python -m pip install --no-cache-dir -r requirements.txt

# Create directories for model cache and generated outputs
# Hugging Face Spaces allows ephemeral disk; /tmp is safe and fast
RUN mkdir -p /tmp/huggingface_cache /tmp/museplayer_outputs && \
    chmod -R 777 /tmp/huggingface_cache /tmp/museplayer_outputs

# Copy the backend application
COPY app.py .

# Hugging Face Spaces exposes this port by default
EXPOSE 7860

# Preload the ACE-Step model on startup so first requests are fast
ENV PRELOAD_MODEL=1

# Start the FastAPI + Gradio server
CMD ["python", "app.py"]