FROM python:3.11-slim # Hugging Face Spaces runs the container as a non-root user (UID 1000). # Create that user and put all writable state (code + model cache) under its home. RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ HF_HOME=/home/user/.cache/huggingface \ PORT=7860 WORKDIR /home/user/app # deps first for layer caching COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt # app code only — GPT-2 / KoGPT2 weights are pulled from the HF hub on first run COPY --chown=user app.py . COPY --chown=user aidetect ./aidetect COPY --chown=user static ./static COPY --chown=user ai_detector_model.joblib . EXPOSE 7860 CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port ${PORT}"]