LogicGoInfotechSpaces commited on
Commit
7658264
·
1 Parent(s): 84e896b

fix: update Dockerfile for Hugging Face Spaces - use port 7860 and follow HF Spaces best practices

Browse files
Files changed (2) hide show
  1. Dockerfile +63 -0
  2. api_server.py +1 -1
Dockerfile ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # GPU-optimized Dockerfile for Face Swap Video API
3
+
4
+ FROM nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu22.04
5
+
6
+ # Install system dependencies
7
+ RUN apt-get update && apt-get install -y \
8
+ python3.10 \
9
+ python3-pip \
10
+ ffmpeg \
11
+ libgl1-mesa-glx \
12
+ libglib2.0-0 \
13
+ git \
14
+ && rm -rf /var/lib/apt/lists/*
15
+
16
+ # Create user for Hugging Face Spaces (following HF Spaces best practices)
17
+ RUN useradd -m -u 1000 user
18
+ USER user
19
+ ENV PATH="/home/user/.local/bin:$PATH"
20
+
21
+ # Set working directory
22
+ WORKDIR /app
23
+
24
+ # Copy requirements file
25
+ COPY --chown=user ./requirements.txt requirements.txt
26
+
27
+ # Install Python dependencies (excluding Gradio for API-only mode)
28
+ RUN pip install --no-cache-dir --upgrade pip && \
29
+ pip install --no-cache-dir --user \
30
+ fastapi>=0.115.2 \
31
+ uvicorn[standard]==0.24.0 \
32
+ python-multipart>=0.0.18 \
33
+ motor==3.3.2 \
34
+ pymongo==4.6.0 \
35
+ python-dotenv==1.0.0 \
36
+ dnspython==2.4.2 \
37
+ numpy==1.24.3 \
38
+ insightface==0.7.3 \
39
+ onnxruntime-gpu==1.17.3 \
40
+ opencv-python \
41
+ psutil==5.9.5 \
42
+ tqdm==4.65.0 \
43
+ Pillow \
44
+ moviepy==1.0.3 \
45
+ imageio-ffmpeg \
46
+ huggingface_hub>=0.23.0
47
+
48
+ # Copy application code
49
+ COPY --chown=user . /app
50
+
51
+ # Create upload directories with proper permissions
52
+ RUN mkdir -p uploads/source_images uploads/target_videos uploads/result_videos uploads/output && \
53
+ chmod -R 755 uploads
54
+
55
+ # Set environment variables
56
+ ENV PYTHONUNBUFFERED=1
57
+ ENV CUDA_VISIBLE_DEVICES=0
58
+
59
+ # Expose port 7860 (required for Hugging Face Spaces)
60
+ EXPOSE 7860
61
+
62
+ # Run the API server on port 7860 (HF Spaces requirement)
63
+ CMD ["uvicorn", "api_server:app", "--host", "0.0.0.0", "--port", "7860"]
api_server.py CHANGED
@@ -434,4 +434,4 @@ async def root():
434
 
435
  if __name__ == "__main__":
436
  import uvicorn
437
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
434
 
435
  if __name__ == "__main__":
436
  import uvicorn
437
+ uvicorn.run(app, host="0.0.0.0", port=7860)