LogicGoInfotechSpaces commited on
Commit
866992e
·
verified ·
1 Parent(s): 9744a1a

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +99 -0
Dockerfile ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive
4
+ ENV PYTHONUNBUFFERED=1
5
+ ENV PYTHONDONTWRITEBYTECODE=1
6
+
7
+ # ---------------------------------------------------------------------------
8
+ # System dependencies + Python 3.11
9
+ # ---------------------------------------------------------------------------
10
+ RUN apt-get update && apt-get install -y --no-install-recommends \
11
+ software-properties-common \
12
+ curl \
13
+ git \
14
+ build-essential \
15
+ libgl1-mesa-glx \
16
+ libglib2.0-0 \
17
+ libsm6 \
18
+ libxext6 \
19
+ libxrender-dev \
20
+ ffmpeg \
21
+ && add-apt-repository ppa:deadsnakes/ppa \
22
+ && apt-get update && apt-get install -y --no-install-recommends \
23
+ python3.11 \
24
+ python3.11-venv \
25
+ python3.11-dev \
26
+ python3.11-distutils \
27
+ && rm -rf /var/lib/apt/lists/*
28
+
29
+ # ---------------------------------------------------------------------------
30
+ # Set Python 3.11 as default + pip
31
+ # ---------------------------------------------------------------------------
32
+ RUN ln -sf /usr/bin/python3.11 /usr/bin/python \
33
+ && ln -sf /usr/bin/python3.11 /usr/bin/python3 \
34
+ && curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11 \
35
+ && python -m pip install --no-cache-dir --upgrade pip setuptools wheel
36
+
37
+ # ---------------------------------------------------------------------------
38
+ # Create non-root user (HF Spaces requirement)
39
+ # ---------------------------------------------------------------------------
40
+ RUN useradd -m -u 1000 user
41
+ ENV HOME=/home/user
42
+ ENV PATH=/home/user/.local/bin:$PATH
43
+
44
+ WORKDIR /app
45
+
46
+ # ---------------------------------------------------------------------------
47
+ # Install Python deps
48
+ # ---------------------------------------------------------------------------
49
+ COPY requirements.txt .
50
+ RUN pip install --no-cache-dir -r requirements.txt
51
+
52
+ # ---------------------------------------------------------------------------
53
+ # Copy app code
54
+ # ---------------------------------------------------------------------------
55
+ COPY . .
56
+
57
+ # ---------------------------------------------------------------------------
58
+ # Install realesrgan (pulls PyPI basicsr==1.4.2 as dependency)
59
+ # ---------------------------------------------------------------------------
60
+ RUN pip install --no-cache-dir realesrgan 2>&1 || true
61
+
62
+ # ---------------------------------------------------------------------------
63
+ # FIX: Uninstall broken PyPI basicsr (it imports removed
64
+ # torchvision.transforms.functional_tensor). CodeFormer's own local
65
+ # basicsr (at /app/CodeFormer/basicsr/) works fine and is used instead
66
+ # via PYTHONPATH below.
67
+ # ---------------------------------------------------------------------------
68
+ RUN pip uninstall -y basicsr 2>&1 || true
69
+
70
+ # ---------------------------------------------------------------------------
71
+ # Use CodeFormer's local basicsr + facelib via PYTHONPATH
72
+ # This makes `import basicsr` and `import facelib` resolve to the
73
+ # CodeFormer-bundled versions that are compatible with modern torchvision.
74
+ # ---------------------------------------------------------------------------
75
+ ENV PYTHONPATH="/app/CodeFormer:${PYTHONPATH}"
76
+
77
+ # ---------------------------------------------------------------------------
78
+ # Download pretrained models (now uses local basicsr — no import errors)
79
+ # ---------------------------------------------------------------------------
80
+ RUN python CodeFormer/scripts/download_pretrained_models.py facelib 2>&1 || true
81
+ RUN python CodeFormer/scripts/download_pretrained_models.py CodeFormer 2>&1 || true
82
+
83
+ # ---------------------------------------------------------------------------
84
+ # Directories + permissions
85
+ # ---------------------------------------------------------------------------
86
+ RUN mkdir -p /app/models /tmp/faceswap \
87
+ && chown -R user:user /app /tmp/faceswap /home/user
88
+
89
+ # ---------------------------------------------------------------------------
90
+ # Switch to non-root
91
+ # ---------------------------------------------------------------------------
92
+ USER user
93
+
94
+ EXPOSE 7860
95
+
96
+ # ---------------------------------------------------------------------------
97
+ # PRODUCTION CMD (GPU SAFE)
98
+ # ---------------------------------------------------------------------------
99
+ CMD ["gunicorn","app:fastapi_app","--workers=1","--worker-class=uvicorn.workers.UvicornWorker","--bind=0.0.0.0:7860","--timeout=600","--graceful-timeout=300","--keep-alive=5","--max-requests=200","--max-requests-jitter=50","--access-logfile=-","--error-logfile=-","--log-level=info"]