Spaces:
Build error
Build error
Update app.py
Browse filesMade changes to the UI
app.py
CHANGED
|
@@ -180,12 +180,10 @@ def run_partcrafter(image_path: str,
|
|
| 180 |
|
| 181 |
"""
|
| 182 |
Generate structured 3D meshes from a 2D image using the PartCrafter pipeline.
|
| 183 |
-
|
| 184 |
This function takes a single 2D image as input and produces a set of part-based 3D meshes,
|
| 185 |
using compositional latent diffusion with attention to structure and part separation.
|
| 186 |
Optionally removes the background using a pretrained background removal model (RMBG),
|
| 187 |
and outputs a merged object mesh.
|
| 188 |
-
|
| 189 |
Args:
|
| 190 |
image_path (str): Path to the input image file on disk.
|
| 191 |
num_parts (int, optional): Number of distinct parts to decompose the object into. Defaults to 1.
|
|
@@ -197,11 +195,9 @@ def run_partcrafter(image_path: str,
|
|
| 197 |
rmbg (bool, optional): Whether to apply background removal before processing. Defaults to True.
|
| 198 |
session_id (str, optional): Optional session ID to manage export paths. If not provided, a random UUID is generated.
|
| 199 |
progress (gr.Progress, optional): Gradio progress object for visual feedback. Automatically handled by Gradio.
|
| 200 |
-
|
| 201 |
Returns:
|
| 202 |
Tuple[str, str, str, str]:
|
| 203 |
- `merged_path` (str): File path to the merged full object mesh (`object.glb`).
|
| 204 |
-
|
| 205 |
Notes:
|
| 206 |
- This function utilizes HuggingFace pretrained weights for both part generation and background removal.
|
| 207 |
- The final output includes merged model parts to visualize object structure.
|
|
@@ -291,9 +287,6 @@ def build_demo():
|
|
| 291 |
gr.HTML(
|
| 292 |
"""
|
| 293 |
<div style="text-align: center;">
|
| 294 |
-
<p style="font-size:16px; display: inline; margin: 0;">
|
| 295 |
-
<strong>PartCrafter</strong> – Structured 3D Mesh Generation via Compositional Latent Diffusion Transformers
|
| 296 |
-
</p>
|
| 297 |
<a href="https://github.com/wgsxm/PartCrafter" style="display: inline-block; vertical-align: middle; margin-left: 0.5em;">
|
| 298 |
<img src="https://img.shields.io/badge/GitHub-Repo-blue" alt="GitHub Repo">
|
| 299 |
</a>
|
|
@@ -310,28 +303,20 @@ def build_demo():
|
|
| 310 |
|
| 311 |
input_image = gr.Image(type="filepath", label="Input Image", height=256)
|
| 312 |
num_parts = gr.Slider(1, MAX_NUM_PARTS, value=4, step=1, label="Number of Parts")
|
| 313 |
-
run_button = gr.Button("Step 1 - 🧩 Craft 3D Parts", variant="primary")
|
| 314 |
-
video_button = gr.Button("Step 2 - 🎥 Generate Split Preview Gif (Optional)")
|
| 315 |
|
| 316 |
-
with gr.Accordion("Advanced Settings", open=False):
|
| 317 |
seed = gr.Number(value=0, label="Random Seed", precision=0)
|
| 318 |
num_tokens = gr.Slider(256, 2048, value=1024, step=64, label="Num Tokens")
|
| 319 |
num_steps = gr.Slider(1, 100, value=50, step=1, label="Inference Steps")
|
| 320 |
guidance = gr.Slider(1.0, 20.0, value=7.0, step=0.1, label="Guidance Scale")
|
| 321 |
flash_decoder = gr.Checkbox(value=False, label="Use Flash Decoder")
|
| 322 |
remove_bg = gr.Checkbox(value=True, label="Remove Background (RMBG)")
|
|
|
|
|
|
|
| 323 |
|
| 324 |
with gr.Column(scale=2):
|
| 325 |
-
gr.
|
| 326 |
-
|
| 327 |
-
<p style="opacity: 0.6; font-style: italic;">
|
| 328 |
-
The 3D Preview might take a few seconds to load the 3D model
|
| 329 |
-
</p>
|
| 330 |
-
"""
|
| 331 |
-
)
|
| 332 |
-
with gr.Row():
|
| 333 |
-
output_model = gr.Model3D(label="Merged 3D Object", height=512, interactive=False)
|
| 334 |
-
video_output = gr.Image(label="Split Preview", height=512)
|
| 335 |
with gr.Row():
|
| 336 |
with gr.Column():
|
| 337 |
examples = gr.Examples(
|
|
@@ -356,8 +341,8 @@ def build_demo():
|
|
| 356 |
|
| 357 |
],
|
| 358 |
inputs=[input_image, num_parts],
|
| 359 |
-
outputs=[output_model
|
| 360 |
-
fn=gen_model_n_video,
|
| 361 |
cache_examples=True
|
| 362 |
)
|
| 363 |
|
|
@@ -365,9 +350,6 @@ def build_demo():
|
|
| 365 |
inputs=[input_image, num_parts, seed, num_tokens, num_steps,
|
| 366 |
guidance, flash_decoder, remove_bg, session_state],
|
| 367 |
outputs=[output_model])
|
| 368 |
-
video_button.click(fn=gen_video,
|
| 369 |
-
inputs=[output_model],
|
| 370 |
-
outputs=[video_output])
|
| 371 |
|
| 372 |
return demo
|
| 373 |
|
|
|
|
| 180 |
|
| 181 |
"""
|
| 182 |
Generate structured 3D meshes from a 2D image using the PartCrafter pipeline.
|
|
|
|
| 183 |
This function takes a single 2D image as input and produces a set of part-based 3D meshes,
|
| 184 |
using compositional latent diffusion with attention to structure and part separation.
|
| 185 |
Optionally removes the background using a pretrained background removal model (RMBG),
|
| 186 |
and outputs a merged object mesh.
|
|
|
|
| 187 |
Args:
|
| 188 |
image_path (str): Path to the input image file on disk.
|
| 189 |
num_parts (int, optional): Number of distinct parts to decompose the object into. Defaults to 1.
|
|
|
|
| 195 |
rmbg (bool, optional): Whether to apply background removal before processing. Defaults to True.
|
| 196 |
session_id (str, optional): Optional session ID to manage export paths. If not provided, a random UUID is generated.
|
| 197 |
progress (gr.Progress, optional): Gradio progress object for visual feedback. Automatically handled by Gradio.
|
|
|
|
| 198 |
Returns:
|
| 199 |
Tuple[str, str, str, str]:
|
| 200 |
- `merged_path` (str): File path to the merged full object mesh (`object.glb`).
|
|
|
|
| 201 |
Notes:
|
| 202 |
- This function utilizes HuggingFace pretrained weights for both part generation and background removal.
|
| 203 |
- The final output includes merged model parts to visualize object structure.
|
|
|
|
| 287 |
gr.HTML(
|
| 288 |
"""
|
| 289 |
<div style="text-align: center;">
|
|
|
|
|
|
|
|
|
|
| 290 |
<a href="https://github.com/wgsxm/PartCrafter" style="display: inline-block; vertical-align: middle; margin-left: 0.5em;">
|
| 291 |
<img src="https://img.shields.io/badge/GitHub-Repo-blue" alt="GitHub Repo">
|
| 292 |
</a>
|
|
|
|
| 303 |
|
| 304 |
input_image = gr.Image(type="filepath", label="Input Image", height=256)
|
| 305 |
num_parts = gr.Slider(1, MAX_NUM_PARTS, value=4, step=1, label="Number of Parts")
|
|
|
|
|
|
|
| 306 |
|
| 307 |
+
with gr.Accordion("Advanced Settings▼", open=False):
|
| 308 |
seed = gr.Number(value=0, label="Random Seed", precision=0)
|
| 309 |
num_tokens = gr.Slider(256, 2048, value=1024, step=64, label="Num Tokens")
|
| 310 |
num_steps = gr.Slider(1, 100, value=50, step=1, label="Inference Steps")
|
| 311 |
guidance = gr.Slider(1.0, 20.0, value=7.0, step=0.1, label="Guidance Scale")
|
| 312 |
flash_decoder = gr.Checkbox(value=False, label="Use Flash Decoder")
|
| 313 |
remove_bg = gr.Checkbox(value=True, label="Remove Background (RMBG)")
|
| 314 |
+
|
| 315 |
+
run_button = gr.Button("🚀 Generate 3D Parts")
|
| 316 |
|
| 317 |
with gr.Column(scale=2):
|
| 318 |
+
output_model = gr.Model3D(label="Merged 3D Object", height=512, interactive=False)
|
| 319 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
with gr.Row():
|
| 321 |
with gr.Column():
|
| 322 |
examples = gr.Examples(
|
|
|
|
| 341 |
|
| 342 |
],
|
| 343 |
inputs=[input_image, num_parts],
|
| 344 |
+
outputs=[output_model],
|
| 345 |
+
fn=lambda img, parts: gen_model_n_video(img, parts)[0],
|
| 346 |
cache_examples=True
|
| 347 |
)
|
| 348 |
|
|
|
|
| 350 |
inputs=[input_image, num_parts, seed, num_tokens, num_steps,
|
| 351 |
guidance, flash_decoder, remove_bg, session_state],
|
| 352 |
outputs=[output_model])
|
|
|
|
|
|
|
|
|
|
| 353 |
|
| 354 |
return demo
|
| 355 |
|