|
|
|
|
|
|
|
|
|
|
|
FROM python:3.10-slim |
|
|
|
|
|
|
|
|
RUN apt-get update && apt-get install -y \ |
|
|
ffmpeg \ |
|
|
libgl1 \ |
|
|
libglib2.0-0 \ |
|
|
libsm6 \ |
|
|
libxext6 \ |
|
|
libxrender-dev \ |
|
|
libgomp1 \ |
|
|
libgthread-2.0-0 \ |
|
|
libgtk-3-0 \ |
|
|
libavcodec-dev \ |
|
|
libavformat-dev \ |
|
|
libswscale-dev \ |
|
|
libv4l-dev \ |
|
|
libxvidcore-dev \ |
|
|
libx264-dev \ |
|
|
libjpeg-dev \ |
|
|
libpng-dev \ |
|
|
libtiff-dev \ |
|
|
libopenblas-dev \ |
|
|
libomp-dev \ |
|
|
python3-dev \ |
|
|
git \ |
|
|
build-essential \ |
|
|
gcc \ |
|
|
g++ \ |
|
|
cmake \ |
|
|
pkg-config \ |
|
|
curl \ |
|
|
wget \ |
|
|
ca-certificates \ |
|
|
&& rm -rf /var/lib/apt/lists/* |
|
|
|
|
|
|
|
|
RUN useradd -m -u 1000 user |
|
|
|
|
|
|
|
|
WORKDIR /app |
|
|
|
|
|
|
|
|
RUN pip install --no-cache-dir --upgrade pip setuptools wheel |
|
|
|
|
|
|
|
|
RUN pip install --no-cache-dir \ |
|
|
fastapi>=0.115.2 \ |
|
|
uvicorn[standard]==0.24.0 \ |
|
|
python-multipart>=0.0.18 \ |
|
|
motor==3.3.2 \ |
|
|
pymongo==4.6.0 \ |
|
|
python-dotenv==1.0.0 \ |
|
|
dnspython==2.4.2 \ |
|
|
firebase-admin>=6.1.0 |
|
|
|
|
|
|
|
|
RUN pip install --no-cache-dir "numpy>=1.24.0,<1.27.0" |
|
|
|
|
|
|
|
|
RUN pip install --no-cache-dir \ |
|
|
psutil==5.9.5 \ |
|
|
tqdm==4.65.0 \ |
|
|
Pillow \ |
|
|
imageio-ffmpeg \ |
|
|
huggingface_hub>=0.23.0 |
|
|
|
|
|
|
|
|
RUN pip install --no-cache-dir opencv-python-headless |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RUN pip install --no-cache-dir onnxruntime || \ |
|
|
pip install --no-cache-dir "onnxruntime>=1.16.0" || \ |
|
|
pip install --no-cache-dir onnxruntime-cpu || \ |
|
|
pip install --no-cache-dir "onnxruntime-cpu>=1.16.0" || \ |
|
|
(echo "ERROR: All ONNX Runtime installation attempts failed" && exit 1) |
|
|
|
|
|
|
|
|
RUN python -c "import onnxruntime; print('ONNX Runtime version:', onnxruntime.__version__)" || \ |
|
|
(echo "ERROR: ONNX Runtime installation verification failed" && exit 1) |
|
|
|
|
|
|
|
|
RUN pip install --no-cache-dir moviepy==1.0.3 |
|
|
|
|
|
|
|
|
RUN pip install --no-cache-dir --no-build-isolation git+https://github.com/deepinsight/insightface.git || \ |
|
|
pip install --no-cache-dir insightface || \ |
|
|
pip install --no-cache-dir "insightface>=0.7.0" || \ |
|
|
(echo "ERROR: Failed to install insightface" && exit 1) |
|
|
|
|
|
|
|
|
RUN python -c "import insightface; print('InsightFace installed successfully')" || \ |
|
|
(echo "ERROR: InsightFace verification failed" && exit 1) |
|
|
|
|
|
|
|
|
COPY --chown=user:user api_server.py /app/ |
|
|
COPY --chown=user:user firebase_app_check.py /app/ |
|
|
COPY --chown=user:user DeepFakeAI/ /app/DeepFakeAI/ |
|
|
|
|
|
COPY --chown=user:user DeepFakeAI/.assets/models/inswapper_128.onnx /app/DeepFakeAI/.assets/models/inswapper_128.onnx |
|
|
|
|
|
|
|
|
RUN mkdir -p /app/uploads/source_images /app/uploads/target_videos /app/uploads/result_videos && \ |
|
|
chown -R user:user /app/uploads |
|
|
|
|
|
|
|
|
RUN mkdir -p /app/.assets/models && chown -R user:user /app/.assets |
|
|
|
|
|
|
|
|
ARG INSWAPPER_URL="" |
|
|
ARG INSWAPPER_TOKEN="" |
|
|
ENV INSIGHTFACE_HOME="/home/user/.insightface" |
|
|
ENV INSWAPPER_PATH="/app/DeepFakeAI/.assets/models/inswapper_128.onnx" |
|
|
RUN set -e; mkdir -p /app/DeepFakeAI/.assets/models /home/user/.insightface/models; \ |
|
|
if [ -n "$INSWAPPER_URL" ]; then \ |
|
|
echo "Downloading inswapper_128.onnx from $INSWAPPER_URL"; \ |
|
|
if [ -n "$INSWAPPER_TOKEN" ]; then \ |
|
|
curl -fsSL -H "Authorization: Bearer $INSWAPPER_TOKEN" "$INSWAPPER_URL" -o "$INSWAPPER_PATH" || echo "Warning: tokenized download failed, continuing without preloaded model"; \ |
|
|
else \ |
|
|
curl -fsSL "$INSWAPPER_URL" -o "$INSWAPPER_PATH" || echo "Warning: download failed, continuing without preloaded model"; \ |
|
|
fi; \ |
|
|
else \ |
|
|
echo "No INSWAPPER_URL provided; skipping model download"; \ |
|
|
fi; \ |
|
|
chown -R user:user /home/user/.insightface /app/DeepFakeAI/.assets |
|
|
|
|
|
|
|
|
USER user |
|
|
ENV PATH="/home/user/.local/bin:$PATH" |
|
|
|
|
|
|
|
|
ENV PYTHONUNBUFFERED=1 |
|
|
|
|
|
|
|
|
EXPOSE 7860 |
|
|
|
|
|
|
|
|
CMD ["/bin/sh", "-lc", "python -m uvicorn api_server:app --host 0.0.0.0 --port ${PORT:-7860}"] |