FROM python:3.11-slim # Set working directory WORKDIR /app # Install system dependencies (including libxml2 and libxslt for lxml) RUN apt-get update && apt-get install -y \ build-essential \ curl \ git \ libxml2-dev \ libxslt1-dev \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/* # Copy requirements COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Create cache directory for models with proper permissions RUN mkdir -p /app/models_cache && chmod 777 /app/models_cache # Expose port (HuggingFace uses port 7860 by default) EXPOSE 7860 # Set environment variables ENV PORT=7860 ENV PYTHONUNBUFFERED=1 ENV TRANSFORMERS_CACHE=/app/models_cache ENV HF_HOME=/app/models_cache # Run with Gunicorn for production stability and timeout handling CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--threads", "4", "--timeout", "300", "--graceful-timeout", "300", "--keep-alive", "5", "combined_server:app"]