# KhmerSense — Hugging Face Spaces (Docker SDK). One container: React UI + FastAPI + model. # ---- 1. build the frontend ---- FROM node:22-slim AS web WORKDIR /web COPY frontend/package.json frontend/package-lock.json ./ RUN npm ci --no-audit --no-fund COPY frontend/ ./ RUN npm run build # ---- 2. Python API + model ---- FROM python:3.12-slim ENV PYTHONUNBUFFERED=1 \ PIP_NO_CACHE_DIR=1 \ HF_HOME=/home/user/.cache/huggingface \ SENTIMENT_BACKEND=hf \ MAX_COMMENTS=5000 # Spaces run the container as user 1000 RUN useradd -m -u 1000 user WORKDIR /home/user/app COPY backend/requirements-deploy.txt ./backend/requirements-deploy.txt RUN pip install --index-url https://download.pytorch.org/whl/cpu torch \ && pip install -r backend/requirements-deploy.txt COPY --chown=user backend/app ./backend/app COPY --chown=user --from=web /web/dist ./frontend/dist USER user # Download the model at build time so the first visitor doesn't wait for it. RUN cd backend && python -c "from app.sentiment import HFAnalyzer; HFAnalyzer('cardiffnlp/twitter-xlm-roberta-base-sentiment').predict(['warm up'])" WORKDIR /home/user/app/backend EXPOSE 7860 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]