Phoenix21's picture
Update Dockerfile
a879d14 verified
raw
history blame
1.1 kB
# Use the official Python 3.9 image as a base image
FROM python:3.9-slim
# Create a new user with UID 1000 and switch to that user
RUN useradd -m -u 1000 user
USER user
# Set environment variables for Hugging Face cache and Python
ENV PATH="/home/user/.local/bin:$PATH"
ENV TRANSFORMERS_CACHE="/home/user/.cache/huggingface/transformers"
ENV HF_HOME="/home/user/.cache/huggingface"
ENV PYTHONUNBUFFERED=1
# Create cache directories
RUN mkdir -p $TRANSFORMERS_CACHE && \
mkdir -p $HF_HOME
# Set the working directory inside the container
WORKDIR /app
# Copy the requirements file into the container and install dependencies
COPY --chown=user ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r /app/requirements.txt
# Copy all project files into the container
COPY --chown=user . /app
# Expose the port that FastAPI will listen on (Hugging Face Spaces requires port 7860)
EXPOSE 7860
# Start the FastAPI app using uvicorn, listening on port 7860
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]