lecturelens-api / Dockerfile
aliSaac510's picture
refactor: simplify project by removing heavy PyTorch/MUSIQ dependency to fix HF build
6c2c36b
Raw
History Blame Contribute Delete
3.61 kB
# syntax=docker/dockerfile:1
# ──────────────────────────────────────────────────────────────────────────────
# LectureLens API β€” Dockerfile
# Target: Hugging Face Spaces (Docker runtime, CPU only, port 7860)
# ──────────────────────────────────────────────────────────────────────────────
FROM python:3.11-slim
# ── System dependencies ───────────────────────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
libsndfile1 \
libgomp1 \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# ── HF Spaces requires a non-root user ───────────────────────────────────────
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"
WORKDIR /home/user/app
# ── Python dependencies ───────────────────────────────────────────────────────
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# ── Application code ──────────────────────────────────────────────────────────
COPY --chown=user app/ ./app/
COPY --chown=user thresholds.yaml .
# ── Download DNSMOS ONNX model at build time ──────────────────────────────────
# Model source: Microsoft DNS-Challenge repo (~8 MB)
RUN mkdir -p dnsmos && \
curl -fL \
"https://github.com/microsoft/DNS-Challenge/raw/master/DNSMOS/DNSMOS/sig_bak_ovr.onnx" \
-o dnsmos/sig_bak_ovr.onnx && \
echo "βœ… DNSMOS model downloaded ($(du -sh dnsmos/sig_bak_ovr.onnx | cut -f1))"
# ── Environment defaults (override in HF Space β†’ Settings β†’ Variables) ────────
ENV LECTURELENS_API_KEY="changeme" \
MAX_FILE_SIZE_MB="500" \
FRAME_SAMPLE_RATE_SECONDS="5" \
THRESHOLDS_CONFIG_PATH="thresholds.yaml" \
DNSMOS_MODEL_PATH="dnsmos/sig_bak_ovr.onnx" \
HOST="0.0.0.0" \
PORT="7860" \
PYTHONUNBUFFERED="1" \
PYTHONDONTWRITEBYTECODE="1"
# ── Port required by Hugging Face Spaces ─────────────────────────────────────
EXPOSE 7860
# ── Health check ──────────────────────────────────────────────────────────────
HEALTHCHECK --interval=30s --timeout=15s --start-period=90s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')"
# ── Start Uvicorn ─────────────────────────────────────────────────────────────
CMD ["uvicorn", "app.main:app", \
"--host", "0.0.0.0", \
"--port", "7860", \
"--workers", "1", \
"--log-level", "info"]