Spaces:
Sleeping
Sleeping
# Use Python 3.11 as base image | |
FROM python:3.11-slim | |
# Set environment variables | |
ENV PYTHONUNBUFFERED=1 | |
ENV PYTHONDONTWRITEBYTECODE=1 | |
# Create user for security (required by Hugging Face Spaces) | |
RUN useradd -m -u 1000 user | |
# Set environment paths | |
ENV HOME=/home/user \ | |
PATH=/home/user/.local/bin:$PATH | |
# Set working directory | |
WORKDIR $HOME/app | |
# Install system dependencies as root | |
USER root | |
RUN apt-get update && apt-get install -y \ | |
wget \ | |
gnupg \ | |
ca-certificates \ | |
fonts-liberation \ | |
libasound2 \ | |
libatk-bridge2.0-0 \ | |
libatk1.0-0 \ | |
libatspi2.0-0 \ | |
libcups2 \ | |
libdbus-1-3 \ | |
libdrm2 \ | |
libgtk-3-0 \ | |
libnspr4 \ | |
libnss3 \ | |
libwayland-client0 \ | |
libx11-6 \ | |
libx11-xcb1 \ | |
libxcb1 \ | |
libxcomposite1 \ | |
libxdamage1 \ | |
libxext6 \ | |
libxfixes3 \ | |
libxrandr2 \ | |
libxss1 \ | |
libxtst6 \ | |
xdg-utils \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Copy requirements first for better caching | |
COPY requirements.txt . | |
# Install Python dependencies | |
RUN pip install --no-cache-dir --upgrade pip | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Install Playwright browsers and their dependencies as root | |
RUN playwright install chromium | |
RUN playwright install-deps chromium | |
# Switch back to user | |
USER user | |
# Copy application code | |
COPY --chown=user . . | |
# Expose the port that Hugging Face Spaces expects | |
EXPOSE 7860 | |
# Command to run the application | |
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--timeout", "300", "--keep-alive", "2", "app:app"] | |