tryitonvirtual commited on
Commit
29d5141
·
verified ·
1 Parent(s): 493ed7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -14
app.py CHANGED
@@ -1,21 +1,11 @@
1
  import gradio as gr
2
  from PIL import Image
3
- from transformers import pipeline
4
-
5
- pipe = pipeline("image-segmentation", model="briaai/RMBG-2.0", trust_remote_code=True)
6
 
7
  def remove_background(image):
8
- result = pipe(image)
9
- if isinstance(result, list):
10
- result = result[0]
11
- output = result.get("image") or result.get("mask")
12
- if output is None:
13
- return image
14
- rgba = image.convert("RGBA")
15
- mask = output.convert("L").resize(rgba.size)
16
- rgba.putalpha(mask)
17
- white_bg = Image.new("RGBA", rgba.size, (255, 255, 255, 255))
18
- white_bg.paste(rgba, mask=mask)
19
  return white_bg.convert("RGB")
20
 
21
  demo = gr.Interface(
 
1
  import gradio as gr
2
  from PIL import Image
3
+ from rembg import remove
 
 
4
 
5
  def remove_background(image):
6
+ output = remove(image)
7
+ white_bg = Image.new("RGBA", output.size, (255, 255, 255, 255))
8
+ white_bg.paste(output, mask=output.split()[3])
 
 
 
 
 
 
 
 
9
  return white_bg.convert("RGB")
10
 
11
  demo = gr.Interface(