cronos3k commited on
Commit
dbd61ff
·
verified ·
1 Parent(s): f3eb6b9

Update app.py

Browse files

Key changes:

Removed the hole-filling option that wasn't working
Added textured high-quality mesh option that applies textures to the full quality mesh
Updated UI text and buttons to reflect the three working options:

Raw Mesh: Maximum detail, untext

Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -172,7 +172,7 @@ def extract_high_quality_mesh(
172
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
173
 
174
  # Get the raw mesh data from state
175
- vertices = state['mesh']['vertices'] # Already in numpy format from pack_state
176
  faces = state['mesh']['faces']
177
  trial_id = state['trial_id']
178
 
@@ -188,29 +188,34 @@ def extract_high_quality_mesh(
188
  return glb_path, glb_path
189
 
190
  @spaces.GPU
191
- def extract_high_quality_mesh_with_holes_filled(
192
  state: dict,
193
  req: gr.Request,
194
  ) -> Tuple[str, str]:
195
  """
196
- Save mesh data with hole filling but no other processing.
197
  """
198
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
199
  gs, mesh, trial_id = unpack_state(state)
200
 
201
- # Use to_glb only for hole filling
202
- raw_mesh = postprocessing_utils.to_glb(
 
 
 
203
  gs,
204
  mesh,
205
- simplify=0.0, # No simplification
206
- fill_holes=True, # Enable hole filling
 
207
  fill_holes_max_size=0.04,
208
  verbose=True
209
  )
210
 
211
- glb_path = os.path.join(user_dir, f"{trial_id}_filled.glb")
212
- raw_mesh.export(glb_path)
213
 
 
214
  return glb_path, glb_path
215
 
216
  @spaces.GPU
@@ -248,8 +253,8 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
248
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
249
  * Upload an image and click "Generate" to create a 3D asset
250
  * After generation, choose from three export options:
251
- * Raw Mesh: Maximum detail, untextured, may have holes
252
- * Filled Mesh: Maximum detail, untextured, holes filled
253
  * Reduced GLB: Reduced size with textures
254
  """)
255
 
@@ -271,7 +276,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
271
 
272
  generate_btn = gr.Button("Generate")
273
  extract_raw_btn = gr.Button("Extract Raw Mesh", interactive=False)
274
- extract_filled_btn = gr.Button("Extract Filled Mesh", interactive=False)
275
 
276
  with gr.Accordion(label="GLB Extraction Settings", open=False):
277
  mesh_simplify = gr.Slider(0.0, 0.98, label="Simplify", value=0.95, step=0.01)
@@ -285,7 +290,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
285
  gr.Markdown("### Download Options")
286
  with gr.Row():
287
  download_raw = gr.DownloadButton(label="Download Raw Mesh", interactive=False)
288
- download_filled = gr.DownloadButton(label="Download Filled Mesh", interactive=False)
289
  download_reduced = gr.DownloadButton(label="Download Reduced GLB", interactive=False)
290
 
291
  output_buf = gr.State()
@@ -325,8 +330,8 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
325
  ).then(
326
  lambda: [gr.Button(interactive=True), gr.Button(interactive=True), gr.Button(interactive=True),
327
  gr.Button(interactive=False), gr.Button(interactive=False), gr.Button(interactive=False)],
328
- outputs=[extract_raw_btn, extract_filled_btn, extract_reduced_btn,
329
- download_raw, download_filled, download_reduced],
330
  )
331
 
332
  extract_raw_btn.click(
@@ -338,13 +343,13 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
338
  outputs=[download_raw],
339
  )
340
 
341
- extract_filled_btn.click(
342
- extract_high_quality_mesh_with_holes_filled,
343
  inputs=[output_buf],
344
- outputs=[model_output, download_filled],
345
  ).then(
346
  lambda: gr.Button(interactive=True),
347
- outputs=[download_filled],
348
  )
349
 
350
  extract_reduced_btn.click(
 
172
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
173
 
174
  # Get the raw mesh data from state
175
+ vertices = state['mesh']['vertices']
176
  faces = state['mesh']['faces']
177
  trial_id = state['trial_id']
178
 
 
188
  return glb_path, glb_path
189
 
190
  @spaces.GPU
191
+ def extract_textured_high_quality_mesh(
192
  state: dict,
193
  req: gr.Request,
194
  ) -> Tuple[str, str]:
195
  """
196
+ Save raw high-quality mesh with textures but no mesh simplification.
197
  """
198
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
199
  gs, mesh, trial_id = unpack_state(state)
200
 
201
+ # Clear cache before starting
202
+ torch.cuda.empty_cache()
203
+
204
+ # Use to_glb with texturing but no simplification
205
+ glb = postprocessing_utils.to_glb(
206
  gs,
207
  mesh,
208
+ simplify=0.0, # Keep full quality
209
+ texture_size=2048, # Maximum texture resolution
210
+ fill_holes=True,
211
  fill_holes_max_size=0.04,
212
  verbose=True
213
  )
214
 
215
+ glb_path = os.path.join(user_dir, f"{trial_id}_full_textured.glb")
216
+ glb.export(glb_path)
217
 
218
+ torch.cuda.empty_cache()
219
  return glb_path, glb_path
220
 
221
  @spaces.GPU
 
253
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
254
  * Upload an image and click "Generate" to create a 3D asset
255
  * After generation, choose from three export options:
256
+ * Raw Mesh: Maximum detail, untextured
257
+ * Full Textured: Maximum detail with textures
258
  * Reduced GLB: Reduced size with textures
259
  """)
260
 
 
276
 
277
  generate_btn = gr.Button("Generate")
278
  extract_raw_btn = gr.Button("Extract Raw Mesh", interactive=False)
279
+ extract_textured_btn = gr.Button("Extract Full Textured", interactive=False)
280
 
281
  with gr.Accordion(label="GLB Extraction Settings", open=False):
282
  mesh_simplify = gr.Slider(0.0, 0.98, label="Simplify", value=0.95, step=0.01)
 
290
  gr.Markdown("### Download Options")
291
  with gr.Row():
292
  download_raw = gr.DownloadButton(label="Download Raw Mesh", interactive=False)
293
+ download_textured = gr.DownloadButton(label="Download Full Textured", interactive=False)
294
  download_reduced = gr.DownloadButton(label="Download Reduced GLB", interactive=False)
295
 
296
  output_buf = gr.State()
 
330
  ).then(
331
  lambda: [gr.Button(interactive=True), gr.Button(interactive=True), gr.Button(interactive=True),
332
  gr.Button(interactive=False), gr.Button(interactive=False), gr.Button(interactive=False)],
333
+ outputs=[extract_raw_btn, extract_textured_btn, extract_reduced_btn,
334
+ download_raw, download_textured, download_reduced],
335
  )
336
 
337
  extract_raw_btn.click(
 
343
  outputs=[download_raw],
344
  )
345
 
346
+ extract_textured_btn.click(
347
+ extract_textured_high_quality_mesh,
348
  inputs=[output_buf],
349
+ outputs=[model_output, download_textured],
350
  ).then(
351
  lambda: gr.Button(interactive=True),
352
+ outputs=[download_textured],
353
  )
354
 
355
  extract_reduced_btn.click(