Spaces:
Runtime error
Runtime error
chore: Refactor preprocess function to always remove background and resize foreground image
Browse files
app.py
CHANGED
@@ -55,12 +55,11 @@ def check_input_image(input_image):
|
|
55 |
raise gr.Error("No image selected!")
|
56 |
|
57 |
|
58 |
-
def preprocess(input_image
|
59 |
-
rembg_session = rembg.new_session()
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
input_image = resize_foreground(input_image, 0.85)
|
64 |
|
65 |
return input_image
|
66 |
|
@@ -215,13 +214,9 @@ with gr.Blocks() as demo:
|
|
215 |
type="pil",
|
216 |
interactive=False
|
217 |
)
|
218 |
-
with gr.Row():
|
219 |
-
with gr.Group():
|
220 |
-
do_remove_background = gr.Checkbox(
|
221 |
-
label="Remove Background", value=True)
|
222 |
with gr.Row():
|
223 |
submit_process = gr.Button(
|
224 |
-
"
|
225 |
with gr.Row(variant="panel"):
|
226 |
gr.Examples(
|
227 |
examples=[os.path.join("examples", img_name) for img_name in sorted(
|
@@ -273,11 +268,10 @@ with gr.Blocks() as demo:
|
|
273 |
mv_images = gr.State()
|
274 |
|
275 |
submit_prompt.click(fn=generate_image, inputs=[prompt], outputs=input_image).success(
|
276 |
-
fn=preprocess, inputs=[input_image
|
277 |
)
|
278 |
submit_process.click(fn=check_input_image, inputs=[input_image]).success(
|
279 |
-
fn=preprocess, inputs=[input_image,
|
280 |
-
do_remove_background], outputs=[processed_image],
|
281 |
)
|
282 |
submit_mesh.click(fn=generate_mvs, inputs=[processed_image, sample_steps, sample_seed], outputs=[mv_images, mv_show_images]).success(
|
283 |
fn=make3d, inputs=[mv_images], outputs=[
|
|
|
55 |
raise gr.Error("No image selected!")
|
56 |
|
57 |
|
58 |
+
def preprocess(input_image):
|
59 |
+
rembg_session = rembg.new_session()
|
60 |
|
61 |
+
input_image = remove_background(input_image, rembg_session)
|
62 |
+
input_image = resize_foreground(input_image, 0.85)
|
|
|
63 |
|
64 |
return input_image
|
65 |
|
|
|
214 |
type="pil",
|
215 |
interactive=False
|
216 |
)
|
|
|
|
|
|
|
|
|
217 |
with gr.Row():
|
218 |
submit_process = gr.Button(
|
219 |
+
"Remove Background", elem_id="process", variant="primary")
|
220 |
with gr.Row(variant="panel"):
|
221 |
gr.Examples(
|
222 |
examples=[os.path.join("examples", img_name) for img_name in sorted(
|
|
|
268 |
mv_images = gr.State()
|
269 |
|
270 |
submit_prompt.click(fn=generate_image, inputs=[prompt], outputs=input_image).success(
|
271 |
+
fn=preprocess, inputs=[input_image], outputs=[processed_image]
|
272 |
)
|
273 |
submit_process.click(fn=check_input_image, inputs=[input_image]).success(
|
274 |
+
fn=preprocess, inputs=[input_image], outputs=[processed_image],
|
|
|
275 |
)
|
276 |
submit_mesh.click(fn=generate_mvs, inputs=[processed_image, sample_steps, sample_seed], outputs=[mv_images, mv_show_images]).success(
|
277 |
fn=make3d, inputs=[mv_images], outputs=[
|