FROM python:3.9 # Create a user with UID 1000 and set as default user RUN useradd -m -u 1000 user USER user # Set environment variables for the user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /app # Set HF_HOME environment variable to a writable directory # This tells huggingface_hub where to store its cache and downloaded models ENV HF_HOME="/app/.cache/huggingface" # Copy requirements.txt first to leverage Docker cache COPY --chown=user ./requirements.txt requirements.txt # Install Python dependencies RUN pip install --no-cache-dir --upgrade -r requirements.txt # Copy the rest of your application code COPY --chown=user . /app # Command to run your Flask application # It will listen on the PORT environment variable provided by Hugging Face Spaces CMD ["python", "app.py"]