Tas01 commited on
Commit
4577c44
·
verified ·
1 Parent(s): 8f01c45

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -61
Dockerfile CHANGED
@@ -1,80 +1,37 @@
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"]
 
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
  libgl1 \
8
  libglib2.0-0 \
9
+ && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
10
 
11
+ # Copy requirements
12
  COPY requirements.txt .
13
 
14
  # Install Python dependencies
15
  RUN pip install --no-cache-dir -r requirements.txt
16
 
17
+ # Create cache directory
18
+ RUN mkdir -p /app/cache
 
 
 
 
 
19
 
20
+ # Copy application
21
+ COPY app.py .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  # Set environment variables
24
  ENV PYTHONUNBUFFERED=1
25
  ENV GRADIO_SERVER_NAME="0.0.0.0"
26
  ENV GRADIO_SERVER_PORT=7860
27
+ ENV TRANSFORMERS_CACHE=/app/cache
28
+ ENV HUGGINGFACE_HUB_CACHE=/app/cache
29
+
30
+ # Expose port
31
+ EXPOSE 7860
32
+
33
+ # Run as non-root user
34
+ RUN useradd -m appuser && chown -R appuser:appuser /app
35
+ USER appuser
36
 
 
37
  CMD ["python", "app.py"]