File size: 18,204 Bytes
db6a3b7
3057b36
db6a3b7
cd41f5f
690b53e
15bf6e6
7d475c1
15bf6e6
 
db6a3b7
15bf6e6
db6a3b7
15bf6e6
 
265efeb
a388355
 
 
15bf6e6
db6a3b7
9880f3d
db6a3b7
 
8e1c768
 
db6a3b7
15bf6e6
bd46f72
cd41f5f
d7b1815
 
15bf6e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd46f72
cd41f5f
15bf6e6
cd41f5f
 
15bf6e6
cd41f5f
15bf6e6
cd41f5f
15bf6e6
 
 
 
cd41f5f
b7b00e2
15bf6e6
 
db894f7
cd41f5f
db6a3b7
b7b00e2
15bf6e6
9880f3d
 
 
 
 
 
 
 
 
 
 
 
 
 
15bf6e6
 
 
9880f3d
 
 
 
 
 
 
 
 
 
 
 
 
265efeb
9880f3d
 
 
 
b7b00e2
9880f3d
cd41f5f
15bf6e6
cd41f5f
 
265efeb
3d94c7d
265efeb
 
3d94c7d
265efeb
 
 
3d94c7d
265efeb
 
 
 
3d94c7d
 
265efeb
 
 
 
 
 
3d94c7d
 
265efeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d94c7d
 
265efeb
a388355
 
265efeb
a388355
3d94c7d
15bf6e6
 
cd41f5f
 
 
 
 
 
f782ff0
 
cd41f5f
265efeb
db6a3b7
265efeb
15bf6e6
 
 
265efeb
15bf6e6
 
 
265efeb
b7b00e2
 
 
 
 
 
 
 
 
 
 
 
 
 
265efeb
15bf6e6
 
 
265efeb
15bf6e6
 
 
 
 
265efeb
15bf6e6
 
265efeb
15bf6e6
 
 
 
 
265efeb
15bf6e6
 
 
 
 
 
 
265efeb
15bf6e6
 
 
 
 
 
 
265efeb
 
 
413af2e
 
265efeb
 
413af2e
265efeb
 
413af2e
265efeb
a388355
265efeb
413af2e
265efeb
 
413af2e
265efeb
 
 
 
 
 
 
9b959b1
a388355
265efeb
 
 
 
 
a388355
265efeb
413af2e
265efeb
9b959b1
265efeb
413af2e
265efeb
a388355
265efeb
 
 
 
15bf6e6
 
 
 
265efeb
15bf6e6
 
 
 
 
 
 
a388355
15bf6e6
a388355
15bf6e6
a388355
15bf6e6
 
 
 
265efeb
 
a388355
15bf6e6
265efeb
15bf6e6
265efeb
 
a388355
15bf6e6
265efeb
 
 
15bf6e6
265efeb
15bf6e6
265efeb
 
15bf6e6
 
 
 
 
 
db6a3b7
b7b00e2
 
15bf6e6
b7b00e2
 
 
 
 
 
 
15bf6e6
265efeb
15bf6e6
265efeb
a388355
265efeb
a388355
15bf6e6
 
265efeb
a388355
15bf6e6
 
 
 
265efeb
 
a388355
15bf6e6
265efeb
 
15bf6e6
265efeb
a388355
15bf6e6
 
265efeb
db6a3b7
15bf6e6
 
 
 
 
 
 
 
 
265efeb
15bf6e6
bd46f72
 
265efeb
15bf6e6
 
 
 
 
 
 
 
 
 
 
 
 
265efeb
15bf6e6
 
 
 
 
 
 
 
 
 
 
 
 
265efeb
15bf6e6
 
 
 
 
 
 
 
 
 
 
 
 
265efeb
15bf6e6
 
 
 
 
265efeb
15bf6e6
 
 
 
265efeb
15bf6e6
 
265efeb
15bf6e6
 
 
 
 
 
 
 
265efeb
15bf6e6
 
 
 
 
265efeb
15bf6e6
 
 
 
 
 
 
 
 
 
265efeb
 
 
 
 
15bf6e6
 
 
 
 
 
265efeb
15bf6e6
 
 
 
 
 
265efeb
15bf6e6
2e78ab8
265efeb
15bf6e6
cd41f5f
 
265efeb
15bf6e6
db6a3b7
15bf6e6
 
db6a3b7
265efeb
db6a3b7
cd41f5f
 
 
 
15bf6e6
 
 
 
 
 
 
265efeb
db6a3b7
15bf6e6
 
 
 
 
265efeb
15bf6e6
265efeb
db6a3b7
265efeb
db6a3b7
15bf6e6
 
 
 
 
265efeb
15bf6e6
265efeb
db6a3b7
265efeb
b7b00e2
 
 
15bf6e6
b7b00e2
15bf6e6
 
db6a3b7
 
 
15bf6e6
265efeb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
import gradio as gr
import spaces
import os
import shutil
os.environ['SPCONV_ALGO'] = 'native'
import tempfile
import numpy as np
import torch
import trimesh
import imageio
from typing import List, Tuple
from PIL import Image
from easydict import EasyDict as edict

# Add missing imports for MagicArticulate API
from gradio_client import Client, handle_file
from gradio_client.exceptions import AppError

# TRELLIS imports
from trellis.pipelines import TrellisImageTo3DPipeline
from trellis.representations import Gaussian, MeshExtractResult
from trellis.utils import render_utils, postprocessing_utils

MAGIC_ARTICULATE_URL = "https://f3fe9e3f800481d9bd.gradio.live"


# Configuration
MAX_SEED = np.iinfo(np.int32).max
TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
os.makedirs(TMP_DIR, exist_ok=True)

# Initialize TRELLIS pipeline globally
pipeline = None

def init_pipeline():
    """Initialize TRELLIS pipeline on first load"""
    global pipeline
    if pipeline is None:
        print("πŸ”„ Loading TRELLIS pipeline...")
        pipeline = TrellisImageTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-image-large")
        pipeline.cuda()
        # Preload rembg
        try:
            pipeline.preprocess_image(Image.fromarray(np.zeros((512, 512, 3), dtype=np.uint8)))
        except:
            pass
        print("βœ… TRELLIS pipeline loaded!")

def start_session(req: gr.Request):
    """Create session directory"""
    user_dir = os.path.join(TMP_DIR, str(req.session_hash))
    os.makedirs(user_dir, exist_ok=True)

def end_session(req: gr.Request):
    """Clean up session directory"""
    user_dir = os.path.join(TMP_DIR, str(req.session_hash))
    try:
        shutil.rmtree(user_dir)
    except:
        pass

def preprocess_image(image: Image.Image) -> Image.Image:
    """Preprocess input image for 3D generation"""
    init_pipeline()
    processed_image = pipeline.preprocess_image(image)
    return processed_image

def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
    """Pack Gaussian and mesh state for storage"""
    return {
        'gaussian': {
            **gs.init_params,
            '_xyz': gs._xyz.cpu().numpy(),
            '_features_dc': gs._features_dc.cpu().numpy(),
            '_scaling': gs._scaling.cpu().numpy(),
            '_rotation': gs._rotation.cpu().numpy(),
            '_opacity': gs._opacity.cpu().numpy(),
        },
        'mesh': {
            'vertices': mesh.vertices.cpu().numpy(),
            'faces': mesh.faces.cpu().numpy(),
        },
    }

def unpack_state(state: dict) -> Tuple[Gaussian, edict]:
    """Unpack Gaussian and mesh state"""
    gs = Gaussian(
        aabb=state['gaussian']['aabb'],
        sh_degree=state['gaussian']['sh_degree'],
        mininum_kernel_size=state['gaussian']['mininum_kernel_size'],
        scaling_bias=state['gaussian']['scaling_bias'],
        opacity_bias=state['gaussian']['opacity_bias'],
        scaling_activation=state['gaussian']['scaling_activation'],
    )
    gs._xyz = torch.tensor(state['gaussian']['_xyz'], device='cuda')
    gs._features_dc = torch.tensor(state['gaussian']['_features_dc'], device='cuda')
    gs._scaling = torch.tensor(state['gaussian']['_scaling'], device='cuda')
    gs._rotation = torch.tensor(state['gaussian']['_rotation'], device='cuda')
    gs._opacity = torch.tensor(state['gaussian']['_opacity'], device='cuda')

    mesh = edict(
        vertices=torch.tensor(state['mesh']['vertices'], device='cuda'),
        faces=torch.tensor(state['mesh']['faces'], device='cuda'),
    )
    return gs, mesh

def get_seed(randomize_seed: bool, seed: int) -> int:
    """Get random seed for generation"""
    return np.random.randint(0, MAX_SEED) if randomize_seed else seed

def call_magic_articulate_api(obj_path: str, api_url: str = MAGIC_ARTICULATE_URL) -> Tuple[str, str, str]:
    """
    Call MagicArticulate Colab API to generate rigging and skeleton from OBJ mesh

    Args:
        obj_path: Path to OBJ file
        api_url: MagicArticulate Colab gradio URL

    Returns:
        Tuple of (rig_pred_path, skeleton_obj_path, info_text)
        - rig_pred_path: Path to generated rig prediction TXT file
        - skeleton_obj_path: Path to generated skeleton OBJ file
        - info_text: Info about rigging results
    """
    try:
        print(f"🦴 Connecting to MagicArticulate API ({api_url})...")
        magic_client = Client(api_url)

        print("πŸ“€ Uploading OBJ to MagicArticulate...")
        result = magic_client.predict(
            input_mesh=handle_file(obj_path),
            api_name="/predict"
        )

        # MagicArticulate returns (rig_pred.txt, skeleton.obj, normalized_mesh.obj)
        rig_pred_file = result[0]
        skeleton_file = result[1]

        print("βœ… MagicArticulate generation successful!")

        # Read skeleton info
        info_text = "Skeleton generated with hierarchical bone ordering"
        if skeleton_file and os.path.exists(skeleton_file):
            skeleton_mesh = trimesh.load(skeleton_file, force='mesh')
            num_vertices = len(skeleton_mesh.vertices)
            info_text = f"Joints: {num_vertices // 2}, Hierarchical structure"

        return rig_pred_file, skeleton_file, info_text

    except AppError as e:
        error_msg = str(e)
        print(f"⚠️ MagicArticulate error: {error_msg}")
        raise
    except Exception as e:
        print(f"⚠️ MagicArticulate API error: {str(e)}")
        raise

@spaces.GPU(duration=180)
def generate_3d_with_rigging(
    image: Image.Image,
    seed: int,
    ss_guidance_strength: float,
    ss_sampling_steps: int,
    slat_guidance_strength: float,
    slat_sampling_steps: int,
    mesh_simplify: float,
    texture_size: int,
    req: gr.Request,
) -> Tuple[dict, str, str, str, str, str, str]:
    """
    Complete pipeline: Image -> 3D Model (TRELLIS) -> OBJ -> Rigging (MagicArticulate)
    """
    try:
        user_dir = os.path.join(TMP_DIR, str(req.session_hash))

        # ============ STEP 1: TRELLIS 3D GENERATION ============
        print("🎨 Generating 3D model with TRELLIS...")
        init_pipeline()

        outputs = pipeline.run(
            image,
            seed=seed,
            formats=["gaussian", "mesh"],
            preprocess_image=False,
            sparse_structure_sampler_params={
                "steps": ss_sampling_steps,
                "cfg_strength": ss_guidance_strength,
            },
            slat_sampler_params={
                "steps": slat_sampling_steps,
                "cfg_strength": slat_guidance_strength,
            },
        )

        # Extract Gaussian and Mesh
        gs = outputs['gaussian'][0]
        mesh = outputs['mesh'][0]

        # ============ STEP 2: RENDER VIDEO ============
        print("πŸ“Ή Rendering 360Β° preview video...")
        video = render_utils.render_video(gs, num_frames=120)['color']
        video_geo = render_utils.render_video(mesh, num_frames=120)['normal']
        video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]

        video_path = os.path.join(user_dir, 'sample.mp4')
        imageio.mimsave(video_path, video, fps=15)

        # ============ STEP 3: EXTRACT GLB ============
        print("🎁 Extracting GLB with textures...")
        glb = postprocessing_utils.to_glb(gs, mesh, simplify=mesh_simplify, texture_size=texture_size, verbose=False)
        glb_path = os.path.join(user_dir, 'sample.glb')
        glb.export(glb_path)

        # ============ STEP 4: CONVERT GLB TO OBJ ============
        print("πŸ”„ Converting GLB to OBJ format...")
        obj_path = os.path.join(user_dir, "model.obj")
        mesh_trimesh = trimesh.load(glb_path, force='mesh')
        original_vertices = len(mesh_trimesh.vertices)
        original_faces = len(mesh_trimesh.faces)
        mesh_trimesh.export(obj_path)

        mesh_info = f"""
πŸ“Š Mesh Statistics:
β€’ Vertices: {original_vertices:,}
β€’ Faces: {original_faces:,}
β€’ Texture Size: {texture_size}px
β€’ Status: βœ“ Ready for rigging
"""

        # ============ STEP 5: MAGIC ARTICULATE RIGGING ============
        print("🦴 Calling MagicArticulate API for automatic skeleton generation...")
        rig_info = ""
        rig_file = None
        skeleton_file = None

        try:
            # Call MagicArticulate Colab API
            rig_result_path, skeleton_result_path, rig_info_text = call_magic_articulate_api(
                obj_path=obj_path,
                api_url=MAGIC_ARTICULATE_URL
            )

            if rig_result_path and os.path.exists(rig_result_path):
                # Copy rig prediction file to user directory
                rig_file = os.path.join(user_dir, 'rig_pred.txt')
                shutil.copy(rig_result_path, rig_file)

            if skeleton_result_path and os.path.exists(skeleton_result_path):
                # Copy skeleton file to user directory
                skeleton_file = os.path.join(user_dir, 'skeleton.obj')
                shutil.copy(skeleton_result_path, skeleton_file)

            rig_info = f"""βœ… MagicArticulate Skeleton Generated:
{rig_info_text}

πŸ“₯ Downloads:
β€’ rig_pred.txt - Joint positions & bone hierarchy
β€’ skeleton.obj - 3D skeleton visualization

πŸ”§ Import into Blender/Maya for animation
"""

        except Exception as e:
            print(f"⚠️ MagicArticulate API error: {str(e)}")
            # Create error file with instructions
            rig_file = os.path.join(user_dir, 'rig_pred.txt')
            with open(rig_file, 'w') as f:
                f.write(f"MagicArticulate Error: {str(e)}\n\n")
                f.write("Workaround: Download OBJ and rig manually in Blender.")

            rig_info = f"⚠️ MagicArticulate API unavailable: {str(e)}\n\n**Solution:** Download OBJ and use Blender Rigify add-on"
            skeleton_file = None

        # ============ STEP 6: PACK RESULTS ============
        print("πŸ“¦ Packaging results...")
        state = pack_state(gs, mesh)
        torch.cuda.empty_cache()

        combined_info = f"""
🎨 TRELLIS Generation:
β€’ Seed: {seed}
β€’ SS Guidance: {ss_guidance_strength}
β€’ SS Steps: {ss_sampling_steps}
β€’ SLAT Guidance: {slat_guidance_strength}
β€’ SLAT Steps: {slat_sampling_steps}

{mesh_info}

{rig_info}

πŸ“₯ Downloads Available:
βœ“ Video preview (360Β° rotation)
βœ“ GLB file (textured 3D model)
βœ“ OBJ file (standard 3D format)
βœ“ Rig prediction (TXT)
βœ“ Skeleton (OBJ)

πŸ”§ Next Steps:
1. Download OBJ + Skeleton files
2. Import into Blender/Maya/C4D
3. Apply rigging from rig_pred.txt
4. Animate your model

πŸ’‘ Pro Tips:
β€’ Skeleton shows joint hierarchy visually
β€’ Rig prediction contains exact joint coordinates
β€’ Model is optimized for animation workflow
"""

        print("βœ… All processing complete!")
        return state, video_path, glb_path, obj_path, rig_file, skeleton_file, combined_info

    except Exception as e:
        import traceback
        error_detail = traceback.format_exc()
        print(f"❌ Error: {str(e)}")
        print(error_detail)
        raise gr.Error(f"❌ Pipeline failed: {str(e)}\n\nDetails:\n{error_detail}")

@spaces.GPU
def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
    """Extract Gaussian splatting file from generated model"""
    user_dir = os.path.join(TMP_DIR, str(req.session_hash))
    gs, _ = unpack_state(state)
    gaussian_path = os.path.join(user_dir, 'sample.ply')
    gs.save_ply(gaussian_path)
    torch.cuda.empty_cache()
    return gaussian_path, gaussian_path

# ============ GRADIO UI ============
with gr.Blocks(title="Image to Rigged 3D Model (MagicArticulate)", delete_cache=(600, 600)) as demo:
    gr.Markdown("""
# 🎭 Image β†’ 3D β†’ Rigging (MagicArticulate Pipeline)

**Automated 3D generation with hierarchical skeleton rigging!**

This unified pipeline combines:
- **TRELLIS** (Image-to-3D, Microsoft Research)
- **MagicArticulate** (Auto-skeleton generation, CVPR 2025)

### πŸš€ Workflow:
1. πŸ“€ Upload image of object/character
2. 🎨 TRELLIS generates high-quality 3D mesh (GPU)
3. πŸ”„ Convert to OBJ format
4. 🦴 MagicArticulate generates hierarchical skeleton
5. πŸ’Ύ Download mesh + rigging + skeleton for animation

### ✨ Benefits:
- βœ… Hierarchical bone ordering for better animation
- βœ… Automatic joint placement and bone connections
- βœ… Production-ready output for Blender/Maya
- βœ… Visual skeleton + rig data included

⏱️ **Estimated time:** 2-5 minutes
""")

    with gr.Row():
        with gr.Column(scale=1):
            gr.Markdown("### πŸ“₯ Input")
            input_image = gr.Image(
                label="Upload Image",
                format="png",
                image_mode="RGBA",
                type="pil",
                height=300
            )

            with gr.Accordion("βš™οΈ TRELLIS Parameters", open=False):
                seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1)
                randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)

                gr.Markdown("**Stage 1: Sparse Structure**")
                ss_guidance = gr.Slider(
                    0.0, 10.0,
                    label="Guidance Strength",
                    value=7.5,
                    step=0.1
                )
                ss_steps = gr.Slider(
                    1, 50,
                    label="Sampling Steps",
                    value=12,
                    step=1
                )

                gr.Markdown("**Stage 2: Structured Latent**")
                slat_guidance = gr.Slider(
                    0.0, 10.0,
                    label="Guidance Strength",
                    value=3.0,
                    step=0.1
                )
                slat_steps = gr.Slider(
                    1, 50,
                    label="Sampling Steps",
                    value=12,
                    step=1
                )

            with gr.Accordion("βš™οΈ Output Settings", open=False):
                mesh_simplify = gr.Slider(
                    0.9, 0.98,
                    label="Mesh Simplification",
                    value=0.95,
                    step=0.01
                )
                texture_size = gr.Slider(
                    512, 2048,
                    label="Texture Size",
                    value=1024,
                    step=512
                )

            generate_btn = gr.Button(
                "πŸš€ Generate Rigged Model",
                variant="primary",
                size="lg"
            )

            extract_gs_btn = gr.Button(
                "πŸ“₯ Extract Gaussian (PLY)",
                interactive=False
            )

        with gr.Column(scale=1):
            gr.Markdown("### πŸ“€ Outputs")

            with gr.Tabs():
                with gr.Tab("πŸ“Ή Preview"):
                    video_output = gr.Video(
                        label="360Β° Preview",
                        autoplay=True,
                        loop=True,
                        height=300
                    )

                with gr.Tab("🎨 3D Viewer"):
                    model_output = gr.Model3D(
                        label="GLB Viewer",
                        height=400
                    )

                with gr.Tab("πŸ“¦ Files"):
                    glb_download = gr.DownloadButton(
                        label="πŸ“₯ Download GLB",
                        interactive=False
                    )
                    obj_download = gr.DownloadButton(
                        label="πŸ“₯ Download OBJ",
                        interactive=False
                    )
                    rig_download = gr.DownloadButton(
                        label="🦴 Download Rig Prediction (TXT)",
                        interactive=False
                    )
                    skeleton_download = gr.DownloadButton(
                        label="🦴 Download Skeleton (OBJ)",
                        interactive=False
                    )
                    gs_download = gr.DownloadButton(
                        label="✨ Download Gaussian (PLY)",
                        interactive=False
                    )

                with gr.Tab("ℹ️ Info"):
                    info_output = gr.Textbox(
                        label="Pipeline Information",
                        lines=20,
                        max_lines=30
                    )

    # State management
    output_buf = gr.State()

    # Event handlers
    demo.load(start_session)
    demo.unload(end_session)

    input_image.upload(
        preprocess_image,
        inputs=[input_image],
        outputs=[input_image],
    )

    generate_btn.click(
        get_seed,
        inputs=[randomize_seed, seed],
        outputs=[seed],
    ).then(
        generate_3d_with_rigging,
        inputs=[
            input_image, seed,
            ss_guidance, ss_steps,
            slat_guidance, slat_steps,
            mesh_simplify, texture_size
        ],
        outputs=[output_buf, video_output, model_output, obj_download, rig_download, skeleton_download, info_output],
    ).then(
        lambda: (
            gr.Button(interactive=True),
            gr.DownloadButton(interactive=True),
            gr.DownloadButton(interactive=True),
            gr.DownloadButton(interactive=True),
            gr.DownloadButton(interactive=True),
        ),
        outputs=[extract_gs_btn, glb_download, obj_download, rig_download, skeleton_download],
    )

    video_output.clear(
        lambda: (
            gr.Button(interactive=False),
            gr.DownloadButton(interactive=False),
            gr.DownloadButton(interactive=False),
            gr.DownloadButton(interactive=False),
            gr.DownloadButton(interactive=False),
        ),
        outputs=[extract_gs_btn, glb_download, obj_download, rig_download, skeleton_download],
    )

    extract_gs_btn.click(
        extract_gaussian,
        inputs=[output_buf],
        outputs=[model_output, gs_download],
    ).then(
        lambda: gr.DownloadButton(interactive=True),
        outputs=[gs_download],
    )

if __name__ == "__main__":
    init_pipeline()
    demo.launch()