Spaces:
Running
Running
File size: 1,565 Bytes
bac60fc 9ef9a4e bac60fc 46aca47 bac60fc c4c3ebf bac60fc 9ef9a4e bac60fc 9ef9a4e bac60fc 46aca47 bac60fc 9ef9a4e bac60fc c4c3ebf bac60fc 9ef9a4e 5344861 bac60fc 9ef9a4e |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# Multi-stage build for optimized image
FROM python:3.9-slim as builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Final stage
FROM python:3.9-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Set working directory
WORKDIR /app
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
TRANSFORMERS_CACHE=/app/model_cache \
HF_HOME=/app/model_cache \
HUGGINGFACE_HUB_CACHE=/app/model_cache \
MODEL_NAME=microsoft/DialoGPT-medium
# Create cache directories with proper permissions
RUN mkdir -p /app/model_cache && chmod 777 /app/model_cache
# Copy installed packages from builder stage
COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY . .
# Create non-root user and set permissions
RUN useradd -m -u 1000 user && \
chown -R user:user /app && \
chmod 777 /app/model_cache
USER user
# Expose HuggingFace Spaces port (7860)
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=300s --retries=3 \
CMD curl -f https://cronjob-python-chatbot.hf.space/health || exit 1
# Run FastAPI application
CMD ["python", "main.py"] |