# Use the base Python 3.9 image FROM python:3.9 # Set the working directory to /code WORKDIR /code # Create a non-root user to avoid permission issues RUN useradd -m myuser # Create the cache directory with correct ownership RUN mkdir -p /code/cache && chown -R myuser:myuser /code/cache # Set the environment variable for the Hugging Face cache ENV HF_HOME=/code/cache # Copy the requirements file into the container COPY ./requirements.txt /code/requirements.txt # Switch to the non-root user before installing dependencies USER myuser # Install dependencies from requirements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt # Switch back to root user to copy the rest of the files USER root # Copy all files from the current directory into the container COPY . . # Set ownership of all files to the non-root user RUN chown -R myuser:myuser /code # Expose the correct port for Flask EXPOSE 7860 # Switch to the non-root user again USER myuser # Set the default command to run the Flask app CMD ["python", "app.py"]