diego2554 commited on
Commit
99c661e
1 Parent(s): a3b85f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -1,8 +1,7 @@
1
  import gradio as gr
2
  import os
3
  import cv2
4
- from rembg import new_session, remove
5
- from RemBG_super/rembg/bg import remove as bg_remove # Importa la función 'remove' desde bg.py
6
 
7
  def inference(file, mask, model, alpha_influence, segmentation_strength):
8
  im = cv2.imread(file, cv2.IMREAD_COLOR)
@@ -14,22 +13,19 @@ def inference(file, mask, model, alpha_influence, segmentation_strength):
14
  with open(input_path, 'rb') as i:
15
  with open(output_path, 'wb') as o:
16
  input = i.read()
17
- if mask == "Mask only":
18
- output = bg_remove(input, only_mask=True)
19
- else:
20
- session = new_session(model)
21
- output = remove(
22
- input,
23
- session=session,
24
- alpha_influence=alpha_influence,
25
- bg_color=(0, 0, 0, segmentation_strength)
26
- )
27
 
28
  o.write(output)
29
  return os.path.join("output.png")
30
 
31
- title = "RemBG with bg.py"
32
- description = "Gradio demo for RemBG using bg.py. To use it, simply upload your image and adjust the alpha influence and segmentation strength."
33
  article = "<p style='text-align: center;'><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
34
 
35
  gr.Interface(
 
1
  import gradio as gr
2
  import os
3
  import cv2
4
+ from bg import remove
 
5
 
6
  def inference(file, mask, model, alpha_influence, segmentation_strength):
7
  im = cv2.imread(file, cv2.IMREAD_COLOR)
 
13
  with open(input_path, 'rb') as i:
14
  with open(output_path, 'wb') as o:
15
  input = i.read()
16
+ output = remove(
17
+ input,
18
+ session=new_session(model),
19
+ only_mask=(True if mask == "Mask only" else False),
20
+ alpha=alpha_influence,
21
+ bg_color=(0, 0, 0, segmentation_strength)
22
+ )
 
 
 
23
 
24
  o.write(output)
25
  return os.path.join("output.png")
26
 
27
+ title = "RemBG"
28
+ description = "Gradio demo for RemBG. To use it, simply upload your image and adjust the alpha influence and segmentation strength."
29
  article = "<p style='text-align: center;'><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
30
 
31
  gr.Interface(