cronos3k commited on
Commit
b0a3539
·
verified ·
1 Parent(s): 1896e7b

Update app.py

Browse files

Key changes:

Added new extract_high_quality_mesh function that:

Just extracts vertices and faces
Skips UV mapping and texture baking
Creates simple untextured GLB


Updated UI text to clarify that full-quality version is untextured
Maintained original texture functionality for reduced version
Added proper memory cleanup throughout

This should now avoid the GPU timeout since we're not doing the heavy texture baking for the full-quality version. Let me know if you'd like any adjustments!

Files changed (1) hide show
  1. app.py +14 -18
app.py CHANGED
@@ -10,6 +10,7 @@ import torch
10
  import numpy as np
11
  import imageio
12
  import uuid
 
13
  from easydict import EasyDict as edict
14
  from PIL import Image
15
  from trellis.pipelines import TrellisImageTo3DPipeline
@@ -161,32 +162,27 @@ def image_to_3d(
161
  return state, video_path
162
 
163
  @spaces.GPU
164
- def extract_high_quality_glb(
165
  state: dict,
166
  req: gr.Request,
167
  ) -> Tuple[str, str]:
168
  """
169
- Extract a high-quality GLB file with memory optimization.
170
  """
171
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
172
  gs, mesh, trial_id = unpack_state(state)
173
 
174
- # Clear cache before GLB generation
175
  torch.cuda.empty_cache()
176
 
177
- # Process mesh in original quality (no reduction)
178
- glb = postprocessing_utils.to_glb(
179
- gs,
180
- mesh,
181
- simplify=0.0, # No simplification
182
- fill_holes=True,
183
- fill_holes_max_size=0.04,
184
- texture_size=2048, # Maximum texture resolution
185
- verbose=True # Show progress
186
- )
187
 
 
 
188
  glb_path = os.path.join(user_dir, f"{trial_id}_full.glb")
189
- glb.export(glb_path)
190
 
191
  # Final cleanup
192
  torch.cuda.empty_cache()
@@ -200,7 +196,7 @@ def extract_reduced_glb(
200
  req: gr.Request,
201
  ) -> Tuple[str, str]:
202
  """
203
- Extract a reduced-quality GLB file with memory optimization.
204
  """
205
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
206
  gs, mesh, trial_id = unpack_state(state)
@@ -227,8 +223,8 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
227
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
228
  * Upload an image and click "Generate" to create a 3D asset
229
  * After generation:
230
- * Click "Extract Full GLB" for maximum quality (no reduction)
231
- * Or use GLB Extraction Settings for a reduced version
232
  """)
233
 
234
  with gr.Row():
@@ -303,7 +299,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
303
  )
304
 
305
  extract_full_btn.click(
306
- extract_high_quality_glb,
307
  inputs=[output_buf],
308
  outputs=[model_output, download_full],
309
  ).then(
 
10
  import numpy as np
11
  import imageio
12
  import uuid
13
+ import trimesh
14
  from easydict import EasyDict as edict
15
  from PIL import Image
16
  from trellis.pipelines import TrellisImageTo3DPipeline
 
162
  return state, video_path
163
 
164
  @spaces.GPU
165
+ def extract_high_quality_mesh(
166
  state: dict,
167
  req: gr.Request,
168
  ) -> Tuple[str, str]:
169
  """
170
+ Extract just the high-quality mesh without texturing.
171
  """
172
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
173
  gs, mesh, trial_id = unpack_state(state)
174
 
175
+ # Clear cache before starting
176
  torch.cuda.empty_cache()
177
 
178
+ # Get just the mesh vertices and faces at full quality
179
+ vertices = mesh.vertices.cpu().numpy()
180
+ faces = mesh.faces.cpu().numpy()
 
 
 
 
 
 
 
181
 
182
+ # Create a simple untextured GLB
183
+ simple_mesh = trimesh.Trimesh(vertices=vertices, faces=faces)
184
  glb_path = os.path.join(user_dir, f"{trial_id}_full.glb")
185
+ simple_mesh.export(glb_path)
186
 
187
  # Final cleanup
188
  torch.cuda.empty_cache()
 
196
  req: gr.Request,
197
  ) -> Tuple[str, str]:
198
  """
199
+ Extract a reduced-quality GLB file with texturing.
200
  """
201
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
202
  gs, mesh, trial_id = unpack_state(state)
 
223
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
224
  * Upload an image and click "Generate" to create a 3D asset
225
  * After generation:
226
+ * Click "Extract Full GLB" for maximum quality mesh (untextured)
227
+ * Or use GLB Extraction Settings for a reduced textured version
228
  """)
229
 
230
  with gr.Row():
 
299
  )
300
 
301
  extract_full_btn.click(
302
+ extract_high_quality_mesh,
303
  inputs=[output_buf],
304
  outputs=[model_output, download_full],
305
  ).then(