File size: 1,474 Bytes
91e999e
 
 
 
 
 
 
725e4de
 
91e999e
 
 
 
 
 
 
 
 
 
 
 
 
 
725e4de
 
 
91e999e
 
 
725e4de
 
 
91e999e
 
725e4de
 
 
 
91e999e
 
725e4de
 
91e999e
 
725e4de
 
91e999e
725e4de
 
91e999e
 
 
 
 
 
 
 
 
 
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
57
58
59
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PORT=7860 \
    BASE_DIR=/app \
    NLTK_DATA=/app/nltk_data

# Install Python and other dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3 \
    python3-pip \
    python3-dev \
    build-essential \
    git \
    gcc \
    g++ \
    make \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user
RUN useradd -m -u 1000 user

# Set working directory
WORKDIR /app

# Create necessary directories and set permissions
RUN mkdir -p /app/data/pdfs /app/data/texts /app/data/index /app/nltk_data && \
    chown -R user:user /app

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

# Switch to non-root user
USER user

# Install Python packages
RUN pip3 install --no-cache-dir --user -r requirements.txt
RUN pip3 install --no-cache-dir --user gradio

# Copy your application code and data
COPY --chown=user:user app/ /app/
COPY --chown=user:user data/ /app/data/

# Copy your Gradio interface
COPY --chown=user:user spaces_app.py /app/

# Expose the port Hugging Face Spaces expects
EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:${PORT}/health || exit 1

# Command to run the application
CMD ["python3", "spaces_app.py"]