Spaces:
Runtime error
Runtime error
metadata
title: gradio-model4dgs
colorFrom: purple
colorTo: yellow
sdk: gradio
sdk_version: 4.29.0
app_file: app.py
pinned: false
license: mit
gradio_model4dgs
Python library for easily interacting with trained machine learning models
Installation
pip install gradio_model4dgs
Usage
import gradio as gr
from gradio_model4dgs import Model4DGS
import os
from PIL import Image
import hashlib
def check_img_input(control_image):
if control_image is None:
raise gr.Error("Please select or upload an input image")
if __name__ == "__main__":
_TITLE = '''DreamGaussian: Generative Gaussian Splatting for Efficient 3D Content Creation'''
_DESCRIPTION = '''
<div>
<a style="display:inline-block" href="https://jiawei-ren.github.io/projects/dreamgaussian4d/"><img src='https://img.shields.io/badge/public_website-8A2BE2'></a>
<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,iVBORw0KGgoAAAANSUhEUgAAADcAAABMCAYAAADJPi9EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAuIwAALiMBeKU/dgAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAa2SURBVHja3Zt7bBRFGMAXUCDGF4rY7m7bAwuhlggKStFgLBgFEkCIIRJEEoOBYHwRFYKilUgEReVNJEGCJJpehHI3M9vZvd3bUP1DjNhEIRQQsQgSHiJgQZ5dv7krWEvvdmZ7d7vHJN+ft/f99pv5XvOtJMFCqvoCUpTdIEeRLC+L9Ox5i3Q9LACaCeK0kXoSChVcD3C/tQPHpAEsquQ73IkUcEz2kcLCknyGW5MGjkljRFVL8xJOKyi4CwCOuQAeAkfTP1+tNxLkogvgEbDgffkJqKqvuMA5ifOpqg/5qWecRstNg7xoUTI1Fovdxg8oy2s5AP8CGeYHmGngeZaOL4I4LXLcpHg4149/GDz4xqgsb+UAbMKKUpkrqHA43MUyyJpWUK0EHeG2YKRXr7tB+QMcgGewLD+ebTDbtrtbBt7UPlhS4rV4IvcDI7J8P1OeA/AcAI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wDuFOJc1Na6sRWL/cCeMIwUN9ggSVbe3v/5/EgzTKWLvEAiBrYRUkgwNI2ZaFQNT75UDxEUEx97zYnzpmiLEmbaYCbNxYtFAb0/Z4AztgUrhyxuNgxPnhfHFDHz/vTgFWUQZxTRkkJhQ6YNdVUEPAfO6ZV5BRss6LcCVb7VaAma9giy0XJZBt9IQh42NY0NSdgbLIPlLUF6rEdrdt0CUCK1wsCbkcI3ZSLc7ZSwGLbmJXbPsNxnE5xilYKAobZ77LpGZ8TAIun+/iCKQoF71IxQDI3K2CCd+ARNvXg9sykBcnHAoCZG4u66hlDoQLe6QV4CRtFSxZQ+D0BwNO2jgdkzoGoah1nj3FVlSR19taTSYxI8QLut23U8dsgzqHulJNCQpcqBnpTALCuQ6NSYLHpmR5i42gZzuIdcrMMvMJbQlxe3jXxyZnLACl7ARm/FjPIDOY8ODtpM71sxwfcZpvBeUzKWmfNINM5AS+wO0Khh7dMqKccu4+qatarZjYAwDlgetzStHtEt+XedsBOQtU9XMrRgjg4KTnc5nr+dmqadit/4C4uLm8DuA9koJTj1TL7fI5nDL+qqoo/FLGAzL7dYT17PzvAcQONYSUQRxW/QMrHZVIyik0ZuQA2mzp+Ji8BW4YM3Mbzm9inaHkJCGfrUZZjujiYailfFwA8DHIy3acwUj4v9vUVa+SmgNsl5fuyDTKovW9/IAmfLV0Pi2UncA515kjYdrwC9i9rpuHiq3JwtAAAAABJRU5ErkJggg=="></a>
<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>
</div>
We introduce DreamGaussian4D, an efficient 4D generation framework that builds on 4D Gaussian Splatting representation.
'''
# load images in 'assets' folder as examples
image_dir = os.path.join(os.path.dirname(__file__), "assets")
examples_img = None
if os.path.exists(image_dir) and os.path.isdir(image_dir) and os.listdir(image_dir):
examples_4d = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.ply')]
examples_img = [os.path.join(image_dir, file) for file in os.listdir(image_dir) if file.endswith('.png')]
else:
examples_4d = [os.path.join(os.path.dirname(__file__), example) for example in Model4DGS().example_inputs()]
def optimize(image_block: Image.Image):
# temporarily only show tiger
return f'{os.path.join(os.path.dirname(__file__), "logs")}/tiger.glb', examples_4d
# Compose demo layout & data flow
with gr.Blocks(title=_TITLE, theme=gr.themes.Soft()) as demo:
with gr.Row():
with gr.Column(scale=1):
gr.Markdown('# ' + _TITLE)
gr.Markdown(_DESCRIPTION)
with gr.Row(variant='panel'):
left_column = gr.Column(scale=5)
with left_column:
image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Input image')
preprocess_chk = gr.Checkbox(True,
label='Preprocess image automatically (remove background and recenter object)')
with gr.Column(scale=5):
obj3d = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Final)")
obj4d = Model4DGS(label="4D Model")
with left_column:
gr.Examples(
examples=examples_img, # NOTE: elements must match inputs list!
inputs=image_block,
outputs=obj3d,
fn=optimize,
label='Examples (click one of the images below to start)',
examples_per_page=40
)
img_run_btn = gr.Button("Generate 4D")
# if there is an input image, continue with inference
# else display an error message
img_run_btn.click(check_img_input, inputs=[image_block], queue=False).success(
optimize, inputs=[image_block], outputs=[obj3d, obj4d])
if __name__ == "__main__":
demo.launch(share=True)
Model4DGS
Initialization
name | type | default | description |
---|---|---|---|
value |
|
None |
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 |
|
None |
height of the model4DGS component, in pixels. |
label |
|
None |
None |
show_label |
|
None |
None |
every |
|
None |
None |
container |
|
True |
None |
scale |
|
None |
None |
min_width |
|
160 |
None |
interactive |
|
None |
None |
visible |
|
True |
None |
elem_id |
|
None |
None |
elem_classes |
|
None |
None |
render |
|
True |
None |
Events
name | description |
---|---|
change |
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 |
This listener is triggered when the user uploads a file into the Model4DGS. |
edit |
This listener is triggered when the user edits the Model4DGS (e.g. image) using the built-in editor. |
clear |
This listener is triggered when the user clears the Model4DGS using the X button for the component. |
User function
The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
- When used as an Input, the component only impacts the input signature of the user function.
- When used as an output, the component only impacts the return signature of the user function.
The code snippet below is accurate in cases where the component is used as both an input and an output.
- As output: Is passed, the preprocessed input data sent to the user's function in the backend.
- As input: Should return, the output data received by the component from the user's function in the backend.
def predict(
value: List[str] | None
) -> List[str] | str | None:
return value