Tas01 commited on
Commit
6eb5087
·
verified ·
1 Parent(s): 7692b17

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +80 -24
Dockerfile CHANGED
@@ -1,24 +1,80 @@
1
- FROM python:3.9-slim
2
-
3
- WORKDIR /app
4
-
5
- # Install minimal system dependencies
6
- RUN apt-get update && apt-get install -y --no-install-recommends \
7
- && rm -rf /var/lib/apt/lists/*
8
-
9
- # Copy and install requirements
10
- COPY requirements.txt .
11
- RUN pip install --no-cache-dir -r requirements.txt
12
-
13
- # Copy application
14
- COPY app.py .
15
-
16
- # Set environment variables for Gradio
17
- ENV GRADIO_SERVER_NAME="0.0.0.0"
18
- ENV GRADIO_SERVER_PORT=7860
19
-
20
- # Expose port
21
- EXPOSE 7860
22
-
23
- # Run the app
24
- CMD ["python", "app.py"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install system dependencies for AI models and image processing
6
+ RUN apt-get update && apt-get install -y \
7
+ gcc \
8
+ g++ \
9
+ git \
10
+ curl \
11
+ wget \
12
+ libgl1 \
13
+ libglib2.0-0 \
14
+ libsm6 \
15
+ libxext6 \
16
+ libxrender-dev \
17
+ libgl1-mesa-glx \
18
+ ffmpeg \
19
+ && rm -rf /var/lib/apt/lists/* \
20
+ && apt-get clean
21
+
22
+ # Copy requirements first for better Docker layer caching
23
+ COPY requirements.txt .
24
+
25
+ # Install Python dependencies
26
+ RUN pip install --no-cache-dir -r requirements.txt
27
+
28
+ # Create necessary directories
29
+ RUN mkdir -p \
30
+ /app/models \
31
+ /app/temp \
32
+ /app/uploads \
33
+ /app/outputs \
34
+ /app/examples
35
+
36
+ # Copy application code
37
+ COPY . .
38
+
39
+ # Pre-download and cache AI models during build
40
+ RUN python -c "
41
+ import rembg
42
+ import torch
43
+ from transformers import pipeline
44
+
45
+ # Pre-download background removal model
46
+ print('Downloading background removal model...')
47
+ rembg.remove((255, 255, 255, 255))
48
+
49
+ # Pre-download other essential models
50
+ print('Pre-caching AI models...')
51
+ try:
52
+ # Face detection model
53
+ from insightface.app import FaceAnalysis
54
+ print('Models pre-cached successfully')
55
+ except Exception as e:
56
+ print(f'Model caching: {e}')
57
+ " || true
58
+
59
+ # Create non-root user for security
60
+ RUN groupadd -r appuser && useradd -r -g appuser appuser
61
+ RUN chown -R appuser:appuser /app
62
+ USER appuser
63
+
64
+ # Expose ports
65
+ EXPOSE 7860 # Gradio
66
+ EXPOSE 8000 # FastAPI
67
+
68
+ # Health check
69
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
70
+ CMD python -c "import requests; requests.get('http://localhost:7860/', timeout=10)" || exit 1
71
+
72
+ # Set environment variables
73
+ ENV PYTHONUNBUFFERED=1
74
+ ENV GRADIO_SERVER_NAME="0.0.0.0"
75
+ ENV GRADIO_SERVER_PORT=7860
76
+ ENV MODEL_CACHE_DIR="/app/models"
77
+ ENV TEMP_DIR="/app/temp"
78
+
79
+ # Run the application
80
+ CMD ["python", "app.py"]