File size: 1,414 Bytes
ca6e669
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use Python 3.11 to support Pandas 3.x and newer libraries
FROM python:3.11-slim

# Set the working directory in the container
WORKDIR /app

# Install system dependencies
# libgl1 and libglib2.0-0 are often needed for CV/PDF libraries
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 \
    libglib2.0-0 \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Copy the requirements file
COPY requirements.txt requirements.txt

# Install Python packages with timeout increase
RUN pip install --no-cache-dir --timeout=1000 -r requirements.txt

# Copy application code
COPY . /app

# Create a non-root user (Security Best Practice)
RUN useradd -m -u 1000 user

# Change ownership of the app directory and the temp directories
RUN chown -R user:user /app

# Create temp directories for HuggingFace/Torch cache and set permissions
RUN mkdir -p /tmp/transformers_cache /tmp/hf_home /tmp/torch_home && \
    chown -R user:user /tmp/transformers_cache /tmp/hf_home /tmp/torch_home

# Switch to the non-root user
USER user

# Expose the port (Standard for HF Spaces)
EXPOSE 7860

# Set environment variables
ENV FLASK_HOST=0.0.0.0
ENV FLASK_PORT=7860
ENV FLASK_DEBUG=False

# CRITICAL: Set HF-specific env vars to writable directories
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
ENV HF_HOME=/tmp/hf_home
ENV TORCH_HOME=/tmp/torch_home

# Command to run the app
CMD ["python", "app.py"]