# Hugging Face Spaces - MrrrMe Emotion AI # All-in-one container FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 # Install system dependencies RUN apt-get update && apt-get install -y \ python3.11 \ python3-pip \ python3.11-dev \ libgl1-mesa-glx \ libglib2.0-0 \ libsm6 \ libxext6 \ ffmpeg \ portaudio19-dev \ libsndfile1 \ curl \ nginx \ wget \ gnupg \ && rm -rf /var/lib/apt/lists/* # Install Node.js 20 (required for Next.js 16) 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 RUN update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 WORKDIR /app # Install PyTorch with CUDA 11.8 support 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 # Create constraints file RUN echo "torch==2.4.0" > /tmp/constraints.txt && \ echo "torchvision==0.19.0" >> /tmp/constraints.txt && \ echo "torchaudio==2.4.0" >> /tmp/constraints.txt && \ echo "httpx<0.28.0" >> /tmp/constraints.txt # Install Python dependencies COPY requirements_docker.txt ./ RUN PIP_CONSTRAINT=/tmp/constraints.txt python3.11 -m pip install --no-cache-dir -r requirements_docker.txt # Install avatar dependencies RUN python3.11 -m pip install --no-cache-dir \ fastapi uvicorn python-multipart edge-tts pydub websockets # Copy application code COPY mrrrme/ ./mrrrme/ COPY model/ ./model/ COPY avatar/ ./avatar/ COPY weights/ ./weights/ # Create directories RUN mkdir -p /app/weights /app/avatar/static # Fix openface bug - single line version 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 avatar-frontend/ ./ RUN npm run build # Copy static files to standalone 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" # Create startup script RUN printf '#!/bin/bash\nset -e\necho "Starting MrrrMe..."\ncd /app && python3.11 -m mrrrme.backend_server &\ncd /app/avatar && python3.11 speak_server.py &\ncd /app/frontend/.next/standalone && HOSTNAME=0.0.0.0 PORT=3001 node server.js &\nsleep 10\nnginx -g "daemon off;" &\necho "Ready!"\ntail -f /dev/null\n' > /app/start.sh && chmod +x /app/start.sh # Expose Hugging Face Spaces port EXPOSE 7860 # Start all services CMD ["/app/start.sh"]