Spaces:
Sleeping

File size: 1,070 Bytes
9254159
 
 
 
 
3f41064
9254159
 
 
5e8261a
 
 
 
 
 
 
 
 
 
 
 
 
9254159
 
5e8261a
9254159
 
 
 
 
 
5e8261a
9254159
 
 
 
 
 
969d760
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
FROM python:3.10-slim

# Install system dependencies needed for OpenCV / Pillow / Scipy
RUN apt-get update && apt-get install -y \
    build-essential \
    libgl1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Create user with UID 1000 for Hugging Face Spaces compatibility
RUN useradd -m -u 1000 user
ENV HOME=/home/user
ENV PATH=/home/user/.local/bin:$PATH
ENV U2NET_HOME=/home/user/.u2net

WORKDIR /home/user/app

# Change ownership of working directory to user
RUN chown -R user:user /home/user

# Switch to the non-root user
USER user

# Copy requirements and install
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Pre-download the birefnet-general-lite model so the first request is instant
RUN python -c "from rembg import new_session; new_session('birefnet-general-lite')"

# Copy the rest of the application
COPY --chown=user . .

# Expose port 7860 (Hugging Face Spaces default port)
EXPOSE 7860

# Run Flask on port 7860
CMD ["python", "-m", "flask", "run", "--host=0.0.0.0", "--port=7860"]