diego2554 commited on
Commit
e332358
1 Parent(s): 810e24f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -31
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  import os
3
  import cv2
4
- import numpy as np
5
 
6
  def inference(file, mask, model, alpha_influence, segmentation_strength):
7
  im = cv2.imread(file, cv2.IMREAD_COLOR)
@@ -11,37 +10,26 @@ def inference(file, mask, model, alpha_influence, segmentation_strength):
11
 
12
  input_path = 'input.png'
13
  output_path = 'output.png'
14
- mask_path = 'mask.png'
15
 
16
  with open(input_path, 'rb') as i:
17
  with open(output_path, 'wb') as o:
18
- with open(mask_path, 'wb') as m:
19
- input = i.read()
20
- output = remove(
21
- input,
22
- session=new_session(model),
23
- only_mask=(True if mask == "Mask only" else False),
24
- alpha=alpha_influence, # Control de influencia del canal alfa
25
- bg_color=(0, 0, 0, segmentation_strength) # Control de fuerza de segmentación
26
- )
27
- o.write(output)
28
- m.write(output)
29
 
30
- return os.path.join("output.png"), os.path.join("mask.png")
 
31
 
32
  title = "RemBG"
33
  description = "Gradio demo for RemBG. To use it, simply upload your image and adjust the alpha influence and segmentation strength."
34
  article = "<p style='text-align: center;'><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
35
 
36
- def show_processed_image(output_image_path):
37
- output_image = cv2.imread(output_image_path)
38
- return output_image
39
-
40
- def show_processed_mask(mask_image_path):
41
- mask_image = cv2.imread(mask_image_path)
42
- return mask_image
43
-
44
- iface = gr.Interface(
45
  inference,
46
  [
47
  gr.inputs.Image(type="filepath", label="Input"),
@@ -71,17 +59,11 @@ iface = gr.Interface(
71
  gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Alpha Influence"),
72
  gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Segmentation Strength"),
73
  ],
74
- [
75
- gr.outputs.Image(type="plot", label="Processed Image"),
76
- gr.outputs.Image(type="plot", label="Processed Mask"),
77
- ],
78
  title=title,
79
  description=description,
80
  article=article,
81
  examples=[["lion.png", "Default", "u2net", 0.5, 0.5], ["girl.jpg", "Default", "u2net", 0.5, 0.5], ["anime-girl.jpg", "Default", "isnet-anime", 0.5, 0.5]],
82
  enable_queue=True
83
- )
84
-
85
- iface.launch()
86
-
87
 
 
1
  import gradio as gr
2
  import os
3
  import cv2
 
4
 
5
  def inference(file, mask, model, alpha_influence, segmentation_strength):
6
  im = cv2.imread(file, cv2.IMREAD_COLOR)
 
10
 
11
  input_path = 'input.png'
12
  output_path = 'output.png'
 
13
 
14
  with open(input_path, 'rb') as i:
15
  with open(output_path, 'wb') as o:
16
+ input = i.read()
17
+ output = remove(
18
+ input,
19
+ session=new_session(model),
20
+ only_mask=(True if mask == "Mask only" else False),
21
+ alpha=alpha_influence, # Control de influencia del canal alfa
22
+ bg_color=(0, 0, 0, segmentation_strength) # Control de fuerza de segmentación
23
+ )
 
 
 
24
 
25
+ o.write(output)
26
+ return os.path.join("output.png")
27
 
28
  title = "RemBG"
29
  description = "Gradio demo for RemBG. To use it, simply upload your image and adjust the alpha influence and segmentation strength."
30
  article = "<p style='text-align: center;'><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
31
 
32
+ gr.Interface(
 
 
 
 
 
 
 
 
33
  inference,
34
  [
35
  gr.inputs.Image(type="filepath", label="Input"),
 
59
  gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Alpha Influence"),
60
  gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Segmentation Strength"),
61
  ],
62
+ gr.outputs.Image(type="filepath", label="Output"),
 
 
 
63
  title=title,
64
  description=description,
65
  article=article,
66
  examples=[["lion.png", "Default", "u2net", 0.5, 0.5], ["girl.jpg", "Default", "u2net", 0.5, 0.5], ["anime-girl.jpg", "Default", "isnet-anime", 0.5, 0.5]],
67
  enable_queue=True
68
+ ).launch()
 
 
 
69