diego2554 commited on
Commit
bed615f
1 Parent(s): 7dc56ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -4,7 +4,6 @@ import cv2
4
  from rembg import new_session, remove
5
  from PIL import Image
6
  from io import BytesIO
7
- import shutil
8
 
9
  def inference(file, mask, model, alpha_influence, segmentation_strength, smoothing):
10
  im = cv2.imread(file, cv2.IMREAD_COLOR)
@@ -19,11 +18,11 @@ def inference(file, mask, model, alpha_influence, segmentation_strength, smoothi
19
  output = remove(
20
  input,
21
  only_mask=(True if mask == "Mask only" else False),
22
- alpha_matting=True,
23
- alpha_matting_foreground_threshold=alpha_influence,
24
- alpha_matting_background_threshold=1 - alpha_influence,
25
- alpha_matting_erode_size=int(segmentation_strength * 10),
26
- alpha_matting_smoothing=smoothing,
27
  session=new_session(model)
28
  )
29
 
@@ -31,14 +30,13 @@ def inference(file, mask, model, alpha_influence, segmentation_strength, smoothi
31
 
32
  return Image.open(BytesIO(output))
33
 
34
- def save_image(output_image):
35
- output_image.save("output.png", "PNG")
36
-
37
  title = "Background Using RemBG"
38
- description = "Gradio demo for RemBG. Erase the background of any image by adjusting the sliders and choosing a model from the U2net library. / <a href='https://huggingface.co/spaces/KenjieDec/RemBG' target='_blank'>Model on Hugging Face</a> / <a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a>"
 
 
39
 
40
  gr.Interface(
41
- [inference, save_image], # Lista de funciones
42
  [
43
  gr.inputs.Image(type="filepath", label="Input"),
44
  gr.inputs.Radio(
@@ -68,11 +66,11 @@ gr.Interface(
68
  gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Segmentation Strength"),
69
  gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Smoothing"),
70
  ],
71
- [
72
- gr.outputs.Image(type="PIL", label="Output"),
73
- ],
74
  title=title,
75
  description=description,
 
76
  examples=[["lion.png", "Default", "u2net", 0.5, 0.5, 0.5], ["girl.jpg", "Default", "u2net", 0.5, 0.5, 0.5], ["anime-girl.jpg", "Default", "isnet-anime", 0.5, 0.5, 0.5]],
77
  enable_queue=True
78
  ).launch()
 
4
  from rembg import new_session, remove
5
  from PIL import Image
6
  from io import BytesIO
 
7
 
8
  def inference(file, mask, model, alpha_influence, segmentation_strength, smoothing):
9
  im = cv2.imread(file, cv2.IMREAD_COLOR)
 
18
  output = remove(
19
  input,
20
  only_mask=(True if mask == "Mask only" else False),
21
+ alpha_matting=True, # Habilitar el modo alpha matting
22
+ alpha_matting_foreground_threshold=alpha_influence, # Control de influencia del canal alfa
23
+ alpha_matting_background_threshold=1 - alpha_influence, # Control del canal alfa para el fondo
24
+ alpha_matting_erode_size=int(segmentation_strength * 10), # Control de fuerza de segmentación
25
+ alpha_matting_smoothing=smoothing, # Control de suavizado de bordes de la segmentación
26
  session=new_session(model)
27
  )
28
 
 
30
 
31
  return Image.open(BytesIO(output))
32
 
 
 
 
33
  title = "Background Using RemBG"
34
+ description = "<a href='https://www.buymeacoffee.com/diego2554' target='_blank'>Help me improve my computer equipment, I need RTX 4070 :)</a>Gradio demo for RemBG. erase the background of any image, To use it, simply upload your image and adjust the sliders and choose a eraser plugin from the U2net library. / <a href='https://huggingface.co/spaces/KenjieDec/RemBG' target='_blank'>Original article made by KenjieDec</a> / <a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
35
+ article = "<p style='text-align: center;'><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
36
+ article = "<p style='text-align: center;'><a href='https://huggingface.co/spaces/KenjieDec/RemBG' target='_blank'>Model on Hugging Face</a></p>"
37
 
38
  gr.Interface(
39
+ inference,
40
  [
41
  gr.inputs.Image(type="filepath", label="Input"),
42
  gr.inputs.Radio(
 
66
  gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Segmentation Strength"),
67
  gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Smoothing"),
68
  ],
69
+ gr.outputs.Image(type="PIL", label="Output"),
70
+ #description = "<a href='https://huggingface.co/spaces/KenjieDec/RemBG' target='_blank'>Original article made by KenjieDec</a><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
 
71
  title=title,
72
  description=description,
73
+ article=article,
74
  examples=[["lion.png", "Default", "u2net", 0.5, 0.5, 0.5], ["girl.jpg", "Default", "u2net", 0.5, 0.5, 0.5], ["anime-girl.jpg", "Default", "isnet-anime", 0.5, 0.5, 0.5]],
75
  enable_queue=True
76
  ).launch()