Spaces:
Running
on
Zero
Running
on
Zero
Add TestCode
Browse files
app.py
CHANGED
@@ -15,6 +15,9 @@ from trellis.pipelines import TrellisTextTo3DPipeline
|
|
15 |
from trellis.representations import Gaussian, MeshExtractResult
|
16 |
from trellis.utils import render_utils, postprocessing_utils
|
17 |
|
|
|
|
|
|
|
18 |
|
19 |
MAX_SEED = np.iinfo(np.int32).max
|
20 |
TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
|
@@ -103,28 +106,32 @@ def text_to_3d(
|
|
103 |
dict: The information of the generated 3D model.
|
104 |
str: The path to the video of the 3D model.
|
105 |
"""
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
128 |
|
129 |
|
130 |
@spaces.GPU(duration=90)
|
|
|
15 |
from trellis.representations import Gaussian, MeshExtractResult
|
16 |
from trellis.utils import render_utils, postprocessing_utils
|
17 |
|
18 |
+
import traceback
|
19 |
+
import sys
|
20 |
+
|
21 |
|
22 |
MAX_SEED = np.iinfo(np.int32).max
|
23 |
TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
|
|
|
106 |
dict: The information of the generated 3D model.
|
107 |
str: The path to the video of the 3D model.
|
108 |
"""
|
109 |
+
try:
|
110 |
+
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
111 |
+
outputs = pipeline.run(
|
112 |
+
prompt,
|
113 |
+
seed=seed,
|
114 |
+
formats=["gaussian", "mesh"],
|
115 |
+
sparse_structure_sampler_params={
|
116 |
+
"steps": ss_sampling_steps,
|
117 |
+
"cfg_strength": ss_guidance_strength,
|
118 |
+
},
|
119 |
+
slat_sampler_params={
|
120 |
+
"steps": slat_sampling_steps,
|
121 |
+
"cfg_strength": slat_guidance_strength,
|
122 |
+
},
|
123 |
+
)
|
124 |
+
video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
|
125 |
+
video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
|
126 |
+
video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
|
127 |
+
video_path = os.path.join(user_dir, 'sample.mp4')
|
128 |
+
imageio.mimsave(video_path, video, fps=15)
|
129 |
+
state = pack_state(outputs['gaussian'][0], outputs['mesh'][0])
|
130 |
+
torch.cuda.empty_cache()
|
131 |
+
return state, video_path
|
132 |
+
except Exception as e:
|
133 |
+
et, ev, tb = sys.exc_info()
|
134 |
+
traceback.print_tb(tb)
|
135 |
|
136 |
|
137 |
@spaces.GPU(duration=90)
|