Spaces:
Sleeping
Sleeping
Upload Dockerfile
Browse files- Dockerfile +52 -0
Dockerfile
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime as a parent image
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies (build-essential, git, wget, ca-certificates, and standard runtimes)
|
| 5 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
+
build-essential \
|
| 7 |
+
git \
|
| 8 |
+
wget \
|
| 9 |
+
ca-certificates \
|
| 10 |
+
libgl1 \
|
| 11 |
+
libglib2.0-0 \
|
| 12 |
+
libgomp1 \
|
| 13 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
+
|
| 15 |
+
# Set the working directory in the container
|
| 16 |
+
WORKDIR /code
|
| 17 |
+
|
| 18 |
+
# Copy the requirements file and install dependencies
|
| 19 |
+
COPY requirements.txt /code/requirements.txt
|
| 20 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 21 |
+
|
| 22 |
+
# Create the non-root user and home directory (still as ROOT)
|
| 23 |
+
RUN useradd -m -u 1000 user
|
| 24 |
+
ENV HOME=/home/user \
|
| 25 |
+
PATH=/home/user/.local/bin:$PATH
|
| 26 |
+
|
| 27 |
+
# Set working directory to user home app folder
|
| 28 |
+
WORKDIR /home/user/app
|
| 29 |
+
|
| 30 |
+
# Copy the application code into the container
|
| 31 |
+
COPY . /home/user/app
|
| 32 |
+
|
| 33 |
+
# Pre-download all required AI models (as ROOT, guaranteeing absolute write permissions)
|
| 34 |
+
RUN mkdir -p /home/user/app/backend/models && \
|
| 35 |
+
mkdir -p /home/user/.u2net && \
|
| 36 |
+
wget -q -O /home/user/app/backend/models/depth_anything.onnx "https://huggingface.co/onnx-community/depth-anything-v2-small/resolve/main/onnx/model.onnx" && \
|
| 37 |
+
wget -q -O /home/user/app/backend/models/gfpgan.onnx "https://huggingface.co/hacksider/deep-live-cam/resolve/main/GFPGANv1.4.onnx" && \
|
| 38 |
+
wget -q -O /home/user/app/backend/models/realesrgan.onnx "https://huggingface.co/tidus2102/Real-ESRGAN/resolve/main/Real-ESRGAN_x2plus.onnx" && \
|
| 39 |
+
wget -q -O /home/user/.u2net/u2net.onnx "https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2net.onnx" && \
|
| 40 |
+
wget -q -O /home/user/.u2net/BiRefNet-general-epoch_244.onnx "https://github.com/danielgatis/rembg/releases/download/v0.0.0/BiRefNet-general-epoch_244.onnx"
|
| 41 |
+
|
| 42 |
+
# Recursively give user (1000) full ownership of their files and cached weights
|
| 43 |
+
RUN chown -R user:user /home/user
|
| 44 |
+
|
| 45 |
+
# Switch to the non-root user for execution safety and Hugging Face requirements
|
| 46 |
+
USER user
|
| 47 |
+
|
| 48 |
+
# Expose port 7860, which Hugging Face expects
|
| 49 |
+
EXPOSE 7860
|
| 50 |
+
|
| 51 |
+
# Run the Streamlit application on port 7860
|
| 52 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|