File size: 1,301 Bytes
62cb8f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cee0f63
62cb8f8
 
cee0f63
62cb8f8
 
 
cee0f63
62cb8f8
 
 
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
# Dockerfile for PUBLIC Space
# This loads and runs code from a private HF Space

FROM python:3.12-slim

# Set working directory
WORKDIR /app

# Set Python to run in unbuffered mode (see logs immediately)
ENV PYTHONUNBUFFERED=1

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    build-essential \
    gcc \
    libffi-dev \
    libxml2-dev \
    libxslt1-dev \
    poppler-utils \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Install Python packages needed for loading from private space
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir \
    huggingface-hub \
    Flask

# Copy requirements and install additional dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Create a non-root user
RUN useradd -m -u 1000 appuser && \
    chown -R appuser:appuser /app

# Copy only the loader script
COPY app.py .

# Switch to non-root user
USER appuser

# Set environment variables
ENV PORT=7860

# Expose port
EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
    CMD curl -f http://localhost:7860/ || exit 1

# Run the loader which will download and execute the private space code
CMD ["python", "app.py"]