File size: 3,608 Bytes
75ba57a
 
 
 
 
 
 
 
 
 
 
 
 
84ca867
75ba57a
 
 
84ca867
 
 
 
 
 
75ba57a
 
84ca867
75ba57a
 
 
 
84ca867
 
 
 
 
 
 
 
 
 
75ba57a
84ca867
75ba57a
 
 
 
 
 
 
 
 
 
84ca867
75ba57a
 
84ca867
 
75ba57a
 
84ca867
75ba57a
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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"]