Spaces:
Sleeping
Sleeping
| FROM python:3.11-slim | |
| # Set up a new user named "user" with user ID 1000 | |
| # Hugging Face enforces running as a non-root user | |
| RUN useradd -m -u 1000 user | |
| # Set environment variables | |
| ENV PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 \ | |
| HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| # Switch to root to install dependencies and system packages if needed | |
| USER root | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Switch back to user | |
| USER user | |
| WORKDIR /app | |
| # Copy requirements and install them | |
| COPY --chown=user backend/requirements.txt /app/requirements.txt | |
| RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
| # Copy the rest of the backend files | |
| COPY --chown=user backend/ /app/backend/ | |
| # Expose port 7860 to the outside world | |
| EXPOSE 7860 | |
| # Command to run the application using Gunicorn with Uvicorn workers | |
| # Binding to 0.0.0.0:7860 as required by Hugging Face | |
| CMD ["gunicorn", "--chdir", "/app/backend", "main:app", "--workers", "4", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:7860", "--timeout", "120"] |