File size: 4,269 Bytes
2e3f13f
de66cf1
 
6b5d3ca
e0f1d78
de66cf1
56e425c
 
 
 
 
 
de66cf1
 
 
 
 
 
 
 
86bb0f2
de66cf1
 
 
 
6b5d3ca
de66cf1
 
 
 
 
6b5d3ca
 
de66cf1
 
 
6b5d3ca
de66cf1
 
 
 
 
 
86bb0f2
de66cf1
387a013
de66cf1
86bb0f2
 
814cc61
2e3f13f
814cc61
86bb0f2
e0f1d78
de66cf1
86bb0f2
de66cf1
 
56e425c
 
 
 
de66cf1
 
 
 
91504b2
2e3f13f
 
de66cf1
 
 
 
 
56e425c
de66cf1
 
6b5d3ca
de66cf1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e3f13f
 
43be60a
6b5d3ca
dcdd6cf
 
91504b2
e0f1d78
 
 
86bb0f2
56e425c
86bb0f2
56e425c
de66cf1
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Hugging Face Spaces - MrrrMe with Coqui XTTS v2 + MODULAR BACKEND
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04

# Install system dependencies
# espeak-ng is REQUIRED for Coqui TTS
RUN apt-get update && apt-get install -y \

    bash \
    git \
    git-lfs \
    wget \
    curl \
    procps \
    python3.11 \
    python3-pip \
    python3.11-dev \
    libgl1-mesa-glx \
    libglib2.0-0 \
    ffmpeg \
    portaudio19-dev \
    libsndfile1 \
    espeak-ng \
    nginx \
    gnupg \
    && rm -rf /var/lib/apt/lists/*

# Install Node.js 20
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \

    apt-get install -y nodejs && \
    rm -rf /var/lib/apt/lists/*

# Set Python 3.11 as default
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 && \

    update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1

WORKDIR /app

# Install PyTorch with CUDA 11.8
RUN python3.11 -m pip install --no-cache-dir \

    torch==2.4.0 \
    torchvision==0.19.0 \
    torchaudio==2.4.0 \
    --index-url https://download.pytorch.org/whl/cu118

ENV COQUI_TOS_AGREED=1

# Install Python dependencies
COPY requirements_docker.txt ./
RUN python3.11 -m pip install --no-cache-dir -r requirements_docker.txt

# PRE-DOWNLOAD XTTS V2 MODEL (Memory Safe)
# Uses ModelManager to download without loading to RAM (Fixes Exit 137)
RUN python3.11 -c "from TTS.utils.manage import ModelManager; print('⏳ Downloading XTTS v2 model...'); ModelManager().download_model('tts_models/multilingual/multi-dataset/xtts_v2'); print('βœ… Download complete.')"

# Install avatar dependencies
RUN python3.11 -m pip install --no-cache-dir \

    fastapi uvicorn python-multipart pydub websockets onnxruntime

# Copy application code
COPY --link --chown=1000:1000 mrrrme/ ./mrrrme/
COPY --link --chown=1000:1000 model/ ./model/
COPY --link --chown=1000:1000 avatar/ ./avatar/
COPY --link --chown=1000:1000 weights/ ./weights/

# Create directories
RUN mkdir -p /app/weights /app/avatar/static

# Fix openface bug
RUN python3.11 -c "import os; fp='/usr/local/lib/python3.11/dist-packages/openface/multitask_model.py'; c=open(fp).read() if os.path.exists(fp) else ''; exec(\"if os.path.exists(fp) and 'import cv2' not in c:\\n    open(fp,'w').write('import cv2\\\\n'+c)\\n    print('Patched')\")"

# Build frontend
COPY avatar-frontend/package*.json ./frontend/
WORKDIR /app/frontend
RUN npm ci

COPY --link --chown=1000:1000 avatar-frontend/ ./
RUN npm run build

# Copy static files
RUN cp -r .next/static .next/standalone/.next/ && \

    cp -r public .next/standalone/ 2>/dev/null || true

WORKDIR /app

# Copy nginx config
COPY nginx.spaces.conf /etc/nginx/nginx.conf

# Generate SSL certificates
RUN mkdir -p /etc/nginx/certs && \

    openssl req -x509 -newkey rsa:4096 -nodes \
    -keyout /etc/nginx/certs/key.pem \
    -out /etc/nginx/certs/cert.pem \
    -days 365 \
    -subj "/CN=mrrrme.hf.space"

# βœ… NEW: Create startup script with MODULAR BACKEND
RUN printf '#!/bin/bash\nset -e\nexport HOME=/home/user\nmkdir -p /tmp\n\n# Agree to TOS\nexport COQUI_TOS_AGREED=1\n\nif [ -d "/data" ] && [ -w "/data" ]; then\n    echo "Persistent storage: /data"\n    chmod 777 /data 2>/dev/null || true\nelse\n    echo "Ephemeral storage: /tmp"\nfi\n\npkill -f "backend_new.py" 2>/dev/null || true\npkill -f "speak_server.py" 2>/dev/null || true\npkill -f "node server.js" 2>/dev/null || true\npkill -f "nginx" 2>/dev/null || true\n\nsleep 2\necho "Starting MrrrMe (XTTS v2 + Modular Backend v2.0)..."\n\n# Start NEW modular backend\ncd /app && python3.11 mrrrme/backend_new.py &\n\n# Start avatar TTS\ncd /app/avatar && python3.11 speak_server.py &\n\n# Start Next.js frontend\ncd /app/frontend/.next/standalone && HOSTNAME=0.0.0.0 PORT=3001 node server.js &\n\nsleep 10\nnginx -g "daemon off;" &\necho "Ready!"\nwait\n' > /app/start.sh && chmod +x /app/start.sh

# Set ownership
RUN chown -R 1000:1000 /app

# Ensure non-root user has access to models
RUN mkdir -p /home/user/.local && \

    cp -r /root/.local/share /home/user/.local/ || true && \
    chown -R 1000:1000 /home/user

USER 1000
ENV HOME=/home/user

EXPOSE 7860

CMD ["/app/start.sh"]