# Use an official Python runtime as a parent image | |
FROM python:3.9 | |
# Create a non-root user for security | |
RUN useradd -m -u 1000 user | |
USER user | |
# Set the working directory in the container | |
ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH | |
WORKDIR $HOME/app | |
# Copy the requirements file into the container | |
COPY --chown=user ./requirements.txt requirements.txt | |
# Install any needed packages specified in requirements.txt | |
RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
# Copy the rest of the application code into the container | |
COPY --chown=user . . | |
# Command to run the application. | |
# Hugging Face Spaces expects the app to listen on port 7860. | |
# The command points to the `api_app` object inside the `api/main.py` file. | |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] | |