|
|
|
|
|
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) |
|
|