File size: 1,617 Bytes
945111c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f4d583f
 
 
945111c
f4d583f
 
 
 
 
 
945111c
f4d583f
 
 
945111c
 
 
 
 
 
 
 
 
 
f4d583f
 
 
 
945111c
 
 
 
f4d583f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Use official Python image
FROM python:3.10-slim

# Disable interactive prompts
ENV DEBIAN_FRONTEND=noninteractive

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    ffmpeg \
    libsm6 \
    libxext6 \
    git \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements and install Python packages
COPY requirements.txt .

# Upgrade pip first and set timeout + retries
RUN pip install --upgrade pip \
    && pip config set global.timeout 100 \
    && pip config set global.retries 10 \
    && pip install --no-cache-dir -r requirements.txt

# Set environment variables for cache directories with proper permissions
ENV HF_HOME=/tmp/hf_cache
ENV TRANSFORMERS_CACHE=/tmp/transformers
ENV HF_DATASETS_CACHE=/tmp/datasets
ENV HF_METRICS_CACHE=/tmp/metrics
ENV MPLCONFIGDIR=/tmp/matplotlib

# Create cache directories with proper permissions
RUN mkdir -p /tmp/hf_cache /tmp/transformers /tmp/datasets /tmp/metrics /tmp/matplotlib \
    && chmod -R 777 /tmp/hf_cache /tmp/transformers /tmp/datasets /tmp/metrics /tmp/matplotlib

# Pre-download the SAM model from Hugging Face
RUN python -c "\
from transformers import SamModel, SamProcessor; \
SamModel.from_pretrained('Zigeng/SlimSAM-uniform-50'); \
SamProcessor.from_pretrained('Zigeng/SlimSAM-uniform-50')"

# Copy all project files
COPY . .

# Create necessary directories for the app with proper permissions
RUN mkdir -p static/uploads static/outputs \
    && chmod -R 777 static

# Expose port for Flask
EXPOSE 6000

# Run using gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:6000", "app:app"]