cronos3k commited on
Commit
37c335c
·
verified ·
1 Parent(s): 6ab7fac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -119,8 +119,8 @@ def image_to_3d(
119
  "cfg_strength": slat_guidance_strength,
120
  },
121
  )
122
- video = render_utils.render_video(outputs['gaussian'][0], num_frames=10)['color']
123
- video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=10)['normal']
124
  video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
125
  trial_id = str(uuid.uuid4())
126
  video_path = os.path.join(user_dir, f"{trial_id}.mp4")
@@ -130,26 +130,19 @@ def image_to_3d(
130
  return state, video_path
131
 
132
  @spaces.GPU
133
- def extract_full_glb(
134
  state: dict,
135
  req: gr.Request,
136
  ) -> Tuple[str, str]:
137
  """
138
- Extract a full-quality GLB file from the 3D model.
 
139
  """
140
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
141
  gs, mesh, trial_id = unpack_state(state)
142
 
143
- glb = postprocessing_utils.to_glb(
144
- gs, mesh,
145
- simplify=0.0, # No simplification
146
- fill_holes=True,
147
- fill_holes_max_size=0.04,
148
- texture_size=2048, # Maximum texture resolution
149
- verbose=False
150
- )
151
  glb_path = os.path.join(user_dir, f"{trial_id}_full.glb")
152
- glb.export(glb_path)
153
  return glb_path, glb_path
154
 
155
  @spaces.GPU
@@ -160,7 +153,7 @@ def extract_glb(
160
  req: gr.Request,
161
  ) -> Tuple[str, str]:
162
  """
163
- Extract a reduced-quality GLB file from the 3D model.
164
  """
165
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
166
  gs, mesh, trial_id = unpack_state(state)
@@ -174,7 +167,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
174
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
175
  * 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.
176
  * After generation:
177
- * Click "Extract Full GLB" for maximum quality (no mesh reduction)
178
  * Or use the GLB Extraction Settings for a reduced size version
179
  """)
180
 
@@ -201,7 +194,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
201
  mesh_simplify = gr.Slider(0.0, 0.98, label="Simplify", value=0.95, step=0.01)
202
  texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
203
 
204
- extract_glb_btn = gr.Button("Extract Reduced GLB", interactive=False)
205
 
206
  with gr.Column():
207
  video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
@@ -250,7 +243,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
250
  )
251
 
252
  extract_full_btn.click(
253
- extract_full_glb,
254
  inputs=[output_buf],
255
  outputs=[model_output, download_full],
256
  ).then(
 
119
  "cfg_strength": slat_guidance_strength,
120
  },
121
  )
122
+ video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
123
+ video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
124
  video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
125
  trial_id = str(uuid.uuid4())
126
  video_path = os.path.join(user_dir, f"{trial_id}.mp4")
 
130
  return state, video_path
131
 
132
  @spaces.GPU
133
+ def export_full_quality_glb(
134
  state: dict,
135
  req: gr.Request,
136
  ) -> Tuple[str, str]:
137
  """
138
+ Export a full-quality GLB file from the 3D model state.
139
+ Uses the optimized export_full_quality_glb from postprocessing utils.
140
  """
141
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
142
  gs, mesh, trial_id = unpack_state(state)
143
 
 
 
 
 
 
 
 
 
144
  glb_path = os.path.join(user_dir, f"{trial_id}_full.glb")
145
+ postprocessing_utils.export_full_quality_glb(gs, mesh, glb_path)
146
  return glb_path, glb_path
147
 
148
  @spaces.GPU
 
153
  req: gr.Request,
154
  ) -> Tuple[str, str]:
155
  """
156
+ Extract a GLB file from the 3D model with reduction settings.
157
  """
158
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
159
  gs, mesh, trial_id = unpack_state(state)
 
167
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
168
  * 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.
169
  * After generation:
170
+ * Extract full-quality GLB for maximum detail
171
  * Or use the GLB Extraction Settings for a reduced size version
172
  """)
173
 
 
194
  mesh_simplify = gr.Slider(0.0, 0.98, label="Simplify", value=0.95, step=0.01)
195
  texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
196
 
197
+ extract_glb_btn = gr.Button("Extract GLB", interactive=False)
198
 
199
  with gr.Column():
200
  video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
 
243
  )
244
 
245
  extract_full_btn.click(
246
+ export_full_quality_glb,
247
  inputs=[output_buf],
248
  outputs=[model_output, download_full],
249
  ).then(