| FROM python:3.10-slim |
|
|
| ENV PYTHONDONTWRITEBYTECODE=1 \ |
| PYTHONUNBUFFERED=1 \ |
| PIP_NO_CACHE_DIR=1 \ |
| CUDA_VISIBLE_DEVICES="" \ |
| GRADIO_SERVER_NAME=0.0.0.0 \ |
| GRADIO_SERVER_PORT=7860 |
|
|
| RUN apt-get update && apt-get install -y --no-install-recommends \ |
| ffmpeg \ |
| libsndfile1 \ |
| git \ |
| && rm -rf /var/lib/apt/lists/* |
|
|
| WORKDIR /app |
|
|
| COPY requirements.txt . |
|
|
| RUN pip install --upgrade pip setuptools wheel && \ |
| pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cpu torch torchaudio && \ |
| pip install --no-cache-dir -r requirements.txt |
|
|
| |
| RUN python - <<'PY' |
| import os, re, pathlib |
| import chatterbox |
|
|
| base = pathlib.Path(chatterbox.__file__).resolve().parent |
| print("Patching chatterbox at:", base) |
|
|
| patched = 0 |
| for py in base.rglob("*.py"): |
| txt = py.read_text(encoding="utf-8", errors="ignore") |
|
|
| |
| def repl(m): |
| inside = m.group(1) |
| if "map_location" in inside: |
| return f"torch.load({inside})" |
| return f'torch.load({inside}, map_location="cpu")' |
|
|
| new = re.sub(r"torch\.load\(([^)]*)\)", repl, txt) |
| if new != txt: |
| py.write_text(new, encoding="utf-8") |
| patched += 1 |
| print("patched:", py) |
|
|
| print("Total patched files:", patched) |
| PY |
| |
|
|
| COPY . . |
|
|
| EXPOSE 7860 |
| CMD ["python", "app.py"] |