Spaces:
Runtime error
Runtime error
# Use an official Python runtime as a parent image | |
FROM python:3.9-slim | |
# Define environment variables | |
ENV HOME=/home/user \ | |
PATH=/home/user/.local/bin:$PATH \ | |
HF_HOME=/home/user/hf_home | |
# Set the working directory in the container | |
WORKDIR $HOME/main | |
# Create the user, home directory, and HF_HOME directory | |
RUN useradd -m user && mkdir -p $HOME/main $HF_HOME && chown -R user:user $HOME | |
# Copy the current directory contents into the container | |
COPY --chown=user:user . $HOME/main | |
# Install FastAPI, Uvicorn, Transformers, and PyTorch | |
RUN pip install --no-cache-dir \ | |
fastapi \ | |
uvicorn \ | |
transformers \ | |
torch --extra-index-url https://download.pytorch.org/whl/cpu | |
# Switch to the non-root user | |
USER user | |
# Expose the port that FastAPI will run on | |
EXPOSE 8000 | |
# Run the application | |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] | |
HEALTHCHECK --interval=30s --timeout=30s --retries=3 \ | |
CMD curl --fail http://localhost:8000/ || exit 1 | |