File size: 1,534 Bytes
3bb6958
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Dockerfile for Hugging Face Spaces
FROM python:3.10-slim

# Add metadata for Hugging Face Spaces
LABEL maintainer="AR Collection Agent Demo"
LABEL description="Educational AI agent demonstration for accounts receivable collections"

# Install system dependencies and clean up in one layer
RUN apt-get update && apt-get install -y \
    curl \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

# Create user for Hugging Face Spaces
RUN useradd -m -u 1000 user
USER user

# Set up environment
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1

WORKDIR $HOME/app

# Copy requirements first for better layer caching
COPY --chown=user requirements.txt .

# Install Python dependencies with optimized flags
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir --prefer-binary -r requirements.txt

# Copy application files (excluding credentials via .dockerignore)
COPY --chown=user . .

# Set Gradio environment variables for Hugging Face Spaces
ENV GRADIO_SERVER_NAME="0.0.0.0" \
    GRADIO_SERVER_PORT="7860" \
    GRADIO_THEME_CACHE_DIR="/tmp/gradio_cache"

# Create necessary directories
RUN mkdir -p /tmp/gradio_cache

# Add health check for Hugging Face infrastructure
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Expose port for Hugging Face Spaces
EXPOSE 7860

# Run the application with proper signal handling
CMD ["python", "-u", "app.py"]