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 = '''
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)