image-captioning-api / Dockerfile
dixisouls's picture
new file
ce43c34
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"]