File size: 1,466 Bytes
67b0de8
242e773
 
 
 
e7ef98a
242e773
 
 
 
 
 
 
 
 
 
 
 
f0b9c26
242e773
8eb613e
f0b9c26
242e773
e7ef98a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242e773
 
 
 
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
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

# ===== PATCH chatterbox agar torch.load selalu ke CPU =====
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")

    # ganti torch.load(...) -> torch.load(..., map_location="cpu")
    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"]