File size: 1,391 Bytes
98eddcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
try:
    import gradio as gr
except ImportError as exc:
    raise ImportError(
        "gradio is required for gradio functionality. "
        "Install it with: pip install embed4d[gradio]"
    ) from exc

from embed4d import model3d_viewer

with gr.Blocks() as demo:
    gr.Markdown("# GLB Viewer: Custom HTML vs Gradio Model3D")

    with gr.Row():
        with gr.Column():
            gr.Markdown("## Embed 4D (3D + time) — lightweight GLB/GLTF animation")
            file_input = gr.File(file_types=[".glb"], label="Select GLB File")
            with gr.Row():
                with gr.Column():
                    gr.Markdown("### Custom HTML Viewer")
                    viewer_output_custom = gr.HTML()
                with gr.Column():
                    gr.Markdown("### Gradio Model3D")
                    viewer_output_model3d = gr.Model3D()

    # Update HTML viewer
    # `gr.File` is dynamically typed; pylint can't see `.change()`.
    # pylint: disable=no-member
    file_input.change(
        lambda file: model3d_viewer(file.name if file else None),
        inputs=file_input,
        outputs=viewer_output_custom,
    )

    # Update Model3D viewer (just pass the file path)
    file_input.change(
        lambda file: file.name if file else None,
        inputs=file_input,
        outputs=viewer_output_model3d,
    )
    # pylint: enable=no-member

demo.launch()