# Use the official Python 3.10 slim-buster image as a lightweight base | |
FROM python:3.10-slim | |
# Set the application's working directory inside the container | |
WORKDIR /app | |
# Install essential system-level dependencies | |
# - ffmpeg: Required by the pydub library for audio processing | |
# - git: Required by some pip packages for installation from version control | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
ffmpeg \ | |
git \ | |
&& rm -rf /var/lib/apt/lists/* | |
# set cache dir to a writable location | |
ENV TRANSFORMERS_CACHE=/tmp/hf_cache \ | |
HF_HOME=/tmp/hf_home \ | |
HF_HUB_CACHE=/tmp/hf_hub_cache \ | |
XDG_CACHE_HOME=/tmp | |
# Create necessary directories for Hugging Face cache and set permissions | |
RUN mkdir -p /tmp/hf_cache /tmp/hf_home /tmp/hf_hub_cache \ | |
&& chmod -R 777 /tmp/hf_cache /tmp/hf_home /tmp/hf_hub_cache | |
# Copy the dependency file first to leverage Docker's layer caching | |
COPY requirements.txt . | |
# Install Python packages, disabling the cache to reduce image size | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy the application source code into the container | |
# force a re-installation of all packages | |
COPY src/ src/ | |
# Expose the port Gradio will run on, making it accessible to the host | |
EXPOSE 7860 | |
# Define the default command to run the application. | |
CMD ["python", "-m", "src.app"] |