File size: 1,294 Bytes
a0c5c81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce43c34
 
 
 
91a5e40
ce43c34
 
 
91a5e40
 
 
a0c5c81
 
 
 
ce43c34
 
 
a0c5c81
 
 
 
 
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
FROM python:3.9-slim

WORKDIR /code

# Install system dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements first to leverage Docker cache
COPY requirements.txt .

# Install dependencies
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Create necessary directories with correct permissions
RUN mkdir -p /tmp/uploads && chmod 777 /tmp/uploads
RUN mkdir -p app/models && chmod 777 app/models

# Copy application code
COPY app ./app
COPY app.py .

# Create cache directories with proper permissions
RUN mkdir -p /.cache && chmod 777 /.cache
RUN mkdir -p /root/.cache/torch && chmod -R 777 /root/.cache
RUN mkdir -p /home/.cache/torch && chmod -R 777 /home/.cache

# Set PyTorch cache environment variable
ENV TORCH_HOME=/home/.cache/torch
ENV TRANSFORMERS_CACHE=/home/.cache/transformers

# Download NLTK data with explicit directory
RUN python -c "import nltk; nltk.download('punkt', download_dir='/usr/local/share/nltk_data')"

# Download model files during build
RUN python -m app.download_model

# Download ResNet50 model to avoid permission issues at runtime
RUN python -m app.download_resnet

# Expose port
EXPOSE 7860

# Run the application
CMD ["python", "app.py"]