diego2554 commited on
Commit
3eecd07
1 Parent(s): 1547d0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -15
app.py CHANGED
@@ -10,26 +10,37 @@ def inference(file, mask, model, alpha_influence, segmentation_strength):
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_Super"
29
- description = "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."
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,10 +70,15 @@ gr.Interface(
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()
 
 
 
10
 
11
  input_path = 'input.png'
12
  output_path = 'output.png'
13
+ mask_path = 'mask.png'
14
 
15
  with open(input_path, 'rb') as i:
16
  with open(output_path, 'wb') as o:
17
+ with open(mask_path, 'wb') as m:
18
+ input = i.read()
19
+ output = remove(
20
+ input,
21
+ session=new_session(model),
22
+ only_mask=(True if mask == "Mask only" else False),
23
+ alpha=alpha_influence,
24
+ bg_color=(0, 0, 0, segmentation_strength)
25
+ )
26
+ o.write(output)
27
+ m.write(output)
28
 
29
+ return os.path.join("output.png"), os.path.join("mask.png")
 
30
 
31
+ title = "RemBG"
32
+ description = "Gradio demo for RemBG. 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
+ def show_processed_image(output_image_path):
36
+ output_image = cv2.imread(output_image_path)
37
+ return output_image
38
+
39
+ def show_processed_mask(mask_image_path):
40
+ mask_image = cv2.imread(mask_image_path)
41
+ return mask_image
42
+
43
+ iface = gr.Interface(
44
  inference,
45
  [
46
  gr.inputs.Image(type="filepath", label="Input"),
 
70
  gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Alpha Influence"),
71
  gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Segmentation Strength"),
72
  ],
73
+ [
74
+ gr.outputs.Image(type="plot", label="Processed Image"),
75
+ gr.outputs.Image(type="plot", label="Processed Mask"),
76
+ ],
77
  title=title,
78
  description=description,
79
  article=article,
80
  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]],
81
  enable_queue=True
82
+ )
83
+
84
+ iface.launch()