File size: 966 Bytes
3fd27c0 b15d723 3fd27c0 b15d723 3fd27c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#!/usr/bin/env python
import gradio as gr
import PIL.Image
import rembg
DESCRIPTION = "# rembg - Image background removal"
def remove_background(image: PIL.Image.Image) -> tuple[PIL.Image.Image, PIL.Image.Image]:
"""Remove background from image using `rembg`.
Args:
image: The image to remove the background from.
Returns:
A tuple containing the image with the background removed and the original image.
"""
return rembg.remove(image), image
with gr.Blocks(css_paths="style.css") as demo:
gr.Markdown(DESCRIPTION)
with gr.Row():
with gr.Column():
image = gr.Image(type="pil")
run_button = gr.Button()
with gr.Column():
out = gr.ImageSlider()
gr.Examples(examples=["cats.jpg"], fn=remove_background, inputs=image, outputs=out)
run_button.click(fn=remove_background, inputs=image, outputs=out)
if __name__ == "__main__":
demo.launch(mcp_server=True)
|