FROM python:3.10-slim # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PORT=7860 # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ ffmpeg \ imagemagick \ curl \ git \ build-essential \ fonts-wqy-zenhei \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Fix ImageMagick policy to allow MoviePy to render subtitles and text clips RUN sed -i 's/rights="none" pattern="@\*"/rights="read|write" pattern="@*"/' /etc/ImageMagick-6/policy.xml || true # Set up working directory WORKDIR /app # Copy requirements and install COPY requirements.txt /app/requirements.txt RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application files (including pre-built static assets in resource/public) COPY . /app # Create necessary directories and ensure correct permissions RUN mkdir -p /app/storage/tasks /app/storage/cache_videos /app/resource/public /app/resource/songs /app/resource/fonts && \ ln -s /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc /app/resource/fonts/STHeitiMedium.ttc && \ ln -s /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc /app/resource/fonts/STHeitiLight.ttc && \ ln -s /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc /app/resource/fonts/MicrosoftYaHeiNormal.ttc && \ ln -s /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc /app/resource/fonts/MicrosoftYaHeiBold.ttc # Hugging Face Spaces require running as a non-root user for security and file ownership RUN useradd -m -u 1000 user && \ chown -R user:user /app USER user # Expose port EXPOSE 7860 # Command to run the application CMD ["python", "main.py"]