Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,6 @@ import gradio as gr
|
|
2 |
import spaces
|
3 |
from gradio_litmodel3d import LitModel3D
|
4 |
|
5 |
-
import os
|
6 |
-
import shutil
|
7 |
-
import subprocess
|
8 |
-
import sys
|
9 |
-
|
10 |
# Install local wheels at runtime
|
11 |
def install_local_wheels():
|
12 |
"""Install the local wheel files that couldn't be installed during Docker build."""
|
@@ -24,6 +19,8 @@ def install_local_wheels():
|
|
24 |
# Install wheels before importing trellis
|
25 |
install_local_wheels()
|
26 |
|
|
|
|
|
27 |
os.environ['SPCONV_ALGO'] = 'native'
|
28 |
from typing import *
|
29 |
import torch
|
@@ -55,10 +52,8 @@ def end_session(req: gr.Request):
|
|
55 |
def preprocess_image(image: Image.Image) -> Image.Image:
|
56 |
"""
|
57 |
Preprocess the input image.
|
58 |
-
|
59 |
Args:
|
60 |
image (Image.Image): The input image.
|
61 |
-
|
62 |
Returns:
|
63 |
Image.Image: The preprocessed image.
|
64 |
"""
|
@@ -143,7 +138,6 @@ def image_to_3d(
|
|
143 |
) -> Tuple[dict, str]:
|
144 |
"""
|
145 |
Convert an image to a 3D model.
|
146 |
-
|
147 |
Args:
|
148 |
image (Image.Image): The input image.
|
149 |
multiimages (List[Tuple[Image.Image, str]]): The input images in multi-image mode.
|
@@ -154,7 +148,6 @@ def image_to_3d(
|
|
154 |
slat_guidance_strength (float): The guidance strength for structured latent generation.
|
155 |
slat_sampling_steps (int): The number of sampling steps for structured latent generation.
|
156 |
multiimage_algo (Literal["multidiffusion", "stochastic"]): The algorithm for multi-image generation.
|
157 |
-
|
158 |
Returns:
|
159 |
dict: The information of the generated 3D model.
|
160 |
str: The path to the video of the 3D model.
|
@@ -210,12 +203,10 @@ def extract_glb(
|
|
210 |
) -> Tuple[str, str]:
|
211 |
"""
|
212 |
Extract a GLB file from the 3D model.
|
213 |
-
|
214 |
Args:
|
215 |
state (dict): The state of the generated 3D model.
|
216 |
mesh_simplify (float): The mesh simplification factor.
|
217 |
texture_size (int): The texture resolution.
|
218 |
-
|
219 |
Returns:
|
220 |
str: The path to the extracted GLB file.
|
221 |
"""
|
@@ -235,10 +226,8 @@ def extract_glb(
|
|
235 |
def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
|
236 |
"""
|
237 |
Extract a Gaussian file from the 3D model.
|
238 |
-
|
239 |
Args:
|
240 |
state (dict): The state of the generated 3D model.
|
241 |
-
|
242 |
Returns:
|
243 |
str: The path to the extracted Gaussian file.
|
244 |
"""
|
@@ -281,11 +270,11 @@ def split_image(image: Image.Image) -> List[Image.Image]:
|
|
281 |
|
282 |
with gr.Blocks(delete_cache=(600, 600)) as demo:
|
283 |
gr.Markdown("""
|
284 |
-
##
|
285 |
* 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.
|
286 |
* If you find the generated 3D asset satisfactory, click "Extract GLB" to extract the GLB file and download it.
|
287 |
|
288 |
-
✨
|
289 |
""")
|
290 |
|
291 |
with gr.Row():
|
@@ -366,11 +355,11 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
|
|
366 |
demo.unload(end_session)
|
367 |
|
368 |
single_image_input_tab.select(
|
369 |
-
lambda: tuple([False, gr.update(visible=True), gr.update(visible=False)]),
|
370 |
outputs=[is_multiimage, single_image_example, multiimage_example]
|
371 |
)
|
372 |
multiimage_input_tab.select(
|
373 |
-
lambda: tuple([True, gr.update(visible=False), gr.update(visible=True)]),
|
374 |
outputs=[is_multiimage, single_image_example, multiimage_example]
|
375 |
)
|
376 |
|
|
|
2 |
import spaces
|
3 |
from gradio_litmodel3d import LitModel3D
|
4 |
|
|
|
|
|
|
|
|
|
|
|
5 |
# Install local wheels at runtime
|
6 |
def install_local_wheels():
|
7 |
"""Install the local wheel files that couldn't be installed during Docker build."""
|
|
|
19 |
# Install wheels before importing trellis
|
20 |
install_local_wheels()
|
21 |
|
22 |
+
import os
|
23 |
+
import shutil
|
24 |
os.environ['SPCONV_ALGO'] = 'native'
|
25 |
from typing import *
|
26 |
import torch
|
|
|
52 |
def preprocess_image(image: Image.Image) -> Image.Image:
|
53 |
"""
|
54 |
Preprocess the input image.
|
|
|
55 |
Args:
|
56 |
image (Image.Image): The input image.
|
|
|
57 |
Returns:
|
58 |
Image.Image: The preprocessed image.
|
59 |
"""
|
|
|
138 |
) -> Tuple[dict, str]:
|
139 |
"""
|
140 |
Convert an image to a 3D model.
|
|
|
141 |
Args:
|
142 |
image (Image.Image): The input image.
|
143 |
multiimages (List[Tuple[Image.Image, str]]): The input images in multi-image mode.
|
|
|
148 |
slat_guidance_strength (float): The guidance strength for structured latent generation.
|
149 |
slat_sampling_steps (int): The number of sampling steps for structured latent generation.
|
150 |
multiimage_algo (Literal["multidiffusion", "stochastic"]): The algorithm for multi-image generation.
|
|
|
151 |
Returns:
|
152 |
dict: The information of the generated 3D model.
|
153 |
str: The path to the video of the 3D model.
|
|
|
203 |
) -> Tuple[str, str]:
|
204 |
"""
|
205 |
Extract a GLB file from the 3D model.
|
|
|
206 |
Args:
|
207 |
state (dict): The state of the generated 3D model.
|
208 |
mesh_simplify (float): The mesh simplification factor.
|
209 |
texture_size (int): The texture resolution.
|
|
|
210 |
Returns:
|
211 |
str: The path to the extracted GLB file.
|
212 |
"""
|
|
|
226 |
def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
|
227 |
"""
|
228 |
Extract a Gaussian file from the 3D model.
|
|
|
229 |
Args:
|
230 |
state (dict): The state of the generated 3D model.
|
|
|
231 |
Returns:
|
232 |
str: The path to the extracted Gaussian file.
|
233 |
"""
|
|
|
270 |
|
271 |
with gr.Blocks(delete_cache=(600, 600)) as demo:
|
272 |
gr.Markdown("""
|
273 |
+
## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
|
274 |
* 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.
|
275 |
* If you find the generated 3D asset satisfactory, click "Extract GLB" to extract the GLB file and download it.
|
276 |
|
277 |
+
✨New: 1) Experimental multi-image support. 2) Gaussian file extraction.
|
278 |
""")
|
279 |
|
280 |
with gr.Row():
|
|
|
355 |
demo.unload(end_session)
|
356 |
|
357 |
single_image_input_tab.select(
|
358 |
+
lambda: tuple([False, gr.Row.update(visible=True), gr.Row.update(visible=False)]),
|
359 |
outputs=[is_multiimage, single_image_example, multiimage_example]
|
360 |
)
|
361 |
multiimage_input_tab.select(
|
362 |
+
lambda: tuple([True, gr.Row.update(visible=False), gr.Row.update(visible=True)]),
|
363 |
outputs=[is_multiimage, single_image_example, multiimage_example]
|
364 |
)
|
365 |
|