Spaces:
Sleeping
Sleeping
| # 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"] |