Optimized Dockerfile for HuggingFace Spaces
Browse files- Dockerfile +10 -13
- requirements.txt +1 -0
Dockerfile
CHANGED
|
@@ -2,30 +2,27 @@ FROM python:3.10-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
# Install system dependencies FIRST
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
ffmpeg \
|
| 8 |
libsndfile1 \
|
|
|
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
-
# Upgrade pip first
|
| 12 |
-
RUN pip install --upgrade pip wheel
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
# This prevents errors if old packages like googleads are pulled as dependencies
|
| 16 |
-
# Version 64.0.0 is the last that supports use_2to3, preventing googleads installation errors
|
| 17 |
-
RUN pip install --no-cache-dir "setuptools==64.0.0"
|
| 18 |
-
|
| 19 |
-
# Copy requirements
|
| 20 |
COPY requirements.txt .
|
| 21 |
|
| 22 |
# Install Python dependencies in CORRECT ORDER
|
| 23 |
-
# numpy MUST be first, before torch/torchaudio
|
| 24 |
RUN pip install --no-cache-dir "numpy>=1.24.0,<2.0.0"
|
| 25 |
|
| 26 |
-
# Install requirements
|
| 27 |
-
#
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
# Copy application code
|
| 31 |
COPY . .
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Install system dependencies FIRST (including build tools for compiling packages)
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
ffmpeg \
|
| 8 |
libsndfile1 \
|
| 9 |
+
build-essential \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
+
# Upgrade pip and install wheel first
|
| 13 |
+
RUN pip install --upgrade pip setuptools wheel
|
| 14 |
|
| 15 |
+
# Copy requirements early for better Docker layer caching
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
COPY requirements.txt .
|
| 17 |
|
| 18 |
# Install Python dependencies in CORRECT ORDER
|
| 19 |
+
# numpy MUST be installed first, before torch/torchaudio (prevents conflicts)
|
| 20 |
RUN pip install --no-cache-dir "numpy>=1.24.0,<2.0.0"
|
| 21 |
|
| 22 |
+
# Install remaining requirements
|
| 23 |
+
# numpy is already installed above, pip will skip it if version matches
|
| 24 |
+
# Use --prefer-binary to prefer pre-built wheels (faster, more reliable)
|
| 25 |
+
RUN pip install --no-cache-dir --prefer-binary -r requirements.txt
|
| 26 |
|
| 27 |
# Copy application code
|
| 28 |
COPY . .
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
# Core ML Dependencies - ORDER MATTERS!
|
|
|
|
| 2 |
numpy>=1.24.0,<2.0.0
|
| 3 |
torch==2.0.1
|
| 4 |
torchaudio==2.0.2
|
|
|
|
| 1 |
# Core ML Dependencies - ORDER MATTERS!
|
| 2 |
+
# Note: In Dockerfile, numpy is installed separately first to prevent conflicts
|
| 3 |
numpy>=1.24.0,<2.0.0
|
| 4 |
torch==2.0.1
|
| 5 |
torchaudio==2.0.2
|