Spaces:
Running
Running
# Use Python 3.9 slim image | |
FROM python:3.9-slim | |
# Set working directory | |
WORKDIR /app | |
# Install system dependencies | |
RUN apt-get update && apt-get install -y \ | |
build-essential \ | |
curl \ | |
software-properties-common \ | |
git \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Copy requirements first for better caching | |
COPY requirements.txt . | |
# Install Python dependencies | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy all application files | |
COPY . . | |
# Create a non-root user | |
RUN useradd -m -u 1000 user | |
USER user | |
# Set environment variables | |
ENV HOME=/home/user \ | |
PATH=/home/user/.local/bin:$PATH \ | |
PYTHONPATH=$HOME/app \ | |
PYTHONUNBUFFERED=1 \ | |
GRADIO_ALLOW_FLAGGING=never \ | |
GRADIO_NUM_PORTS=1 \ | |
GRADIO_SERVER_NAME=0.0.0.0 \ | |
GRADIO_THEME=huggingface \ | |
SYSTEM=spaces | |
# Change to user's home directory | |
WORKDIR $HOME/app | |
# Copy files with correct ownership | |
COPY --chown=user . $HOME/app | |
# Expose port 7860 (Hugging Face Spaces default) | |
EXPOSE 7860 | |
# Health check | |
HEALTHCHECK CMD curl --fail http://localhost:7860/_health || exit 1 | |
# Command to run the application | |
CMD ["python", "app.py"] |