Spaces:
Sleeping
Sleeping
| # 1. Start with a lean and official Python base image | |
| FROM python:3.10-slim | |
| # 2. Create a non-root user and group | |
| RUN useradd -m -u 1000 user | |
| # 3. Set environment variables for a writable cache directory | |
| ENV HF_HOME="/app/cache" | |
| ENV TRANSFORMERS_CACHE="/app/cache" | |
| # 4. Set the working directory | |
| WORKDIR /app | |
| # 5. Copy requirements first to leverage Docker caching | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # 6. Copy the application code | |
| COPY ./app /app/app | |
| # 7. Grant ownership of the entire /app directory to the 'user' | |
| RUN chown -R user:user /app | |
| # 8. Switch to the non-root user | |
| USER user | |
| # 9. Define the command to run your application for Hugging Face Spaces | |
| CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--worker-class", "uvicorn.workers.UvicornWorker", "--timeout", "0", "app.main:app"] |