alexnasa commited on
Commit
824b10c
·
verified ·
1 Parent(s): c856a58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -169,8 +169,6 @@ def run_triposg(image_path: str,
169
  if mesh is None:
170
  outputs[i] = trimesh.Trimesh(vertices=[[0,0,0]], faces=[[0,0,0]])
171
 
172
- # Merge and color
173
- merged = get_colored_mesh_composition(outputs)
174
 
175
  export_dir = os.path.join(os.environ["PARTCRAFTER_PROCESSED"], session_id)
176
  os.makedirs(export_dir, exist_ok=True)
@@ -181,13 +179,23 @@ def run_triposg(image_path: str,
181
  part = os.path.join(export_dir, f"part_{idx:02}.glb")
182
  mesh.export(part)
183
  parts.append(part)
 
 
 
 
 
 
 
 
 
 
184
 
185
  glb_path = os.path.join(export_dir, "object.glb")
186
  merged.export(glb_path)
187
 
188
  mesh_file = first_file_from_dir(export_dir, "glb")
189
 
190
- return mesh_file, export_dir
191
 
192
  def cleanup(request: gr.Request):
193
 
@@ -254,6 +262,7 @@ def build_demo():
254
  )
255
  output_model = gr.Model3D(label="Merged 3D Object")
256
  output_dir = gr.Textbox(label="Export Directory", visible=False)
 
257
  examples = gr.Examples(
258
 
259
  examples=[
@@ -262,8 +271,8 @@ def build_demo():
262
  5,
263
  ],
264
  [
265
- "assets/images/np5_bird.png",
266
- 5,
267
  ],
268
  [
269
  "assets/images/np4_7bd5d25aa77b4fb18e780d7a4c97d342.png",
@@ -271,7 +280,7 @@ def build_demo():
271
  ],
272
  ],
273
  inputs=[input_image, num_parts],
274
- outputs=[output_model, output_dir],
275
  fn=run_triposg,
276
  cache_examples=True,
277
  )
@@ -279,7 +288,7 @@ def build_demo():
279
  run_button.click(fn=run_triposg,
280
  inputs=[input_image, num_parts, seed, num_tokens, num_steps,
281
  guidance, flash_decoder, remove_bg, session_state],
282
- outputs=[output_model, output_dir])
283
  return demo
284
 
285
  if __name__ == "__main__":
 
169
  if mesh is None:
170
  outputs[i] = trimesh.Trimesh(vertices=[[0,0,0]], faces=[[0,0,0]])
171
 
 
 
172
 
173
  export_dir = os.path.join(os.environ["PARTCRAFTER_PROCESSED"], session_id)
174
  os.makedirs(export_dir, exist_ok=True)
 
179
  part = os.path.join(export_dir, f"part_{idx:02}.glb")
180
  mesh.export(part)
181
  parts.append(part)
182
+
183
+ zip_path = os.path.join(os.environ["PARTCRAFTER_PROCESSED"], f"{session_id}.zip")
184
+
185
+ # shutil.make_archive wants the base name without extension:
186
+ base_name = zip_path[:-4] # strip off '.zip'
187
+ shutil.make_archive(base_name, 'zip', export_dir)
188
+
189
+ # Merge and color
190
+ merged = get_colored_mesh_composition(outputs)
191
+
192
 
193
  glb_path = os.path.join(export_dir, "object.glb")
194
  merged.export(glb_path)
195
 
196
  mesh_file = first_file_from_dir(export_dir, "glb")
197
 
198
+ return mesh_file, export_dir, zip_path
199
 
200
  def cleanup(request: gr.Request):
201
 
 
262
  )
263
  output_model = gr.Model3D(label="Merged 3D Object")
264
  output_dir = gr.Textbox(label="Export Directory", visible=False)
265
+ download_zip = gr.File(label="Download All Parts (zip)")
266
  examples = gr.Examples(
267
 
268
  examples=[
 
271
  5,
272
  ],
273
  [
274
+ "assets/images/np7_1c004909dedb4ebe8db69b4d7b077434.png",
275
+ 7,
276
  ],
277
  [
278
  "assets/images/np4_7bd5d25aa77b4fb18e780d7a4c97d342.png",
 
280
  ],
281
  ],
282
  inputs=[input_image, num_parts],
283
+ outputs=[output_model, output_dir, download_zip],
284
  fn=run_triposg,
285
  cache_examples=True,
286
  )
 
288
  run_button.click(fn=run_triposg,
289
  inputs=[input_image, num_parts, seed, num_tokens, num_steps,
290
  guidance, flash_decoder, remove_bg, session_state],
291
+ outputs=[output_model, output_dir, download_zip])
292
  return demo
293
 
294
  if __name__ == "__main__":