sentiment-analysis / Dockerfile
JohnDoee's picture
Update Dockerfile
366c5da
raw
history blame
1.19 kB
# 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 and is writable
RUN mkdir -p $HF_HOME && chmod -R 777 $HF_HOME
=
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"]