Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from rembg import remove
|
3 |
+
from PIL import Image
|
4 |
+
import io
|
5 |
+
|
6 |
+
def background_remover(input_image):
|
7 |
+
input_bytes = input_image.read()
|
8 |
+
input_img = Image.open(io.BytesIO(input_bytes))
|
9 |
+
output_img = remove(input_img)
|
10 |
+
|
11 |
+
buf = io.BytesIO()
|
12 |
+
output_img.save(buf, format='PNG')
|
13 |
+
buf.seek(0)
|
14 |
+
return buf
|
15 |
+
|
16 |
+
description = """
|
17 |
+
This app uses the rembg library to remove the background from uploaded images.
|
18 |
+
Simply upload your image and let the model do its work. Download the result immediately after!
|
19 |
+
"""
|
20 |
+
|
21 |
+
with gr.Blocks() as demo:
|
22 |
+
gr.Markdown("<h1 style='text-align: center;'>Background Remover</h1>")
|
23 |
+
gr.Markdown(description)
|
24 |
+
|
25 |
+
with gr.Row():
|
26 |
+
with gr.Column(scale=1):
|
27 |
+
input_image = gr.Image(type='file', label="Upload Image")
|
28 |
+
with gr.Column(scale=1):
|
29 |
+
output_image = gr.Image(type='pil', label="Result")
|
30 |
+
|
31 |
+
with gr.Row():
|
32 |
+
gr.Button("Remove Background").click(
|
33 |
+
fn=background_remover,
|
34 |
+
inputs=input_image,
|
35 |
+
outputs=output_image
|
36 |
+
)
|
37 |
+
|
38 |
+
demo_examples = [["woman.jpg"], ["groot.jpg"]]
|
39 |
+
demo.launch(share=True, examples=demo_examples, theme="soft")
|