vineet88's picture
Deploy SafeChat ML service to Hugging Face Space
1944d2e verified
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
HF_HOME=/tmp/huggingface \
TRANSFORMERS_CACHE=/tmp/huggingface/hub \
SAFECHAT_CLASSIFIER_MODEL=vineet88/safechat-muril-toxicity-finetuned \
SAFECHAT_DETOX_MODEL=ai4bharat/IndicBART \
SAFECHAT_USE_MODEL_DETOX=false
WORKDIR /app
# 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 (Docker cache optimization)
COPY requirements.txt .
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
# Copy only the runtime payload used by the Space.
COPY app ./app
# Create directories
RUN mkdir -p /app/checkpoints /app/models /tmp/huggingface
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \
CMD python -c "import httpx; r = httpx.get('http://localhost:8000/api/v1/health'); exit(0 if r.status_code == 200 else 1)"
# Run with uvicorn (1 worker — models are loaded per worker)
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]