Spaces:
Running
Running
Update app.py
Browse files44 unmodified lines4546474849505152535455565758596061626364656667686970717273747576777879808182838485866 unmodified lines9394959697989910044 unmodified linesmi = torch.min(result)result = (result-mi)/(ma-mi)# image to pilim_array = (result*255).cpu().data.numpy().astype(np.uint8)pil_im = Image.fromarray(np.squeeze(im_array))# paste the mask on the original imagenew_im = Image.new("RGBA", pil_im.size, (0,0,0,0))new_im.paste(orig_image, mask=pil_im)# new_orig_image = orig_image.convert('RGBA')return new_im# return [new_orig_image, new_im]# block = gr.Blocks().queue()# with block:# gr.Markdown("## BRIA RMBG 1.4")# gr.HTML('''# <p style="margin-bottom: 10px; font-size: 94%"># This is a demo for BRIA RMBG 1.4 that using# <a href="https://huggingface.co/briaai/RMBG-1.4" target="_blank">BRIA RMBG-1.4 image matting model</a> as backbone.# </p># ''')# with gr.Row():# with gr.Column():# input_image = gr.Image(sources=None, type="pil") # None for upload, ctrl+v and webcam# # input_image = gr.Image(sources=None, type="numpy") # None for upload, ctrl+v and webcam# run_button = gr.Button(value="Run")# with gr.Column():# result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", columns=[1], height='auto')# ips = [input_image]# run_button.click(fn=process, inputs=ips, outputs=[result_gallery])# block.launch(debug = True)# block = gr.Blocks().queue()gr.Markdown("## BRIA RMBG 1.4")gr.HTML('''<p style="margin-bottom: 10px; font-size: 94%">6 unmodified linesFor 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>"""examples = [['./input.jpg'],]# output = ImageSlider(position=0.5,label='Image without background', type="pil", show_download_button=True)# demo = gr.Interface(fn=process,inputs="image", outputs=output, examples=examples, title=title, description=description)demo = gr.Interface(fn=process,inputs="image", outputs="image", examples=examples, title=title, description=description)if __name__ == "__main__":44 unmodified lines4546474849505152535455565758596 unmodified lines66676869707144 unmodified linesmi = torch.min(result)result = (result-mi)/(ma-mi)# image to pilresult_array = (result*255).cpu().data.numpy().astype(np.uint8)pil_mask = Image.fromarray(np.squeeze(result_array))# add the mask on the original image as alpha channelnew_im = orig_image.copy()new_im.putalpha(pil_mask)return new_im# return [new_orig_image, new_im]gr.Markdown("## BRIA RMBG 1.4")gr.HTML('''<p style="margin-bottom: 10px; font-size: 94%">6 unmodified linesFor 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>"""examples = [['./input.jpg'],]demo = gr.Interface(fn=process,inputs="image", outputs="image", examples=examples, title=title, description=description)if __name__ == "__main__":
app.py+5-34