File size: 1,177 Bytes
14adcdb
 
 
 
7c672d8
14adcdb
7c672d8
 
14adcdb
 
44efe6d
5820f9b
 
 
 
 
44efe6d
7c672d8
14adcdb
 
7c672d8
 
 
 
 
 
 
 
14adcdb
 
7c672d8
14adcdb
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
FROM python:3.9-slim

WORKDIR /app

# Copy requirements first to leverage caching
COPY requirements.txt .

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

# Pre-download models to cache them in the Docker image
RUN python -c "from transformers import pipeline; pipeline('summarization', model='facebook/bart-large-cnn')"
RUN python -c "from transformers import pipeline; pipeline('translation', model='Helsinki-NLP/opus-mt-en-fr')"
RUN python -c "from transformers import pipeline; pipeline('translation', model='Helsinki-NLP/opus-mt-en-de')"
RUN python -c "from transformers import pipeline; pipeline('translation', model='Helsinki-NLP/opus-mt-en-es')"
RUN python -c "from transformers import pipeline; pipeline('translation', model='Helsinki-NLP/opus-mt-en-ar')"

# Copy the rest of the application
COPY . .

# Set environment variable for Hugging Face cache
ENV TRANSFORMERS_CACHE=/app/.cache
ENV HF_HOME=/app/.cache/huggingface

# Create cache directory and set permissions
RUN mkdir -p /app/.cache && chmod -R 777 /app/.cache

# Expose the port
EXPOSE 7860

# Run the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]