File size: 1,199 Bytes
159f871
 
 
 
 
 
 
 
060adf9
 
 
 
159f871
f6e220a
 
060adf9
159f871
 
 
 
ada2814
159f871
f6e220a
 
159f871
 
 
 
 
 
ada2814
060adf9
 
 
159f871
 
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
# Use a stable Python base image
FROM python:3.9-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    LANG=C.UTF-8 \
    HF_HOME="/app/huggingface_cache" \
    HUGGINGFACE_HUB_CACHE="/app/huggingface_cache"

# Set working directory
WORKDIR /app

# Copy required files
COPY requirements.txt .  
COPY main.py .  

# Install dependencies using a virtual environment
RUN python -m venv /app/venv && \
    /app/venv/bin/pip install --no-cache-dir --upgrade pip && \
    /app/venv/bin/pip install --no-cache-dir -r requirements.txt

# Ensure the model cache directory exists
RUN mkdir -p $HF_HOME

# Pre-download models (handle errors gracefully)
RUN /app/venv/bin/python -c "from transformers import pipeline; \
    pipeline('sentiment-analysis', model='tabularisai/multilingual-sentiment-analysis')" || echo "Failed to download model 1"

RUN /app/venv/bin/python -c "from transformers import pipeline; \
    pipeline('sentiment-analysis', model='siebert/sentiment-roberta-large-english')" || echo "Failed to download model 2"

# Expose port for FastAPI
EXPOSE 7860

# Run FastAPI server using virtual environment
CMD ["/app/venv/bin/uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]