Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -220,7 +220,7 @@ def run_triposg(image_path: str,
|
|
220 |
This function takes a single 2D image as input and produces a set of part-based 3D meshes,
|
221 |
using compositional latent diffusion with attention to structure and part separation.
|
222 |
Optionally removes the background using a pretrained background removal model (RMBG),
|
223 |
-
and outputs a merged object mesh, a split preview (exploded view)
|
224 |
|
225 |
Args:
|
226 |
image_path (str): Path to the input image file on disk.
|
@@ -239,7 +239,6 @@ def run_triposg(image_path: str,
|
|
239 |
- `merged_path` (str): File path to the merged full object mesh (`object.glb`).
|
240 |
- `split_preview_path` (str): File path to the exploded-view mesh (`split.glb`).
|
241 |
- `export_dir` (str): Directory where all generated meshes were saved.
|
242 |
-
- `zip_path` (str): Path to the ZIP file containing all individual part meshes.
|
243 |
|
244 |
Notes:
|
245 |
- This function utilizes HuggingFace pretrained weights for both part generation and background removal.
|
@@ -293,12 +292,6 @@ def run_triposg(image_path: str,
|
|
293 |
part = os.path.join(export_dir, f"part_{idx:02}.glb")
|
294 |
mesh.export(part)
|
295 |
parts.append(part)
|
296 |
-
|
297 |
-
zip_path = os.path.join(os.environ["PARTCRAFTER_PROCESSED"], f"{session_id}.zip")
|
298 |
-
|
299 |
-
# shutil.make_archive wants the base name without extension:
|
300 |
-
base_name = zip_path[:-4] # strip off '.zip'
|
301 |
-
shutil.make_archive(base_name, 'zip', export_dir)
|
302 |
|
303 |
# Merge and color
|
304 |
merged = get_colored_mesh_composition(outputs)
|
@@ -310,7 +303,7 @@ def run_triposg(image_path: str,
|
|
310 |
split_preview_path = os.path.join(export_dir, "split.glb")
|
311 |
split_mesh.export(split_preview_path)
|
312 |
|
313 |
-
return merged_path, split_preview_path, export_dir
|
314 |
|
315 |
def cleanup(request: gr.Request):
|
316 |
|
@@ -379,7 +372,6 @@ def build_demo():
|
|
379 |
output_model = gr.Model3D(label="Merged 3D Object", height=512)
|
380 |
split_model = gr.Model3D(label="Split Preview", height=512)
|
381 |
output_dir = gr.Textbox(label="Export Directory", visible=False)
|
382 |
-
download_zip = gr.File(label="Download All Parts (zip)", visible=False)
|
383 |
with gr.Row():
|
384 |
with gr.Column():
|
385 |
examples = gr.Examples(
|
@@ -404,7 +396,7 @@ def build_demo():
|
|
404 |
|
405 |
],
|
406 |
inputs=[input_image, num_parts],
|
407 |
-
outputs=[output_model, split_model, output_dir
|
408 |
fn=run_triposg,
|
409 |
cache_examples=True,
|
410 |
)
|
@@ -412,7 +404,7 @@ def build_demo():
|
|
412 |
run_button.click(fn=run_triposg,
|
413 |
inputs=[input_image, num_parts, seed, num_tokens, num_steps,
|
414 |
guidance, flash_decoder, remove_bg, session_state],
|
415 |
-
outputs=[output_model, split_model, output_dir
|
416 |
return demo
|
417 |
|
418 |
if __name__ == "__main__":
|
|
|
220 |
This function takes a single 2D image as input and produces a set of part-based 3D meshes,
|
221 |
using compositional latent diffusion with attention to structure and part separation.
|
222 |
Optionally removes the background using a pretrained background removal model (RMBG),
|
223 |
+
and outputs a merged object mesh, a split preview (exploded view).
|
224 |
|
225 |
Args:
|
226 |
image_path (str): Path to the input image file on disk.
|
|
|
239 |
- `merged_path` (str): File path to the merged full object mesh (`object.glb`).
|
240 |
- `split_preview_path` (str): File path to the exploded-view mesh (`split.glb`).
|
241 |
- `export_dir` (str): Directory where all generated meshes were saved.
|
|
|
242 |
|
243 |
Notes:
|
244 |
- This function utilizes HuggingFace pretrained weights for both part generation and background removal.
|
|
|
292 |
part = os.path.join(export_dir, f"part_{idx:02}.glb")
|
293 |
mesh.export(part)
|
294 |
parts.append(part)
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
|
296 |
# Merge and color
|
297 |
merged = get_colored_mesh_composition(outputs)
|
|
|
303 |
split_preview_path = os.path.join(export_dir, "split.glb")
|
304 |
split_mesh.export(split_preview_path)
|
305 |
|
306 |
+
return merged_path, split_preview_path, export_dir
|
307 |
|
308 |
def cleanup(request: gr.Request):
|
309 |
|
|
|
372 |
output_model = gr.Model3D(label="Merged 3D Object", height=512)
|
373 |
split_model = gr.Model3D(label="Split Preview", height=512)
|
374 |
output_dir = gr.Textbox(label="Export Directory", visible=False)
|
|
|
375 |
with gr.Row():
|
376 |
with gr.Column():
|
377 |
examples = gr.Examples(
|
|
|
396 |
|
397 |
],
|
398 |
inputs=[input_image, num_parts],
|
399 |
+
outputs=[output_model, split_model, output_dir],
|
400 |
fn=run_triposg,
|
401 |
cache_examples=True,
|
402 |
)
|
|
|
404 |
run_button.click(fn=run_triposg,
|
405 |
inputs=[input_image, num_parts, seed, num_tokens, num_steps,
|
406 |
guidance, flash_decoder, remove_bg, session_state],
|
407 |
+
outputs=[output_model, split_model, output_dir])
|
408 |
return demo
|
409 |
|
410 |
if __name__ == "__main__":
|