Spaces:
Sleeping
Sleeping
Dan Vancea commited on
Commit ·
c55464d
1
Parent(s): ac34b3e
Update Dockerfile
Browse files- Dockerfile +17 -19
Dockerfile
CHANGED
|
@@ -3,38 +3,36 @@ FROM python:3.11-slim
|
|
| 3 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 4 |
ENV PYTHONUNBUFFERED=1
|
| 5 |
|
| 6 |
-
# 1. Install system dependencies
|
| 7 |
RUN apt-get update && apt-get install -y \
|
| 8 |
ffmpeg \
|
| 9 |
git \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
-
# 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
RUN useradd -m -u 1000 user
|
| 14 |
-
USER user
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
WORKDIR $HOME/app
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# 4. Install Python dependencies as the user
|
| 26 |
-
RUN pip install --user --no-cache-dir torch torchaudio --index-url https://download.pytorch.org/whl/cpu
|
| 27 |
-
RUN pip install --user --no-cache-dir -r requirements.txt
|
| 28 |
-
|
| 29 |
-
# 5. Pre-cache Whisper WITHOUT loading it into PyTorch memory to avoid OOM limits.
|
| 30 |
-
# Using whisper._download handles the checksum logic and places it in the user's cache directory.
|
| 31 |
-
RUN python -c "import whisper, os; whisper._download(whisper._MODELS['medium'], os.path.expanduser('~/.cache/whisper'), False)"
|
| 32 |
|
| 33 |
-
#
|
| 34 |
COPY --chown=user . .
|
| 35 |
|
| 36 |
-
# Expose the correct Hugging Face port
|
| 37 |
EXPOSE 7860
|
| 38 |
|
| 39 |
-
# Start the Flask application
|
| 40 |
CMD ["python", "backend.py"]
|
|
|
|
| 3 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 4 |
ENV PYTHONUNBUFFERED=1
|
| 5 |
|
| 6 |
+
# 1. Install system dependencies (root)
|
| 7 |
RUN apt-get update && apt-get install -y \
|
| 8 |
ffmpeg \
|
| 9 |
git \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
+
# 2. Install Python dependencies globally (root).
|
| 13 |
+
# This guarantees that Python can resolve all modules without relying on $PATH injection.
|
| 14 |
+
COPY requirements.txt .
|
| 15 |
+
RUN pip install --no-cache-dir torch torchaudio --index-url https://download.pytorch.org/whl/cpu
|
| 16 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 17 |
+
|
| 18 |
+
# 3. Create the unprivileged user required by Hugging Face Spaces (UID 1000)
|
| 19 |
RUN useradd -m -u 1000 user
|
|
|
|
| 20 |
|
| 21 |
+
# 4. Pre-create the cache directory and assign ownership to the new user.
|
| 22 |
+
# This ensures the user has write permissions when the _download function executes.
|
| 23 |
+
RUN mkdir -p /home/user/.cache/whisper && chown -R user:user /home/user/.cache
|
| 24 |
|
| 25 |
+
# 5. Switch context to the unprivileged user
|
| 26 |
+
USER user
|
| 27 |
+
ENV HOME=/home/user
|
| 28 |
WORKDIR $HOME/app
|
| 29 |
|
| 30 |
+
# 6. Safely pre-cache Whisper directly to disk without loading PyTorch tensors into memory
|
| 31 |
+
RUN python -c "import whisper; whisper._download(whisper._MODELS['medium'], '/home/user/.cache/whisper', False)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
# 7. Copy the application code and transfer ownership
|
| 34 |
COPY --chown=user . .
|
| 35 |
|
|
|
|
| 36 |
EXPOSE 7860
|
| 37 |
|
|
|
|
| 38 |
CMD ["python", "backend.py"]
|