File size: 2,788 Bytes
0eaebb2 | 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 | # ββ Base: Python 3.10 on slim Debian ββββββββββββββββββββββββββββββββββββββ
# python:3.10-slim is critical:
# - Python 3.13 (HF default) removed audioop β gradio/pydub crash
# - Python 3.10 has audioop built-in and is TF 2.15 compatible
FROM python:3.10-slim
# ββ Working directory ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
WORKDIR /app
# ββ System dependencies ββββββββββββββββββββββββββββββββββββββββββββββββββββ
# libgomp1: required by TensorFlow for OpenMP multi-threading
RUN apt-get update && \
apt-get install -y --no-install-recommends libgomp1 && \
rm -rf /var/lib/apt/lists/*
# ββ Python dependencies ββββββββββββββββββββββββββββββββββββββββββββββββββββ
# numpy MUST be installed before tensorflow β TF checks numpy at install time
# Each on separate RUN so Docker caches each layer independently
# If you change app.py later, packages won't reinstall (fast rebuild)
RUN pip install --no-cache-dir "numpy==1.26.4"
# tensorflow-cpu: CPU-only build (~500MB) β HF Spaces has no GPU
RUN pip install --no-cache-dir "tensorflow-cpu==2.15.0"
# FastAPI stack β lightweight web server, no gradio dependency hell
RUN pip install --no-cache-dir \
"fastapi==0.110.0" \
"uvicorn[standard]==0.29.0" \
"python-multipart==0.0.9" \
"pillow==10.3.0" \
"h5py==3.11.0"
# ββ Copy application files βββββββββββββββββββββββββββββββββββββββββββββββββ
COPY app.py .
# Copy model files (must exist before building image or uploading to HF)
COPY models/ ./models/
# ββ Runtime config βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Suppress TensorFlow C++ verbose logs
ENV TF_CPP_MIN_LOG_LEVEL=3
ENV TF_ENABLE_ONEDNN_OPTS=0
# HF Spaces routes external traffic to this port
EXPOSE 7860
# ββ Start command ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# uvicorn serves FastAPI directly β no gradio server check, no localhost issues
CMD ["uvicorn", "app:app", \
"--host", "0.0.0.0", \
"--port", "7860", \
"--workers", "1", \
"--log-level", "info"]
|