# Hugging Face Docker Space (or any container host). FROM python:3.11-slim RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg libsndfile1 \ && rm -rf /var/lib/apt/lists/* # Spaces run the container as user 1000; give it a writable home and model cache. RUN useradd -m -u 1000 user ENV HOME=/home/user \ HF_HOME=/home/user/.cache/huggingface \ PATH=/home/user/.local/bin:$PATH \ PYTHONUNBUFFERED=1 WORKDIR /home/user/app # PyTorch build. CPU hardware: keep this. GPU hardware: set the Space variable # TORCH_INDEX to https://download.pytorch.org/whl/cu124 and rebuild. ARG TORCH_INDEX=https://download.pytorch.org/whl/cpu RUN pip install --no-cache-dir numpy scipy soundfile pydantic fastapi uvicorn python-multipart huggingface_hub python-docx \ && pip install --no-cache-dir torch torchaudio --index-url ${TORCH_INDEX} \ && pip install --no-cache-dir "transformers>=4.40" sentencepiece USER user # Bake the (gated) ASR model into the image so restarts don't re-download ~1 GB. # Needs the Space secret HF_TOKEN, which Spaces expose to the build as a secret mount. # Without it the build still succeeds and the model downloads when the server starts. ARG ASR_MODEL=ARTPARK-IISc/SraVaani-1.0 RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=false \ if [ -f /run/secrets/HF_TOKEN ]; then \ HF_TOKEN="$(cat /run/secrets/HF_TOKEN)" python -c "import os; from huggingface_hub import snapshot_download; snapshot_download('${ASR_MODEL}', token=os.environ['HF_TOKEN'])" \ || echo 'Model pre-download failed (terms not accepted?); it will be retried at start.'; \ else echo 'No HF_TOKEN build secret; the model downloads at start.'; fi COPY --chown=user . . ENV SCQC_DATA=/tmp/scqc_data \ SCQC_SEED_EXAMPLES=0 \ SCQC_ASR=sravaani:${ASR_MODEL} # Runtime secrets: SCQC_ADMIN_PASSWORD (first admin account), SCQC_ADMIN_TOKEN, SCQC_REVIEW_TOKEN # (defaults are public), HF_TOKEN. Variables: SCQC_ASR=sravaani,indicconformer for two models # (GPU hardware recommended), SCQC_CONFIDENCE_MODEL for a calibrated confidence score. # If SraVaani fails to load, the server still runs (acoustic checks + human review) # and /api/health shows the error, e.g. a missing Python package to add above. EXPOSE 7860 CMD ["python", "-m", "uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]