Spaces:
Runtime error
Runtime error
add input image valid check
Browse files
app.py
CHANGED
@@ -61,10 +61,14 @@ This model is trained on Objaverse-LVIS (**~45K** synthetic objects) only. And n
|
|
61 |
2. Please wait until the completion of the reconstruction of the previous model before proceeding with the next one, otherwise, it may cause bug. We will fix it soon.
|
62 |
"""
|
63 |
|
64 |
-
def
|
65 |
-
if
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
68 |
|
69 |
# input_raw = Image.open(image_path)
|
70 |
input_raw.thumbnail([512, 512], Image.Resampling.LANCZOS)
|
@@ -76,7 +80,7 @@ def preprocess(input_raw, preprocess, save_path, lower_contrast=False):
|
|
76 |
# if save_path is None:
|
77 |
# save_path, ext = os.path.splitext(image_path)
|
78 |
# save_path = save_path + "_rgba.png"
|
79 |
-
image_preprocess(image_sam, save_path, lower_contrast=
|
80 |
|
81 |
# print("image save path = ", save_path)
|
82 |
return save_path
|
@@ -138,7 +142,7 @@ def launch(port):
|
|
138 |
"""
|
139 |
)
|
140 |
camera_dist_slider = gr.Slider(1.0, 4.0, value=1.9, step=0.1, label="Camera Distance")
|
141 |
-
preprocess_ckb = gr.Checkbox(value=True, label="Remove background")
|
142 |
img_run_btn = gr.Button("Reconstruction", variant="primary")
|
143 |
|
144 |
gr.Examples(
|
@@ -170,22 +174,22 @@ def launch(port):
|
|
170 |
|
171 |
trial_dir = gr.State()
|
172 |
img_run_btn.click(
|
|
|
|
|
|
|
|
|
173 |
fn=init_trial_dir,
|
174 |
outputs=[trial_dir],
|
175 |
-
concurrency_limit=1,
|
176 |
).success(
|
177 |
fn=preprocess,
|
178 |
-
inputs=[input_image,
|
179 |
outputs=[seg_image],
|
180 |
-
concurrency_limit=1,
|
181 |
).success(fn=run,
|
182 |
inputs=[seg_image, camera_dist_slider, trial_dir],
|
183 |
outputs=[output_3dgs],
|
184 |
-
concurrency_limit=1
|
185 |
).success(fn=run_video,
|
186 |
inputs=[seg_image, camera_dist_slider, trial_dir],
|
187 |
-
outputs=[output_video]
|
188 |
-
concurrency_limit=1)
|
189 |
|
190 |
launch_args = {"server_port": port}
|
191 |
demo.queue(max_size=20)
|
|
|
61 |
2. Please wait until the completion of the reconstruction of the previous model before proceeding with the next one, otherwise, it may cause bug. We will fix it soon.
|
62 |
"""
|
63 |
|
64 |
+
def assert_input_image(input_image):
|
65 |
+
if input_image is None:
|
66 |
+
raise gr.Error("No image selected or uploaded!")
|
67 |
+
|
68 |
+
def preprocess(input_raw, save_path):
|
69 |
+
# if not preprocess:
|
70 |
+
# print("No preprocess")
|
71 |
+
# # return image_path
|
72 |
|
73 |
# input_raw = Image.open(image_path)
|
74 |
input_raw.thumbnail([512, 512], Image.Resampling.LANCZOS)
|
|
|
80 |
# if save_path is None:
|
81 |
# save_path, ext = os.path.splitext(image_path)
|
82 |
# save_path = save_path + "_rgba.png"
|
83 |
+
image_preprocess(image_sam, save_path, lower_contrast=False, rescale=True)
|
84 |
|
85 |
# print("image save path = ", save_path)
|
86 |
return save_path
|
|
|
142 |
"""
|
143 |
)
|
144 |
camera_dist_slider = gr.Slider(1.0, 4.0, value=1.9, step=0.1, label="Camera Distance")
|
145 |
+
# preprocess_ckb = gr.Checkbox(value=True, label="Remove background")
|
146 |
img_run_btn = gr.Button("Reconstruction", variant="primary")
|
147 |
|
148 |
gr.Examples(
|
|
|
174 |
|
175 |
trial_dir = gr.State()
|
176 |
img_run_btn.click(
|
177 |
+
fn=assert_input_image,
|
178 |
+
inputs=[input_image],
|
179 |
+
queue=False
|
180 |
+
).success(
|
181 |
fn=init_trial_dir,
|
182 |
outputs=[trial_dir],
|
|
|
183 |
).success(
|
184 |
fn=preprocess,
|
185 |
+
inputs=[input_image, trial_dir],
|
186 |
outputs=[seg_image],
|
|
|
187 |
).success(fn=run,
|
188 |
inputs=[seg_image, camera_dist_slider, trial_dir],
|
189 |
outputs=[output_3dgs],
|
|
|
190 |
).success(fn=run_video,
|
191 |
inputs=[seg_image, camera_dist_slider, trial_dir],
|
192 |
+
outputs=[output_video])
|
|
|
193 |
|
194 |
launch_args = {"server_port": port}
|
195 |
demo.queue(max_size=20)
|