Spaces:
Running
on
Zero
Running
on
Zero
JeffreyXiang
commited on
Commit
•
7d475c1
1
Parent(s):
31fcf48
Update
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
-
|
4 |
|
5 |
import os
|
6 |
from typing import *
|
|
|
7 |
import imageio
|
8 |
import uuid
|
9 |
from PIL import Image
|
@@ -37,11 +38,13 @@ def image_to_3d(image: Image.Image) -> Tuple[dict, str]:
|
|
37 |
str: The path to the video of the 3D model.
|
38 |
"""
|
39 |
outputs = pipeline(image, formats=["gaussian", "mesh"], preprocess_image=False)
|
40 |
-
video = render_utils.render_video(outputs['gaussian'][0])['color']
|
|
|
|
|
41 |
model_id = uuid.uuid4()
|
42 |
video_path = f"/tmp/Trellis-demo/{model_id}.mp4"
|
43 |
os.makedirs(os.path.dirname(video_path), exist_ok=True)
|
44 |
-
imageio.mimsave(video_path, video, fps=
|
45 |
model = {'gaussian': outputs['gaussian'][0], 'mesh': outputs['mesh'][0], 'model_id': model_id}
|
46 |
return model, video_path
|
47 |
|
@@ -74,18 +77,25 @@ def deactivate_button() -> gr.Button:
|
|
74 |
|
75 |
|
76 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
with gr.Row():
|
78 |
with gr.Column():
|
79 |
image_prompt = gr.Image(label="Image Prompt", image_mode="RGBA", type="pil", height=300)
|
80 |
-
generate_btn = gr.Button("Generate"
|
81 |
|
|
|
82 |
mesh_simplify = gr.Slider(0.9, 0.98, label="Simplify", value=0.95, step=0.01)
|
83 |
texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
|
84 |
extract_glb_btn = gr.Button("Extract GLB", interactive=False)
|
85 |
|
86 |
with gr.Column():
|
87 |
video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
|
88 |
-
model_output =
|
89 |
download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
|
90 |
|
91 |
# Example images at the bottom of the page
|
@@ -96,8 +106,8 @@ with gr.Blocks() as demo:
|
|
96 |
for image in os.listdir("assets/example_image")
|
97 |
],
|
98 |
inputs=[image_prompt],
|
99 |
-
fn=lambda image:
|
100 |
-
outputs=[image_prompt
|
101 |
run_on_click=True,
|
102 |
examples_per_page=64,
|
103 |
)
|
@@ -109,14 +119,6 @@ with gr.Blocks() as demo:
|
|
109 |
preprocess_image,
|
110 |
inputs=[image_prompt],
|
111 |
outputs=[image_prompt],
|
112 |
-
).then(
|
113 |
-
activate_button,
|
114 |
-
outputs=[generate_btn],
|
115 |
-
)
|
116 |
-
|
117 |
-
image_prompt.clear(
|
118 |
-
deactivate_button,
|
119 |
-
outputs=[generate_btn],
|
120 |
)
|
121 |
|
122 |
generate_btn.click(
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
+
from gradio_litmodel3d import LitModel3D
|
4 |
|
5 |
import os
|
6 |
from typing import *
|
7 |
+
import numpy as np
|
8 |
import imageio
|
9 |
import uuid
|
10 |
from PIL import Image
|
|
|
38 |
str: The path to the video of the 3D model.
|
39 |
"""
|
40 |
outputs = pipeline(image, formats=["gaussian", "mesh"], preprocess_image=False)
|
41 |
+
video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
|
42 |
+
video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
|
43 |
+
video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
|
44 |
model_id = uuid.uuid4()
|
45 |
video_path = f"/tmp/Trellis-demo/{model_id}.mp4"
|
46 |
os.makedirs(os.path.dirname(video_path), exist_ok=True)
|
47 |
+
imageio.mimsave(video_path, video, fps=15)
|
48 |
model = {'gaussian': outputs['gaussian'][0], 'mesh': outputs['mesh'][0], 'model_id': model_id}
|
49 |
return model, video_path
|
50 |
|
|
|
77 |
|
78 |
|
79 |
with gr.Blocks() as demo:
|
80 |
+
gr.Markdown("""
|
81 |
+
## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
|
82 |
+
* Upload an image and click "Generate" to create a 3D asset. If the image has alpha channel, it be used as the mask. Otherwise, we use `rembg` to remove the background.
|
83 |
+
* If you find the generated 3D asset satisfactory, click "Extract GLB" to extract the GLB file and download it.
|
84 |
+
""")
|
85 |
+
|
86 |
with gr.Row():
|
87 |
with gr.Column():
|
88 |
image_prompt = gr.Image(label="Image Prompt", image_mode="RGBA", type="pil", height=300)
|
89 |
+
generate_btn = gr.Button("Generate")
|
90 |
|
91 |
+
gr.Markdown("GLB Extraction Parameters:")
|
92 |
mesh_simplify = gr.Slider(0.9, 0.98, label="Simplify", value=0.95, step=0.01)
|
93 |
texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
|
94 |
extract_glb_btn = gr.Button("Extract GLB", interactive=False)
|
95 |
|
96 |
with gr.Column():
|
97 |
video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
|
98 |
+
model_output = LitModel3D(label="Extracted GLB", exposure=20.0, height=300)
|
99 |
download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
|
100 |
|
101 |
# Example images at the bottom of the page
|
|
|
106 |
for image in os.listdir("assets/example_image")
|
107 |
],
|
108 |
inputs=[image_prompt],
|
109 |
+
fn=lambda image: preprocess_image(image),
|
110 |
+
outputs=[image_prompt],
|
111 |
run_on_click=True,
|
112 |
examples_per_page=64,
|
113 |
)
|
|
|
119 |
preprocess_image,
|
120 |
inputs=[image_prompt],
|
121 |
outputs=[image_prompt],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
)
|
123 |
|
124 |
generate_btn.click(
|
requirements.txt
CHANGED
@@ -22,6 +22,7 @@ xformers==0.0.27.post2
|
|
22 |
kaolin==0.17.0
|
23 |
spconv-cu120==2.3.6
|
24 |
transformers==4.46.3
|
|
|
25 |
https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.0.post2/flash_attn-2.7.0.post2+cu12torch2.4cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
|
26 |
https://huggingface.co/spaces/JeffreyXiang/TRELLIS/resolve/main/wheels/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl?download=true
|
27 |
https://huggingface.co/spaces/JeffreyXiang/TRELLIS/resolve/main/wheels/nvdiffrast-0.3.3-py3-none-any.whl?download=true
|
|
|
22 |
kaolin==0.17.0
|
23 |
spconv-cu120==2.3.6
|
24 |
transformers==4.46.3
|
25 |
+
gradio_litmodel3d==0.0.1
|
26 |
https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.0.post2/flash_attn-2.7.0.post2+cu12torch2.4cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
|
27 |
https://huggingface.co/spaces/JeffreyXiang/TRELLIS/resolve/main/wheels/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl?download=true
|
28 |
https://huggingface.co/spaces/JeffreyXiang/TRELLIS/resolve/main/wheels/nvdiffrast-0.3.3-py3-none-any.whl?download=true
|
wheels/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl
CHANGED
Binary files a/wheels/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl and b/wheels/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl differ
|
|