ihabooe commited on
Commit
b36c965
·
verified ·
1 Parent(s): 3399fa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -20
app.py CHANGED
@@ -23,8 +23,9 @@ def resize_image(image):
23
  image = image.resize(model_input_size, Image.BILINEAR)
24
  return image
25
 
26
- # Background removal process
27
- def process(image):
 
28
  # Prepare the input
29
  orig_image = Image.fromarray(image)
30
  w, h = orig_im_size = orig_image.size
@@ -41,6 +42,8 @@ def process(image):
41
  # Inference with the model
42
  result = net(im_tensor)
43
 
 
 
44
  # Post-process the result
45
  result = torch.squeeze(F.interpolate(result[0][0], size=(h, w), mode='bilinear'), 0)
46
  ma = torch.max(result)
@@ -60,7 +63,8 @@ def process(image):
60
  new_im.save(temp_file, format='PNG')
61
  temp_file.close() # Ensure the file is closed before Gradio uses it
62
 
63
- return temp_file.name # Return the path to the temporary file for downloading
 
64
 
65
  # Gradio interface setup
66
  gr.Markdown("## BRIA RMBG 1.4")
@@ -71,20 +75,4 @@ gr.HTML('''<p style="margin-bottom: 10px; font-size: 94%">
71
 
72
  title = "Background Removal"
73
  description = r"""Background removal model developed by <a href='https://BRIA.AI' target='_blank'><b>BRIA.AI</b></a>, trained on a carefully selected dataset and is available as an open-source model for non-commercial use.<br>
74
- For testing, 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>"""
75
-
76
- examples = [['./input.jpg'],]
77
-
78
- # Modify the interface to use live updates and file download
79
- demo = gr.Interface(
80
- fn=process, # The function to process the image
81
- inputs=gr.Image(type="numpy"), # Input type (image)
82
- outputs=gr.File(label="Download Processed Image"), # Output as a file (download button)
83
- examples=examples, # Example images for users to try
84
- title=title, # Title of the app
85
- description=description, # Description of the app
86
- live=True # Automatically processes when an image is uploaded
87
- )
88
-
89
- if __name__ == "__main__":
90
- demo.launch(share=False)
 
23
  image = image.resize(model_input_size, Image.BILINEAR)
24
  return image
25
 
26
+ # Background removal process with progress bar
27
+ def process(image, progress=gr.Progress()):
28
+ progress(0.1) # Start with 10% for loading
29
  # Prepare the input
30
  orig_image = Image.fromarray(image)
31
  w, h = orig_im_size = orig_image.size
 
42
  # Inference with the model
43
  result = net(im_tensor)
44
 
45
+ progress(0.5) # Progress 50% during inference
46
+
47
  # Post-process the result
48
  result = torch.squeeze(F.interpolate(result[0][0], size=(h, w), mode='bilinear'), 0)
49
  ma = torch.max(result)
 
63
  new_im.save(temp_file, format='PNG')
64
  temp_file.close() # Ensure the file is closed before Gradio uses it
65
 
66
+ progress(1.0) # Completion of the process
67
+ return orig_image, new_im, temp_file.name # Return both the original and processed images for display
68
 
69
  # Gradio interface setup
70
  gr.Markdown("## BRIA RMBG 1.4")
 
75
 
76
  title = "Background Removal"
77
  description = r"""Background removal model developed by <a href='https://BRIA.AI' target='_blank'><b>BRIA.AI</b></a>, trained on a carefully selected dataset and is available as an open-source model for non-commercial use.<br>
78
+ For testing, 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 li