FROM python:3.9-slim | |
# 1. Install system dependencies including ffmpeg for audio processing | |
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg git && \ | |
apt-get clean && \ | |
rm -rf /var/lib/apt/lists/* | |
# 2. Set up a writable Hugging Face cache directory | |
# This is the standard and correct way to avoid permission errors in Hugging Face Spaces. | |
ENV HF_HOME=/tmp/huggingface | |
ENV TRANSFORMERS_CACHE=/tmp/huggingface/transformers | |
ENV XDG_CACHE_HOME=/tmp/huggingface | |
RUN mkdir -p $HF_HOME && chmod -R 777 $HF_HOME | |
# 3. Install Python dependencies | |
COPY requirements.txt . | |
RUN pip install --no-cache-dir --upgrade pip && \ | |
pip install --no-cache-dir -r requirements.txt | |
# 4. Copy the application files into the container | |
COPY . . | |
# 5. Set the command to run the application using Gunicorn | |
# This is a production-ready web server. | |
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"] | |