Spaces:
Runtime error
Runtime error
jiawi-ren
commited on
Commit
•
285fe22
1
Parent(s):
12d905b
add duplicate, fix cache
Browse files
app.py
CHANGED
@@ -11,6 +11,10 @@ def check_img_input(control_image):
|
|
11 |
if control_image is None:
|
12 |
raise gr.Error("Please select or upload an input image")
|
13 |
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def optimize_stage_1(image_block: Image.Image, preprocess_chk: bool, elevation_slider: float):
|
16 |
if not os.path.exists('tmp_data'):
|
@@ -52,6 +56,10 @@ if __name__ == "__main__":
|
|
52 |
</div>
|
53 |
We present DreamGausssion, a 3D content generation framework that significantly improves the efficiency of 3D content creation.
|
54 |
'''
|
|
|
|
|
|
|
|
|
55 |
_IMG_USER_GUIDE = "Please upload an image in the block above (or choose an example above) and click **Generate 3D**."
|
56 |
|
57 |
# load images in 'data' folder as examples
|
@@ -65,14 +73,14 @@ if __name__ == "__main__":
|
|
65 |
with gr.Row():
|
66 |
with gr.Column(scale=1):
|
67 |
gr.Markdown('# ' + _TITLE)
|
68 |
-
|
69 |
-
|
70 |
-
# elem_id='duplicate-button')
|
71 |
gr.Markdown(_DESCRIPTION)
|
72 |
|
73 |
# Image-to-3D
|
74 |
with gr.Row(variant='panel'):
|
75 |
-
|
|
|
76 |
image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Input image', tool=None)
|
77 |
|
78 |
elevation_slider = gr.Slider(-90, 90, value=0, step=1, label='Estimated elevation angle')
|
@@ -82,21 +90,25 @@ if __name__ == "__main__":
|
|
82 |
preprocess_chk = gr.Checkbox(True,
|
83 |
label='Preprocess image automatically (remove background and recenter object)')
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
gr.Examples(
|
86 |
examples=examples_full, # NOTE: elements must match inputs list!
|
87 |
inputs=[image_block],
|
88 |
-
outputs=[
|
89 |
-
|
|
|
90 |
label='Examples (click one of the images below to start)',
|
91 |
examples_per_page=40
|
92 |
)
|
93 |
img_run_btn = gr.Button("Generate 3D")
|
94 |
img_guide_text = gr.Markdown(_IMG_USER_GUIDE, visible=True)
|
95 |
|
96 |
-
with gr.Column(scale=5):
|
97 |
-
obj3d_stage1 = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Stage 1)")
|
98 |
-
obj3d = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Final)")
|
99 |
-
|
100 |
# if there is an input image, continue with inference
|
101 |
# else display an error message
|
102 |
img_run_btn.click(check_img_input, inputs=[image_block], queue=False).success(optimize_stage_1,
|
|
|
11 |
if control_image is None:
|
12 |
raise gr.Error("Please select or upload an input image")
|
13 |
|
14 |
+
def optimize(image_block: Image.Image, preprocess_chk=True, elevation_slider=0):
|
15 |
+
stage_1_output = optimize_stage_1(image_block, preprocess_chk, elevation_slider)
|
16 |
+
stage_2_output = optimize_stage_2(elevation_slider)
|
17 |
+
return stage_1_output, stage_2_output
|
18 |
|
19 |
def optimize_stage_1(image_block: Image.Image, preprocess_chk: bool, elevation_slider: float):
|
20 |
if not os.path.exists('tmp_data'):
|
|
|
56 |
</div>
|
57 |
We present DreamGausssion, a 3D content generation framework that significantly improves the efficiency of 3D content creation.
|
58 |
'''
|
59 |
+
|
60 |
+
_DUPLICATE ='''
|
61 |
+
[![Duplicate this Space](https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-md.svg)](https://huggingface.co/spaces/jiawei011/dreamgaussian?duplicate=true)
|
62 |
+
'''
|
63 |
_IMG_USER_GUIDE = "Please upload an image in the block above (or choose an example above) and click **Generate 3D**."
|
64 |
|
65 |
# load images in 'data' folder as examples
|
|
|
73 |
with gr.Row():
|
74 |
with gr.Column(scale=1):
|
75 |
gr.Markdown('# ' + _TITLE)
|
76 |
+
with gr.Column(scale=0):
|
77 |
+
gr.Markdown(_DUPLICATE)
|
|
|
78 |
gr.Markdown(_DESCRIPTION)
|
79 |
|
80 |
# Image-to-3D
|
81 |
with gr.Row(variant='panel'):
|
82 |
+
left_column = gr.Column(scale=5)
|
83 |
+
with left_column:
|
84 |
image_block = gr.Image(type='pil', image_mode='RGBA', height=290, label='Input image', tool=None)
|
85 |
|
86 |
elevation_slider = gr.Slider(-90, 90, value=0, step=1, label='Estimated elevation angle')
|
|
|
90 |
preprocess_chk = gr.Checkbox(True,
|
91 |
label='Preprocess image automatically (remove background and recenter object)')
|
92 |
|
93 |
+
|
94 |
+
|
95 |
+
with gr.Column(scale=5):
|
96 |
+
obj3d_stage1 = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Stage 1)")
|
97 |
+
obj3d = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model (Final)")
|
98 |
+
|
99 |
+
with left_column:
|
100 |
gr.Examples(
|
101 |
examples=examples_full, # NOTE: elements must match inputs list!
|
102 |
inputs=[image_block],
|
103 |
+
outputs=[obj3d_stage1, obj3d],
|
104 |
+
fn=optimize,
|
105 |
+
cache_examples=True,
|
106 |
label='Examples (click one of the images below to start)',
|
107 |
examples_per_page=40
|
108 |
)
|
109 |
img_run_btn = gr.Button("Generate 3D")
|
110 |
img_guide_text = gr.Markdown(_IMG_USER_GUIDE, visible=True)
|
111 |
|
|
|
|
|
|
|
|
|
112 |
# if there is an input image, continue with inference
|
113 |
# else display an error message
|
114 |
img_run_btn.click(check_img_input, inputs=[image_block], queue=False).success(optimize_stage_1,
|