Spaces:
Sleeping
Sleeping
| # Use an official Python runtime as a parent image | |
| FROM python:3.11-slim | |
| # Avoid interactive prompts | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # Install system dependencies required for audio/image processing | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| ffmpeg \ | |
| libsndfile1 \ | |
| sox \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| build-essential \ | |
| git \ | |
| pkg-config \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set the working directory in the container | |
| WORKDIR /app | |
| # Copy project files | |
| COPY . /app | |
| # Create writable cache/temp directories at build time so non-root processes | |
| # (like the Spaces runtime user) can write to them. Make them world-writable | |
| # to avoid UID/GID assumptions. | |
| RUN mkdir -p /app/app_cache /app/app_tmp /app/speechbrain_cache /app/.cache/matplotlib \ | |
| && chmod -R 0777 /app/app_cache /app/app_tmp /app/speechbrain_cache /app/.cache/matplotlib || true | |
| # Make the entire /app directory writable so runtime processes (which may run | |
| # as an unprivileged user inside Spaces) can create files directly under /app | |
| # such as transcription_result.json. This is a pragmatic fix; see notes below | |
| # for a safer alternative. | |
| RUN chmod -R 0777 /app || true | |
| # Ensure entrypoint script is executable | |
| RUN chmod +x /app/scripts/entrypoint.sh | |
| # Upgrade pip and wheel tooling | |
| RUN python -m pip install --upgrade pip setuptools wheel | |
| # Install numpy first (helps dependency resolution), then install PyTorch CPU wheels | |
| # using the official PyTorch index and prefer-binary to avoid building from source. | |
| # Use slim Python base and install PyTorch CPU wheels explicitly | |
| RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/* | |
| # Install numpy first (helps dependency resolution) | |
| RUN pip install --no-cache-dir numpy==2.0.2 | |
| # Install torch (CPU) from PyTorch's CPU wheel index | |
| # Then install torchaudio CPU wheel with --no-deps to avoid pip trying to | |
| # re-resolve torch versions (we already installed torch). | |
| RUN pip install --no-cache-dir --prefer-binary \ | |
| -f https://download.pytorch.org/whl/cpu/torch_stable.html \ | |
| "torch==2.8.0" "torchaudio==2.8.0" | |
| # Install remaining Python dependencies at build-time so the image is self-contained | |
| # and ready to run on HF Spaces. If pip fails due to transient network issues, retry once. | |
| RUN pip install --no-cache-dir -r /app/requirements.txt || pip install --no-cache-dir -r /app/requirements.txt | |
| # Expose the port that the app runs on | |
| EXPOSE 7860 | |
| # Define environment variables | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV IN_DOCKER=1 | |
| ENTRYPOINT ["/app/scripts/entrypoint.sh"] |