Sentiment / Dockerfile
NzTama's picture
Initial clean deploy: Sentiment Analysis
fa8ff66
# ─── Base Image ─────────────────────────────────────────────────────────────
FROM python:3.11-slim
# Environment Variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# ─── System Dependencies ─────────────────────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
wget curl gnupg ca-certificates unzip \
# Chromium + driver (AUTO MATCH, STABLE)
chromium chromium-driver \
# Required libs
libnss3 libnspr4 libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 \
libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 \
libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 \
libasound2 libxshmfence1 fonts-liberation libappindicator3-1 \
xdg-utils libvulkan1 libx11-xcb1 \
# Fonts
fonts-noto fonts-noto-cjk \
# Build tools
gcc g++ build-essential \
&& rm -rf /var/lib/apt/lists/*
# ─── Set Chromium Path ───────────────────────────────────────────────────────
ENV CHROME_BIN=/usr/bin/chromium
ENV CHROMEDRIVER_PATH=/usr/bin/chromedriver
# ─── Hugging Face Spaces Rules (Non-Root User) ───────────────────────────────
# Hugging Face Spaces requires running Docker as a non-root user (UID 1000)
RUN useradd -m -u 1000 user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app
# Pre-create output directory and ensure permissions
RUN mkdir -p $HOME/app/static/output && chown -R user:user $HOME
# Switch to the non-root user
USER user
# ─── App Setup ───────────────────────────────────────────────────────────────
COPY --chown=user:user requirements.txt .
# Install dependencies into user directory
# PyTorch CPU version specified explicitly
RUN pip install --no-cache-dir --user torch --index-url https://download.pytorch.org/whl/cpu && \
pip install --no-cache-dir --user -r requirements.txt
# Copy project files
COPY --chown=user:user . .
# ─── Expose Port ─────────────────────────────────────────────────────────────
# Hugging Face exposes port 7860
EXPOSE 7860
# ─── Run App ────────────────────────────────────────────────────────────────
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]