Spaces:
Sleeping
Sleeping
Create app.py (#1)
Browse files- Create app.py (21c61926c2249d7ce8630808ceff8f4453fe87a3)
- add requirements (b8d31c59dcba63498adfb451ac8bd958ba009764)
- app.py +43 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
import gradio as gr
|
| 3 |
+
except ImportError as exc:
|
| 4 |
+
raise ImportError(
|
| 5 |
+
"gradio is required for gradio functionality. "
|
| 6 |
+
"Install it with: pip install embed4d[gradio]"
|
| 7 |
+
) from exc
|
| 8 |
+
|
| 9 |
+
from embed4d import model3d_viewer
|
| 10 |
+
|
| 11 |
+
with gr.Blocks() as demo:
|
| 12 |
+
gr.Markdown("# GLB Viewer: Custom HTML vs Gradio Model3D")
|
| 13 |
+
|
| 14 |
+
with gr.Row():
|
| 15 |
+
with gr.Column():
|
| 16 |
+
gr.Markdown("## Embed 4D (3D + time) — lightweight GLB/GLTF animation")
|
| 17 |
+
file_input = gr.File(file_types=[".glb"], label="Select GLB File")
|
| 18 |
+
with gr.Row():
|
| 19 |
+
with gr.Column():
|
| 20 |
+
gr.Markdown("### Custom HTML Viewer")
|
| 21 |
+
viewer_output_custom = gr.HTML()
|
| 22 |
+
with gr.Column():
|
| 23 |
+
gr.Markdown("### Gradio Model3D")
|
| 24 |
+
viewer_output_model3d = gr.Model3D()
|
| 25 |
+
|
| 26 |
+
# Update HTML viewer
|
| 27 |
+
# `gr.File` is dynamically typed; pylint can't see `.change()`.
|
| 28 |
+
# pylint: disable=no-member
|
| 29 |
+
file_input.change(
|
| 30 |
+
lambda file: model3d_viewer(file.name if file else None),
|
| 31 |
+
inputs=file_input,
|
| 32 |
+
outputs=viewer_output_custom,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Update Model3D viewer (just pass the file path)
|
| 36 |
+
file_input.change(
|
| 37 |
+
lambda file: file.name if file else None,
|
| 38 |
+
inputs=file_input,
|
| 39 |
+
outputs=viewer_output_model3d,
|
| 40 |
+
)
|
| 41 |
+
# pylint: enable=no-member
|
| 42 |
+
|
| 43 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
embed4d[gradio]
|