# Use an official Python runtime as a parent image | |
FROM python:3.10-slim | |
# Set the working directory in the container | |
WORKDIR /code | |
# --- FIX FOR PERMISSION ERROR --- | |
# Set an environment variable to use a writable directory for the cache | |
ENV HF_HOME=/tmp/huggingface_cache | |
ENV TORCH_HOME=/tmp/torch_cache | |
# Install system dependencies required by OpenCV | |
RUN apt-get update && apt-get install -y \ | |
libgl1-mesa-glx \ | |
libglib2.0-0 \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Copy the requirements file into the container | |
COPY ./requirements.txt /code/requirements.txt | |
# Install the Python packages | |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt | |
# Copy the rest of your application files into the container | |
COPY . /code/ | |
# Tell Gunicorn to run your app on the port Hugging Face expects (7860) | |
# The --timeout flag prevents the server from crashing during long model-loading times. | |
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "300", "app:app"] |