import gradio as gr import argparse import os, sys import torch def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser() parser.add_argument('--device', type=str, default='cpu') parser.add_argument('--theme', type=str) parser.add_argument('--live', action='store_true') parser.add_argument('--share', action='store_true') parser.add_argument('--port', type=int) parser.add_argument('--disable-queue', dest='enable_queue', action='store_false') parser.add_argument('--allow-flagging', type=str, default='never') parser.add_argument('--allow-screenshot', action='store_true') return parser.parse_args() _TITLE = '''DreamGaussian: Generative Gaussian Splatting for Efficient 3D Content Creation''' _DESCRIPTION = '''
We present DreamGausssion, a 3D content generation framework that significantly improves the efficiency of 3D content creation. ''' _IMG_USER_GUIDE = "Please upload an image in the block above (or choose an example above) and click **Run Generation**." _TXT_USER_GUIDE = "Please type what you want to generate in the block above and click **Run Generation**." # trigger Image-to-3D model def inference_img(img): pass # trigger Text-to-3D model def inference_txt(txt): pass def run_demo(): args = parse_args() args.device = 'cuda' if torch.cuda.is_available() else 'cpu' print('*** Now using %s.'%(args.device)) # append README as extra info with open('README.md', 'r') as f: article = f.read() # NOTE: Examples must match inputs example_folder = os.path.join(os.path.dirname(__file__), 'demo_examples') example_fns = os.listdir(example_folder) example_fns.sort() examples_full = [os.path.join(example_folder, x) for x in example_fns if x.endswith('.png')] # Compose demo layout & data flow with gr.Blocks(title=_TITLE, css="style.css") as demo: with gr.Row(): with gr.Column(scale=1): gr.Markdown('# ' + _TITLE) with gr.Column(scale=0): gr.DuplicateButton(value='Duplicate Space for private use', elem_id='duplicate-button') gr.Markdown(_DESCRIPTION) # Image-to-3D with gr.Row(variant='panel'): with gr.Column(scale=6): image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Input image', tool=None) elevation_slider = gr.Slider(-90, 90, value=0, step=1, label='Estimated elevation angle') gr.Markdown("default to 0 (horizontal), range from [-90, 90]. If you upload a look-down image, try a value like -30") preprocess_chk = gr.Checkbox(True, label='Preprocess image automatically (remove background and recenter object)') gr.Examples( examples=examples_full, # NOTE: elements must match inputs list! inputs=[image_block], outputs=[image_block], cache_examples=False, label='Examples (click one of the images below to start)', examples_per_page=40 ) img_run_btn = gr.Button('Run Generation', variant='primary', interactive=False) img_guide_text = gr.Markdown(_IMG_USER_GUIDE, visible=True) with gr.Column(scale=4): processed_image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Processed image', tool=None) img_mesh_output = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="Textured Mesh", elem_id="img-model-3d-out") # Text-to-3D with gr.Row(variant='panel'): with gr.Column(scale=6): text_block = gr.Textbox(label="Input text") txt_run_btn = gr.Button('Run Generation', variant='primary', interactive=False) txt_guide_text = gr.Markdown(_TXT_USER_GUIDE, visible=True) with gr.Column(scale=4): txt_mesh_output = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="Textured Mesh", elem_id="txt-model-3d-out") gr.Markdown(article) gr.HTML(""" """) demo.queue().launch(share=True, max_threads=80) # auth=("admin", os.environ['PASSWD']) if __name__ == '__main__': run_demo()