Spaces:
Paused
Paused
- Dockerfile +5 -7
- app.py +48 -19
- examples/b.jpg +0 -0
Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
FROM nvidia/cuda:11.
|
| 2 |
|
| 3 |
ENV DEBIAN_FRONTEND=noninteractive \
|
| 4 |
TZ=America/Los_Angeles
|
|
@@ -48,13 +48,11 @@ 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
|
| 52 |
pip install -r requirements.txt && \
|
| 53 |
-
pip install -
|
| 54 |
-
pip install -
|
| 55 |
-
|
| 56 |
-
pip install -q https://github.com/camenduru/diff-gaussian-rasterization/releases/download/v1.0/nvdiffrast-0.3.1-py3-none-any.whl && \
|
| 57 |
-
pip install -q https://github.com/camenduru/diff-gaussian-rasterization/releases/download/v1.0/kiui-0.1.8-py3-none-any.whl
|
| 58 |
USER user
|
| 59 |
# Set home to the user's home directory
|
| 60 |
ENV HOME=/home/user \
|
|
|
|
| 1 |
+
FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu18.04
|
| 2 |
|
| 3 |
ENV DEBIAN_FRONTEND=noninteractive \
|
| 4 |
TZ=America/Los_Angeles
|
|
|
|
| 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 -e git+https://github.com/NVlabs/nvdiffrast.git@main#egg=nvdiffrast && \
|
| 54 |
+
pip install -e git+https://github.com/ashawkey/kiuikit.git@main#egg=kiui
|
| 55 |
+
|
|
|
|
|
|
|
| 56 |
USER user
|
| 57 |
# Set home to the user's home directory
|
| 58 |
ENV HOME=/home/user \
|
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import re
|
| 2 |
import subprocess
|
| 3 |
import gradio as gr
|
|
@@ -5,9 +6,17 @@ import trimesh
|
|
| 5 |
import tempfile
|
| 6 |
import time
|
| 7 |
import pathlib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def create_from_text(prompt):
|
| 10 |
-
temp_dir = tempfile.mkdtemp()
|
| 11 |
sanitized_prompt = re.sub("[^0-9a-zA-Z]+", "_", prompt)
|
| 12 |
cmd1 = [
|
| 13 |
"python",
|
|
@@ -17,6 +26,8 @@ def create_from_text(prompt):
|
|
| 17 |
f"prompt={prompt}",
|
| 18 |
f"outdir={temp_dir}",
|
| 19 |
f"save_path={sanitized_prompt}",
|
|
|
|
|
|
|
| 20 |
]
|
| 21 |
cmd2 = [
|
| 22 |
"python",
|
|
@@ -26,14 +37,17 @@ def create_from_text(prompt):
|
|
| 26 |
f"prompt={prompt}",
|
| 27 |
f"outdir={temp_dir}",
|
| 28 |
f"save_path={sanitized_prompt}",
|
|
|
|
|
|
|
| 29 |
]
|
| 30 |
subprocess.run(cmd1)
|
| 31 |
subprocess.run(cmd2)
|
| 32 |
-
glb_path =
|
| 33 |
-
return get_html_model(glb_path)
|
| 34 |
-
|
|
|
|
| 35 |
def create_from_image(image):
|
| 36 |
-
temp_dir = tempfile.mkdtemp()
|
| 37 |
sanitized_prompt = "image"
|
| 38 |
image.save(f"{temp_dir}/{sanitized_prompt}.png")
|
| 39 |
cmd1 = [
|
|
@@ -51,6 +65,8 @@ def create_from_image(image):
|
|
| 51 |
f"outdir={temp_dir}",
|
| 52 |
f"input={temp_dir}/{sanitized_prompt}_rgba.png",
|
| 53 |
f"save_path={sanitized_prompt}",
|
|
|
|
|
|
|
| 54 |
]
|
| 55 |
cmd3 = [
|
| 56 |
"python",
|
|
@@ -60,25 +76,25 @@ def create_from_image(image):
|
|
| 60 |
f"outdir={temp_dir}",
|
| 61 |
f"input={temp_dir}/{sanitized_prompt}_rgba.png",
|
| 62 |
f"save_path={sanitized_prompt}",
|
|
|
|
|
|
|
| 63 |
]
|
|
|
|
|
|
|
|
|
|
| 64 |
subprocess.run(cmd1)
|
| 65 |
subprocess.run(cmd2)
|
| 66 |
subprocess.run(cmd3)
|
| 67 |
-
glb_path =
|
| 68 |
-
return get_html_model(glb_path)
|
| 69 |
|
| 70 |
|
| 71 |
-
def
|
| 72 |
-
|
| 73 |
-
m = trimesh.load(obj_path, split_object=True, group_material=False, process=False)
|
| 74 |
-
m.export(f_path)
|
| 75 |
-
return f_path
|
| 76 |
|
|
|
|
| 77 |
|
| 78 |
-
def get_html_model(f_path):
|
| 79 |
-
iframe = f"""<iframe src="file=model.html" model-url="file={f_path}" width="100%" height="500px"></iframe>"""
|
| 80 |
|
| 81 |
-
return iframe
|
| 82 |
def generate(prompt, image):
|
| 83 |
if prompt:
|
| 84 |
gr.Info("Generating from prompt")
|
|
@@ -105,9 +121,22 @@ source: https://github.com/dreamgaussian/dreamgaussian
|
|
| 105 |
btn = gr.Button("Generate")
|
| 106 |
with gr.Column():
|
| 107 |
model_3d = gr.HTML(label="Model 3D", show_label=True)
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
demo.queue(api_open=False, concurrency_count=1)
|
| 113 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
| 1 |
+
%cd /content/dreamgaussian/
|
| 2 |
import re
|
| 3 |
import subprocess
|
| 4 |
import gradio as gr
|
|
|
|
| 6 |
import tempfile
|
| 7 |
import time
|
| 8 |
import pathlib
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
os.system("pip install -e ./simple-knn")
|
| 12 |
+
os.system("pip install -e ./diff-gaussian-rasterization")
|
| 13 |
+
|
| 14 |
+
TEMP_DIR = "/tmp/dreamgaussian"
|
| 15 |
+
os.makedirs(TEMP_DIR, exist_ok=True)
|
| 16 |
+
|
| 17 |
|
| 18 |
def create_from_text(prompt):
|
| 19 |
+
temp_dir = tempfile.mkdtemp(dir=TEMP_DIR)
|
| 20 |
sanitized_prompt = re.sub("[^0-9a-zA-Z]+", "_", prompt)
|
| 21 |
cmd1 = [
|
| 22 |
"python",
|
|
|
|
| 26 |
f"prompt={prompt}",
|
| 27 |
f"outdir={temp_dir}",
|
| 28 |
f"save_path={sanitized_prompt}",
|
| 29 |
+
"force_cuda_rast=True",
|
| 30 |
+
"mesh_format=glb",
|
| 31 |
]
|
| 32 |
cmd2 = [
|
| 33 |
"python",
|
|
|
|
| 37 |
f"prompt={prompt}",
|
| 38 |
f"outdir={temp_dir}",
|
| 39 |
f"save_path={sanitized_prompt}",
|
| 40 |
+
"force_cuda_rast=True",
|
| 41 |
+
"mesh_format=glb",
|
| 42 |
]
|
| 43 |
subprocess.run(cmd1)
|
| 44 |
subprocess.run(cmd2)
|
| 45 |
+
glb_path = f"{temp_dir}/{sanitized_prompt}.glb"
|
| 46 |
+
return get_html_model(glb_path)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
def create_from_image(image):
|
| 50 |
+
temp_dir = tempfile.mkdtemp(dir=TEMP_DIR)
|
| 51 |
sanitized_prompt = "image"
|
| 52 |
image.save(f"{temp_dir}/{sanitized_prompt}.png")
|
| 53 |
cmd1 = [
|
|
|
|
| 65 |
f"outdir={temp_dir}",
|
| 66 |
f"input={temp_dir}/{sanitized_prompt}_rgba.png",
|
| 67 |
f"save_path={sanitized_prompt}",
|
| 68 |
+
"force_cuda_rast=True",
|
| 69 |
+
"mesh_format=glb",
|
| 70 |
]
|
| 71 |
cmd3 = [
|
| 72 |
"python",
|
|
|
|
| 76 |
f"outdir={temp_dir}",
|
| 77 |
f"input={temp_dir}/{sanitized_prompt}_rgba.png",
|
| 78 |
f"save_path={sanitized_prompt}",
|
| 79 |
+
"force_cuda_rast=True",
|
| 80 |
+
"mesh_format=glb",
|
| 81 |
]
|
| 82 |
+
print(cmd1)
|
| 83 |
+
print(cmd2)
|
| 84 |
+
print(cmd3)
|
| 85 |
subprocess.run(cmd1)
|
| 86 |
subprocess.run(cmd2)
|
| 87 |
subprocess.run(cmd3)
|
| 88 |
+
glb_path = f"{temp_dir}/{sanitized_prompt}.glb"
|
| 89 |
+
return get_html_model(glb_path)
|
| 90 |
|
| 91 |
|
| 92 |
+
def get_html_model(f_path):
|
| 93 |
+
iframe = f"""<iframe src="file=model.html" model-url="file={f_path}" width="100%" height="500px"></iframe>"""
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
return iframe
|
| 96 |
|
|
|
|
|
|
|
| 97 |
|
|
|
|
| 98 |
def generate(prompt, image):
|
| 99 |
if prompt:
|
| 100 |
gr.Info("Generating from prompt")
|
|
|
|
| 121 |
btn = gr.Button("Generate")
|
| 122 |
with gr.Column():
|
| 123 |
model_3d = gr.HTML(label="Model 3D", show_label=True)
|
| 124 |
+
gr.Examples(
|
| 125 |
+
[["A pokemon", None],
|
| 126 |
+
[None, "./examples/b.jpg"]],
|
| 127 |
+
inputs=[prompt, image],
|
| 128 |
+
outputs=[model_3d],
|
| 129 |
+
cache_examples=True,
|
| 130 |
+
)
|
| 131 |
+
btn.click(generate, inputs=[prompt, image], outputs=[model_3d])
|
| 132 |
+
clear.click(
|
| 133 |
+
lambda x: (gr.update(value=None), gr.update(value=None)),
|
| 134 |
+
None,
|
| 135 |
+
[prompt, image],
|
| 136 |
+
queue=False,
|
| 137 |
+
)
|
| 138 |
|
| 139 |
demo.queue(api_open=False, concurrency_count=1)
|
| 140 |
+
demo.launch(
|
| 141 |
+
debug=True, show_api=False, inline=False, share=True, allowed_paths=[TEMP_DIR]
|
| 142 |
+
)
|
examples/b.jpg
ADDED
|