radames commited on
Commit
f6a6fb3
·
1 Parent(s): 3c068f3
Files changed (3) hide show
  1. Dockerfile +75 -0
  2. app.py +41 -0
  3. requirements.txt +0 -0
Dockerfile ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive \
4
+ TZ=America/Los_Angeles
5
+
6
+ ARG USE_PERSISTENT_DATA
7
+
8
+ RUN apt-get update && apt-get install -y \
9
+ git \
10
+ make build-essential libssl-dev zlib1g-dev libc6 libc-bin \
11
+ libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
12
+ libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev git-lfs \
13
+ ffmpeg libsm6 libxext6 cmake libgl1-mesa-glx xvfb \
14
+ && rm -rf /var/lib/apt/lists/* \
15
+ && git lfs install
16
+
17
+ WORKDIR /code
18
+
19
+ COPY ./requirements.txt /code/requirements.txt
20
+
21
+ # User
22
+ RUN useradd -m -u 1000 user
23
+ USER user
24
+ ENV HOME=/home/user \
25
+ PATH=/home/user/.local/bin:$PATH
26
+
27
+ # Pyenv
28
+ RUN curl https://pyenv.run | bash
29
+ ENV PATH=$HOME/.pyenv/shims:$HOME/.pyenv/bin:$PATH
30
+
31
+ ARG PYTHON_VERSION=3.10.13
32
+ # Python
33
+
34
+ RUN pyenv install $PYTHON_VERSION && \
35
+ pyenv global $PYTHON_VERSION && \
36
+ pyenv rehash && \
37
+ pip install --no-cache-dir --upgrade pip setuptools wheel && \
38
+ pip install --no-cache-dir \
39
+ datasets \
40
+ huggingface-hub "protobuf<4" "click<8.1"
41
+ # pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu116
42
+
43
+
44
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
45
+
46
+ # Set the working directory to /data if USE_PERSISTENT_DATA is set, otherwise set to $HOME/app
47
+ WORKDIR $HOME/app
48
+
49
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
50
+
51
+ RUN git clone https://github.com/dreamgaussian/dreamgaussian . && \
52
+ pip install -r requirements.txt && \
53
+ pip install -q torch-ema einops tensorboardX plyfile dearpygui huggingface_hub diffusers accelerate transformers xatlas && \
54
+ pip install -q trimesh PyMCubes pymeshlab rembg[gpu,cli] omegaconf ninja gradio && \
55
+ pip install -q https://github.com/camenduru/diff-gaussian-rasterization/releases/download/v1.0/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.1.whl && \
56
+ pip install -q https://github.com/camenduru/diff-gaussian-rasterization/releases/download/v1.0/simple_knn-0.0.0-cp310-cp310-linux_x86_64.1.whl && \
57
+ pip install -q https://github.com/camenduru/diff-gaussian-rasterization/releases/download/v1.0/nvdiffrast-0.3.1-py3-none-any.whl && \
58
+ pip install -q https://github.com/camenduru/diff-gaussian-rasterization/releases/download/v1.0/kiui-0.1.8-py3-none-any.whl
59
+
60
+ USER user
61
+ # Set home to the user's home directory
62
+ ENV HOME=/home/user \
63
+ PATH=/home/user/.local/bin:$PATH \
64
+ PYTHONPATH=$HOME/app \
65
+ PYTHONUNBUFFERED=1 \
66
+ GRADIO_ALLOW_FLAGGING=never \
67
+ GRADIO_NUM_PORTS=1 \
68
+ GRADIO_SERVER_NAME=0.0.0.0 \
69
+ GRADIO_THEME=huggingface \
70
+ SYSTEM=spaces
71
+
72
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
73
+ COPY --chown=user . $HOME/app
74
+
75
+ CMD ["python3", "app.py"]
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import subprocess
3
+ import gradio as gr
4
+ import tempfile
5
+
6
+ def create_from_text(prompt):
7
+ temp_dir = tempfile.mkdtemp()
8
+ sanitized_prompt = re.sub('[^0-9a-zA-Z]+', '_', prompt)
9
+ cmd1 = ["python", "main.py", "--config", "configs/text.yaml", f"prompt={prompt}", f"save_path={temp_dir}"]
10
+ cmd2 = ["python", "main2.py", "--config", "configs/text.yaml", f"prompt={prompt}", f"save_path={temp_dir}"]
11
+ cmd3 = ["xvfb-run", "python", "-m", "kiui.render", f"{temp_dir}/{sanitized_prompt}.obj", "--save_video", f"{temp_dir}/{sanitized_prompt}.mp4"]
12
+ subprocess.run(cmd1)
13
+ subprocess.run(cmd2)
14
+ subprocess.run(cmd3)
15
+ return f"{temp_dir}/{sanitized_prompt}.mp4"
16
+
17
+ def create_from_image(image):
18
+ sanitized_prompt = 'image'
19
+ image.save(f"{sanitized_prompt}.png")
20
+ cmd1 = ["python", "process.py", f"{sanitized_prompt}.png", "--size", "512"] # <<< 256 may be a good default
21
+ cmd2 = ["python", "main.py", "--config", "configs/image.yaml", f"input={sanitized_prompt}_rgba.png", f"save_path={sanitized_prompt}"]
22
+ cmd3 = ["python", "main2.py", "--config", "configs/image.yaml", f"input={sanitized_prompt}_rgba.png", f"save_path={sanitized_prompt}"]
23
+ cmd4 = ["xvfb-run", "python", "-m", "kiui.render", f"logs/{sanitized_prompt}.obj", "--save_video", f"{sanitized_prompt}.mp4"]
24
+ subprocess.run(cmd1)
25
+ subprocess.run(cmd2)
26
+ subprocess.run(cmd3)
27
+ subprocess.run(cmd4)
28
+ return f"{sanitized_prompt}.mp4"
29
+
30
+ with gr.Blocks() as demo:
31
+ prompt = gr.Textbox(lines=2, placeholder="Enter Prompt...")
32
+ image = gr.Image(type="pil", label="Image")
33
+ btn = gr.Button("Generate from text")
34
+ btn_2 = gr.Button("Generate from image")
35
+ video = gr.Video(type="mp4")
36
+ btn.click(create_from_text, inputs=prompt, outputs=video)
37
+ btn_2.click(create_from_image, inputs=image, outputs=video)
38
+
39
+
40
+ demo.queue(concurrency_count=1)
41
+ demo.launch(debug=True)
requirements.txt ADDED
File without changes