Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- README.md +22 -65
- app.py +8 -65
- space.py +10 -66
- src/README.md +22 -65
- src/backend/gradio_model4dgs/model4dgs.py +2 -0
- src/backend/gradio_model4dgs/templates/component/index.js +0 -0
- src/demo/app.py +8 -64
- src/demo/space.py +10 -66
- src/frontend/Index.svelte +2 -0
- src/frontend/shared/Model4DGS.svelte +3 -1
- src/pyproject.toml +1 -1
README.md
CHANGED
@@ -26,73 +26,17 @@ pip install gradio_model4dgs
|
|
26 |
import gradio as gr
|
27 |
from gradio_model4dgs import Model4DGS
|
28 |
import os
|
29 |
-
from PIL import Image
|
30 |
-
import hashlib
|
31 |
|
32 |
-
|
33 |
-
if control_image is None:
|
34 |
-
raise gr.Error("Please select or upload an input image")
|
35 |
|
36 |
-
if
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
</div>
|
45 |
-
We introduce DreamGaussian4D, an efficient 4D generation framework that builds on 4D Gaussian Splatting representation.
|
46 |
-
'''
|
47 |
-
|
48 |
-
# load images in 'assets' folder as examples
|
49 |
-
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
50 |
-
examples_img = None
|
51 |
-
|
52 |
-
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
53 |
-
examples_4d = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.ply')]
|
54 |
-
examples_img = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.png')]
|
55 |
-
else:
|
56 |
-
examples_4d = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
57 |
-
|
58 |
-
def optimize(image_block: Image.Image):
|
59 |
-
# temporarily only show tiger
|
60 |
-
return f'{os.path.join(os.path.dirname(__file__), "logs")}/tiger.glb', examples_4d
|
61 |
-
|
62 |
-
# Compose demo layout & data flow
|
63 |
-
with gr.Blocks(title=_TITLE, theme=gr.themes.Soft()) as demo:
|
64 |
-
with gr.Row():
|
65 |
-
with gr.Column(scale=1):
|
66 |
-
gr.Markdown('# ' + _TITLE)
|
67 |
-
gr.Markdown(_DESCRIPTION)
|
68 |
-
|
69 |
-
with gr.Row(variant='panel'):
|
70 |
-
left_column = gr.Column(scale=5)
|
71 |
-
with left_column:
|
72 |
-
image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Input image')
|
73 |
-
|
74 |
-
preprocess_chk = gr.Checkbox(True,
|
75 |
-
label='Preprocess image automatically (remove background and recenter object)')
|
76 |
-
|
77 |
-
with gr.Column(scale=5):
|
78 |
-
obj3d = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Final)")
|
79 |
-
obj4d = Model4DGS(label="4D Model")
|
80 |
-
|
81 |
-
with left_column:
|
82 |
-
gr.Examples(
|
83 |
-
examples=examples_img, # NOTE: elements must match inputs list!
|
84 |
-
inputs=image_block,
|
85 |
-
outputs=obj3d,
|
86 |
-
fn=optimize,
|
87 |
-
label='Examples (click one of the images below to start)',
|
88 |
-
examples_per_page=40
|
89 |
-
)
|
90 |
-
img_run_btn = gr.Button("Generate 4D")
|
91 |
-
|
92 |
-
# if there is an input image, continue with inference
|
93 |
-
# else display an error message
|
94 |
-
img_run_btn.click(check_img_input, inputs=[image_block], queue=False).success(
|
95 |
-
optimize, inputs=[image_block], outputs=[obj3d, obj4d])
|
96 |
|
97 |
if __name__ == "__main__":
|
98 |
demo.launch(share=True)
|
@@ -125,6 +69,19 @@ str | Callable | None
|
|
125 |
<td align="left">path to (.splat) file to show in model4DGS viewer. If callable, the function will be called whenever the app loads to set the initial value of the component.</td>
|
126 |
</tr>
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
<tr>
|
129 |
<td align="left"><code>height</code></td>
|
130 |
<td align="left" style="width: 25%;">
|
|
|
26 |
import gradio as gr
|
27 |
from gradio_model4dgs import Model4DGS
|
28 |
import os
|
|
|
|
|
29 |
|
30 |
+
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
|
|
|
|
31 |
|
32 |
+
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
33 |
+
examples = [os.path.join(image_dir, file) for file in os.listdir(image_dir)]
|
34 |
+
else:
|
35 |
+
examples = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
36 |
+
|
37 |
+
with gr.Blocks() as demo:
|
38 |
+
with gr.Row():
|
39 |
+
Model4DGS(value=examples, label="4D Model", fps=8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
if __name__ == "__main__":
|
42 |
demo.launch(share=True)
|
|
|
69 |
<td align="left">path to (.splat) file to show in model4DGS viewer. If callable, the function will be called whenever the app loads to set the initial value of the component.</td>
|
70 |
</tr>
|
71 |
|
72 |
+
<tr>
|
73 |
+
<td align="left"><code>fps</code></td>
|
74 |
+
<td align="left" style="width: 25%;">
|
75 |
+
|
76 |
+
```python
|
77 |
+
float
|
78 |
+
```
|
79 |
+
|
80 |
+
</td>
|
81 |
+
<td align="left"><code>8</code></td>
|
82 |
+
<td align="left">None</td>
|
83 |
+
</tr>
|
84 |
+
|
85 |
<tr>
|
86 |
<td align="left"><code>height</code></td>
|
87 |
<td align="left" style="width: 25%;">
|
app.py
CHANGED
@@ -1,74 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
from gradio_model4dgs import Model4DGS
|
3 |
import os
|
4 |
-
from PIL import Image
|
5 |
-
import hashlib
|
6 |
|
7 |
-
|
8 |
-
if control_image is None:
|
9 |
-
raise gr.Error("Please select or upload an input image")
|
10 |
|
11 |
-
if
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
<div>
|
16 |
-
<a style="display:inline-block" href="https://jiawei-ren.github.io/projects/dreamgaussian4d/"><img src='https://img.shields.io/badge/public_website-8A2BE2'></a>
|
17 |
-
<a style="display:inline-block; margin-left: .5em" href="https://arxiv.org/abs/2312.17142"><img src="https://img.shields.io/badge/2309.16653-f9f7f7?logo=data:image/png;base64,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"></a>
|
18 |
-
<a style="display:inline-block; margin-left: .5em" href='https://github.com/jiawei-ren/dreamgaussian4d'><img src='https://img.shields.io/github/stars/jiawei-ren/dreamgaussian4d?style=social'/></a>
|
19 |
-
</div>
|
20 |
-
We introduce DreamGaussian4D, an efficient 4D generation framework that builds on 4D Gaussian Splatting representation.
|
21 |
-
'''
|
22 |
-
|
23 |
-
# load images in 'assets' folder as examples
|
24 |
-
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
25 |
-
examples_img = None
|
26 |
-
|
27 |
-
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
28 |
-
examples_4d = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.ply')]
|
29 |
-
examples_img = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.png')]
|
30 |
-
else:
|
31 |
-
examples_4d = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
32 |
-
|
33 |
-
def optimize(image_block: Image.Image):
|
34 |
-
# temporarily only show tiger
|
35 |
-
return f'{os.path.join(os.path.dirname(__file__), "logs")}/tiger_rgba.glb', examples_4d
|
36 |
-
|
37 |
-
# Compose demo layout & data flow
|
38 |
-
with gr.Blocks(title=_TITLE, theme=gr.themes.Soft()) as demo:
|
39 |
-
with gr.Row():
|
40 |
-
with gr.Column(scale=1):
|
41 |
-
gr.Markdown('# ' + _TITLE)
|
42 |
-
gr.Markdown(_DESCRIPTION)
|
43 |
-
|
44 |
-
with gr.Row(variant='panel'):
|
45 |
-
left_column = gr.Column(scale=5)
|
46 |
-
with left_column:
|
47 |
-
image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Input image')
|
48 |
-
|
49 |
-
preprocess_chk = gr.Checkbox(True,
|
50 |
-
label='Preprocess image automatically (remove background and recenter object)')
|
51 |
-
|
52 |
-
with gr.Column(scale=5):
|
53 |
-
obj3d = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Final)")
|
54 |
-
obj4d = Model4DGS(label="4D Model")
|
55 |
-
|
56 |
-
with left_column:
|
57 |
-
gr.Examples(
|
58 |
-
examples=examples_img, # NOTE: elements must match inputs list!
|
59 |
-
inputs=image_block,
|
60 |
-
outputs=obj3d,
|
61 |
-
fn=optimize,
|
62 |
-
cache_examples=False,
|
63 |
-
label='Examples (click one of the images below to start)',
|
64 |
-
examples_per_page=40
|
65 |
-
)
|
66 |
-
img_run_btn = gr.Button("Generate 4D")
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
optimize, inputs=[image_block], outputs=[obj3d, obj4d])
|
72 |
|
73 |
if __name__ == "__main__":
|
74 |
demo.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_model4dgs import Model4DGS
|
3 |
import os
|
|
|
|
|
4 |
|
5 |
+
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
|
|
|
|
6 |
|
7 |
+
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
8 |
+
examples = [os.path.join(image_dir, file) for file in os.listdir(image_dir)]
|
9 |
+
else:
|
10 |
+
examples = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
with gr.Blocks() as demo:
|
13 |
+
with gr.Row():
|
14 |
+
Model4DGS(value=examples, label="4D Model", fps=8)
|
|
|
15 |
|
16 |
if __name__ == "__main__":
|
17 |
demo.launch(share=True)
|
space.py
CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
|
|
3 |
from app import demo as app
|
4 |
import os
|
5 |
|
6 |
-
_docs = {'Model4DGS': {'description': 'Component allows users to upload or view 4D Gaussian Splatting files (.splat).', 'members': {'__init__': {'value': {'type': 'str | Callable | None', 'default': 'None', 'description': 'path to (.splat) file to show in model4DGS viewer. If callable, the function will be called whenever the app loads to set the initial value of the component.'}, 'height': {'type': 'int | None', 'default': 'None', 'description': 'height of the model4DGS component, in pixels.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int', 'default': '160', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}}, 'postprocess': {'value': {'type': 'List[str] | str | None', 'description': "The output data received by the component from the user's function in the backend."}}, 'preprocess': {'return': {'type': 'List[str] | None', 'description': "The preprocessed input data sent to the user's function in the backend."}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the Model4DGS changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'upload': {'type': None, 'default': None, 'description': 'This listener is triggered when the user uploads a file into the Model4DGS.'}, 'edit': {'type': None, 'default': None, 'description': 'This listener is triggered when the user edits the Model4DGS (e.g. image) using the built-in editor.'}, 'clear': {'type': None, 'default': None, 'description': 'This listener is triggered when the user clears the Model4DGS using the X button for the component.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Model4DGS': []}}}
|
7 |
|
8 |
abs_path = os.path.join(os.path.dirname(__file__), "css.css")
|
9 |
|
@@ -41,73 +41,17 @@ pip install gradio_model4dgs
|
|
41 |
import gradio as gr
|
42 |
from gradio_model4dgs import Model4DGS
|
43 |
import os
|
44 |
-
from PIL import Image
|
45 |
-
import hashlib
|
46 |
|
47 |
-
|
48 |
-
if control_image is None:
|
49 |
-
raise gr.Error("Please select or upload an input image")
|
50 |
|
51 |
-
if
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
</div>
|
60 |
-
We introduce DreamGaussian4D, an efficient 4D generation framework that builds on 4D Gaussian Splatting representation.
|
61 |
-
'''
|
62 |
-
|
63 |
-
# load images in 'assets' folder as examples
|
64 |
-
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
65 |
-
examples_img = None
|
66 |
-
|
67 |
-
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
68 |
-
examples_4d = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.ply')]
|
69 |
-
examples_img = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.png')]
|
70 |
-
else:
|
71 |
-
examples_4d = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
72 |
-
|
73 |
-
def optimize(image_block: Image.Image):
|
74 |
-
# temporarily only show tiger
|
75 |
-
return f'{os.path.join(os.path.dirname(__file__), "logs")}/tiger.glb', examples_4d
|
76 |
-
|
77 |
-
# Compose demo layout & data flow
|
78 |
-
with gr.Blocks(title=_TITLE, theme=gr.themes.Soft()) as demo:
|
79 |
-
with gr.Row():
|
80 |
-
with gr.Column(scale=1):
|
81 |
-
gr.Markdown('# ' + _TITLE)
|
82 |
-
gr.Markdown(_DESCRIPTION)
|
83 |
-
|
84 |
-
with gr.Row(variant='panel'):
|
85 |
-
left_column = gr.Column(scale=5)
|
86 |
-
with left_column:
|
87 |
-
image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Input image')
|
88 |
-
|
89 |
-
preprocess_chk = gr.Checkbox(True,
|
90 |
-
label='Preprocess image automatically (remove background and recenter object)')
|
91 |
-
|
92 |
-
with gr.Column(scale=5):
|
93 |
-
obj3d = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Final)")
|
94 |
-
obj4d = Model4DGS(label="4D Model")
|
95 |
-
|
96 |
-
with left_column:
|
97 |
-
gr.Examples(
|
98 |
-
examples=examples_img, # NOTE: elements must match inputs list!
|
99 |
-
inputs=image_block,
|
100 |
-
outputs=obj3d,
|
101 |
-
fn=optimize,
|
102 |
-
label='Examples (click one of the images below to start)',
|
103 |
-
examples_per_page=40
|
104 |
-
)
|
105 |
-
img_run_btn = gr.Button("Generate 4D")
|
106 |
-
|
107 |
-
# if there is an input image, continue with inference
|
108 |
-
# else display an error message
|
109 |
-
img_run_btn.click(check_img_input, inputs=[image_block], queue=False).success(
|
110 |
-
optimize, inputs=[image_block], outputs=[obj3d, obj4d])
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
demo.launch(share=True)
|
|
|
3 |
from app import demo as app
|
4 |
import os
|
5 |
|
6 |
+
_docs = {'Model4DGS': {'description': 'Component allows users to upload or view 4D Gaussian Splatting files (.splat).', 'members': {'__init__': {'value': {'type': 'str | Callable | None', 'default': 'None', 'description': 'path to (.splat) file to show in model4DGS viewer. If callable, the function will be called whenever the app loads to set the initial value of the component.'}, 'fps': {'type': 'float', 'default': '8', 'description': None}, 'height': {'type': 'int | None', 'default': 'None', 'description': 'height of the model4DGS component, in pixels.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int', 'default': '160', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}}, 'postprocess': {'value': {'type': 'List[str] | str | None', 'description': "The output data received by the component from the user's function in the backend."}}, 'preprocess': {'return': {'type': 'List[str] | None', 'description': "The preprocessed input data sent to the user's function in the backend."}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the Model4DGS changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'upload': {'type': None, 'default': None, 'description': 'This listener is triggered when the user uploads a file into the Model4DGS.'}, 'edit': {'type': None, 'default': None, 'description': 'This listener is triggered when the user edits the Model4DGS (e.g. image) using the built-in editor.'}, 'clear': {'type': None, 'default': None, 'description': 'This listener is triggered when the user clears the Model4DGS using the X button for the component.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Model4DGS': []}}}
|
7 |
|
8 |
abs_path = os.path.join(os.path.dirname(__file__), "css.css")
|
9 |
|
|
|
41 |
import gradio as gr
|
42 |
from gradio_model4dgs import Model4DGS
|
43 |
import os
|
|
|
|
|
44 |
|
45 |
+
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
|
|
|
|
46 |
|
47 |
+
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
48 |
+
examples = [os.path.join(image_dir, file) for file in os.listdir(image_dir)]
|
49 |
+
else:
|
50 |
+
examples = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
51 |
+
|
52 |
+
with gr.Blocks() as demo:
|
53 |
+
with gr.Row():
|
54 |
+
Model4DGS(value=examples, label="4D Model", fps=8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
if __name__ == "__main__":
|
57 |
demo.launch(share=True)
|
src/README.md
CHANGED
@@ -26,73 +26,17 @@ pip install gradio_model4dgs
|
|
26 |
import gradio as gr
|
27 |
from gradio_model4dgs import Model4DGS
|
28 |
import os
|
29 |
-
from PIL import Image
|
30 |
-
import hashlib
|
31 |
|
32 |
-
|
33 |
-
if control_image is None:
|
34 |
-
raise gr.Error("Please select or upload an input image")
|
35 |
|
36 |
-
if
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
</div>
|
45 |
-
We introduce DreamGaussian4D, an efficient 4D generation framework that builds on 4D Gaussian Splatting representation.
|
46 |
-
'''
|
47 |
-
|
48 |
-
# load images in 'assets' folder as examples
|
49 |
-
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
50 |
-
examples_img = None
|
51 |
-
|
52 |
-
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
53 |
-
examples_4d = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.ply')]
|
54 |
-
examples_img = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.png')]
|
55 |
-
else:
|
56 |
-
examples_4d = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
57 |
-
|
58 |
-
def optimize(image_block: Image.Image):
|
59 |
-
# temporarily only show tiger
|
60 |
-
return f'{os.path.join(os.path.dirname(__file__), "logs")}/tiger.glb', examples_4d
|
61 |
-
|
62 |
-
# Compose demo layout & data flow
|
63 |
-
with gr.Blocks(title=_TITLE, theme=gr.themes.Soft()) as demo:
|
64 |
-
with gr.Row():
|
65 |
-
with gr.Column(scale=1):
|
66 |
-
gr.Markdown('# ' + _TITLE)
|
67 |
-
gr.Markdown(_DESCRIPTION)
|
68 |
-
|
69 |
-
with gr.Row(variant='panel'):
|
70 |
-
left_column = gr.Column(scale=5)
|
71 |
-
with left_column:
|
72 |
-
image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Input image')
|
73 |
-
|
74 |
-
preprocess_chk = gr.Checkbox(True,
|
75 |
-
label='Preprocess image automatically (remove background and recenter object)')
|
76 |
-
|
77 |
-
with gr.Column(scale=5):
|
78 |
-
obj3d = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Final)")
|
79 |
-
obj4d = Model4DGS(label="4D Model")
|
80 |
-
|
81 |
-
with left_column:
|
82 |
-
gr.Examples(
|
83 |
-
examples=examples_img, # NOTE: elements must match inputs list!
|
84 |
-
inputs=image_block,
|
85 |
-
outputs=obj3d,
|
86 |
-
fn=optimize,
|
87 |
-
label='Examples (click one of the images below to start)',
|
88 |
-
examples_per_page=40
|
89 |
-
)
|
90 |
-
img_run_btn = gr.Button("Generate 4D")
|
91 |
-
|
92 |
-
# if there is an input image, continue with inference
|
93 |
-
# else display an error message
|
94 |
-
img_run_btn.click(check_img_input, inputs=[image_block], queue=False).success(
|
95 |
-
optimize, inputs=[image_block], outputs=[obj3d, obj4d])
|
96 |
|
97 |
if __name__ == "__main__":
|
98 |
demo.launch(share=True)
|
@@ -125,6 +69,19 @@ str | Callable | None
|
|
125 |
<td align="left">path to (.splat) file to show in model4DGS viewer. If callable, the function will be called whenever the app loads to set the initial value of the component.</td>
|
126 |
</tr>
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
<tr>
|
129 |
<td align="left"><code>height</code></td>
|
130 |
<td align="left" style="width: 25%;">
|
|
|
26 |
import gradio as gr
|
27 |
from gradio_model4dgs import Model4DGS
|
28 |
import os
|
|
|
|
|
29 |
|
30 |
+
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
|
|
|
|
31 |
|
32 |
+
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
33 |
+
examples = [os.path.join(image_dir, file) for file in os.listdir(image_dir)]
|
34 |
+
else:
|
35 |
+
examples = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
36 |
+
|
37 |
+
with gr.Blocks() as demo:
|
38 |
+
with gr.Row():
|
39 |
+
Model4DGS(value=examples, label="4D Model", fps=8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
if __name__ == "__main__":
|
42 |
demo.launch(share=True)
|
|
|
69 |
<td align="left">path to (.splat) file to show in model4DGS viewer. If callable, the function will be called whenever the app loads to set the initial value of the component.</td>
|
70 |
</tr>
|
71 |
|
72 |
+
<tr>
|
73 |
+
<td align="left"><code>fps</code></td>
|
74 |
+
<td align="left" style="width: 25%;">
|
75 |
+
|
76 |
+
```python
|
77 |
+
float
|
78 |
+
```
|
79 |
+
|
80 |
+
</td>
|
81 |
+
<td align="left"><code>8</code></td>
|
82 |
+
<td align="left">None</td>
|
83 |
+
</tr>
|
84 |
+
|
85 |
<tr>
|
86 |
<td align="left"><code>height</code></td>
|
87 |
<td align="left" style="width: 25%;">
|
src/backend/gradio_model4dgs/model4dgs.py
CHANGED
@@ -32,6 +32,7 @@ class Model4DGS(Component):
|
|
32 |
self,
|
33 |
value: str | Callable | None = None,
|
34 |
*,
|
|
|
35 |
height: int | None = None,
|
36 |
label: str | None = None,
|
37 |
show_label: bool | None = None,
|
@@ -51,6 +52,7 @@ class Model4DGS(Component):
|
|
51 |
height: height of the model4DGS component, in pixels.
|
52 |
"""
|
53 |
self.height = height
|
|
|
54 |
super().__init__(
|
55 |
label=label,
|
56 |
every=every,
|
|
|
32 |
self,
|
33 |
value: str | Callable | None = None,
|
34 |
*,
|
35 |
+
fps: float = 8,
|
36 |
height: int | None = None,
|
37 |
label: str | None = None,
|
38 |
show_label: bool | None = None,
|
|
|
52 |
height: height of the model4DGS component, in pixels.
|
53 |
"""
|
54 |
self.height = height
|
55 |
+
self.fps=fps
|
56 |
super().__init__(
|
57 |
label=label,
|
58 |
every=every,
|
src/backend/gradio_model4dgs/templates/component/index.js
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
src/demo/app.py
CHANGED
@@ -1,73 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
from gradio_model4dgs import Model4DGS
|
3 |
import os
|
4 |
-
from PIL import Image
|
5 |
-
import hashlib
|
6 |
|
7 |
-
|
8 |
-
if control_image is None:
|
9 |
-
raise gr.Error("Please select or upload an input image")
|
10 |
|
11 |
-
if
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
<div>
|
16 |
-
<a style="display:inline-block" href="https://jiawei-ren.github.io/projects/dreamgaussian4d/"><img src='https://img.shields.io/badge/public_website-8A2BE2'></a>
|
17 |
-
<a style="display:inline-block; margin-left: .5em" href="https://arxiv.org/abs/2312.17142"><img src="https://img.shields.io/badge/2309.16653-f9f7f7?logo=data:image/png;base64,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"></a>
|
18 |
-
<a style="display:inline-block; margin-left: .5em" href='https://github.com/jiawei-ren/dreamgaussian4d'><img src='https://img.shields.io/github/stars/jiawei-ren/dreamgaussian4d?style=social'/></a>
|
19 |
-
</div>
|
20 |
-
We introduce DreamGaussian4D, an efficient 4D generation framework that builds on 4D Gaussian Splatting representation.
|
21 |
-
'''
|
22 |
-
|
23 |
-
# load images in 'assets' folder as examples
|
24 |
-
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
25 |
-
examples_img = None
|
26 |
-
|
27 |
-
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
28 |
-
examples_4d = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.ply')]
|
29 |
-
examples_img = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.png')]
|
30 |
-
else:
|
31 |
-
examples_4d = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
32 |
-
|
33 |
-
def optimize(image_block: Image.Image):
|
34 |
-
# temporarily only show tiger
|
35 |
-
return f'{os.path.join(os.path.dirname(__file__), "logs")}/tiger.glb', examples_4d
|
36 |
-
|
37 |
-
# Compose demo layout & data flow
|
38 |
-
with gr.Blocks(title=_TITLE, theme=gr.themes.Soft()) as demo:
|
39 |
-
with gr.Row():
|
40 |
-
with gr.Column(scale=1):
|
41 |
-
gr.Markdown('# ' + _TITLE)
|
42 |
-
gr.Markdown(_DESCRIPTION)
|
43 |
-
|
44 |
-
with gr.Row(variant='panel'):
|
45 |
-
left_column = gr.Column(scale=5)
|
46 |
-
with left_column:
|
47 |
-
image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Input image')
|
48 |
-
|
49 |
-
preprocess_chk = gr.Checkbox(True,
|
50 |
-
label='Preprocess image automatically (remove background and recenter object)')
|
51 |
-
|
52 |
-
with gr.Column(scale=5):
|
53 |
-
obj3d = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Final)")
|
54 |
-
obj4d = Model4DGS(label="4D Model")
|
55 |
-
|
56 |
-
with left_column:
|
57 |
-
gr.Examples(
|
58 |
-
examples=examples_img, # NOTE: elements must match inputs list!
|
59 |
-
inputs=image_block,
|
60 |
-
outputs=obj3d,
|
61 |
-
fn=optimize,
|
62 |
-
label='Examples (click one of the images below to start)',
|
63 |
-
examples_per_page=40
|
64 |
-
)
|
65 |
-
img_run_btn = gr.Button("Generate 4D")
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
optimize, inputs=[image_block], outputs=[obj3d, obj4d])
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
demo.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_model4dgs import Model4DGS
|
3 |
import os
|
|
|
|
|
4 |
|
5 |
+
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
|
|
|
|
6 |
|
7 |
+
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
8 |
+
examples = [os.path.join(image_dir, file) for file in os.listdir(image_dir)]
|
9 |
+
else:
|
10 |
+
examples = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
with gr.Blocks() as demo:
|
13 |
+
with gr.Row():
|
14 |
+
Model4DGS(value=examples, label="4D Model", fps=8)
|
|
|
15 |
|
16 |
if __name__ == "__main__":
|
17 |
demo.launch(share=True)
|
src/demo/space.py
CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
|
|
3 |
from app import demo as app
|
4 |
import os
|
5 |
|
6 |
-
_docs = {'Model4DGS': {'description': 'Component allows users to upload or view 4D Gaussian Splatting files (.splat).', 'members': {'__init__': {'value': {'type': 'str | Callable | None', 'default': 'None', 'description': 'path to (.splat) file to show in model4DGS viewer. If callable, the function will be called whenever the app loads to set the initial value of the component.'}, 'height': {'type': 'int | None', 'default': 'None', 'description': 'height of the model4DGS component, in pixels.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int', 'default': '160', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}}, 'postprocess': {'value': {'type': 'List[str] | str | None', 'description': "The output data received by the component from the user's function in the backend."}}, 'preprocess': {'return': {'type': 'List[str] | None', 'description': "The preprocessed input data sent to the user's function in the backend."}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the Model4DGS changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'upload': {'type': None, 'default': None, 'description': 'This listener is triggered when the user uploads a file into the Model4DGS.'}, 'edit': {'type': None, 'default': None, 'description': 'This listener is triggered when the user edits the Model4DGS (e.g. image) using the built-in editor.'}, 'clear': {'type': None, 'default': None, 'description': 'This listener is triggered when the user clears the Model4DGS using the X button for the component.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Model4DGS': []}}}
|
7 |
|
8 |
abs_path = os.path.join(os.path.dirname(__file__), "css.css")
|
9 |
|
@@ -41,73 +41,17 @@ pip install gradio_model4dgs
|
|
41 |
import gradio as gr
|
42 |
from gradio_model4dgs import Model4DGS
|
43 |
import os
|
44 |
-
from PIL import Image
|
45 |
-
import hashlib
|
46 |
|
47 |
-
|
48 |
-
if control_image is None:
|
49 |
-
raise gr.Error("Please select or upload an input image")
|
50 |
|
51 |
-
if
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
</div>
|
60 |
-
We introduce DreamGaussian4D, an efficient 4D generation framework that builds on 4D Gaussian Splatting representation.
|
61 |
-
'''
|
62 |
-
|
63 |
-
# load images in 'assets' folder as examples
|
64 |
-
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
65 |
-
examples_img = None
|
66 |
-
|
67 |
-
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
68 |
-
examples_4d = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.ply')]
|
69 |
-
examples_img = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.png')]
|
70 |
-
else:
|
71 |
-
examples_4d = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
72 |
-
|
73 |
-
def optimize(image_block: Image.Image):
|
74 |
-
# temporarily only show tiger
|
75 |
-
return f'{os.path.join(os.path.dirname(__file__), "logs")}/tiger.glb', examples_4d
|
76 |
-
|
77 |
-
# Compose demo layout & data flow
|
78 |
-
with gr.Blocks(title=_TITLE, theme=gr.themes.Soft()) as demo:
|
79 |
-
with gr.Row():
|
80 |
-
with gr.Column(scale=1):
|
81 |
-
gr.Markdown('# ' + _TITLE)
|
82 |
-
gr.Markdown(_DESCRIPTION)
|
83 |
-
|
84 |
-
with gr.Row(variant='panel'):
|
85 |
-
left_column = gr.Column(scale=5)
|
86 |
-
with left_column:
|
87 |
-
image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Input image')
|
88 |
-
|
89 |
-
preprocess_chk = gr.Checkbox(True,
|
90 |
-
label='Preprocess image automatically (remove background and recenter object)')
|
91 |
-
|
92 |
-
with gr.Column(scale=5):
|
93 |
-
obj3d = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Final)")
|
94 |
-
obj4d = Model4DGS(label="4D Model")
|
95 |
-
|
96 |
-
with left_column:
|
97 |
-
gr.Examples(
|
98 |
-
examples=examples_img, # NOTE: elements must match inputs list!
|
99 |
-
inputs=image_block,
|
100 |
-
outputs=obj3d,
|
101 |
-
fn=optimize,
|
102 |
-
label='Examples (click one of the images below to start)',
|
103 |
-
examples_per_page=40
|
104 |
-
)
|
105 |
-
img_run_btn = gr.Button("Generate 4D")
|
106 |
-
|
107 |
-
# if there is an input image, continue with inference
|
108 |
-
# else display an error message
|
109 |
-
img_run_btn.click(check_img_input, inputs=[image_block], queue=False).success(
|
110 |
-
optimize, inputs=[image_block], outputs=[obj3d, obj4d])
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
demo.launch(share=True)
|
|
|
3 |
from app import demo as app
|
4 |
import os
|
5 |
|
6 |
+
_docs = {'Model4DGS': {'description': 'Component allows users to upload or view 4D Gaussian Splatting files (.splat).', 'members': {'__init__': {'value': {'type': 'str | Callable | None', 'default': 'None', 'description': 'path to (.splat) file to show in model4DGS viewer. If callable, the function will be called whenever the app loads to set the initial value of the component.'}, 'fps': {'type': 'float', 'default': '8', 'description': None}, 'height': {'type': 'int | None', 'default': 'None', 'description': 'height of the model4DGS component, in pixels.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int', 'default': '160', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}}, 'postprocess': {'value': {'type': 'List[str] | str | None', 'description': "The output data received by the component from the user's function in the backend."}}, 'preprocess': {'return': {'type': 'List[str] | None', 'description': "The preprocessed input data sent to the user's function in the backend."}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the Model4DGS changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'upload': {'type': None, 'default': None, 'description': 'This listener is triggered when the user uploads a file into the Model4DGS.'}, 'edit': {'type': None, 'default': None, 'description': 'This listener is triggered when the user edits the Model4DGS (e.g. image) using the built-in editor.'}, 'clear': {'type': None, 'default': None, 'description': 'This listener is triggered when the user clears the Model4DGS using the X button for the component.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Model4DGS': []}}}
|
7 |
|
8 |
abs_path = os.path.join(os.path.dirname(__file__), "css.css")
|
9 |
|
|
|
41 |
import gradio as gr
|
42 |
from gradio_model4dgs import Model4DGS
|
43 |
import os
|
|
|
|
|
44 |
|
45 |
+
image_dir = os.path.join(os.path.dirname(__file__), "assets")
|
|
|
|
|
46 |
|
47 |
+
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
|
48 |
+
examples = [os.path.join(image_dir, file) for file in os.listdir(image_dir)]
|
49 |
+
else:
|
50 |
+
examples = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
|
51 |
+
|
52 |
+
with gr.Blocks() as demo:
|
53 |
+
with gr.Row():
|
54 |
+
Model4DGS(value=examples, label="4D Model", fps=8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
if __name__ == "__main__":
|
57 |
demo.launch(share=True)
|
src/frontend/Index.svelte
CHANGED
@@ -26,6 +26,7 @@
|
|
26 |
export let min_width: number | undefined = undefined;
|
27 |
export let gradio: Gradio;
|
28 |
export let height: number | undefined = undefined;
|
|
|
29 |
|
30 |
let dragging = false;
|
31 |
</script>
|
@@ -53,6 +54,7 @@
|
|
53 |
{show_label}
|
54 |
{root}
|
55 |
{proxy_url}
|
|
|
56 |
/>
|
57 |
{:else}
|
58 |
<BlockLabel {show_label} Icon={File} label={label || "Splat"} />
|
|
|
26 |
export let min_width: number | undefined = undefined;
|
27 |
export let gradio: Gradio;
|
28 |
export let height: number | undefined = undefined;
|
29 |
+
export let fps=8;
|
30 |
|
31 |
let dragging = false;
|
32 |
</script>
|
|
|
54 |
{show_label}
|
55 |
{root}
|
56 |
{proxy_url}
|
57 |
+
{fps}
|
58 |
/>
|
59 |
{:else}
|
60 |
<BlockLabel {show_label} Icon={File} label={label || "Splat"} />
|
src/frontend/shared/Model4DGS.svelte
CHANGED
@@ -13,6 +13,8 @@
|
|
13 |
export let label = "";
|
14 |
export let show_label: boolean;
|
15 |
export let i18n: I18nFormatter;
|
|
|
|
|
16 |
|
17 |
let currFrameIndex = 0;
|
18 |
let NUM_FRAMES = 1;
|
@@ -55,7 +57,7 @@
|
|
55 |
requestAnimationFrame(update);
|
56 |
const timeDelta = performance.now() - startTime;
|
57 |
|
58 |
-
if (timeDelta >
|
59 |
const prevSplatScene = viewer.getSplatScene(currFrameIndex);
|
60 |
prevSplatScene.scale.copy(invisible_scale);
|
61 |
|
|
|
13 |
export let label = "";
|
14 |
export let show_label: boolean;
|
15 |
export let i18n: I18nFormatter;
|
16 |
+
export let fps=8;
|
17 |
+
|
18 |
|
19 |
let currFrameIndex = 0;
|
20 |
let NUM_FRAMES = 1;
|
|
|
57 |
requestAnimationFrame(update);
|
58 |
const timeDelta = performance.now() - startTime;
|
59 |
|
60 |
+
if (timeDelta > 1000/fps) {
|
61 |
const prevSplatScene = viewer.getSplatScene(currFrameIndex);
|
62 |
prevSplatScene.scale.copy(invisible_scale);
|
63 |
|
src/pyproject.toml
CHANGED
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
|
|
8 |
|
9 |
[project]
|
10 |
name = "gradio_model4dgs"
|
11 |
-
version = "0.0.
|
12 |
description = "Python library for easily interacting with trained machine learning models"
|
13 |
readme = "README.md"
|
14 |
license = "MIT"
|
|
|
8 |
|
9 |
[project]
|
10 |
name = "gradio_model4dgs"
|
11 |
+
version = "0.0.5"
|
12 |
description = "Python library for easily interacting with trained machine learning models"
|
13 |
readme = "README.md"
|
14 |
license = "MIT"
|