Spaces:
Running
Running
| # Use a lightweight Python base image | |
| FROM python:3.10-slim | |
| # Set up a working directory | |
| WORKDIR /app | |
| # In HuggingFace Spaces it's crucial to set up the correct user privileges | |
| # Spaces require running as a non-root user with UID 1000 | |
| RUN useradd -m -u 1000 user && \ | |
| mkdir -p /app && \ | |
| chown -R user:user /app | |
| USER user | |
| # Set environmental variables | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| # Copy in the requirements file and install dependencies | |
| COPY --chown=user:user requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy the actual Python script and .env if it exists | |
| COPY --chown=user:user main.py . | |
| # We don't forcibly COPY .env because users should use HF Secrets, | |
| # but if it's there it won't break anything. | |
| # The command to start our infinite loop script | |
| # The -u flag is REQUIRED for Docker/HuggingFace so logs print immediately! | |
| CMD ["python", "-u", "main.py", "--run"] |