Spaces:
Runtime error
Runtime error
File size: 1,017 Bytes
8ce9715 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # Use an official lightweight Python image
FROM python:3.11-slim
# Create a non-root user (Hugging Face Spaces recommends running as a non-root user)
RUN useradd -m -u 1000 user
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PORT=7860
# MongoDB is required. If you use a cloud DB, you can inject MONGO_URI in HuggingFace Secrets.
# ENV MONGO_URI=mongodb+srv://...
# Switch to the non-root user and set the working directory
USER user
WORKDIR /home/user/app
# Copy the requirements file and install dependencies
COPY --chown=user requirements.txt .
# Install dependencies into the user's local environment
RUN pip install --no-cache-dir --user -r requirements.txt
# Add the local bin to PATH
ENV PATH="/home/user/.local/bin:${PATH}"
# Copy the application code
COPY --chown=user . .
# Expose the Hugging Face Spaces default port
EXPOSE 7860
# Run the FastAPI application using Uvicorn
CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|