radames commited on
Commit
e24fdc0
·
1 Parent(s): 3f9e8ed
Files changed (3) hide show
  1. Dockerfile +5 -7
  2. app.py +48 -19
  3. examples/b.jpg +0 -0
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
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 -b dev https://github.com/camenduru/dreamgaussian . && \
52
  pip install -r requirements.txt && \
53
- pip install -q bpy \
54
- 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 && \
55
- 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 && \
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 = convert_obj_to_glb(f"{temp_dir}/{sanitized_prompt}.obj", temp_dir)
33
- return get_html_model(glb_path), 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 = convert_obj_to_glb(f"{temp_dir}/{sanitized_prompt}.obj", temp_dir)
68
- return get_html_model(glb_path), glb_path
69
 
70
 
71
- def convert_obj_to_glb(obj_path, out_path):
72
- f_path = out_path + "/model.GLB"
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
- file = gr.File()
109
- btn.click(generate, inputs=[prompt, image], outputs=[model_3d, file])
110
- clear.click(lambda x: (gr.update(value=None),gr.update(value=None)), None, [prompt, image], queue=False)
 
 
 
 
 
 
 
 
 
 
 
111
 
112
  demo.queue(api_open=False, concurrency_count=1)
113
- demo.launch(debug=True, show_api=False, inline=False, share=True)
 
 
 
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