OriLib commited on
Commit
da78fee
·
verified ·
1 Parent(s): d5e41f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -34
app.py CHANGED
@@ -45,42 +45,15 @@ def process(image):
45
  mi = torch.min(result)
46
  result = (result-mi)/(ma-mi)
47
  # image to pil
48
- im_array = (result*255).cpu().data.numpy().astype(np.uint8)
49
- pil_im = Image.fromarray(np.squeeze(im_array))
50
- # paste the mask on the original image
51
- new_im = Image.new("RGBA", pil_im.size, (0,0,0,0))
52
- new_im.paste(orig_image, mask=pil_im)
53
- # new_orig_image = orig_image.convert('RGBA')
54
-
55
  return new_im
56
  # return [new_orig_image, new_im]
57
 
58
 
59
- # block = gr.Blocks().queue()
60
-
61
- # with block:
62
- # gr.Markdown("## BRIA RMBG 1.4")
63
- # gr.HTML('''
64
- # <p style="margin-bottom: 10px; font-size: 94%">
65
- # This is a demo for BRIA RMBG 1.4 that using
66
- # <a href="https://huggingface.co/briaai/RMBG-1.4" target="_blank">BRIA RMBG-1.4 image matting model</a> as backbone.
67
- # </p>
68
- # ''')
69
- # with gr.Row():
70
- # with gr.Column():
71
- # input_image = gr.Image(sources=None, type="pil") # None for upload, ctrl+v and webcam
72
- # # input_image = gr.Image(sources=None, type="numpy") # None for upload, ctrl+v and webcam
73
- # run_button = gr.Button(value="Run")
74
-
75
- # with gr.Column():
76
- # result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", columns=[1], height='auto')
77
- # ips = [input_image]
78
- # run_button.click(fn=process, inputs=ips, outputs=[result_gallery])
79
-
80
- # block.launch(debug = True)
81
-
82
- # block = gr.Blocks().queue()
83
-
84
  gr.Markdown("## BRIA RMBG 1.4")
85
  gr.HTML('''
86
  <p style="margin-bottom: 10px; font-size: 94%">
@@ -93,8 +66,6 @@ description = r"""Background removal model developed by <a href='https://BRIA.AI
93
  For test upload your image and wait. Read more at model card <a href='https://huggingface.co/briaai/RMBG-1.4' target='_blank'><b>briaai/RMBG-1.4</b></a>. To purchase a commercial license, simply click <a href='https://go.bria.ai/3ZCBTLH' target='_blank'><b>Here</b></a>. <br>
94
  """
95
  examples = [['./input.jpg'],]
96
- # output = ImageSlider(position=0.5,label='Image without background', type="pil", show_download_button=True)
97
- # demo = gr.Interface(fn=process,inputs="image", outputs=output, examples=examples, title=title, description=description)
98
  demo = gr.Interface(fn=process,inputs="image", outputs="image", examples=examples, title=title, description=description)
99
 
100
  if __name__ == "__main__":
 
45
  mi = torch.min(result)
46
  result = (result-mi)/(ma-mi)
47
  # image to pil
48
+ result_array = (result*255).cpu().data.numpy().astype(np.uint8)
49
+ pil_mask = Image.fromarray(np.squeeze(result_array))
50
+ # add the mask on the original image as alpha channel
51
+ new_im = orig_image.copy()
52
+ new_im.putalpha(pil_mask)
 
 
53
  return new_im
54
  # return [new_orig_image, new_im]
55
 
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  gr.Markdown("## BRIA RMBG 1.4")
58
  gr.HTML('''
59
  <p style="margin-bottom: 10px; font-size: 94%">
 
66
  For test upload your image and wait. Read more at model card <a href='https://huggingface.co/briaai/RMBG-1.4' target='_blank'><b>briaai/RMBG-1.4</b></a>. To purchase a commercial license, simply click <a href='https://go.bria.ai/3ZCBTLH' target='_blank'><b>Here</b></a>. <br>
67
  """
68
  examples = [['./input.jpg'],]
 
 
69
  demo = gr.Interface(fn=process,inputs="image", outputs="image", examples=examples, title=title, description=description)
70
 
71
  if __name__ == "__main__":